void gv_properties_set( GvProperties *properties, const char * name, const char * value ) { guint keyid = gvpk_keyid_from_string( name ); GQuark valueq = g_quark_from_string( value ); int i; /* -------------------------------------------------------------------- */ /* Initial allocation of properties. */ /* -------------------------------------------------------------------- */ if( *properties == NULL ) { *properties = g_new( guint32, 14 ); PROP_MAXCOUNT(properties) = 6; PROP_COUNT(properties) = 0; } /* -------------------------------------------------------------------- */ /* Does the key already exist in the properties list? If so, */ /* just reset the value. */ /* -------------------------------------------------------------------- */ for( i = 0; i < PROP_COUNT(properties); i++ ) { if( PROP_KEYID(properties,i) == keyid ) { PROP_VALUEID(properties,i) = (guint32) valueq; return; } } /* -------------------------------------------------------------------- */ /* We need to add the name/value pair to the list. Does the */ /* allocation of the list need to be grown? */ /* -------------------------------------------------------------------- */ if( PROP_MAXCOUNT(properties) == PROP_COUNT(properties) ) { int new_max = (int)(PROP_MAXCOUNT(properties) * 1.5); new_max = (new_max < 6 ? 6 : new_max); *properties = g_renew( guint32, *properties, new_max * 2 + 2 ); PROP_MAXCOUNT(properties) = new_max; } /* -------------------------------------------------------------------- */ /* Add the new name/value pair. */ /* -------------------------------------------------------------------- */ i = PROP_COUNT(properties); PROP_COUNT(properties)++; PROP_KEYID(properties,i) = keyid; PROP_VALUEID(properties,i) = (guint32) valueq; }
void gv_properties_copy( GvProperties *source, GvProperties *target ) { if( *source == NULL ) { *target = NULL; return; } *target = g_new( guint32, PROP_COUNT(source) * 2 + 2 ); memcpy( *target, *source, sizeof(guint32) * (PROP_COUNT(source)*2 + 2)); PROP_MAXCOUNT(target) = PROP_COUNT(target); }
int gv_properties_count( GvProperties *properties ) { if( *properties == NULL ) return 0; else return PROP_COUNT(properties); }
void gv_properties_remove( GvProperties *properties, const char * key ) { guint32 keyid = gvpk_keyid_from_string( key ); int i; if( *properties == NULL ) return; for( i = 0; i < PROP_COUNT(properties); i++ ) { if( PROP_KEYID(properties,i) == keyid ) { int last_prop = PROP_COUNT(properties)-1; PROP_KEYID(properties,i) = PROP_KEYID(properties,last_prop); PROP_VALUEID(properties,i) = PROP_VALUEID(properties,last_prop); PROP_COUNT(properties)--; return; } } }
const char * gv_properties_get_value_by_index( GvProperties * properties, int prop_index ) { GQuark value_id; if( *properties == NULL ) return NULL; if( prop_index < 0 || prop_index >= PROP_COUNT(properties) ) return NULL; value_id = (GQuark) PROP_VALUEID(properties,prop_index); return g_quark_to_string( value_id ); }
const char * gv_properties_get( GvProperties *properties, const char * name ) { guint32 keyid = gvpk_keyid_from_string( name ); int i; if( *properties == NULL ) return NULL; for( i = 0; i < PROP_COUNT(properties); i++ ) { if( PROP_KEYID(properties,i) == keyid ) return g_quark_to_string( (GQuark) PROP_VALUEID(properties,i) ); } return NULL; }
const char * gv_properties_get_name_by_index( GvProperties * properties, int prop_index ) { guint32 keyid; if( *properties == NULL ) return NULL; if( prop_index < 0 || prop_index >= PROP_COUNT(properties) ) return NULL; keyid = PROP_KEYID(properties,prop_index); g_assert( keyid >= 1 && keyid <= gvpk_keyid_seq_id ); return gvpk_keyids[keyid-1]; }
} //--------------------------------------------------------------------------- // Properties //--------------------------------------------------------------------------- static void * prop_valp(struct properties *ps, void *context, size_t offset ) { (void) ps; (void) context, (void) offset; return 0; } static property_t proplist[] = { { pt_int32, "frequency", 0, &freq, 0, 0, 0, 0 }, }; static properties_t props = { ".dev", proplist, PROP_COUNT(proplist), prop_valp }; // Stop device static int beep_stop(phantom_device_t *dev) { (void) dev; nosound(); return 0; } static int beep_read(struct phantom_device *dev, void *buf, int len)