00001 #include <gtask/gtask-remove-watch-packet.h>
00002
00005
00006
00007 enum {
00008 PROP_0,
00009 PROP_WATCH_ID
00010 };
00011
00012 static gpointer parent_class = NULL;
00013
00014 static void
00015 gtask_remove_watch_packet_class_init( GTaskRemoveWatchPacketClass *klass );
00016
00017 static void
00018 gtask_remove_watch_packet_init( GTaskRemoveWatchPacket *packet,
00019 gpointer g_class );
00020
00021 static void
00022 gtask_remove_watch_packet_finalize( GObject *packet );
00023
00024 static gboolean
00025 gtask_remove_watch_packet_serialize_to( GTaskPacket *packet,
00026 GTaskConnection *conn );
00027
00028
00029 static void
00030 gtask_remove_watch_packet_set_property( GObject *object,
00031 guint param_id,
00032 const GValue *value,
00033 GParamSpec *pspec );
00034
00035 static void
00036 gtask_remove_watch_packet_get_property( GObject *object,
00037 guint param_id,
00038 GValue *value,
00039 GParamSpec *pspec );
00040
00041 GType gtask_remove_watch_packet_get_type( void ) {
00042 static GType type = 0;
00043
00044 if( type == 0 ) {
00045 static const GTypeInfo info = {
00046 sizeof( GTaskRemoveWatchPacketClass ),
00047 NULL,
00048 NULL,
00049 (GClassInitFunc) gtask_remove_watch_packet_class_init,
00050 NULL,
00051 NULL,
00052 sizeof( GTaskRemoveWatchPacket ),
00053 0,
00054 (GInstanceInitFunc) gtask_remove_watch_packet_init
00055 };
00056
00057 type = g_type_register_static( GTASK_PACKET_TYPE,
00058 "GTaskRemoveWatchPacket",
00059 &info,
00060 0 );
00061 }
00062
00063 return type;
00064 }
00065
00066 static void
00067 gtask_remove_watch_packet_class_init( GTaskRemoveWatchPacketClass *klass ) {
00068 GObjectClass *gobject_class = G_OBJECT_CLASS( klass );
00069 GTaskPacketClass *packet_class = GTASK_PACKET_CLASS( klass );
00070
00071 parent_class = g_type_class_peek_parent( klass );
00072
00073 gobject_class->finalize = gtask_remove_watch_packet_finalize;
00074 gobject_class->set_property = gtask_remove_watch_packet_set_property;
00075 gobject_class->get_property = gtask_remove_watch_packet_get_property;
00076
00077 packet_class->serialize_packet = gtask_remove_watch_packet_serialize_to;
00078
00079 g_object_class_install_property( (GObjectClass *) klass,
00080 PROP_WATCH_ID,
00081 g_param_spec_string( "watch-id",
00082 "Watch Id",
00083 "The identifier of the watch that is to be removed",
00084 "",
00085 G_PARAM_READWRITE ) );
00086 }
00087
00088 static void
00089 gtask_remove_watch_packet_init( GTaskRemoveWatchPacket *packet,
00090 gpointer g_class )
00091 {
00092 packet->private = g_new0( GTaskRemoveWatchPacketPrivate, 1 );
00093
00094 packet->private->watch_id = g_string_new( NULL );
00095 }
00096
00097 static void
00098 gtask_remove_watch_packet_finalize( GObject *obj ) {
00099 GTaskRemoveWatchPacket *packet = GTASK_REMOVE_WATCH_PACKET( obj );
00100
00101 g_string_free( packet->private->watch_id, TRUE );
00102
00103 g_free( packet->private );
00104
00105 if( G_OBJECT_CLASS( parent_class )->finalize )
00106 G_OBJECT_CLASS( parent_class )->finalize( obj );
00107 }
00108
00109 static void
00110 gtask_remove_watch_packet_set_property( GObject *object,
00111 guint param_id,
00112 const GValue *value,
00113 GParamSpec *pspec )
00114 {
00115 GTaskRemoveWatchPacket *packet = GTASK_REMOVE_WATCH_PACKET( object );
00116
00117 switch( param_id ) {
00118 case PROP_WATCH_ID:
00119 gtask_remove_watch_packet_set_watch_id( packet,
00120 g_value_get_string( value ) );
00121 break;
00122 default:
00123 G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00124 }
00125 }
00126
00127 static void
00128 gtask_remove_watch_packet_get_property( GObject *object,
00129 guint param_id,
00130 GValue *value,
00131 GParamSpec *pspec )
00132 {
00133 GTaskRemoveWatchPacket *packet = GTASK_REMOVE_WATCH_PACKET( object );
00134
00135 switch( param_id ) {
00136 case PROP_WATCH_ID:
00137 g_value_set_string( value, packet->private->watch_id->str );
00138 break;
00139 default:
00140 G_OBJECT_WARN_INVALID_PROPERTY_ID( object, param_id, pspec );
00141 }
00142 }
00143
00158 static gboolean
00159 gtask_remove_watch_packet_serialize_to( GTaskPacket *packet,
00160 GTaskConnection *conn )
00161 {
00162 GTaskRemoveWatchPacket *g_packet;
00163 xmlOutputBufferPtr xml_output;
00164 xmlDocPtr doc;
00165 xmlNodePtr node;
00166
00167 g_return_val_if_fail( GTASK_IS_REMOVE_WATCH_PACKET( packet ), FALSE );
00168 g_return_val_if_fail( GTASK_IS_CONNECTION( conn ), FALSE );
00169 g_return_val_if_fail( gtask_connection_is_connected( conn ), FALSE );
00170
00171 g_packet = ( GTaskRemoveWatchPacket * ) packet;
00172
00173 doc = xmlNewDoc( "1.0" );
00174
00175 if( !doc )
00176 return FALSE;
00177
00178 node = xmlNewNode( NULL, "remove-watch" );
00179
00180 if( !node ) {
00181 xmlFreeDoc( doc );
00182
00183 return FALSE;
00184 }
00185
00186 xmlDocSetRootElement( doc, node );
00187 if( !xmlNewProp( node, "id", g_packet->private->watch_id->str ) ) {
00188 xmlFreeDoc( doc );
00189
00190 return FALSE;
00191 }
00192
00193 xml_output = gtask_connection_get_xml_output_buffer( conn );
00194 xmlNodeDumpOutput( xml_output, doc, node, 1, 0, NULL );
00195 xmlOutputBufferFlush( xml_output );
00196
00197 xmlFreeDoc( doc );
00198
00199 return TRUE;
00200 }
00201
00209 GTaskRemoveWatchPacket *
00210 gtask_remove_watch_packet_new( ) {
00211 return g_object_new( GTASK_REMOVE_WATCH_PACKET_TYPE, NULL );
00212 }
00213
00223 GTaskRemoveWatchPacket *
00224 gtask_remove_watch_packet_new_with_watch_id( const char *watch_id ) {
00225 GTaskRemoveWatchPacket *packet = gtask_remove_watch_packet_new( );
00226
00227 gtask_remove_watch_packet_set_watch_id( packet, watch_id );
00228
00229 return packet;
00230 }
00231
00241 const char *
00242 gtask_remove_watch_packet_get_watch_id( GTaskRemoveWatchPacket *packet ) {
00243 g_return_val_if_fail( GTASK_IS_REMOVE_WATCH_PACKET( packet ), "" );
00244
00245 return packet->private->watch_id->str;
00246 }
00247
00256 void
00257 gtask_remove_watch_packet_set_watch_id( GTaskRemoveWatchPacket *packet,
00258 const char *watch_id )
00259 {
00260 g_return_if_fail( GTASK_IS_REMOVE_WATCH_PACKET( packet ) );
00261 g_return_if_fail( watch_id != NULL );
00262
00263 g_string_assign( packet->private->watch_id, watch_id );
00264
00265 g_object_notify( (GObject *) packet, "watch-id" );
00266 }
00267
00268