10 cm( inst, this,
"ConfigStream" ),
45 [
this ]( std::ostream & out )
47 out <<
"Configuration '"<< this->name <<
"'" << std::endl;
51 cfs->stream_read( this->name, f );
72 #if IV_CONFIG_FS_ENABLED
93 for( StreamListener & listener : this->stream_listeners )
95 auto timestamp = this->stream_timestamp( listener.name );
96 if( timestamp > listener.timestamp )
98 listener.timestamp = timestamp;
99 listener.listener->config_stream_changed();
109 context->
out() <<
"Configuration path: " << this->base_dir <<
"." << std::endl;
111 for( StreamListener
const & listener : this->stream_listeners )
113 context->
out() <<
"Stream '"<< listener.name <<
"':" << std::endl;
116 context->
out() <<
"filepath " << this->stream_filepath( listener.name ) << std::endl;
117 context->
out() <<
"exists " << ( fs::is_regular_file( this->stream_filepath( listener.name ) ) ?
"true" :
"false" ) << std::endl;
119 if( listener.timestamp == fs::file_time_type::min() )
121 context->
out() <<
"timestamp -" << std::endl;
125 std::time_t t = fs::file_time_type::clock::to_time_t( listener.timestamp );
126 context->
out() <<
"timestamp " << std::asctime( std::localtime( &t ) ) << std::endl;
133 fs::path ConfigFileSystem::stream_filepath( std::string
const & name )
136 return this->base_dir / name;
139 fs::file_time_type ConfigFileSystem::stream_timestamp( std::string
const & name )
142 auto result = fs::last_write_time( this->stream_filepath( name ), ec );
145 this->
warning(
SRC_INFO,
"Can not determine last write time for file '", this->stream_filepath( name ),
"'. ",
146 "Error code: ", ec.value(),
" - '", ec.message(),
"'." );
147 return fs::file_time_type::min();
155 this->stream_listeners.push_back( StreamListener( listener, name, this->stream_timestamp( name ) ) );
160 for(
size_t i = 0; i < this->stream_listeners.size(); i++ )
161 if( this->stream_listeners[ i ].listener == listener )
163 this->stream_listeners.erase( this->stream_listeners.begin() + i );
170 fs::path fp = this->stream_filepath( name );
171 TextOutput <<
"ConfigStream: reading '" << fp <<
"'" << std::endl;
173 std::ifstream in( fp.c_str(), std::ios_base::in | std::ios_base::binary );
177 in = std::ifstream( fp.c_str(), std::ios_base::in | std::ios_base::binary );
186 fs::path fp = this->stream_filepath( name );
187 std::ifstream in( fp.c_str(), std::ios_base::in | std::ios_base::binary );
194 fs::path fp = this->stream_filepath( name );
195 fs::path basedir = fp;
196 basedir.remove_filename();
200 fs::create_directories( basedir, ec );
203 this->
warning(
SRC_INFO,
"Failed to create directories for config stream file. ",
204 "Directory is '", basedir,
"', error code is ", ec.value(),
" - '", ec.message(),
"'." );
209 std::ofstream out( fp, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc );
212 this->
warning(
SRC_INFO,
"Can not open configuration file '", fp,
"' for writing." );
222 return this->stream_filepath( name ).string();