Exemplo n.º 1
0
std::string SzbaseWrapper::search_data( const std::string& param ,
									    const std::string& from ,
										const std::string& to ,
										TimeType time_type ,
										SearchDir dir ,
										ProbeType pt
										) const
	throw( szbase_init_error, szbase_param_not_found_error, szbase_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) );
	if( !tparam )
		throw szbase_param_not_found_error( "Param " + param + ", does not exist." );

	std::string result;

	switch (time_type) {
		case TimeType::NANOSECOND:
			result = search_data_helper<sz4::nanosecond_time_t>( base , tparam , from , to , dir , pt );
			break;
		case TimeType::SECOND:
			result = search_data_helper<sz4::second_time_t>    ( base , tparam , from , to , dir , pt );
			break;
	}

	purge_cache();

	return result;
}
Exemplo n.º 2
0
void SzbaseProt::remove_param(const std::string& base, const std::string& pname)
{
	auto i = user_params.find( std::make_pair( base , pname ) );
	if ( i == user_params.end() )
		throw szbase_param_not_found_error("param not found");

	vars.get_updater().remove_param( i->first.first, i->second );

	user_params_inverted.erase( i->second );
	user_params.erase( i );
}
Exemplo n.º 3
0
SzbaseObserverToken SzbaseWrapper::register_observer( const std::string& param , std::function<void( void )> callback )
	throw( szbase_init_error , szbase_param_not_found_error , szbase_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) );
	if( !tparam )
		throw szbase_param_not_found_error( "Param " + param + ", does not exist." );

	return std::make_shared<SzbaseObserverImpl>( convert_string( base_name + ":" + param )
											   , IPKContainer::GetObject()
											   , base
											   , callback );
}
Exemplo n.º 4
0
SzbaseObserverImpl::SzbaseObserverImpl( const std::wstring& param_name
									  , IPKContainer* ipk
									  , sz4::base* base
									  , std::function<void( void )> callback )
									  : param_name( param_name )
									  , ipk( ipk )
									  , base( base )
									  , callback( callback )
{
	TParam* tparam = ipk->GetParam( param_name );
	if( !tparam )
		throw szbase_param_not_found_error(
			(const char*)SC::S2U(L"Param " + param_name + L", does not exist.").c_str()
			);

	base->register_observer( this , std::vector<TParam*>{ tparam } );
}
Exemplo n.º 5
0
std::string SzbaseWrapper::get_data( const std::string& param ,
									 const std::string& from ,
									 const std::string& to ,
									 ValueType value_type ,
									 TimeType time_type ,
									 ProbeType pt ) const
		throw( szbase_init_error, szbase_param_not_found_error, szbase_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	std::ostringstream ss;

	TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) );
	if( !tparam )
		throw szbase_param_not_found_error( "Param " + param + ", does not exist." );

	try{
		switch (time_type) {
			case TimeType::NANOSECOND:
				::get_data<sz4::nanosecond_time_t>( base , tparam ,
								    from , to ,
								    value_type , pt.get_szarp_pt() ,
								    ss );
				break;
			case TimeType::SECOND:
				::get_data<sz4::second_time_t>    ( base , tparam ,
								    from , to ,
								    value_type , pt.get_szarp_pt() ,
								    ss );
				break;
		}
	} catch ( sz4::exception& e ) {
		throw szbase_error( "Cannot get data for param " + param + ": " + e.what() );
	}

	purge_cache();

	return ss.str();
}