Back to index

unity  6.0.0
test_service_main.c
Go to the documentation of this file.
00001 #include <glib-object.h>
00002 
00003 #include "test_service_lens.h"
00004 #include "test_service_model.h"
00005 #include "test_service_hud.h"
00006 #include "test_service_gdbus_wrapper.h"
00007 
00008 static void on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null);
00009 static void handle_method_call(GDBusConnection       *connection,
00010                                const gchar           *sender,
00011                                const gchar           *object_path,
00012                                const gchar           *interface_name,
00013                                const gchar           *method_name,
00014                                GVariant              *parameters,
00015                                GDBusMethodInvocation *invocation,
00016                                gpointer               user_data);
00017 
00018 
00019 static GDBusNodeInfo* introspection_data = NULL;
00020 static const gchar introspection_xml[] =
00021   "<node>"
00022   "  <interface name='com.canonical.Unity.Test'>"
00023   ""
00024   "    <method name='Exit'>"
00025   "    </method>"
00026   ""
00027   "  </interface>"
00028   "</node>";
00029 static const GDBusInterfaceVTable interface_vtable = 
00030 {
00031   handle_method_call,
00032   NULL,
00033   NULL
00034 };
00035 
00036 static GMainLoop* loop_ = NULL;
00037 static ServiceLens* lens_ = NULL;
00038 static ServiceModel* model_ = NULL;
00039 static ServiceHud* hud_ = NULL;
00040 static ServiceGDBusWrapper* gdbus_wrapper_ = NULL;
00041 gint
00042 main(gint argc, gchar** argv)
00043 {
00044   g_type_init();
00045 
00046   loop_ = g_main_loop_new(NULL, FALSE);
00047 
00048   lens_ = service_lens_new();
00049   model_ = service_model_new();
00050   hud_ = service_hud_new();
00051   gdbus_wrapper_ = service_gdbus_wrapper_new();
00052 
00053   g_bus_own_name(G_BUS_TYPE_SESSION,
00054                  "com.canonical.Unity.Test",
00055                  G_BUS_NAME_OWNER_FLAGS_NONE,
00056                  on_bus_aquired,
00057                  NULL,
00058                  NULL,
00059                  NULL,
00060                  NULL);
00061 
00062   g_main_loop_run(loop_);
00063   g_main_loop_unref(loop_);
00064 
00065   //g_object_unref(lens_);
00066   //g_object_unref(model_);
00067   g_object_unref(hud_);
00068   g_dbus_node_info_unref(introspection_data);
00069 
00070   return 0;
00071 }
00072 
00073 static void
00074 on_bus_aquired(GDBusConnection* conn, const gchar* name, gpointer null)
00075 {
00076   introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
00077   g_dbus_connection_register_object(conn,
00078                                     "/com/canonical/unity/test/controller",
00079                                     introspection_data->interfaces[0],
00080                                     &interface_vtable,
00081                                     NULL,
00082                                     NULL,
00083                                     NULL);
00084 }
00085 
00086 static void
00087 handle_method_call(GDBusConnection       *connection,
00088                    const gchar           *sender,
00089                    const gchar           *object_path,
00090                    const gchar           *interface_name,
00091                    const gchar           *method_name,
00092                    GVariant              *parameters,
00093                    GDBusMethodInvocation *invocation,
00094                    gpointer               user_data)
00095 {
00096   if (g_strcmp0(method_name, "Exit") == 0)
00097   {
00098     g_main_loop_quit(loop_);
00099   }
00100 }