blob: 4c2ca35782707cdf9e9899ea786d06da52c28309 [file] [log] [blame]
Norman Jamesce46e3e2015-08-30 22:25:55 -05001#include "interfaces/fru.h"
2#include "openbmc.h"
3
4
5/* ---------------------------------------------------------------------------------------------------- */
6
7static const gchar* dbus_object_path = "/org/openbmc/frus/Fan";
8static const gchar* dbus_name = "org.openbmc.frus.Fan";
9static const guint poll_interval = 5000;
10static guint heartbeat = 0;
11
12static GDBusObjectManagerServer *manager = NULL;
13
14static gboolean
15poll_sensor(gpointer user_data)
16{
17 //FruFan *fan = object_get_fan((Object*)user_data);
18 return TRUE;
19}
20
21
22
23static gboolean
24on_set_speed (FruFan *fan,
25 GDBusMethodInvocation *invocation,
26 guint speed,
27 gpointer user_data)
28{
29 fru_fan_set_speed(fan,speed);
30 fru_fan_complete_set_speed(fan,invocation);
31 return TRUE;
32}
33
34static gboolean
35on_get_speed (FruFan *fan,
36 GDBusMethodInvocation *invocation,
37 gpointer user_data)
38{
39 guint reading = fru_fan_get_speed(fan);
40 fru_fan_complete_get_speed(fan,invocation,reading);
41 return TRUE;
42}
43
Norman Jamesce46e3e2015-08-30 22:25:55 -050044static void
45on_bus_acquired (GDBusConnection *connection,
46 const gchar *name,
47 gpointer user_data)
48{
49 g_print ("Acquired a message bus connection: %s\n",name);
50
51 cmdline *cmd = user_data;
52 if (cmd->argc < 2)
53 {
54 g_print("No objects created. Put object name(s) on command line\n");
55 return;
56 }
57 manager = g_dbus_object_manager_server_new (dbus_object_path);
58 int i=0;
59 for (i=1;i<cmd->argc;i++)
60 {
61 gchar *s;
62 s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
63 ObjectSkeleton *object = object_skeleton_new (s);
64 g_free (s);
65
66 FruFan *fan = fru_fan_skeleton_new ();
67 object_skeleton_set_fru_fan (object, fan);
68 g_object_unref (fan);
69
70 Fru *fru = fru_skeleton_new ();
71 object_skeleton_set_fru (object, fru);
72 g_object_unref (fru);
73
74 //define method callbacks here
75 g_signal_connect (fan,
76 "handle-get-speed",
77 G_CALLBACK (on_get_speed),
78 NULL); /* user_data */
79 g_signal_connect (fan,
80 "handle-set-speed",
81 G_CALLBACK (on_set_speed),
82 NULL); /* user_data */
Norman Jamesce46e3e2015-08-30 22:25:55 -050083
84 //g_timeout_add(poll_interval, poll_sensor, object);
85
86 /* Export the object (@manager takes its own reference to @object) */
87 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
88 g_object_unref (object);
89 }
90
91 /* Export all objects */
92 g_dbus_object_manager_server_set_connection (manager, connection);
93}
94
95static void
96on_name_acquired (GDBusConnection *connection,
97 const gchar *name,
98 gpointer user_data)
99{
100 g_print ("Acquired the name %s\n", name);
101}
102
103static void
104on_name_lost (GDBusConnection *connection,
105 const gchar *name,
106 gpointer user_data)
107{
108 g_print ("Lost the name %s\n", name);
109}
110
111
112gint
113main (gint argc, gchar *argv[])
114{
115 GMainLoop *loop;
116 cmdline cmd;
117 cmd.argc = argc;
118 cmd.argv = argv;
119 guint id;
120 loop = g_main_loop_new (NULL, FALSE);
121
122 id = g_bus_own_name (G_BUS_TYPE_SESSION,
123 dbus_name,
124 G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT |
125 G_BUS_NAME_OWNER_FLAGS_REPLACE,
126 on_bus_acquired,
127 on_name_acquired,
128 on_name_lost,
129 &cmd,
130 NULL);
131
132 g_main_loop_run (loop);
133
134 g_bus_unown_name (id);
135 g_main_loop_unref (loop);
136 return 0;
137}