Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

gtask-role-packet.c

Go to the documentation of this file.
00001 #include <string.h>
00002 #include <gtask/gtask-role-packet.h>
00003 
00006 /* @{ */
00007 
00008 static gpointer parent_class = NULL;
00009 
00010 static void
00011 gtask_role_packet_class_init( GTaskRolePacketClass *klass );
00012 
00013 static void
00014 gtask_role_packet_init( GTaskRolePacket *packet, gpointer g_class );
00015 
00016 static void
00017 gtask_role_packet_finalize( GObject *obj );
00018 
00019 static gboolean
00020 gtask_role_packet_serialize_to( GTaskPacket *packet,
00021                                 GTaskConnection *conn );
00022 
00023 /*
00024 static void
00025 gtask_role_packet_set_property( GObject *object,
00026                                 guint param_id,
00027                                 const GValue *value,
00028                                 GParamSpec *pspec  );
00029 
00030 static void
00031 gtask_role_packet_get_property( GObject *object,
00032                                 guint param_id,
00033                                 const GValue *value,
00034                                 GParamSpec *pspec  );
00035 */
00036 
00037 GType gtask_activity_state_get_type( ) {
00038     static GType type = 0;
00039 
00040     if( type == 0 ) {
00041         static const GEnumValue values[] = {
00042             { GTASK_ROLE_NONE, "GTASK_ROLE_NONE", "none" },
00043             { GTASK_ROLE_NONE, "GTASK_ROLE_PROXY", "proxy" },
00044             { GTASK_ROLE_NONE, "GTASK_ROLE_REPORTER", "reporter" },
00045             { GTASK_ROLE_NONE, "GTASK_ROLE_PROVIDER", "provider" },
00046             { 0, NULL, NULL }
00047         };
00048 
00049         type = g_enum_register_static( "GTaskRole", values );
00050     }
00051 
00052     return type;
00053 }
00054 
00055 
00056 GType gtask_role_packet_get_type( void ) {
00057     static GType type = 0;
00058 
00059     if( type == 0 ) {
00060         static const GTypeInfo info = {
00061             sizeof( GTaskRolePacketClass ),
00062             NULL,   /* base_init */
00063             NULL,   /* base_finalize */
00064             (GClassInitFunc) gtask_role_packet_class_init,  /* class_init */
00065             NULL,   /* class_finalize */
00066             NULL,   /* class_data */
00067             sizeof( GTaskRolePacket ),
00068             0,      /* n_preallocs */
00069             (GInstanceInitFunc) gtask_role_packet_init
00070         };
00071 
00072         type = g_type_register_static( GTASK_PACKET_TYPE,
00073                                        "GTaskRolePacket",
00074                                        &info,
00075                                        0 );
00076     }
00077 
00078     return type;
00079 }
00080 
00081 static void
00082 gtask_role_packet_class_init( GTaskRolePacketClass *klass ) {
00083     GObjectClass     *gobject_class = G_OBJECT_CLASS( klass );
00084     GTaskPacketClass *packet_class = GTASK_PACKET_CLASS( klass );
00085 
00086     parent_class = g_type_class_peek_parent( klass );
00087 
00088     gobject_class->finalize = gtask_role_packet_finalize;
00089     /*
00090     gobject_class->set_property = gtask_role_packet_set_property;
00091     gobject_class->get_property = gtask_role_packet_get_property;
00092     */
00093 
00094     packet_class->serialize_packet = gtask_role_packet_serialize_to;
00095 }
00096 
00097 static void
00098 gtask_role_packet_init( GTaskRolePacket *packet, gpointer g_class ) {
00099     packet->private = g_new0( GTaskRolePacketPrivate, 1 );
00100 
00101     packet->private->role = GTASK_ROLE_NONE;
00102 }
00103 
00104 static void
00105 gtask_role_packet_finalize( GObject *obj ) {
00106     GTaskRolePacket *packet = GTASK_ROLE_PACKET( obj );
00107 
00108     g_free( packet->private );
00109 
00110     if( G_OBJECT_CLASS( parent_class )->finalize )
00111         G_OBJECT_CLASS( parent_class )->finalize( obj );
00112 }
00113 
00128 static gboolean
00129 gtask_role_packet_serialize_to( GTaskPacket *packet,
00130                                 GTaskConnection *conn )
00131 {
00132     GTaskRolePacket    *r_packet;
00133     xmlOutputBufferPtr  xml_output;
00134     xmlDocPtr           doc;
00135     xmlNodePtr          role_node;
00136     xmlNodePtr          role;
00137 
00138     g_return_val_if_fail( GTASK_IS_ROLE_PACKET( packet ), FALSE );
00139     g_return_val_if_fail( GTASK_IS_CONNECTION( conn ), FALSE );
00140     g_return_val_if_fail( gtask_connection_is_connected( conn ), FALSE );
00141 
00142     r_packet = (GTaskRolePacket *) packet;
00143 
00144     doc = xmlNewDoc( "1.0" );
00145 
00146     if( !doc )
00147         return FALSE;
00148 
00149     role_node = xmlNewNode( NULL, "role" );
00150 
00151     if( !role_node ) {
00152         xmlFreeDoc( doc );
00153 
00154          return FALSE;
00155     }
00156 
00157     xmlDocSetRootElement( doc, role_node );
00158 
00159     role = xmlNewText( gtask_role_packet_get_role_name( r_packet ) );
00160 
00161     if( !role ) {
00162         xmlFreeDoc( doc );
00163 
00164         return FALSE;
00165     }
00166 
00167     xmlAddChild( role_node, role );
00168 
00169     xml_output = gtask_connection_get_xml_output_buffer( conn );
00170     xmlNodeDumpOutput( xml_output, doc, role_node, 1, 0, NULL );
00171     xmlOutputBufferFlush( xml_output );
00172 
00173     xmlFreeDoc( doc );
00174 
00175     return TRUE;
00176 }
00177 
00185 GTaskRolePacket *
00186 gtask_role_packet_new( void ) {
00187     g_warning( "GTaskRolePacket has been deprecated. GTaskConnection now completely wraps its functionality." );
00188 
00189     return g_object_new( GTASK_ROLE_PACKET_TYPE, NULL );
00190 }
00191 
00201 GTaskRolePacket *
00202 gtask_role_packet_new_with_role( GTaskRole role ) {
00203     GTaskRolePacket *packet = gtask_role_packet_new( );
00204 
00205     gtask_role_packet_set_role( packet, role );
00206 
00207     return packet;
00208 }
00209 
00219 GTaskRole
00220 gtask_role_packet_get_role( GTaskRolePacket *packet ) {
00221     g_return_val_if_fail( GTASK_IS_ROLE_PACKET( packet ), GTASK_ROLE_NONE );
00222 
00223     return packet->private->role;
00224 }
00225 
00234 void
00235 gtask_role_packet_set_role( GTaskRolePacket *packet, GTaskRole role ) {
00236     g_return_if_fail( GTASK_IS_ROLE_PACKET( packet ) );
00237 
00238     packet->private->role = role;
00239 }
00240 
00253 void
00254 gtask_role_packet_set_role_from_name( GTaskRolePacket *packet,
00255                                       const char *name )
00256 {
00257     g_return_if_fail( GTASK_IS_ROLE_PACKET( packet ) );
00258     g_return_if_fail( name != NULL );
00259 
00260     gtask_role_packet_set_role( packet, gtask_role_from_name( name ) );
00261 }
00262 
00272 const char *
00273 gtask_role_packet_get_role_name( GTaskRolePacket *packet ) {
00274     g_return_val_if_fail( GTASK_IS_ROLE_PACKET( packet ), "none" );
00275 
00276     return gtask_role_name( gtask_role_packet_get_role( packet ) );
00277 }
00278 
00289 GTaskRole
00290 gtask_role_from_name( const char *name ) {
00291     g_return_val_if_fail( name != NULL, GTASK_ROLE_NONE );
00292 
00293     if( strcasecmp( name, "proxy" ) == 0 ) {
00294         return GTASK_ROLE_PROXY;
00295     } else if( strcasecmp( name, "reporter" ) == 0 ) {
00296         return GTASK_ROLE_REPORTER;
00297     } else if( strcasecmp( name, "provider" ) == 0 ) {
00298         return GTASK_ROLE_PROVIDER;
00299     }
00300 
00301     return GTASK_ROLE_NONE;
00302 }
00303 
00313 const char *
00314 gtask_role_name( GTaskRole role ) {
00315     switch( role ) {
00316         case GTASK_ROLE_PROXY:
00317             return "proxy";
00318         case GTASK_ROLE_REPORTER:
00319             return "reporter";
00320         case GTASK_ROLE_PROVIDER:
00321             return "provider";
00322         case GTASK_ROLE_NONE:
00323         default:
00324             return "none";
00325     }
00326 
00327     return "none";
00328 }
00329 
00330 /* @} */

Generated on Mon Feb 2 21:26:14 2004 for libgtask by doxygen 1.3.4