LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-12-2011, 04:25 AM   #1
deepa@tcs
LQ Newbie
 
Registered: Dec 2011
Posts: 1

Rep: Reputation: Disabled
Objec and service registration in dbus.


Hi
Iam new to dbus and i want to register object and service to dbus using c code.
I tried with some example code but none of them is registering the object and hence i cant call those methods remotely.
Can any one help me in this?
My server side code is as follows:

#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-bindings.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
int hello_alarm_alarm_example_callapi(int a);
#include "hello_alarm.h"

typedef struct
{

DBusGConnection *bus;
} AppData;

/* Define new GObject structure
* HelloAlarm */
typedef struct
{
GObject parent;
/* Define a pointer to store
* appdata */
AppData *appdata;
} HelloAlarm;

/* Define HelloAlarm's class */
typedef struct
{
GObjectClass parent;

/* HelloAlarm's say_hello-method.
* This will be registered as a DBUS-method */
int (*alarm_example_callapi)(int a);
} HelloAlarmClass;

static void hello_alarm_class_init(HelloAlarmClass *klass)
{
/* Define implementation location of the
* say_hello-method */
klass->alarm_example_callapi =hello_alarm_alarm_example_callapi;
}
GType hello_alarm_get_type()
{
static GType type = 0;
/* If the type is already registered,
* return it, otherwise register the
* GTypeInfoStructure */
if(!type)
{
static const GTypeInfo info =
{
sizeof(HelloAlarmClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc)hello_alarm_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(HelloAlarm),
0, /* n_preallocs */
NULL, /* instance_init */
};

type = g_type_register_static(G_TYPE_OBJECT, "HelloAlarmType",
&info, 0);
}

return type;
}


static gboolean
register_service(DBusGConnection *bus, GObject *obj,
const DBusGObjectInfo *info,
gchar *name, gchar *path, GError **error)
{
DBusGProxy *system;
gboolean result;
guint request_name_result;
/* Install GObject's info so glib knows
* what kind of interface to present on
* D-BUS */

/* Register the object to D-BUS using
* given object path */

dbus_g_object_type_install_info(G_TYPE_FROM_INSTANCE(obj),info);
dbus_g_connection_register_g_object(bus,
path, obj);
/* Get proxy D-BUS-service */
system = dbus_g_proxy_new_for_name(bus,
"org.maemo.alarm_example",
"/org/maemo/alarm_example",
"org.maemo.alarm_example");

/* system=dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");*/


/* if (!dbus_g_proxy_call (system, "RequestName", &error,
G_TYPE_STRING, "org.designfu.SampleService",
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
printf("Failed to acquire org.designfu.SampleService %s", error); */

/* Request a name for the service from D-BUS */
/*result = org_freedesktop_DBus_request_name(system,
"org.designfu.SampleService", DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL, error);*/
result = org_freedesktop_DBus_request_name(system,
name, 0, NULL, error);
dbus_g_connection_register_g_object(bus,
"/", obj);



/* Check that the name request went OK */
if(!result)
{
g_debug("result is false");

g_object_unref(system);
return FALSE;
}

g_object_unref(system);
return TRUE;
}

int hello_alarm_alarm_example_callapi(int a)
{
printf("HERE IS VALUE %d\n",a);
return 1;
}

int main(int argc,char **argv)
{
GError *error = NULL;
AppData appdata;
HelloAlarm *server;
g_type_init();

//conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
appdata.bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (appdata.bus == NULL) {
g_warning("Error %s\n", error->message);
g_error_free(error);
return 1;
}
else
{
g_debug("conn object is %d\n", appdata.bus);
}




server = g_object_new(hello_alarm_get_type(), NULL);

server->appdata = &appdata;
register_service(appdata.bus, G_OBJECT(server),
&dbus_glib_hello_alarm_object_info,
"org.maemo.alarm_example",
"/org/maemo/alarm_example", &error);


/* Check that the registration was successfull */

if(error)
{
g_error("Couldn't register service: %s", error->message);
g_error_free(error);
return 1;
}

dbus_g_connection_unref(appdata.bus);


return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to obtain the dependencies of a dbus service? ajaygarg Linux - Newbie 0 10-26-2011 01:17 PM
LXer: Firewire Audio on Linux: Fixing FFADO dbus-service Errors LXer Syndicated Linux News 0 07-14-2010 02:10 PM
boot up error on /var/log/messages [server.ERROR] cannot start systen DBus service junust Linux - General 0 08-04-2009 04:55 AM
dbus as IPC for web service problem kannerke Programming 1 03-25-2009 09:59 AM
Fedora Core 9 update dbus.exception & dbus.proxies & DBus.Error.AccessDenied errors trien27 Fedora 1 12-08-2008 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration