blob: afe33180d080a785ad52f9999eb66b70773a2193 [file] [log] [blame]
Norman James362a80f2015-09-14 14:04:39 -05001#include "interfaces/openbmc_intf.h"
Norman Jamesce46e3e2015-08-30 22:25:55 -05002#include "openbmc.h"
3
4
5/* ---------------------------------------------------------------------------------------------------- */
6
Norman James362a80f2015-09-14 14:04:39 -05007static const gchar* dbus_object_path = "/org/openbmc/control";
8static const gchar* dbus_name = "org.openbmc.control.Fan";
Norman Jamesce46e3e2015-08-30 22:25:55 -05009static guint heartbeat = 0;
10
11static GDBusObjectManagerServer *manager = NULL;
12
13static gboolean
14poll_sensor(gpointer user_data)
15{
16 //FruFan *fan = object_get_fan((Object*)user_data);
17 return TRUE;
18}
19
20
21
22static gboolean
Norman James362a80f2015-09-14 14:04:39 -050023on_set_speed (Fan *fan,
Norman Jamesce46e3e2015-08-30 22:25:55 -050024 GDBusMethodInvocation *invocation,
25 guint speed,
26 gpointer user_data)
27{
Norman James362a80f2015-09-14 14:04:39 -050028 fan_set_speed(fan,speed);
29 fan_complete_set_speed(fan,invocation);
Norman Jamesce46e3e2015-08-30 22:25:55 -050030 return TRUE;
31}
32
33static gboolean
Norman James362a80f2015-09-14 14:04:39 -050034on_get_speed (Fan *fan,
Norman Jamesce46e3e2015-08-30 22:25:55 -050035 GDBusMethodInvocation *invocation,
36 gpointer user_data)
37{
Norman James362a80f2015-09-14 14:04:39 -050038 guint reading = fan_get_speed(fan);
39 fan_complete_get_speed(fan,invocation,reading);
Norman Jamesce46e3e2015-08-30 22:25:55 -050040 return TRUE;
41}
42
Norman Jamesce46e3e2015-08-30 22:25:55 -050043static void
44on_bus_acquired (GDBusConnection *connection,
45 const gchar *name,
46 gpointer user_data)
47{
Norman James362a80f2015-09-14 14:04:39 -050048 //g_print ("Acquired a message bus connection: %s\n",name);
Norman Jamesce46e3e2015-08-30 22:25:55 -050049
50 cmdline *cmd = user_data;
51 if (cmd->argc < 2)
52 {
53 g_print("No objects created. Put object name(s) on command line\n");
54 return;
55 }
56 manager = g_dbus_object_manager_server_new (dbus_object_path);
57 int i=0;
58 for (i=1;i<cmd->argc;i++)
59 {
60 gchar *s;
61 s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
62 ObjectSkeleton *object = object_skeleton_new (s);
63 g_free (s);
64
Norman James362a80f2015-09-14 14:04:39 -050065 Fan *fan = fan_skeleton_new ();
66 object_skeleton_set_fan (object, fan);
Norman Jamesce46e3e2015-08-30 22:25:55 -050067 g_object_unref (fan);
Norman Jamesce46e3e2015-08-30 22:25:55 -050068
69 //define method callbacks here
70 g_signal_connect (fan,
71 "handle-get-speed",
72 G_CALLBACK (on_get_speed),
73 NULL); /* user_data */
74 g_signal_connect (fan,
75 "handle-set-speed",
76 G_CALLBACK (on_set_speed),
77 NULL); /* user_data */
Norman Jamesce46e3e2015-08-30 22:25:55 -050078
79 //g_timeout_add(poll_interval, poll_sensor, object);
80
81 /* Export the object (@manager takes its own reference to @object) */
82 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
83 g_object_unref (object);
84 }
85
86 /* Export all objects */
87 g_dbus_object_manager_server_set_connection (manager, connection);
88}
89
90static void
91on_name_acquired (GDBusConnection *connection,
92 const gchar *name,
93 gpointer user_data)
94{
Norman James362a80f2015-09-14 14:04:39 -050095 //g_print ("Acquired the name %s\n", name);
Norman Jamesce46e3e2015-08-30 22:25:55 -050096}
97
98static void
99on_name_lost (GDBusConnection *connection,
100 const gchar *name,
101 gpointer user_data)
102{
Norman James362a80f2015-09-14 14:04:39 -0500103 //g_print ("Lost the name %s\n", name);
Norman Jamesce46e3e2015-08-30 22:25:55 -0500104}
105
106
107gint
108main (gint argc, gchar *argv[])
109{
110 GMainLoop *loop;
111 cmdline cmd;
112 cmd.argc = argc;
113 cmd.argv = argv;
114 guint id;
115 loop = g_main_loop_new (NULL, FALSE);
116
Norman James5e792e32015-10-07 17:36:17 -0500117 id = g_bus_own_name (DBUS_TYPE,
Norman Jamesce46e3e2015-08-30 22:25:55 -0500118 dbus_name,
119 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
120 G_BUS_NAME_OWNER_FLAGS_REPLACE,
121 on_bus_acquired,
122 on_name_acquired,
123 on_name_lost,
124 &cmd,
125 NULL);
126
127 g_main_loop_run (loop);
128
129 g_bus_unown_name (id);
130 g_main_loop_unref (loop);
131 return 0;
132}