blob: bd68382d836a926b62be90f00e5114748ff30808 [file] [log] [blame]
Norman James362a80f2015-09-14 14:04:39 -05001#include "interfaces/openbmc_intf.h"
2#include "openbmc.h"
3
4
5/* ---------------------------------------------------------------------------------------------------- */
6
7static const gchar* dbus_object_path = "/org/openbmc/sensors";
8static const gchar* dbus_name = "org.openbmc.sensors.Occ";
9static guint heartbeat = 0;
10
11static GDBusObjectManagerServer *manager = NULL;
12static gchar *instance_name = NULL;
13
14static gboolean poll_occ(gpointer user_data)
15{
16/*
17 gchar *s;
18 s = g_strdup_printf ("%s/Temperature/%d",g_dbus_object_get_object_path(G_DBUS_OBJECT(user_data)), 1);
19 g_print("%s\n",s);
20
21 GDBusInterface* interface = g_dbus_object_manager_get_interface((GDBusObjectManager*)manager,s,
22 "org.openbmc.SensorValue");
23
24 if (interface != NULL)
25 {
26 SensorValue* sensor = (SensorValue*) interface;
27 GVariant *value = NEW_VARIANT_U(10);
28 sensor_value_set_value(sensor,value);
29 const gchar* units = sensor_value_get_units(sensor);
30 sensor_value_emit_changed(sensor,sensor_value_get_value(sensor),units);
31 }
32 g_free (s);
33 //g_free(interface);
34*/
35 return TRUE;
36}
37
38
39
40static gboolean
41on_init (Occ *occ,
42 GDBusMethodInvocation *invocation,
43 gpointer user_data)
44{
45 guint poll_interval = occ_get_poll_interval(occ);
46 g_timeout_add(poll_interval, poll_occ, user_data);
47 occ_complete_init(occ,invocation);
48 return TRUE;
49}
50static gboolean
51on_init_sensor (SensorValue *sensor,
52 GDBusMethodInvocation *invocation,
53 gpointer user_data)
54{
55 //must implement init method
56 sensor_value_complete_init(sensor,invocation);
57 return TRUE;
58}
59
60
61
62static void
63on_bus_acquired (GDBusConnection *connection,
64 const gchar *name,
65 gpointer user_data)
66{
67 //g_print ("Acquired a message bus connection: %s\n",name);
68
69 cmdline *cmd = user_data;
70 if (cmd->argc < 2)
71 {
72 g_print("No objects created. Put object name(s) on command line\n");
73 return;
74 }
75 manager = g_dbus_object_manager_server_new (dbus_object_path);
76 int i=0;
77 for (i=1;i<cmd->argc;i++)
78 {
79 gchar *s;
80 s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
81 ObjectSkeleton *object = object_skeleton_new (s);
82 g_free (s);
83
84 Occ *occ = occ_skeleton_new ();
85 object_skeleton_set_occ (object, occ);
86 g_object_unref (occ);
87
88 SensorI2c *i2c = sensor_i2c_skeleton_new ();
89 object_skeleton_set_sensor_i2c (object, i2c);
90 g_object_unref (i2c);
91
92 g_signal_connect (occ,
93 "handle-init",
94 G_CALLBACK (on_init),
95 object); /* user_data */
96
97 //g_timeout_add(3000, poll_occ, object);
98
99 /* Export the object (@manager takes its own reference to @object) */
100 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
101 g_object_unref (object);
102
103 int c;
104 for (c=0;c<12;c++)
105 {
106 s = g_strdup_printf ("%s/Temperature/P8_%s_Core_%d",dbus_object_path,cmd->argv[i],c);
107 ObjectSkeleton *object = object_skeleton_new (s);
108 g_free (s);
109
110 SensorValue *sensor = sensor_value_skeleton_new ();
111 object_skeleton_set_sensor_value (object, sensor);
112 g_object_unref (sensor);
113 GVariant* v_new_value = NEW_VARIANT_U(c);
114 sensor_value_set_value(sensor,v_new_value);
115 sensor_value_set_units(sensor,"C");
116
117 g_signal_connect (sensor,
118 "handle-init",
119 G_CALLBACK (on_init_sensor),
120 NULL); /* user_data */
121
122 //emit changed signal so sensor manager sees initial value
123 sensor_value_emit_changed(sensor,sensor_value_get_value(sensor),sensor_value_get_units(sensor));
124 /* Export the object (@manager takes its own reference to @object) */
125 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
126 g_object_unref (object);
127
128 }
129 }
130
131 /* Export all objects */
132 g_dbus_object_manager_server_set_connection (manager, connection);
133}
134
135static void
136on_name_acquired (GDBusConnection *connection,
137 const gchar *name,
138 gpointer user_data)
139{
140// g_print ("Acquired the name %s\n", name);
141}
142
143static void
144on_name_lost (GDBusConnection *connection,
145 const gchar *name,
146 gpointer user_data)
147{
148 //g_print ("Lost the name %s\n", name);
149 g_print("shutting down: %s\n",name);
150 cmdline *cmd = user_data;
151 g_main_loop_quit(cmd->loop);
152}
153
154
155gint
156main (gint argc, gchar *argv[])
157{
158 GMainLoop *loop;
159 cmdline cmd;
160 cmd.argc = argc;
161 cmd.argv = argv;
162
163 guint id;
164 loop = g_main_loop_new (NULL, FALSE);
165 cmd.loop = loop;
166
167 id = g_bus_own_name (G_BUS_TYPE_SESSION,
168 dbus_name,
169 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
170 G_BUS_NAME_OWNER_FLAGS_REPLACE,
171 on_bus_acquired,
172 on_name_acquired,
173 on_name_lost,
174 &cmd,
175 NULL);
176
177 g_main_loop_run (loop);
178
179 g_bus_unown_name (id);
180 g_main_loop_unref (loop);
181 return 0;
182}