00001 #include <gtask/gtask-packet.h>
00002
00005
00006
00007 static gpointer parent_class;
00008
00009 static void
00010 gtask_packet_init( GTaskPacket *packet, gpointer g_class );
00011
00012 static void
00013 gtask_packet_class_init( GTaskPacketClass *klass );
00014
00015 static void
00016 gtask_packet_dispose( GObject *packet );
00017
00018 static void
00019 gtask_packet_finalize( GObject *packet );
00020
00021 GType gtask_packet_get_type( ) {
00022 static GType type = 0;
00023
00024 if( type == 0 ) {
00025 static const GTypeInfo info = {
00026 sizeof( GTaskPacketClass ),
00027 NULL,
00028 NULL,
00029 (GClassInitFunc) gtask_packet_class_init,
00030 NULL,
00031 NULL,
00032 sizeof( GTaskPacket ),
00033 0,
00034 (GInstanceInitFunc) gtask_packet_init
00035 };
00036
00037 type = g_type_register_static( G_TYPE_OBJECT,
00038 "GTaskPacket",
00039 &info,
00040 0 );
00041 }
00042
00043 return type;
00044 }
00045
00046 static void
00047 gtask_packet_init( GTaskPacket *packet, gpointer g_class ) {
00048 packet->private = g_new0( GTaskPacketPrivate, 1 );
00049
00050 packet->private->conn_group = NULL;
00051 }
00052
00053 static void
00054 gtask_packet_class_init( GTaskPacketClass *klass ) {
00055 GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00056
00057 parent_class = g_type_class_peek_parent( klass );
00058
00059 gobject_class->dispose = gtask_packet_dispose;
00060 gobject_class->finalize = gtask_packet_finalize;
00061
00062 klass->serialize_packet = NULL;
00063 }
00064
00065 static void
00066 gtask_packet_dispose( GObject *obj ) {
00067 GTaskPacket *packet = GTASK_PACKET( obj );
00068
00069 if( packet->private->dispose_has_run )
00070 return;
00071
00072 g_object_unref( packet->private->conn_group );
00073
00074 packet->private->conn_group = NULL;
00075
00076 packet->private->dispose_has_run = TRUE;
00077
00078 if( G_OBJECT_CLASS( parent_class )->dispose )
00079 G_OBJECT_CLASS( parent_class )->dispose( obj );
00080 }
00081
00082 static void
00083 gtask_packet_finalize( GObject *obj ) {
00084 GTaskPacket *packet = GTASK_PACKET( obj );
00085
00086 g_free( packet->private );
00087
00088 if( G_OBJECT_CLASS( parent_class )->finalize )
00089 G_OBJECT_CLASS( parent_class )->finalize( obj );
00090 }
00091
00102 gboolean
00103 gtask_packet_serialize( GTaskPacket *packet ) {
00104 GSList *conns;
00105 gboolean ret = TRUE;
00106
00107 g_return_val_if_fail( GTASK_IS_PACKET( packet ), FALSE );
00108 g_return_val_if_fail( !packet->private->dispose_has_run, FALSE );
00109
00110 conns = gtask_connection_group_get_list( packet->private->conn_group );
00111
00112 while( conns ) {
00113 if( !gtask_packet_serialize_to( packet, (GTaskConnection *) conns->data ) )
00114 ret = FALSE;
00115
00116 conns = g_slist_next( conns );
00117 }
00118
00119 return ret;
00120 }
00121
00132 gboolean
00133 gtask_packet_serialize_to( GTaskPacket *packet, GTaskConnection *conn ) {
00134 g_return_val_if_fail( GTASK_IS_PACKET( packet ), FALSE );
00135 g_return_val_if_fail( GTASK_IS_CONNECTION( conn ), FALSE );
00136
00137 if( !GTASK_PACKET_GET_CLASS(packet)->serialize_packet ) {
00138 g_warning( "GTASK_PACKET_GET_CLASS(packet)->serialize_packet is NULL. Perhaps this packet type was not properly subclassed?" );
00139
00140 return FALSE;
00141 }
00142
00143 return GTASK_PACKET_GET_CLASS(packet)->serialize_packet( packet, conn );
00144 }
00145
00158 GTaskConnectionGroup *
00159 gtask_packet_get_connection_group( GTaskPacket *packet ) {
00160 g_return_val_if_fail( GTASK_IS_PACKET( packet ),
00161 gtask_connection_group_new( ) );
00162
00163 return packet->private->conn_group;
00164 }
00165
00177 void
00178 gtask_packet_set_connection_group( GTaskPacket *packet,
00179 GTaskConnectionGroup *conn_group ) {
00180 g_return_if_fail( GTASK_IS_PACKET( packet ) );
00181 g_return_if_fail( GTASK_IS_CONNECTION_GROUP( conn_group ) );
00182
00183 if( packet->private->conn_group )
00184 g_object_unref( packet->private->conn_group );
00185
00186 g_object_ref( conn_group );
00187
00188 packet->private->conn_group = conn_group;
00189 }
00190
00191