Example #1
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_error )
{
    std::ostringstream ss;

    TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) );
    if( !tparam )
        throw szbase_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() );
    }

    return ss.str();
}
Example #2
0
double SzbaseWrapper::get_avg(
    const std::string& param ,
    time_t time ,
    ProbeType type ) const
throw( szbase_init_error, szbase_get_value_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_get_value_error( "Cannot get value from param " + param + ", param not found" );

    sz4::weighted_sum<double, unsigned> sum;
    try {
        base->get_weighted_sum( tparam ,
                                unsigned( time ) ,
                                unsigned( next( time , type , 1 ) ) ,
                                type.get_szarp_pt() ,
                                sum );
    } catch( sz4::exception& e ) {
        throw szbase_get_value_error( "Cannot get value from param " + param + ": " + e.what() );
    }

    return sz4::scale_value(sum.avg(), tparam);
}
Example #3
0
time_t SzbaseWrapper::get_latest(
			const std::string& param ,
			ProbeType type ) const
	throw( szbase_init_error, szbase_get_value_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	bool ok;
	std::wstring error;

	/**
	 * It looks like szbase has different aruments for "search all" in
	 * case of 10sec and other probles
	 */
	time_t start = type == ProbeType( ProbeType::Type::LIVE ) ?
		-1 :
		std::numeric_limits<time_t>::max();

	auto t = Szbase::GetObject()->Search( 
			convert_string( base_name + ":" + param ) ,
			start , time_t(-1) , -1 ,
			type.get_szarp_pt() , ok , error );

	if( !ok )
		throw szbase_get_value_error("Cannot get latest time of param " + param + ": " + SC::S2A(error) );

	/**
	 * Round by hand because Szbase::Search returns probes rounded to 
	 * either 10min or 10sec, not to exact pt
	 */
	return round( t , type );
}
Example #4
0
double SzbaseWrapper::get_avg_no_sync(
			const std::string& param ,
			time_t time ,
			ProbeType type ) const
	throw( szbase_init_error, szbase_get_value_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	bool is_fixed, ok;
	std::wstring error;
	double val = Szbase::GetObject()->GetValue(
			convert_string( base_name + ":" + param ) ,
			time , type.get_szarp_pt() , type.get_len() ,
			&is_fixed , ok , error );

	if( !ok )
		throw szbase_get_value_error("Cannot get value from param " + param + ": " + SC::S2A(error) );

	return val;
}
Example #5
0
void Params::param_value_changed( iterator itr , double value , ProbeType pt )
{
	if( itr.itr == params.end() ) {
		sz_log(1, "Value changed of undefined param %s", itr->c_str() );
		return;
	}

	using std::isnan;

	auto pvalue = itr.itr->second->get_value( pt );
	if( pt.get_type() == ProbeType::Type::LIVE
	 && (value == pvalue || (isnan(value) && isnan(pvalue))) )
		/**
		 * With LIVE probes if values are equal even
		 * if both are NaNs do nothing. For other probe
		 * types always send update.
		 */
		return;

	itr.itr->second->set_value( value , pt );
	emit_value_changed( itr.itr->second , value , pt );
}
Example #6
0
time_t SzbaseWrapper::round( time_t t , ProbeType pt )
{
    return szb_round_time( t , pt.get_szarp_pt() , pt.get_len() );
}
Example #7
0
time_t SzbaseWrapper::next( time_t t , ProbeType pt , int num )
{
    return szb_move_time( t , num , pt.get_szarp_pt() , pt.get_len() );
}