geoclue_master.c 7.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* Geomap - A DBus api and wrapper for getting geography pictures
 * Copyright (C) 2006 Garmin
 * 
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2 as published by the Free Software Foundation; 
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include <geoclue_master.h>
#include <geoclue_master_server_glue.h>
//#include <geoclue_map_signal_marshal.h>
#include <dbus/dbus-glib-bindings.h>

24

25
//#include <geoclue_map_client_glue.h>
26 27 28 29
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

30 31 32 33




34
G_DEFINE_TYPE(GeoclueMaster, geoclueserver_master, G_TYPE_OBJECT)
35 36 37 38 39 40 41 42 43 44 45


/* Filter signals and args */
enum {
  /* FILL ME */
  LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];


46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
static void
geoclueserver_add_backend(GeoclueMaster *obj, char* path)
{
    printf("Added %s\n", path);
    int newfile = g_open(path, O_RDONLY,0);
    if(newfile != -2)
    {                

        char** backendstrings = malloc(sizeof(char*)*5);
        GIOChannel* channel = g_io_channel_unix_new(newfile);
        g_io_channel_read_line(channel,&backendstrings[0],NULL, NULL, NULL);
        g_io_channel_read_line(channel,&backendstrings[1],NULL, NULL, NULL);
        g_io_channel_read_line(channel,&backendstrings[2],NULL, NULL, NULL);
        g_io_channel_read_line(channel,&backendstrings[3],NULL, NULL, NULL);     
        backendstrings[4] = NULL;
        printf("Added %s\n", backendstrings[0]);
        obj->backends = g_list_prepend(obj->backends, (void*)backendstrings);      
    }
    
}
66 67 68 69 70




static void
71
geoclueserver_master_init (GeoclueMaster *obj)
72
{
73 74 75 76 77 78
    obj->client = gconf_client_get_default();
    gconf_client_add_dir(obj->client,
                       "/apps/geoclue",
                       GCONF_CLIENT_PRELOAD_RECURSIVE,
                       NULL);
    
79

80
    obj->backends = NULL;
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
	GError *error = NULL;
	DBusGProxy *driver_proxy;
	GeoclueMasterClass *klass = GEOCLUE_MASTER_GET_CLASS(obj);
	guint request_ret;
	
	/* Register DBUS path */
	dbus_g_connection_register_g_object (klass->connection,
			GEOCLUE_MASTER_DBUS_PATH ,
			G_OBJECT (obj));


	/* Register the service name, the constant here are defined in dbus-glib-bindings.h */
	driver_proxy = dbus_g_proxy_new_for_name (klass->connection,
			DBUS_SERVICE_DBUS,
			DBUS_PATH_DBUS,
			DBUS_INTERFACE_DBUS);


	if(!org_freedesktop_DBus_request_name (driver_proxy,
			GEOCLUE_MASTER_DBUS_SERVICE,
			0, &request_ret,    /* See tutorial for more infos about these */
			&error))
	{
		g_printerr("Unable to register geomap service: %s", error->message);
		g_error_free (error);
	}	

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
  GDir* dir = g_dir_open("/usr/local/share/geoclue/backend",0,NULL);
  const gchar* filename;
  if(dir != NULL)
  {
      filename = g_dir_read_name(dir);
      while(filename != NULL)
      {
        char* fullpath = g_strconcat("/usr/local/share/geoclue/backend", "/", filename, NULL);
        geoclueserver_add_backend(obj, fullpath);
        free(fullpath);
        filename = g_dir_read_name(dir);
      }
  }

  dir = g_dir_open("/usr/share/geoclue/backend",0,NULL);
  if(dir != NULL)
  {  
      filename = g_dir_read_name(dir);
      while(filename != NULL)
      {
        char* fullpath = g_strconcat("/usr/share/geoclue/backend", "/", filename, NULL);
        geoclueserver_add_backend(obj, fullpath);
        free(fullpath);
        filename = g_dir_read_name(dir);
      }
  }

135 136 137 138 139 140 141 142
  


}



static void
143
geoclueserver_master_class_init (GeoclueMasterClass *klass)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
{
	GError *error = NULL;

    klass->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);

   
    
    
	if (klass->connection == NULL)
	{
		g_printerr("Unable to connect to dbus: %s", error->message);
		g_error_free (error);
		return;
	}	
	/* &dbus_glib__object_info is provided in the server-bindings.h file */
	/* OBJECT_TYPE_SERVER is the GType of your server object */
	dbus_g_object_type_install_info (TYPE_GEOCLUE_MASTER, &dbus_glib_geoclue_master_object_info);	
	    
}


gboolean geoclue_master_version (GeoclueMaster *obj, gint* OUT_major, gint* OUT_minor, gint* OUT_micro, GError **error)
{
   
    return TRUE;
}



173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188


gboolean geoclue_master_get_default_position_provider (GeoclueMaster *obj, char ** OUT_service, char ** OUT_path, char ** OUT_description, GError **error)
{
    guint length =  g_list_length(obj->backends);
    printf("length %d\n",length);
    int i;    
    for(i = 0; i < length; i++)
    {
        char** backend = g_list_nth_data(obj->backends, i);
        printf("Services \n\t%s\n\t%s\n\t%s\n\t%s\n", backend[0], backend[1], backend[2], backend[3]);
    }   


	*OUT_service = gconf_client_get_string(obj->client, "/apps/geoclue/position/defaultservice",NULL);
	*OUT_path = gconf_client_get_string(obj->client, "/apps/geoclue/position/defaultpath",NULL); 
189 190 191
		  
    return TRUE;
}
192
gboolean geoclue_master_get_all_position_providers (GeoclueMaster *obj, char *** OUT_service, char *** OUT_path, char *** OUT_description,  GError **error)
193
{
194 195 196 197 198 199 200 201 202 203 204 205
    guint length =  g_list_length(obj->backends);
    printf("length %d\n",length);
    int i;
    for(i = 0; i < length; i++)
    {
        char** backend = g_list_nth_data(obj->backends, i);
        printf("Services \n\t%s\n\t%s\n\t%s\n\t%s\n", backend[0], backend[1], backend[2], backend[3]);
    }    

    
    
    
206 207 208 209
	*OUT_service = malloc(3 * sizeof(char*));
	*OUT_path = malloc(3 * sizeof(char*));
	(*OUT_service)[0] = strdup("org.foinse_project.geoclue.position.manual");
	(*OUT_path)[0] = strdup("/org/foinse_project/geoclue/position/manual"); 
210 211
	(*OUT_service)[1] = strdup("org.foinse_project.geoclue.position.hostip");
	(*OUT_path)[1] = strdup("/org/foinse_project/geoclue/position/hostip"); 	
212 213 214 215 216 217 218
	(*OUT_service)[2] = NULL;
	(*OUT_path)[2] = NULL;
    
    return TRUE;
}


219
gboolean geoclue_master_position_provider_update (GeoclueMaster *obj, const char * IN_service, const char * IN_path, const gint IN_accuracy, const gboolean IN_active, GError **error)
220 221 222 223 224 225
{   
    return TRUE;
}



226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
gboolean geoclue_master_get_default_map_provider (GeoclueMaster *obj, char ** OUT_service, char ** OUT_path, char ** OUT_description, GError **error)
{   
    return TRUE;
}


gboolean geoclue_master_get_all_map_providers (GeoclueMaster *obj, char *** OUT_service, char *** OUT_path, char *** OUT_description,  GError **error)
{   
    return TRUE;
}


gboolean geoclue_master_map_provider_update (GeoclueMaster *obj, const char * IN_service, const char * IN_path, const gint IN_accuracy, const gboolean IN_active, GError **error)
{   
    return TRUE;
}


gboolean geoclue_master_get_default_geocode_provider (GeoclueMaster *obj, char ** OUT_service, char ** OUT_path, char ** OUT_description, GError **error)
{   
    return TRUE;
}


gboolean geoclue_master_get_all_geocode_providers (GeoclueMaster *obj, char *** OUT_service, char *** OUT_path, char *** OUT_description,  GError **error)
{   
    return TRUE;
}


gboolean geoclue_master_geocode_provider_update (GeoclueMaster *obj, const char * IN_service, const char * IN_path, const gint IN_accuracy, const gboolean IN_active, GError **error)
{   
    return TRUE;
}




264 265 266 267 268 269 270


int main( int   argc,
          char *argv[] )
{
    
    g_type_init ();
271 272 273
    gconf_init(argc, argv, NULL);
    
    
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
   
    GMainLoop*  loop = g_main_loop_new(NULL,TRUE);
    
    
      

    GeoclueMaster* obj = NULL; 
  
    obj = GEOCLUE_MASTER(g_type_create_instance (TYPE_GEOCLUE_MASTER));
        



    g_main_loop_run(loop);
    
    g_object_unref(obj);   
    g_main_loop_unref(loop);
    
    
    return 0;
}