Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-10-12 17:21:09 (GMT)
committer Tomeu Vizoso <tomeu.vizoso@collabora.co.uk>2010-08-18 18:08:32 (GMT)
commite337d3b26e9e1baa37fc63af8a2daa7fc92296e2 (patch)
treee9ba05b3a90ee77e0a96b10ab96598ec2bcc535f
parentaebe0f2de3440ba1511c122f23e64a46121a65cb (diff)
Add session classes to the typelib
-rw-r--r--src/sugar/Makefile.am6
-rw-r--r--src/sugar/gsm-client-xsmp.c170
-rw-r--r--src/sugar/gsm-client-xsmp.h14
-rw-r--r--src/sugar/gsm-xsmp.c4
4 files changed, 100 insertions, 94 deletions
diff --git a/src/sugar/Makefile.am b/src/sugar/Makefile.am
index dd3a22f..75bf407 100644
--- a/src/sugar/Makefile.am
+++ b/src/sugar/Makefile.am
@@ -27,7 +27,9 @@ public_headers = \
sexy-icon-entry.h \
eggsmclient.h \
acme-volume.h \
- acme-volume-alsa.h
+ acme-volume-alsa.h \
+ gsm-client.h \
+ gsm-client-xsmp.h
libsugarext_la_SOURCES = \
$(BUILT_SOURCES) \
@@ -36,9 +38,7 @@ libsugarext_la_SOURCES = \
acme-volume-alsa.c \
gsm-app.h \
gsm-app.c \
- gsm-client.h \
gsm-client.c \
- gsm-client-xsmp.h \
gsm-client-xsmp.c \
gsm-xsmp.h \
gsm-xsmp.c \
diff --git a/src/sugar/gsm-client-xsmp.c b/src/sugar/gsm-client-xsmp.c
index 632dec9..cfecc99 100644
--- a/src/sugar/gsm-client-xsmp.c
+++ b/src/sugar/gsm-client-xsmp.c
@@ -33,6 +33,18 @@
/* FIXME */
#define GsmDesktopFile "_Gsm_DesktopFile"
+struct _GsmClientXSMPPriv
+{
+ SmsConn conn;
+ IceConn ice_conn;
+
+ guint watch_id, protocol_timeout;
+
+ int current_save_yourself, next_save_yourself;
+ char *id, *description;
+ GPtrArray *props;
+};
+
static gboolean client_iochannel_watch (GIOChannel *channel,
GIOCondition condition,
gpointer data);
@@ -89,31 +101,31 @@ gsm_client_xsmp_class_init (GsmClientXSMPClass *klass)
}
GsmClientXSMP *
-gsm_client_xsmp_new (IceConn ice_conn)
+_gsm_client_xsmp_new (IceConn ice_conn)
{
GsmClientXSMP *xsmp;
GIOChannel *channel;
int fd;
xsmp = g_object_new (GSM_TYPE_CLIENT_XSMP, NULL);
- xsmp->props = g_ptr_array_new ();
+ xsmp->priv->props = g_ptr_array_new ();
- xsmp->ice_conn = ice_conn;
- xsmp->current_save_yourself = -1;
- xsmp->next_save_yourself = -1;
+ xsmp->priv->ice_conn = ice_conn;
+ xsmp->priv->current_save_yourself = -1;
+ xsmp->priv->next_save_yourself = -1;
fd = IceConnectionNumber (ice_conn);
fcntl (fd, F_SETFD, fcntl (fd, F_GETFD, 0) | FD_CLOEXEC);
channel = g_io_channel_unix_new (fd);
- xsmp->watch_id = g_io_add_watch (channel, G_IO_IN | G_IO_ERR,
+ xsmp->priv->watch_id = g_io_add_watch (channel, G_IO_IN | G_IO_ERR,
client_iochannel_watch, xsmp);
g_io_channel_unref (channel);
- xsmp->protocol_timeout = g_timeout_add_seconds (5, client_protocol_timeout, xsmp);
+ xsmp->priv->protocol_timeout = g_timeout_add_seconds (5, client_protocol_timeout, xsmp);
set_description (xsmp);
- g_debug ("New client '%s'", xsmp->description);
+ g_debug ("New client '%s'", xsmp->priv->description);
return xsmp;
}
@@ -123,18 +135,18 @@ xsmp_finalize (GObject *object)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *) object;
- g_debug ("xsmp_finalize (%s)", xsmp->description);
+ g_debug ("xsmp_finalize (%s)", xsmp->priv->description);
- if (xsmp->watch_id)
- g_source_remove (xsmp->watch_id);
+ if (xsmp->priv->watch_id)
+ g_source_remove (xsmp->priv->watch_id);
- if (xsmp->conn)
- SmsCleanUp (xsmp->conn);
+ if (xsmp->priv->conn)
+ SmsCleanUp (xsmp->priv->conn);
else
- IceCloseConnection (xsmp->ice_conn);
+ IceCloseConnection (xsmp->priv->ice_conn);
- if (xsmp->protocol_timeout)
- g_source_remove (xsmp->protocol_timeout);
+ if (xsmp->priv->protocol_timeout)
+ g_source_remove (xsmp->priv->protocol_timeout);
G_OBJECT_CLASS (gsm_client_xsmp_parent_class)->finalize (object);
}
@@ -147,19 +159,19 @@ client_iochannel_watch (GIOChannel *channel,
GsmClient *client = data;
GsmClientXSMP *xsmp = data;
- switch (IceProcessMessages (xsmp->ice_conn, NULL, NULL))
+ switch (IceProcessMessages (xsmp->priv->ice_conn, NULL, NULL))
{
case IceProcessMessagesSuccess:
return TRUE;
case IceProcessMessagesIOError:
- g_debug ("IceProcessMessagesIOError on '%s'", xsmp->description);
+ g_debug ("IceProcessMessagesIOError on '%s'", xsmp->priv->description);
gsm_client_disconnected (client);
return FALSE;
case IceProcessMessagesConnectionClosed:
g_debug ("IceProcessMessagesConnectionClosed on '%s'",
- xsmp->description);
+ xsmp->priv->description);
return FALSE;
default:
@@ -177,7 +189,7 @@ client_protocol_timeout (gpointer data)
GsmClientXSMP *xsmp = data;
g_debug ("client_protocol_timeout for client '%s' in ICE status %d",
- xsmp->description, IceConnectionStatus (xsmp->ice_conn));
+ xsmp->priv->description, IceConnectionStatus (xsmp->priv->ice_conn));
gsm_client_disconnected (client);
return FALSE;
@@ -193,7 +205,7 @@ register_client_callback (SmsConn conn,
char *id;
g_debug ("Client '%s' received RegisterClient(%s)",
- xsmp->description,
+ xsmp->priv->description,
previous_id ? previous_id : "NULL");
id = gsm_session_register_client (global_session, client, previous_id);
@@ -205,20 +217,20 @@ register_client_callback (SmsConn conn,
return FALSE;
}
- xsmp->id = id;
+ xsmp->priv->id = id;
set_description (xsmp);
- g_debug ("Sending RegisterClientReply to '%s'", xsmp->description);
+ g_debug ("Sending RegisterClientReply to '%s'", xsmp->priv->description);
- SmsRegisterClientReply (conn, xsmp->id);
+ SmsRegisterClientReply (conn, xsmp->priv->id);
if (!previous_id)
{
/* Send the initial SaveYourself. */
g_debug ("Sending initial SaveYourself");
SmsSaveYourself (conn, SmSaveLocal, False, SmInteractStyleNone, False);
- xsmp->current_save_yourself = SmSaveLocal;
+ xsmp->priv->current_save_yourself = SmSaveLocal;
free (previous_id);
}
@@ -229,36 +241,36 @@ register_client_callback (SmsConn conn,
static void
do_save_yourself (GsmClientXSMP *xsmp, int save_type)
{
- if (xsmp->next_save_yourself != -1)
+ if (xsmp->priv->next_save_yourself != -1)
{
/* Either we're currently doing a shutdown and there's a checkpoint
* queued after it, or vice versa. Either way, the new SaveYourself
* is redundant.
*/
g_debug (" skipping redundant SaveYourself for '%s'",
- xsmp->description);
+ xsmp->priv->description);
}
- else if (xsmp->current_save_yourself != -1)
+ else if (xsmp->priv->current_save_yourself != -1)
{
g_debug (" queuing new SaveYourself for '%s'",
- xsmp->description);
- xsmp->next_save_yourself = save_type;
+ xsmp->priv->description);
+ xsmp->priv->next_save_yourself = save_type;
}
else
{
- xsmp->current_save_yourself = save_type;
+ xsmp->priv->current_save_yourself = save_type;
switch (save_type)
{
case SmSaveLocal:
/* Save state */
- SmsSaveYourself (xsmp->conn, SmSaveLocal, FALSE,
+ SmsSaveYourself (xsmp->priv->conn, SmSaveLocal, FALSE,
SmInteractStyleNone, FALSE);
break;
default:
/* Logout */
- SmsSaveYourself (xsmp->conn, save_type, TRUE,
+ SmsSaveYourself (xsmp->priv->conn, save_type, TRUE,
SmInteractStyleAny, FALSE);
break;
}
@@ -277,7 +289,7 @@ save_yourself_request_callback (SmsConn conn,
GsmClientXSMP *xsmp = manager_data;
g_debug ("Client '%s' received SaveYourselfRequest(%s, %s, %s, %s, %s)",
- xsmp->description,
+ xsmp->priv->description,
save_type == SmSaveLocal ? "SmSaveLocal" :
save_type == SmSaveGlobal ? "SmSaveGlobal" : "SmSaveBoth",
shutdown ? "Shutdown" : "!Shutdown",
@@ -348,7 +360,7 @@ xsmp_save_yourself (GsmClient *client, gboolean save_state)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *)client;
- g_debug ("xsmp_save_yourself ('%s', %s)", xsmp->description,
+ g_debug ("xsmp_save_yourself ('%s', %s)", xsmp->priv->description,
save_state ? "True" : "False");
do_save_yourself (xsmp, save_state ? SmSaveBoth : SmSaveGlobal);
@@ -362,14 +374,14 @@ save_yourself_phase2_request_callback (SmsConn conn,
GsmClientXSMP *xsmp = manager_data;
g_debug ("Client '%s' received SaveYourselfPhase2Request",
- xsmp->description);
+ xsmp->priv->description);
- if (xsmp->current_save_yourself == SmSaveLocal)
+ if (xsmp->priv->current_save_yourself == SmSaveLocal)
{
/* WTF? Anyway, if it's checkpointing, it doesn't have to wait
* for anyone else.
*/
- SmsSaveYourselfPhase2 (xsmp->conn);
+ SmsSaveYourselfPhase2 (xsmp->priv->conn);
}
else
gsm_client_request_phase2 (client);
@@ -380,9 +392,9 @@ xsmp_save_yourself_phase2 (GsmClient *client)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *)client;
- g_debug ("xsmp_save_yourself_phase2 ('%s')", xsmp->description);
+ g_debug ("xsmp_save_yourself_phase2 ('%s')", xsmp->priv->description);
- SmsSaveYourselfPhase2 (xsmp->conn);
+ SmsSaveYourselfPhase2 (xsmp->priv->conn);
}
static void
@@ -393,7 +405,7 @@ interact_request_callback (SmsConn conn,
GsmClient *client = manager_data;
GsmClientXSMP *xsmp = manager_data;
- g_debug ("Client '%s' received InteractRequest(%s)", xsmp->description,
+ g_debug ("Client '%s' received InteractRequest(%s)", xsmp->priv->description,
dialog_type == SmInteractStyleAny ? "Any" : "Errors");
gsm_client_request_interaction (client);
@@ -404,9 +416,9 @@ xsmp_interact (GsmClient *client)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *) client;
- g_debug ("xsmp_interact ('%s')", xsmp->description);
+ g_debug ("xsmp_interact ('%s')", xsmp->priv->description);
- SmsInteract (xsmp->conn);
+ SmsInteract (xsmp->priv->conn);
}
static void
@@ -418,7 +430,7 @@ interact_done_callback (SmsConn conn,
GsmClientXSMP *xsmp = manager_data;
g_debug ("Client '%s' received InteractDone(cancel_shutdown = %s)",
- xsmp->description, cancel_shutdown ? "True" : "False");
+ xsmp->priv->description, cancel_shutdown ? "True" : "False");
gsm_client_interaction_done (client, cancel_shutdown);
}
@@ -428,9 +440,9 @@ xsmp_shutdown_cancelled (GsmClient *client)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *) client;
- g_debug ("xsmp_shutdown_cancelled ('%s')", xsmp->description);
+ g_debug ("xsmp_shutdown_cancelled ('%s')", xsmp->priv->description);
- SmsShutdownCancelled (xsmp->conn);
+ SmsShutdownCancelled (xsmp->priv->conn);
}
static void
@@ -438,9 +450,9 @@ xsmp_die (GsmClient *client)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *) client;
- g_debug ("xsmp_die ('%s')", xsmp->description);
+ g_debug ("xsmp_die ('%s')", xsmp->priv->description);
- SmsDie (xsmp->conn);
+ SmsDie (xsmp->priv->conn);
}
static void
@@ -452,25 +464,25 @@ save_yourself_done_callback (SmsConn conn,
GsmClientXSMP *xsmp = manager_data;
g_debug ("Client '%s' received SaveYourselfDone(success = %s)",
- xsmp->description, success ? "True" : "False");
+ xsmp->priv->description, success ? "True" : "False");
- if (xsmp->current_save_yourself == SmSaveLocal)
+ if (xsmp->priv->current_save_yourself == SmSaveLocal)
{
- xsmp->current_save_yourself = -1;
- SmsSaveComplete (xsmp->conn);
+ xsmp->priv->current_save_yourself = -1;
+ SmsSaveComplete (xsmp->priv->conn);
gsm_client_saved_state (client);
}
else
{
- xsmp->current_save_yourself = -1;
+ xsmp->priv->current_save_yourself = -1;
gsm_client_save_yourself_done (client);
}
- if (xsmp->next_save_yourself)
+ if (xsmp->priv->next_save_yourself)
{
- int save_type = xsmp->next_save_yourself;
+ int save_type = xsmp->priv->next_save_yourself;
- xsmp->next_save_yourself = -1;
+ xsmp->priv->next_save_yourself = -1;
do_save_yourself (xsmp, save_type);
}
}
@@ -485,7 +497,7 @@ close_connection_callback (SmsConn conn,
GsmClientXSMP *xsmp = manager_data;
int i;
- g_debug ("Client '%s' received CloseConnection", xsmp->description);
+ g_debug ("Client '%s' received CloseConnection", xsmp->priv->description);
for (i = 0; i < count; i++)
g_debug (" close reason: '%s'", reason_msgs[i]);
SmFreeReasons (count, reason_msgs);
@@ -532,9 +544,9 @@ find_property (GsmClientXSMP *client, const char *name, int *index)
SmProp *prop;
int i;
- for (i = 0; i < client->props->len; i++)
+ for (i = 0; i < client->priv->props->len; i++)
{
- prop = client->props->pdata[i];
+ prop = client->priv->props->pdata[i];
if (!strcmp (prop->name, name))
{
@@ -569,7 +581,7 @@ delete_property (GsmClientXSMP *client, const char *name)
gsm_client_run_discard (client);
#endif
- g_ptr_array_remove_index_fast (client->props, index);
+ g_ptr_array_remove_index_fast (client->priv->props, index);
SmFreeProperty (prop);
}
@@ -582,12 +594,12 @@ set_properties_callback (SmsConn conn,
GsmClientXSMP *client = manager_data;
int i;
- g_debug ("Set properties from client '%s'", client->description);
+ g_debug ("Set properties from client '%s'", client->priv->description);
for (i = 0; i < num_props; i++)
{
delete_property (client, props[i]->name);
- g_ptr_array_add (client->props, props[i]);
+ g_ptr_array_add (client->priv->props, props[i]);
debug_print_property (props[i]);
@@ -608,7 +620,7 @@ delete_properties_callback (SmsConn conn,
GsmClientXSMP *client = manager_data;
int i;
- g_debug ("Delete properties from '%s'", client->description);
+ g_debug ("Delete properties from '%s'", client->priv->description);
for (i = 0; i < num_props; i++)
{
@@ -626,10 +638,10 @@ get_properties_callback (SmsConn conn,
{
GsmClientXSMP *client = manager_data;
- g_debug ("Get properties request from '%s'", client->description);
+ g_debug ("Get properties request from '%s'", client->priv->description);
- SmsReturnProperties (conn, client->props->len,
- (SmProp **)client->props->pdata);
+ SmsReturnProperties (conn, client->priv->props->len,
+ (SmProp **)client->priv->props->pdata);
}
static const char *
@@ -637,7 +649,7 @@ xsmp_get_client_id (GsmClient *client)
{
GsmClientXSMP *xsmp = (GsmClientXSMP *) client;
- return xsmp->id;
+ return xsmp->priv->id;
}
static pid_t
@@ -756,33 +768,33 @@ set_description (GsmClientXSMP *client)
{
SmProp *prop = find_property (client, SmProgram, NULL);
- g_free (client->description);
+ g_free (client->priv->description);
if (prop)
{
- client->description = g_strdup_printf ("%p [%.*s %s]", client,
+ client->priv->description = g_strdup_printf ("%p [%.*s %s]", client,
prop->vals[0].length,
(char *)prop->vals[0].value,
- client->id);
+ client->priv->id);
}
- else if (client->id)
- client->description = g_strdup_printf ("%p [%s]", client, client->id);
+ else if (client->priv->id)
+ client->priv->description = g_strdup_printf ("%p [%s]", client, client->priv->id);
else
- client->description = g_strdup_printf ("%p", client);
+ client->priv->description = g_strdup_printf ("%p", client);
}
void
-gsm_client_xsmp_connect (GsmClientXSMP *client, SmsConn conn,
+_gsm_client_xsmp_connect (GsmClientXSMP *client, SmsConn conn,
unsigned long *mask_ret, SmsCallbacks *callbacks_ret)
{
- client->conn = conn;
+ client->priv->conn = conn;
- if (client->protocol_timeout)
+ if (client->priv->protocol_timeout)
{
- g_source_remove (client->protocol_timeout);
- client->protocol_timeout = 0;
+ g_source_remove (client->priv->protocol_timeout);
+ client->priv->protocol_timeout = 0;
}
- g_debug ("Initializing client %s", client->description);
+ g_debug ("Initializing client %s", client->priv->description);
*mask_ret = 0;
diff --git a/src/sugar/gsm-client-xsmp.h b/src/sugar/gsm-client-xsmp.h
index 46e34a5..b7c739e 100644
--- a/src/sugar/gsm-client-xsmp.h
+++ b/src/sugar/gsm-client-xsmp.h
@@ -35,19 +35,13 @@ G_BEGIN_DECLS
typedef struct _GsmClientXSMP GsmClientXSMP;
typedef struct _GsmClientXSMPClass GsmClientXSMPClass;
+typedef struct _GsmClientXSMPPriv GsmClientXSMPPriv;
struct _GsmClientXSMP
{
GsmClient parent;
- SmsConn conn;
- IceConn ice_conn;
-
- guint watch_id, protocol_timeout;
-
- int current_save_yourself, next_save_yourself;
- char *id, *description;
- GPtrArray *props;
+ GsmClientXSMPPriv *priv;
};
struct _GsmClientXSMPClass
@@ -58,9 +52,9 @@ struct _GsmClientXSMPClass
GType gsm_client_xsmp_get_type (void) G_GNUC_CONST;
-GsmClientXSMP *gsm_client_xsmp_new (IceConn ice_conn);
+GsmClientXSMP *_gsm_client_xsmp_new (IceConn ice_conn);
-void gsm_client_xsmp_connect (GsmClientXSMP *client,
+void _gsm_client_xsmp_connect (GsmClientXSMP *client,
SmsConn conn,
unsigned long *mask_ret,
SmsCallbacks *callbacks_ret);
diff --git a/src/sugar/gsm-xsmp.c b/src/sugar/gsm-xsmp.c
index aa9dff1..4f0a9a3 100644
--- a/src/sugar/gsm-xsmp.c
+++ b/src/sugar/gsm-xsmp.c
@@ -307,7 +307,7 @@ accept_ice_connection (GIOChannel *source,
return TRUE;
}
- client = gsm_client_xsmp_new (ice_conn);
+ client = _gsm_client_xsmp_new (ice_conn);
ice_conn->context = client;
return TRUE;
}
@@ -338,7 +338,7 @@ accept_xsmp_connection (SmsConn sms_conn, SmPointer manager_data,
g_return_val_if_fail (client != NULL, TRUE);
- gsm_client_xsmp_connect (client, sms_conn, mask_ret, callbacks_ret);
+ _gsm_client_xsmp_connect (client, sms_conn, mask_ret, callbacks_ret);
return TRUE;
}