e01742c67173a1c803c1eb5b0de5e9d07b1b1be6
[systembsd.git] / src / modules / hostnamed / hostnamed.c
1 /* #include <glib-2.0/glib.h> */
2 #include <gio/gio.h>
3
4 /* testing, for now */
5 static GDBusNodeInfo *spect_data = NULL;
6 static const gchar spect_xml[] =
7 "<node>"
8 " <interface name='org.freedesktop.DBus.Peer'>"
9 " <method name='Ping'/>"
10 " <method name='GetMachineId'>"
11 " <arg type='s' name='machine_uuid' direction='out'/>"
12 " </method>"
13 " </interface>"
14 " <interface name='org.freedesktop.DBus.Introspectable'>"
15 " <method name='Introspect'>"
16 " <arg name='data' type='s' direction='out'/>"
17 " </method>"
18 " </interface>"
19 " <interface name='org.freedesktop.DBus.Properties'>"
20 " <method name='Get'>"
21 " <arg name='interface' direction='in' type='s'/>"
22 " <arg name='property' direction='in' type='s'/>"
23 " <arg name='value' direction='out' type='v'/>"
24 " </method>"
25 " <method name='GetAll'>"
26 " <arg name='interface' direction='in' type='s'/>"
27 " <arg name='properties' direction='out' type='a{sv}'/>"
28 " </method>"
29 " <method name='Set'>"
30 " <arg name='interface' direction='in' type='s'/>"
31 " <arg name='property' direction='in' type='s'/>"
32 " <arg name='value' direction='in' type='v'/>"
33 " </method>"
34 " <signal name='PropertiesChanged'>"
35 " <arg type='s' name='interface'/>"
36 " <arg type='a{sv}' name='changed_properties'/>"
37 " <arg type='as' name='invalidated_properties'/>"
38 " </signal>"
39 " </interface>"
40 " <interface name='org.freedesktop.hostname1'>"
41 " <property name='Hostname' type='s' access='read'>"
42 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='false'/>"
43 " </property>"
44 " <property name='StaticHostname' type='s' access='read'>"
45 " </property>"
46 " <property name='PrettyHostname' type='s' access='read'>"
47 " </property>"
48 " <property name='IconName' type='s' access='read'>"
49 " </property>"
50 " <property name='Chassis' type='s' access='read'>"
51 " </property>"
52 " <property name='KernelName' type='s' access='read'>"
53 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
54 " </property>"
55 " <property name='KernelRelease' type='s' access='read'>"
56 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
57 " </property>"
58 " <property name='KernelVersion' type='s' access='read'>"
59 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
60 " </property>"
61 " <property name='OperatingSystemPrettyName' type='s' access='read'>"
62 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
63 " </property>"
64 " <property name='OperatingSystemCPEName' type='s' access='read'>"
65 " <annotation name='org.freedesktop.DBus.Property.EmitsChangedSignal' value='const'/>"
66 " </property>"
67 " <method name='SetHostname'>"
68 " <arg type='s' direction='in'/>"
69 " <arg type='b' direction='in'/>"
70 " </method>"
71 " <method name='SetStaticHostname'>"
72 " <arg type='s' direction='in'/>"
73 " <arg type='b' direction='in'/>"
74 " </method>"
75 " <method name='SetPrettyHostname'>"
76 " <arg type='s' direction='in'/>"
77 " <arg type='b' direction='in'/>"
78 " </method>"
79 " <method name='SetIconName'>"
80 " <arg type='s' direction='in'/>"
81 " <arg type='b' direction='in'/>"
82 " </method>"
83 " <method name='SetChassis'>"
84 " <arg type='s' direction='in'/>"
85 " <arg type='b' direction='in'/>"
86 " </method>"
87 " </interface>"
88 "</node>";
89
90 static void handle_method_call() {}
91 static GVariant * handle_get_property() {return NULL;}
92 static gboolean handle_set_property() {return FALSE;}
93
94 /* TODO: what's this guy do */
95 static const GDBusInterfaceVTable interface_vtable =
96 {
97 handle_method_call,
98 handle_get_property,
99 handle_set_property
100 };
101
102
103
104 static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) {
105 g_print("got bus, name: %s\n", name);
106
107 spect_data = g_dbus_node_info_new_for_xml(spect_xml, NULL);
108 guint reg_id;
109
110 reg_id = g_dbus_connection_register_object (conn,
111 "/org/freedesktop/hostname1",
112 spect_data->interfaces[0],
113 &interface_vtable,
114 NULL,
115 NULL,
116 NULL );
117 g_assert(reg_id > 0);
118 }
119
120 static void on_name_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) {
121 g_print("got name %s\n", name);
122 }
123
124 static void on_name_lost(GDBusConnection *conn, const gchar *name, gpointer user_data) {
125 g_print("lost name %s\n", name);
126 }
127
128 void hostnamed_init() {
129
130 guint bus_descriptor;
131 GError *err = NULL;
132
133 bus_descriptor = g_bus_own_name(G_BUS_TYPE_SESSION,
134 (gchar *)"org.freedesktop.hostname1",
135 G_BUS_NAME_OWNER_FLAGS_NONE,
136 on_bus_acquired,
137 on_name_acquired,
138 on_name_lost,
139 NULL,
140 NULL);
141 }
142
143