bool Service::SaveConfig( ConfigBase &config ) { config.WriteConfig( "ServiceID", service_id ); config.WriteConfig( "PID", pid ); config.WriteConfig( "Type", type ); config.WriteConfig( "Name", name ); config.WriteConfig( "Provider", provider ); config.WriteConfig( "Channel", channel ? channel->GetKey( ) : -1 ); config.DeleteConfig( "Streams" ); Setting &n = config.ConfigList( "Streams" ); ConfigBase c( n ); for( std::map<uint16_t, Stream *>::iterator it = streams.begin( ); it != streams.end( ); it++ ) { Setting &n2 = c.ConfigGroup( ); ConfigBase c2( n2 ); it->second->SaveConfig( c2 ); } config.DeleteConfig( "CA" ); Setting &n2 = config.ConfigList( "CA" ); ConfigBase c2( n2 ); for( std::set<std::pair<uint16_t, uint16_t> >::iterator it = caids.begin( ); it != caids.end( ); it++ ) { Setting &n3 = c2.ConfigGroup( ); ConfigBase c3( n3 ); c3.WriteConfig( "CA_id", it->first ); c3.WriteConfig( "CA_pid", it->second ); } return true; }
// this will *ignore* options not present in both configs t_config_option_keys ConfigBase::diff(ConfigBase &other) { t_config_option_keys diff; t_config_option_keys my_keys = this->keys(); for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) { if (other.has(*opt_key) && other.serialize(*opt_key) != this->serialize(*opt_key)) { diff.push_back(*opt_key); } } return diff; }
void ConfigBase::apply(const ConfigBase &other, bool ignore_nonexistent) { // get list of option keys to apply t_config_option_keys opt_keys = other.keys(); // loop through options and apply them for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) { ConfigOption* my_opt = this->option(*it, true); if (my_opt == NULL) { if (ignore_nonexistent == false) throw "Attempt to apply non-existent option"; continue; } // not the most efficient way, but easier than casting pointers to subclasses bool res = my_opt->deserialize( other.option(*it)->serialize() ); if (!res) { std::string error = "Unexpected failure when deserializing serialized value for " + *it; CONFESS(error.c_str()); } } }
bool Event::LoadConfig( ConfigBase &config ) { config.ReadConfig( "EventID", id ); config.ReadConfig( "Start", start ); config.ReadConfig( "Duration", duration ); config.ReadConfig( "Name", name ); config.ReadConfig( "Description", description ); config.ReadConfig( "Language", language ); }
bool Service::LoadConfig( ConfigBase &config ) { config.ReadConfig( "ServiceID", service_id ); config.ReadConfig( "PID", pid ); config.ReadConfig( "Type", (int &) type ); std::string t; config.ReadConfig( "Name", t ); SetName( t ); config.ReadConfig( "Provider", provider ); int channel_id; config.ReadConfig( "Channel", channel_id ); if( channel_id != -1 ) { channel = TVDaemon::Instance( )->GetChannel( channel_id ); if( channel ) { channel->AddService( this ); transponder.HasChannels( true ); } else { LogError( "Service '%s': channel %d not found", name.c_str( ), channel_id ); channel_id == -1; } } Setting &n = config.ConfigList( "Streams" ); for( int i = 0; i < n.getLength( ); i++ ) { ConfigBase c2( n[i] ); Stream *s = new Stream( *this ); s->LoadConfig( c2 ); streams[s->GetKey( )] = s; } Setting &n2 = config.ConfigList( "CA" ); for( int i = 0; i < n2.getLength( ); i++ ) { ConfigBase c3( n2[i] ); uint16_t ca_id, ca_pid; c3.ReadConfig( "CA_id", ca_id ); c3.ReadConfig( "CA_pid", ca_pid ); SetCA(ca_id, ca_pid); } return true; }