00001 #include <gtask/gtask-watch-packet.h>
00002
00005
00006
00007 gpointer parent_class;
00008
00009 static void
00010 gtask_watch_packet_class_init( GTaskWatchPacketClass *klass );
00011
00012 static void
00013 gtask_watch_packet_init( GTaskWatchPacket *packet, gpointer g_class );
00014
00015 static void
00016 gtask_watch_packet_finalize( GObject *packet );
00017
00018 static gboolean
00019 gtask_watch_packet_serialize_to( GTaskPacket *packet,
00020 GTaskConnection *conn );
00021
00022
00023 GType gtask_watch_packet_get_type( void ) {
00024 static GType type = 0;
00025
00026 if( type == 0 ) {
00027 static const GTypeInfo info = {
00028 sizeof( GTaskWatchPacketClass ),
00029 NULL,
00030 NULL,
00031 (GClassInitFunc) gtask_watch_packet_class_init,
00032 NULL,
00033 NULL,
00034 sizeof( GTaskWatchPacket ),
00035 0,
00036 (GInstanceInitFunc) gtask_watch_packet_init
00037 };
00038
00039 type = g_type_register_static( GTASK_PACKET_TYPE,
00040 "GTaskWatchPacket",
00041 &info,
00042 0 );
00043 }
00044
00045 return type;
00046 }
00047
00048 static void
00049 gtask_watch_packet_class_init( GTaskWatchPacketClass *klass ) {
00050 GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00051 GTaskPacketClass *packet_class = GTASK_PACKET_CLASS( klass );
00052
00053 parent_class = g_type_class_peek_parent( klass );
00054
00055 gobject_class->finalize = gtask_watch_packet_finalize;
00056
00057 packet_class->serialize_packet = gtask_watch_packet_serialize_to;
00058 }
00059
00060 static void
00061 gtask_watch_packet_init( GTaskWatchPacket *packet, gpointer g_class ) {
00062 packet->private = g_new0( GTaskWatchPacketPrivate, 1 );
00063
00064 packet->private->watch_id = g_string_new( NULL );
00065 }
00066
00067 static void
00068 gtask_watch_packet_finalize( GObject *obj ) {
00069 GTaskWatchPacket *packet = GTASK_WATCH_PACKET( obj );
00070
00071 g_string_free( packet->private->watch_id, TRUE );
00072
00073 g_free( packet->private );
00074
00075 if( G_OBJECT_CLASS( parent_class )->finalize )
00076 G_OBJECT_CLASS( parent_class )->finalize( obj );
00077 }
00078
00093 static gboolean
00094 gtask_watch_packet_serialize_to( GTaskPacket *packet,
00095 GTaskConnection *conn )
00096 {
00097 GTaskWatchPacket *w_packet;
00098 xmlOutputBufferPtr xml_output;
00099 xmlDocPtr doc;
00100 xmlNodePtr watch_node;
00101
00102 g_return_val_if_fail( GTASK_IS_WATCH_PACKET( packet ), FALSE );
00103 g_return_val_if_fail( GTASK_IS_CONNECTION( conn ), FALSE );
00104 g_return_val_if_fail( gtask_connection_is_connected( conn ), FALSE );
00105
00106 w_packet = (GTaskWatchPacket *) packet;
00107
00108 doc = xmlNewDoc( "1.0" );
00109
00110 if( !doc )
00111 return FALSE;
00112
00113 watch_node = xmlNewNode( NULL, "watch" );
00114
00115 if( !watch_node ) {
00116 xmlFreeDoc( doc );
00117
00118 return FALSE;
00119 }
00120
00121 xmlDocSetRootElement( doc, watch_node );
00122
00123 if( !xmlNewProp( watch_node, "id", w_packet->private->watch_id->str ) ) {
00124 xmlFreeDoc( doc );
00125
00126 return FALSE;
00127 }
00128
00129
00130 xml_output = gtask_connection_get_xml_output_buffer( conn );
00131 xmlNodeDumpOutput( xml_output, doc, watch_node, 1, 0, NULL );
00132 xmlOutputBufferFlush( xml_output );
00133
00134 xmlFreeDoc( doc );
00135
00136 return TRUE;
00137 }
00138
00146 GTaskWatchPacket *
00147 gtask_watch_packet_new( ) {
00148 return g_object_new( GTASK_WATCH_PACKET_TYPE, NULL );
00149 }
00150
00160 GTaskWatchPacket *
00161 gtask_watch_packet_new_with_watch_id( const char *watch_id ) {
00162 GTaskWatchPacket *packet = gtask_watch_packet_new( );
00163
00164 gtask_watch_packet_set_watch_id( packet, watch_id );
00165
00166 return packet;
00167 }
00168
00178 const char *
00179 gtask_watch_packet_get_watch_id( GTaskWatchPacket *packet ) {
00180 g_return_val_if_fail( GTASK_IS_WATCH_PACKET( packet ), "" );
00181
00182 return packet->private->watch_id->str;
00183 }
00184
00193 void
00194 gtask_watch_packet_set_watch_id( GTaskWatchPacket *packet, const char *watch_id )
00195 {
00196 g_return_if_fail( GTASK_IS_WATCH_PACKET( packet ) );
00197
00198 g_string_assign( packet->private->watch_id, watch_id );
00199
00201
00202 }
00203
00204