23
23
#include <stdbool.h>
24
24
#include <stdint.h>
25
25
26
+ #define MAIN_OBJECT_PATH "/Registrar"
27
+
26
28
struct _RegistrarApplication
27
29
{
28
30
GApplication parent ;
29
31
RegistrarDBusMenu * registrar ;
30
32
u_int32_t dbusmenu_binding ;
33
+ u_int32_t private_binding ;
31
34
};
32
35
36
+ extern const char * private_xml ;
37
+
33
38
G_DEFINE_TYPE (RegistrarApplication , registrar_application , G_TYPE_APPLICATION )
34
39
35
40
static const GOptionEntry options [4 ] =
@@ -53,20 +58,18 @@ static const GOptionEntry options[4] =
53
58
54
59
RegistrarApplication * registrar_application_new ()
55
60
{
56
- return REGISTRAR_APPLICATION (g_object_new (registrar_application_get_type (),
57
- "application-id" ,
58
- "org.valapanel.AppMenu.Registrar" ,
59
- "flags" ,
60
- G_APPLICATION_HANDLES_COMMAND_LINE ,
61
- "resource-base-path" ,
62
- "/org/valapanel/registrar" ,
63
- NULL ));
61
+ return REGISTRAR_APPLICATION (
62
+ g_object_new (registrar_application_get_type (),
63
+ "application-id" ,
64
+ "org.valapanel.AppMenu.Registrar" ,
65
+ "flags" ,
66
+ G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_IS_SERVICE ,
67
+ "resource-base-path" ,
68
+ "/org/valapanel/registrar" ,
69
+ NULL ));
64
70
}
65
71
static void registrar_application_activate (GApplication * base )
66
72
{
67
- RegistrarApplication * self = REGISTRAR_APPLICATION (base );
68
- if (self -> dbusmenu_binding > 0 )
69
- g_application_hold (base );
70
73
}
71
74
static int registrar_application_handle_local_options (GApplication * application ,
72
75
GVariantDict * options )
@@ -94,9 +97,7 @@ static void registrar_application_on_dbus_name_aquired(GDBusConnection *connecti
94
97
RegistrarApplication * self = REGISTRAR_APPLICATION (user_data );
95
98
g_autoptr (GError ) err = NULL ;
96
99
registrar_dbus_menu_register (self -> registrar , connection , & err );
97
- if (!err )
98
- g_application_hold (G_APPLICATION (user_data ));
99
- else
100
+ if (err )
100
101
{
101
102
g_print ("%s\n" , err -> message );
102
103
}
@@ -105,8 +106,31 @@ static void registrar_application_on_dbus_name_lost(GDBusConnection *connection,
105
106
gpointer user_data )
106
107
{
107
108
GApplication * app = G_APPLICATION (user_data );
108
- g_application_release (app );
109
109
}
110
+
111
+ static void registrar_application_method_call (GDBusConnection * connection , const char * sender ,
112
+ const char * object_path , const char * interface_name ,
113
+ const char * method_name , GVariant * parameters ,
114
+ GDBusMethodInvocation * invocation , gpointer user_data )
115
+ {
116
+ GApplication * app = G_APPLICATION (user_data );
117
+ if (g_strcmp0 (method_name , "Reference" ) == 0 )
118
+ {
119
+ g_application_hold (app );
120
+ }
121
+ else if (g_strcmp0 (method_name , "UnReference" ) == 0 )
122
+ {
123
+ g_application_release (app );
124
+ }
125
+ else
126
+ {
127
+ g_object_unref (invocation );
128
+ }
129
+ }
130
+ static const GDBusInterfaceVTable _interface_vtable = { registrar_application_method_call ,
131
+ NULL ,
132
+ NULL };
133
+
110
134
static bool registrar_application_dbus_register (GApplication * base , GDBusConnection * connection ,
111
135
const char * object_path , GError * * error )
112
136
{
@@ -125,7 +149,17 @@ static bool registrar_application_dbus_register(GApplication *base, GDBusConnect
125
149
registrar_application_on_dbus_name_lost ,
126
150
self ,
127
151
NULL );
128
- return ret && self -> dbusmenu_binding ;
152
+ GDBusNodeInfo * info = g_dbus_node_info_new_for_xml (private_xml , NULL );
153
+ self -> private_binding =
154
+ g_dbus_connection_register_object (connection ,
155
+ MAIN_OBJECT_PATH ,
156
+ (GDBusInterfaceInfo * )info -> interfaces [0 ],
157
+ & _interface_vtable ,
158
+ self ,
159
+ NULL ,
160
+ error );
161
+
162
+ return ret && self -> dbusmenu_binding && self -> private_binding ;
129
163
}
130
164
static void registrar_application_dbus_unregister (GApplication * base , GDBusConnection * connection ,
131
165
const char * object_path )
@@ -134,8 +168,9 @@ static void registrar_application_dbus_unregister(GApplication *base, GDBusConne
134
168
g_return_if_fail (connection != NULL );
135
169
g_return_if_fail (object_path != NULL );
136
170
g_bus_unown_name (self -> dbusmenu_binding );
171
+ registrar_dbus_menu_unregister (self -> registrar , connection );
172
+ g_dbus_connection_unregister_object (connection , self -> private_binding );
137
173
self -> dbusmenu_binding = 0 ;
138
- g_application_release (base );
139
174
G_APPLICATION_CLASS (registrar_application_parent_class )
140
175
-> dbus_unregister (base , connection , object_path );
141
176
}
@@ -153,7 +188,6 @@ static void registrar_application_init(RegistrarApplication *application)
153
188
application -> registrar =
154
189
REGISTRAR_DBUS_MENU (g_object_new (registrar_dbus_menu_get_type (), NULL ));
155
190
g_application_add_main_option_entries (G_APPLICATION (application ), options );
156
- g_application_hold (application );
157
191
}
158
192
159
193
static void registrar_application_class_init (RegistrarApplicationClass * klass )
0 commit comments