blob: fb61c5c67ca57e40281ed27de71976ca775349ba [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"
Norman Jamescfc2b442015-10-31 17:31:46 -05003#include "object_mapper.h"
Norman Jamesce46e3e2015-08-30 22:25:55 -05004
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
Norman Jamescfc2b442015-10-31 17:31:46 -050069 ObjectMapper* mapper = object_mapper_skeleton_new ();
70 object_skeleton_set_object_mapper (object, mapper);
71 g_object_unref (mapper);
72
Norman Jamesce46e3e2015-08-30 22:25:55 -050073 //define method callbacks here
74 g_signal_connect (fan,
75 "handle-get-speed",
76 G_CALLBACK (on_get_speed),
77 NULL); /* user_data */
78 g_signal_connect (fan,
79 "handle-set-speed",
80 G_CALLBACK (on_set_speed),
81 NULL); /* user_data */
Norman Jamesce46e3e2015-08-30 22:25:55 -050082
83 //g_timeout_add(poll_interval, poll_sensor, object);
84
85 /* Export the object (@manager takes its own reference to @object) */
86 g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
87 g_object_unref (object);
88 }
89
90 /* Export all objects */
91 g_dbus_object_manager_server_set_connection (manager, connection);
Norman Jamescfc2b442015-10-31 17:31:46 -050092 emit_object_added((GDBusObjectManager*)manager);
Norman Jamesce46e3e2015-08-30 22:25:55 -050093}
94
95static void
96on_name_acquired (GDBusConnection *connection,
97 const gchar *name,
98 gpointer user_data)
99{
Norman James362a80f2015-09-14 14:04:39 -0500100 //g_print ("Acquired the name %s\n", name);
Norman Jamesce46e3e2015-08-30 22:25:55 -0500101}
102
103static void
104on_name_lost (GDBusConnection *connection,
105 const gchar *name,
106 gpointer user_data)
107{
Norman James362a80f2015-09-14 14:04:39 -0500108 //g_print ("Lost the name %s\n", name);
Norman Jamesce46e3e2015-08-30 22:25:55 -0500109}
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
Norman James5e792e32015-10-07 17:36:17 -0500122 id = g_bus_own_name (DBUS_TYPE,
Norman Jamesce46e3e2015-08-30 22:25:55 -0500123 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}