static void on_bus_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { ObjectSkeleton *object; cmdline *cmd = user_data; manager = g_dbus_object_manager_server_new(dbus_object_path); int i = 0; for(i=0;i<NUM_HWMONS;i++) { if(!is_hwmon_valid(&hwmons[i])) { continue; } gchar *s; s = g_strdup_printf("%s/%s",dbus_object_path,hwmons[i].name); object = object_skeleton_new(s); g_free(s); Hwmon *hwmon = hwmon_skeleton_new(); object_skeleton_set_hwmon(object, hwmon); g_object_unref(hwmon); SensorValue *sensor = sensor_value_skeleton_new(); object_skeleton_set_sensor_value(object, sensor); g_object_unref(sensor); hwmon_set_sysfs_path(hwmon,hwmons[i].filename); hwmon_set_scale(hwmon,hwmons[i].scale); sensor_value_set_units(sensor,hwmons[i].units); //define method callbacks here g_signal_connect(sensor, "handle-set-value", G_CALLBACK(on_set_value), object); /* user_data */ if(hwmons[i].poll_interval > 0) { g_timeout_add(hwmons[i].poll_interval, poll_hwmon, object); } /* Export the object (@manager takes its own reference to @object) */ g_dbus_object_manager_server_set_connection(manager, connection); g_dbus_object_manager_server_export(manager, G_DBUS_OBJECT_SKELETON(object)); g_object_unref(object); } }
static void on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data) { //g_print ("Acquired a message bus connection: %s\n",name); cmdline *cmd = user_data; if (cmd->argc < 2) { g_print("No objects created. Put object name(s) on command line\n"); return; } manager = g_dbus_object_manager_server_new (dbus_object_path); int i=0; for (i=1;i<cmd->argc;i++) { gchar *s; s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]); ObjectSkeleton *object = object_skeleton_new (s); g_free (s); Occ *occ = occ_skeleton_new (); object_skeleton_set_occ (object, occ); g_object_unref (occ); occ_set_instance_name(occ,cmd->argv[i]); SensorI2c *i2c = sensor_i2c_skeleton_new (); object_skeleton_set_sensor_i2c (object, i2c); g_object_unref (i2c); g_signal_connect (occ, "handle-init", G_CALLBACK (on_init), object); /* user_data */ //g_timeout_add(3000, poll_occ, object); /* Export the object (@manager takes its own reference to @object) */ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object)); g_object_unref (object); int c; for (c=0;c<12;c++) { s = g_strdup_printf ("%s/Temperature/P8_%s_Core_%d",dbus_object_path,cmd->argv[i],c); ObjectSkeleton *object = object_skeleton_new (s); g_free (s); SensorValue *sensor = sensor_value_skeleton_new (); object_skeleton_set_sensor_value (object, sensor); g_object_unref (sensor); GVariant* v_new_value = NEW_VARIANT_U(c); sensor_value_set_value(sensor,v_new_value); sensor_value_set_units(sensor,"C"); g_signal_connect (sensor, "handle-init", G_CALLBACK (on_init_sensor), NULL); /* user_data */ //emit changed signal so sensor manager sees initial value sensor_value_emit_changed(sensor,sensor_value_get_value(sensor),sensor_value_get_units(sensor)); /* Export the object (@manager takes its own reference to @object) */ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object)); g_object_unref (object); } } /* Export all objects */ g_dbus_object_manager_server_set_connection (manager, connection); }