Exemplo n.º 1
0
static void 
on_bus_acquired (GDBusConnection *connection,
                 const gchar     *name,
                 gpointer         user_data)
{
	ObjectSkeleton *object;
	//g_print ("Acquired a message bus connection: %s\n",name);
 	cmdline *cmd = user_data;
  	manager = g_dbus_object_manager_server_new (dbus_object_path);
  	int i=0;
	gchar *s;
	s = g_strdup_printf ("%s/%s",dbus_object_path,instance_name);
	object = object_skeleton_new (s);
	g_free (s);

	Button* button = button_skeleton_new ();
	object_skeleton_set_button (object, button);
	g_object_unref (button);

	ObjectMapper* mapper = object_mapper_skeleton_new ();
	object_skeleton_set_object_mapper (object, mapper);
	g_object_unref (mapper);

	//define method callbacks
	g_signal_connect (button,
                   "handle-is-on",
                   G_CALLBACK (on_is_on),
                   NULL); /* user_data */
	g_signal_connect (button,
                    "handle-sim-button-press",
                    G_CALLBACK (on_button_press),
                    NULL); /* user_data */

		
	/* 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);

	// get gpio device paths
	int rc = GPIO_OK;
	do {
		rc = gpio_init(connection,&gpio_button);
		if (rc != GPIO_OK) { break; }
		rc = gpio_open_interrupt(&gpio_button,on_button_interrupt,object);
		if (rc != GPIO_OK) { break; }
	} while(0);
	if (rc != GPIO_OK)
	{
		printf("ERROR PowerButton: GPIO setup (rc=%d)\n",rc);
	}
	emit_object_added((GDBusObjectManager*)manager); 
}
Exemplo n.º 2
0
static void 
on_bus_acquired (GDBusConnection *connection,
                 const gchar     *name,
                 gpointer         user_data)
{
  	cmdline *cmd = user_data;
  	manager = g_dbus_object_manager_server_new (dbus_object_path);
		gchar *s;
 		s = g_strdup_printf ("%s/%s",dbus_object_path,instance_name);
		ObjectSkeleton *object = object_skeleton_new (s);
		g_free (s);

		Watchdog *wd = watchdog_skeleton_new ();
  		object_skeleton_set_watchdog (object, wd);
  		g_object_unref (wd);

		ObjectMapper* mapper = object_mapper_skeleton_new ();
		object_skeleton_set_object_mapper (object, mapper);
		g_object_unref (mapper);
		
  		// set properties
  		watchdog_set_watchdog(wd,1);
		
		//define method callbacks here
 		g_signal_connect (wd,
                    "handle-start",
                    G_CALLBACK (on_start),
                    object); /* user_data */
 
 		g_signal_connect (wd,
                    "handle-poke",
                    G_CALLBACK (on_poke),
                    object); /* user_data */

        g_signal_connect (wd,
                    "handle-stop",
                    G_CALLBACK (on_stop),
                    object); /* user_data */

        g_signal_connect (wd,
                    "handle-set",
                    G_CALLBACK (set_poll_interval),
                    object); /* user_data */

  		/* 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);
  emit_object_added((GDBusObjectManager*)manager); 
}
Exemplo n.º 3
0
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;

	//TODO: don't use fixed buffer
	char flasher_path[512];
	memset(flasher_path, '\0', sizeof(flasher_path));
	bool found = false;
	gchar *flasher_file;
	int c = strlen(cmd->argv[0]);
	while(c>0)
	{
		if (cmd->argv[0][c] == '/')
		{
			strncpy(flasher_path,cmd->argv[0],c);
			flasher_file = g_strdup_printf ("%s/%s",flasher_path,FLASHER_BIN);
			break;
		}
		c--;
	}

	const char* inst[] = {"bios"};
  	for (i=0;i<1;i++)
  	{
		gchar* s;
		s = g_strdup_printf ("%s/%s",dbus_object_path,inst[i]);
		object = object_skeleton_new (s);
		g_free (s);

		Flash* flash = flash_skeleton_new ();
		object_skeleton_set_flash (object, flash);
 		g_object_unref (flash);

		SharedResource* lock = shared_resource_skeleton_new ();
		object_skeleton_set_shared_resource (object, lock);
 		g_object_unref (lock);

		ObjectMapper* mapper = object_mapper_skeleton_new ();
		object_skeleton_set_object_mapper (object, mapper);
		g_object_unref (mapper);

		shared_resource_set_lock(lock,false);
		shared_resource_set_name(lock,"");

		flash_set_flasher_path(flash,flasher_file);
		flash_set_flasher_name(flash,FLASHER_BIN);
		flash_set_flasher_instance(flash,inst[i]);
		//g_free (s);


		//define method callbacks here
		g_signal_connect (lock,
                    "handle-lock",
                    G_CALLBACK (on_lock),
                    NULL); /* user_data */
		g_signal_connect (lock,
                    "handle-unlock",
                    G_CALLBACK (on_unlock),
                    NULL); /* user_data */
		g_signal_connect (lock,
                    "handle-is-locked",
                    G_CALLBACK (on_is_locked),
                    NULL); /* user_data */

		g_signal_connect (flash,
                    "handle-update",
                    G_CALLBACK (on_update),
                    object); /* user_data */

		g_signal_connect (flash,
                    "handle-error",
                    G_CALLBACK (on_error),
                    object); /* user_data */

		g_signal_connect (flash,
                    "handle-done",
                    G_CALLBACK (on_done),
                    object); /* user_data */

		g_signal_connect (flash,
                    "handle-update-via-tftp",
                    G_CALLBACK (on_update_via_tftp),
                    object); /* user_data */

		g_signal_connect (flash,
                    "handle-init",
                    G_CALLBACK (on_init),
                    object); /* user_data */

		s = g_strdup_printf ("/org/openbmc/control/%s",inst[i]);
		g_dbus_connection_signal_subscribe(connection,
                                   NULL,
                                   "org.openbmc.FlashControl",
                                   "Progress",
                                   s,
                                   NULL,
                                   G_DBUS_SIGNAL_FLAGS_NONE,
                                   (GDBusSignalCallback) on_flash_progress,
                                   object,
                                   NULL );

		g_free (s);

 
		flash_set_filename(flash,"");
		/* 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);
	}
	g_free(flasher_file);
	/* Export all objects */
	g_dbus_object_manager_server_set_connection (manager, connection);
	emit_object_added((GDBusObjectManager*)manager); 
}