summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-31 18:07:36 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2009-12-31 18:07:36 +0000
commit1fc9816fa509822525285dc2ce03b707111ceff8 (patch)
tree23938278433e0122de593a8540f237a2c85c75e9
parentdc30c9a81abef063f080c7e1ff1a9719b7a59e3a (diff)
downloadtelepathy-logger-1fc9816fa509822525285dc2ce03b707111ceff8.tar.gz
DBus service enhancements (still proto)
* fixed .service file generation in Makefile.am * implemented the basic (silly) code for LastMessages method, returning the last 5 lines of chat for the selected account+identifier * TODO: understand what type return (as?)
-rw-r--r--src/Makefile.am8
-rw-r--r--src/org.freedesktop.Telepathy.Client.TelepathyLogger.client2
-rw-r--r--src/org.freedesktop.Telepathy.TelepathyLoggerService.service.in2
-rw-r--r--src/test_api.c107
-rw-r--r--src/tpl-dbus-service.c104
-rw-r--r--src/tpl-dbus-service.h11
-rw-r--r--src/tpl-dbus-service.xml8
7 files changed, 138 insertions, 104 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 286dcac..122164e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,10 +85,10 @@ EXTRA_DIST = \
#Rule to generate the binding headers
tpl-dbus-service-server.h: tpl-dbus-service.xml
- dbus-binding-tool --prefix=tpl_dbus_service --mode=glib-server $<> $@
+ dbus-binding-tool --prefix=tpl_dbus_service --mode=glib-server $< > $@
tpl-dbus-service-client.h: tpl-dbus-service.xml
- dbus-binding-tool --prefix=tpl_dbus_service --mode=glib-client $<> $@
+ dbus-binding-tool --prefix=tpl_dbus_service --mode=glib-client $< > $@
# rules for making the glib enum objects
@@ -121,5 +121,5 @@ service_DATA = \
org.freedesktop.Telepathy.Client.TelepathyLogger.client
# Rule to make the service file with bindir expanded
-$(service_DATA): $(service_in_files) Makefile
- @sed -e "s|%bindir%|$(bindir)|" $<> $@
+%.service: %.service.in
+ sed -e "s|%bindir%|$(bindir)|" $< > $@
diff --git a/src/org.freedesktop.Telepathy.Client.TelepathyLogger.client b/src/org.freedesktop.Telepathy.Client.TelepathyLogger.client
index 21e6792..e34b892 100644
--- a/src/org.freedesktop.Telepathy.Client.TelepathyLogger.client
+++ b/src/org.freedesktop.Telepathy.Client.TelepathyLogger.client
@@ -1,3 +1,3 @@
[DBus Service]
-Name=org.freedesktop.Telepathy.Client.TelepathyLoggerDBusService
+Name=org.freedesktop.Telepathy.TelepathyLoggerService
Exec=/usr/local/bin/telepathy-logger-dbus
diff --git a/src/org.freedesktop.Telepathy.TelepathyLoggerService.service.in b/src/org.freedesktop.Telepathy.TelepathyLoggerService.service.in
index adab198..8831103 100644
--- a/src/org.freedesktop.Telepathy.TelepathyLoggerService.service.in
+++ b/src/org.freedesktop.Telepathy.TelepathyLoggerService.service.in
@@ -1,3 +1,3 @@
[DBus Service]
-Name=org.freedesktop.Telepathy.Client.TelepathyLoggerDBusService
+Name=org.freedesktop.Telepathy.TelepathyLoggerService
Exec=%bindir%/telepathy-logger-dbus
diff --git a/src/test_api.c b/src/test_api.c
index a2ae44f..0cdff38 100644
--- a/src/test_api.c
+++ b/src/test_api.c
@@ -20,79 +20,64 @@
*/
#include <glib.h>
-#include <stdio.h>
+//#include <stdio.h>
+//#include <dbus/dbus-glib-bindings.h>
-#include <tpl-log-manager.h>
-#include <telepathy-glib/account.h>
+//#include <tpl-log-manager.h>
+//#include <telepathy-glib/account.h>
#include <telepathy-glib/dbus.h>
-//static GMainLoop *loop = NULL;
+#include <tpl-dbus-service-client.h>
+#include <tpl-dbus-service.h>
-int main(int argc, char *argv[])
-{
- TplLogManager *manager;
- //GList *l;
- TpAccount *acc;
- //DBusGConnection *bus;
- TpDBusDaemon *tp_bus;
- GError *err=NULL;
- GList *lst;
- g_type_init ();
- //tpl_headless_logger_init ();
-
- //bus = tp_get_bus();
- tp_bus = tp_dbus_daemon_dup(&err);
- acc = tp_account_new(tp_bus,
- "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0",
- &err);
+static GMainLoop *loop = NULL;
- if(err) {
- g_debug(err->message);
- return 0;
+static void cb (DBusGProxy *proxy, char *OUT_str_ret, GError *error, gpointer userdata) {
+ if(error!=NULL) {
+ g_error("ERROR: %s\n", error->message);
+ return;
}
+ g_message("answer it: %s\n", OUT_str_ret);
+}
- manager = tpl_log_manager_dup_singleton ();
+int main(int argc, char *argv[])
+{
+ DBusGProxy *proxy;
+ gchar *result;
+ DBusGConnection *connection;
+ GError *error=NULL;
- lst = tpl_log_manager_search_in_identifier_chats_new(manager,
- acc, "echo@test.collabora.co.uk", "foo");
- for(;lst;lst=g_list_next(lst)) {
- TplLogSearchHit *hit = lst->data;
- g_message("HIT %s\n", hit->chat_id);
+ g_type_init ();
+ //connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ connection = tp_get_bus();
+ proxy = dbus_g_proxy_new_for_name (connection,
+ TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME,
+ TPL_DBUS_SRV_OBJECT_PATH,
+ TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME);
+
+
+ if (!org_freedesktop_Telepathy_TelepathyLoggerService_last_messages
+ (proxy, "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0", "echo@test.collabora.co.uk", FALSE, &result, &error))
+ {
+ g_warning ("Woops remote method failed: %s", error->message);
+ g_error_free (error);
+ return 1;
}
+ g_message("RESULT: %s\n", result);
+
+ if (!org_freedesktop_Telepathy_TelepathyLoggerService_last_messages_async
+ (proxy, "/org/freedesktop/Telepathy/Account/gabble/jabber/cosimo_2ealfarano_40collabora_2eco_2euk0", "echofoo", FALSE, cb, NULL))
+ {
+ g_warning ("Async Woops remote method failed: %s", error->message);
+ g_error_free (error);
+ return 1;
+ }
+// g_object_unref (proxy);
- tpl_log_manager_search_new(manager, "foo");
-
-
-
-/*
- l = tpl_log_manager_get_chats(manager, acc);
- int lenght = g_list_length(l);
- for(int i=0;i<lenght;++i) {
- TplLogSearchHit *hit = g_list_nth_data(l,i);
- g_debug("%d: %s\n", i, hit->filename);
- GList *gl;
-
- gl = tpl_log_manager_get_dates (manager, acc, hit->chat_id, hit->is_chatroom);
-
- for(guint ii=0;ii<g_list_length(gl);++ii) {
- GList *msgs;
- gchar *date = g_list_nth_data(gl, i);
- g_message(date);
- msgs = tpl_log_manager_get_messages_for_date(manager, acc, hit->chat_id,
- hit->is_chatroom, date);
- for(guint m=0;m<g_list_length(msgs);++m) {
- TplLogEntry *log = g_list_nth_data(msgs, m);
- TplLogEntryText *tlog = TPL_LOG_ENTRY_TEXT(tpl_log_entry_get_entry(log));
-
- g_message("BODY: %s\n", tpl_log_entry_text_get_message(tlog));
- }
- }
- }
-*/
- //loop = g_main_loop_new (NULL, FALSE);
- //g_main_loop_run (loop);
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
return 0;
}
diff --git a/src/tpl-dbus-service.c b/src/tpl-dbus-service.c
index f5af6cb..f838116 100644
--- a/src/tpl-dbus-service.c
+++ b/src/tpl-dbus-service.c
@@ -20,52 +20,24 @@
*/
#include <glib.h>
+#include <glib/gprintf.h>
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/account.h>
#include <tpl-dbus-service.h>
+#include <tpl-log-manager.h>
static gboolean
tpl_dbus_service_last_messages (TplDBusService *self,
gchar const* account_path, gchar const* identifier,
- gboolean is_chatroom, gint lines, gchar **str_ret);
+ gboolean is_chatroom, gchar **answer, GError **error);
#include <tpl-dbus-service-server.h>
G_DEFINE_TYPE (TplDBusService, tpl_dbus_service, G_TYPE_OBJECT)
-static gboolean
-tpl_dbus_service_last_messages (TplDBusService *self,
- gchar const* account_path, gchar const* identifier,
- gboolean is_chatroom, gint lines, gchar **str_ret)
-{
- TpAccount *account;
- DBusGConnection *dbus;
- TpDBusDaemon *tp_dbus;
- GError *error=NULL;
-
- g_message("TPL DBUS A: %s %s\n", account_path, identifier);
-
- dbus = tp_get_bus();
- tp_dbus = tp_dbus_daemon_new(dbus);
-
- account = tp_account_new(tp_dbus, account_path, &error);
- if (error!=NULL) {
- g_error("during TpAccount creation: %s\n",
- error->message);
- g_object_unref(tp_dbus);
- return FALSE;
- }
-
- str_ret = NULL;
- return TRUE;
-}
-
-
-
-
static void
tpl_dbus_service_finalize (GObject *obj)
{
@@ -100,6 +72,7 @@ tpl_dbus_service_class_init(TplDBusServiceClass* klass)
static void
tpl_dbus_service_init(TplDBusService* self)
{
+ self->manager = tpl_log_manager_dup_singleton ();
}
@@ -109,3 +82,72 @@ TplDBusService *tpl_dbus_service_new (void)
}
+static gboolean
+tpl_dbus_service_last_messages (TplDBusService *self,
+ gchar const* account_path, gchar const* identifier,
+ gboolean is_chatroom, gchar **answer, GError **error)
+{
+ TpAccount *account;
+ DBusGConnection *dbus;
+ TpDBusDaemon *tp_dbus;
+ GList *ret=NULL;
+ guint lines = 0;
+
+ g_message("TPL DBUS A: %s %s\n", account_path, identifier);
+
+ dbus = tp_get_bus();
+ tp_dbus = tp_dbus_daemon_new(dbus);
+
+ account = tp_account_new(tp_dbus, account_path, error);
+ if (!account) {
+ g_error("during TpAccount creation: %s\n",
+ (*error)->message);
+ g_object_unref(tp_dbus);
+ return FALSE;
+ }
+
+
+ GList *dates = tpl_log_manager_get_dates(self->manager, account, identifier, is_chatroom);
+ if(!dates) {
+ g_set_error(error,
+ TPL_DBUS_SERVICE_ERROR,
+ TPL_DBUS_SERVICE_ERROR_GENERIC,
+ "Error during date list retrieving");
+ return FALSE;
+ }
+
+ for(guint i=g_list_length(dates); i>0 && lines<=5; --i) {
+ gchar *date = g_list_nth_data(dates, i-1);
+ g_message("%d: %s\n", i, date);
+ GList *messages = tpl_log_manager_get_messages_for_date(self->manager,
+ account, identifier, is_chatroom, date);
+ gint msgs_len = g_list_length(messages);
+ // get the last 5 messages or less if lentgh<5
+ gint msg_guard = msgs_len>=6 ? 6 : 0;
+ for(gint m=msgs_len-1; m>=msg_guard && lines<=5; --m) {
+ TplLogEntry *entry = g_list_nth_data(messages, m);
+ g_message("CONSIDERING: %s\n", tpl_log_entry_text_get_message(entry->entry.text));
+ ret = g_list_append(ret, entry);
+ lines+=1;
+ }
+ }
+
+ for(guint i=0;i<g_list_length(ret);++i) {
+ TplLogEntry *entry = g_list_nth_data (ret, i);
+ g_message("RET %d: %s\n", i, tpl_log_entry_text_get_message( entry->entry.text));
+ }
+ *answer = g_strdup_printf("%s %s %s %s %s",
+ tpl_log_entry_text_get_message(((TplLogEntry*) g_list_nth_data(ret,0))->entry.text ),
+ tpl_log_entry_text_get_message(((TplLogEntry*) g_list_nth_data(ret,1))->entry.text ),
+ tpl_log_entry_text_get_message(((TplLogEntry*) g_list_nth_data(ret,2))->entry.text ),
+ tpl_log_entry_text_get_message(((TplLogEntry*) g_list_nth_data(ret,3))->entry.text ),
+ tpl_log_entry_text_get_message(((TplLogEntry*) g_list_nth_data(ret,4))->entry.text )
+ );
+ return TRUE;
+}
+
+GQuark
+tpl_dbus_service_error_quark (void)
+{
+ return g_quark_from_static_string ("tpl-dbus-service-error-quark");
+}
diff --git a/src/tpl-dbus-service.h b/src/tpl-dbus-service.h
index 7e08c51..4d13c21 100644
--- a/src/tpl-dbus-service.h
+++ b/src/tpl-dbus-service.h
@@ -23,11 +23,12 @@
#define __TPL_DBUS_SERVICE_H__
#define TPL_DBUS_SRV_WELL_KNOWN_BUS_NAME \
- "org.freedesktop.Telepathy..TelepathyLoggerService"
+ "org.freedesktop.Telepathy.TelepathyLoggerService"
#define TPL_DBUS_SRV_OBJECT_PATH \
"/org/freedesktop/Telepathy/TelepathyLoggerService"
#include <glib-object.h>
+#include <tpl-log-manager.h>
G_BEGIN_DECLS
@@ -38,11 +39,19 @@ G_BEGIN_DECLS
#define TPL_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TPL_TYPE_DBUS_SERVICE))
#define TPL_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_DBUS_SERVICE, TplDBusServiceClass))
+#define TPL_DBUS_SERVICE_ERROR tpl_dbus_service_error_quark ()
+GQuark
+tpl_dbus_service_error_quark (void);
+
+typedef enum {
+ TPL_DBUS_SERVICE_ERROR_GENERIC
+} TplDBusServiceErrorCode;
typedef struct {
GObject parent;
/* Private */
+ TplLogManager *manager;
} TplDBusService;
typedef struct {
diff --git a/src/tpl-dbus-service.xml b/src/tpl-dbus-service.xml
index f801041..425a3c5 100644
--- a/src/tpl-dbus-service.xml
+++ b/src/tpl-dbus-service.xml
@@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<node name="/org/freedesktop/Telepathy/Client/TelepathyLoggerDBusService">
- <interface name="org.freedesktop.Telepathy.Client.TelepathyLoggerDBusService">
- <annotation name="org.freedesktop.DBus.GLib.Asyn" value=""/>
+<node name="/org/freedesktop/Telepathy/TelepathyLoggerService">
+ <interface name="org.freedesktop.Telepathy.TelepathyLoggerService">
<method name="LastMessages">
<arg type="o" name="account" direction="in" />
<arg type="s" name="identifier" direction="in" />
<arg type="b" name="is_chatroom" direction="in" />
- <arg type="i" name="lines" direction="in" />
- <arg type="as" name="str_ret" direction="out" />
+ <arg type="s" name="answer" direction="out" />
</method>
</interface>
</node>