void CTestBlockController::CreateObjectL(TTEFBlockItem& aCommand)
	{
	// Retrieve the object name from the ini file
	TPtrC	name;
	if( GetStringFromConfig(aCommand.iSection, KName, name) &&
		0 != aCommand.iSection.Compare(KTEFNull) )
		{
		// Create the wrapper
		CDataWrapper*	data = CreateDataL(aCommand.iObjectType);
		if( NULL != data)
			{
			CleanupStack::PushL(data);
			data->SetTestBlockController(this);
			data->SetDataDictionary(&iDataDictionary);
			data->InitialiseL();
			// Add it to the dictionary with the lookup name provided
			iDataDictionary.AddDataL(name, data);
			CleanupStack::Pop(data);
			}
		else
			{
			aCommand.iError = KErrNotFound;
			ERR_PRINTF2( KErrWrapperCreate, &name );
			}
		}
	else
		{
		ERR_PRINTF1(KErrNoName);
		aCommand.iError = KErrNotFound;
		}
	}
void CTestBlockController::RestoreObjectL(TTEFBlockItem& aCommand)
	{
	if( IsSharedDataMode() )
		{
		// Retrieve the object name from the ini file
		TPtrC	name;
		if( 0 != aCommand.iSection.Compare(KTEFNull) &&
			GetStringFromConfig(aCommand.iSection, KName, name) )
			{
			// Create the wrapper
			CDataWrapper*	data = CreateDataL(aCommand.iObjectType);

			if( NULL != data)
				{
				CleanupStack::PushL(data);
				data->SetTestBlockController(this);
				data->SetDataDictionary(&iDataDictionary);
				data->InitialiseL();

				// Add it to the dictionary with the lookup name provided
				iDataDictionary.AddDataL(name, data);

				// Retrieve the object from the persistent store
				TAny*	object = NULL;
				TRAPD( err, object = iSharedData->GetObjectAndOwnL(name) );
				if( KErrNone == err )
					{
					CleanupStack::PushL(object);
					// Update the object contained within the wrapper
					iDataDictionary.SetObjectL(name, object);
					CleanupStack::Pop(object);
					}
				else
					{
					ERR_PRINTF1(KErrNotExist);
					iDataDictionary.DeleteDataL(name);
					aCommand.iError = KErrNotFound;
					}
				CleanupStack::Pop(data);
				}
			else
				{
				aCommand.iError = KErrNotFound;
				ERR_PRINTF2( KErrWrapperCreate, &name );
				}
			}
		else
			{
			ERR_PRINTF1(KErrNoName);
			aCommand.iError = KErrNotFound;
			}
		}
	else
		{
		ERR_PRINTF1(KErrSharedData);
		aCommand.iError = KErrNotSupported;
		}
	}
Exemplo n.º 3
0
/*---------------------------------------------------------------------------------
 
 ---------------------------------------------------------------------------------*/
CDataWrapper *AttributeValue::getValueAsCDatawrapperPtr(bool from_json) {
    CDataWrapper *result = NULL;
    if(!from_json) {
        result = new CDataWrapper((const char *)value_buffer);
    } else {
        result = new CDataWrapper();
        result->setSerializedJsonData((const char *)value_buffer);
    }
    return result;
}
void CTestBlockController::StoreL(TTEFBlockItem& aCommand)
	{
	if( IsSharedDataMode() )
		{
		// Retrieve the object name from the ini file
		TPtrC	name;
		if( 0 != aCommand.iSection.Compare(KTEFNull) &&
			GetStringFromConfig(aCommand.iSection, KName, name) )
			{
			// Lookup the wrapper
			CDataWrapper*	data = iDataDictionary.GetDataL( name );

			// Retrieve the object being wrapped
			TAny*			object = data->GetObject();
			if ( object!=NULL )
				{
				// Add it to the persistent store
				TCleanupOperation	operation=data->CleanupOperation();
				if ( operation!=NULL )
					{
					iSharedData->PutAndDisownL(name, object, operation);
					data->DisownObjectL();
					}
				else
					{
					ERR_PRINTF1(KErrNoCleanup);
					aCommand.iError = KErrNotFound;
					}
				}
			else
				{
				ERR_PRINTF1(KErrNotExist);
				aCommand.iError = KErrNotFound;
				}
			}
		else
			{
			ERR_PRINTF1(KErrNoName);
			SetTestStepResult(EFail);
			}
		}
	else
		{
		ERR_PRINTF1(KErrSharedData);
		aCommand.iError = KErrNotSupported;
		}
	}
Exemplo n.º 5
0
/*
 Initialization method for output buffer
 */
void ZMQClient::init(void *init_data) throw(CException) {
    CDataWrapper *cfg = reinterpret_cast<CDataWrapper*>(init_data);
    ZMQC_LAPP << "initialization";
    int32_t threadNumber = cfg->hasKey(InitOption::OPT_RPC_SERVER_THREAD_NUMBER)? cfg->getInt32Value(InitOption::OPT_RPC_SERVER_THREAD_NUMBER):1;
    ZMQC_LAPP << "ObjectProcessingQueue<CDataWrapper> initialization with "<< threadNumber <<" thread";
    CObjectProcessingQueue<NetworkForwardInfo>::init(threadNumber);
    ZMQC_LAPP << "ObjectProcessingQueue<NetworkForwardInfo> initialized";
    
    ZMQC_LAPP << "ConnectionPool initialization";
    zmq_context = zmq_ctx_new();
    CHAOS_ASSERT(zmq_context)
    
    //et the thread number
    zmq_ctx_set(zmq_context, ZMQ_IO_THREADS, threadNumber);
    
    if(GlobalConfiguration::getInstance()->getRpcImplKVParam().count("zmq_timeout")) {
        CHAOS_NOT_THROW(zmq_timeout = boost::lexical_cast<int>(GlobalConfiguration::getInstance()->getRpcImplKVParam()["zmq_timeout"]););
Exemplo n.º 6
0
/*---------------------------------------------------------------------------------
 
 ---------------------------------------------------------------------------------*/
bool AttributeValue::setValue(CDataWrapper& attribute_value,
                              bool tag_has_changed) {
	attribute_value.copyAllTo(cdvalue);
	//set the relative field for set has changed
	if(tag_has_changed) sharedBitmapChangedAttribute->set(index);
	 return true;

}
Exemplo n.º 7
0
/*---------------------------------------------------------------------------------
 
 ---------------------------------------------------------------------------------*/
void AttributeValue::writeToCDataWrapper(CDataWrapper& data_wrapper) {
    switch(type) {
        case chaos::DataType::TYPE_BYTEARRAY:{
            switch(sub_type.size()) {
                case 1:
                    data_wrapper.addBinaryValue(name, sub_type[0], (const char *)value_buffer, size);
                    break;
                    
                default:
                    data_wrapper.addBinaryValue(name, (const char *)value_buffer, size);
                    break;
            }
            break;
        }
        case chaos::DataType::TYPE_CLUSTER:{

            data_wrapper.addCSDataValue(name,cdvalue);
            break;
        }
        case chaos::DataType::TYPE_STRING:{
            unsigned long str_len = value_buffer?std::strlen((const char *)value_buffer):0;
            str_len = (str_len>=size?size:str_len);
            data_wrapper.addStringValue(name, (str_len?std::string(static_cast<const char*>(value_buffer), str_len):""));
            break;
        }
            
        case chaos::DataType::TYPE_BOOLEAN:{
            data_wrapper.addBoolValue(name, *getValuePtr<bool>());
            break;
        }
            
        case chaos::DataType::TYPE_DOUBLE:{
            data_wrapper.addDoubleValue(name, *getValuePtr<double>());
            break;
        }
            
        case chaos::DataType::TYPE_INT32:{
            data_wrapper.addInt32Value(name, *getValuePtr<int32_t>());
            break;
        }
            
        case chaos::DataType::TYPE_INT64:{
            data_wrapper.addInt64Value(name, *getValuePtr<int64_t>());
            break;
        }
        default:
            break;
    }
}
void CTestBlockController::CommandL(TTEFBlockItem& aCommand, const TInt aAsyncErrorIndex)
	{
	// Retrieve the object name from the ini file
	TPtrC	name;
	if( 0 != aCommand.iCommand.iObject.Compare(KTEFNull) &&
		GetStringFromConfig(aCommand.iCommand.iObject, KName, name) )
		{
		CDataWrapper*	data = iDataDictionary.GetDataL(name);
		if( data!=NULL )
			{
			TBool cmdExists = EFalse;
			TRAPD(err, cmdExists = data->DoCommandL(aCommand.iCommand.iFunction, aCommand.iSection, aAsyncErrorIndex));
			if (KErrNone != err)
				{
				ERR_PRINTF4(_L("Command \"%S\" of the object \"%S\" leaves with error code %d"), &aCommand.iCommand.iFunction, &aCommand.iCommand.iObject, err);
				aCommand.iError = err;
				SetBlockResult(EFail);
				}
			else if( !cmdExists )
				{
				ERR_PRINTF1(KErrNoFunction);
				aCommand.iError = KErrNotFound;
				}
			}
		else
			{
			ERR_PRINTF1(KErrNotExist);
			aCommand.iError = KErrNotFound;
			}
		}
	else
		{
		ERR_PRINTF1(KErrNoName);
		aCommand.iError = KErrNotFound;
		}
	}
Exemplo n.º 9
0
//------------------------------------
int DeviceMessageChannel::setAttributeValue(CDataWrapper& attributesValues,
                                            bool noWait,
                                            int32_t millisec_to_wait) {
    //create the pack
    attributesValues.addStringValue(NodeDefinitionKey::NODE_UNIQUE_ID, device_network_address->device_id);
    if(noWait){
        sendMessage(device_network_address->node_id, ControlUnitNodeDomainAndActionRPC::CONTROL_UNIT_APPLY_INPUT_DATASET_ATTRIBUTE_CHANGE_SET, &attributesValues);
    } else {
        auto_ptr<CDataWrapper> initResult(sendRequest(device_network_address->node_id,
                                                      ControlUnitNodeDomainAndActionRPC::CONTROL_UNIT_APPLY_INPUT_DATASET_ATTRIBUTE_CHANGE_SET,
                                                      &attributesValues,
                                                      millisec_to_wait));
    }
    setOnline(!CHAOS_IS_RPC_SERVER_OFFLINE(getLastErrorCode()));
    return getLastErrorCode();
}
Exemplo n.º 10
0
int initialize_from_old_mds(std::string conf){
    std::stringstream stringa;
    std::ifstream f(conf.c_str());
    if(f.fail()){
       throw CException(-3,__FUNCTION__,"Cannot open file:"+ conf);
    }
    std::cout<<"* reading:"<<conf<<std::endl;
    stringa << f.rdbuf();
    //std::cout<<"read:"<<stringa.str()<<std::endl;
   // BSONObj bson(" \"data_servers\" : [ { \"hostname\" : \"192.168.150.21:1672:30175|0\" , \"id_server\" : 5 , \"is_live\" : true} , { \"hostname\" : \"192.168.150.22:1672:30175|0\" , \"id_server\" : 6 , \"is_live\" : true} , { \"hostname\" : \"192.168.150.23:1672:30175|0\" , \"id_server\" : 7 , \"is_live\" : true}]");
    //BSONObj bson(strdup(stringa.str().c_str()));
    //std::cout<<"BJSON:"<<bson.jsonString();
    CDataWrapper mdsconf;
    
    mdsconf.setSerializedJsonData(stringa.str().c_str());

    //! rest ALL
  //  std::cout<<"json:"<<data.getJSONString()<<std::endl;
    std::auto_ptr<CMultiTypeDataArrayWrapper> data_servers(mdsconf.getVectorValue("data_servers"));
    if(data_servers.get()){
         for(int cnt=0;cnt<data_servers->size();cnt++){
             std::basic_string<char>::iterator  pnt;
             int chan=0;
            std::stringstream ss;
            ss<<"data_server"<<cnt;
            std::auto_ptr<CDataWrapper> ele(data_servers->getCDataWrapperElementAtIndex(cnt));
            GET_CONFIG_STRING(ele.get(),hostname);
          //  GET_CONFIG_INT(data_servers->getCDataWrapperElementAtIndex(cnt),id_server);
            pnt=hostname.begin()+hostname.rfind('|');
            if(pnt!=hostname.end()){
                std::string schan;
                schan.assign(pnt+1,hostname.end());
                chan=atoi(schan.c_str());
                hostname.erase(pnt,hostname.end());
            }

            std::cout<<"* found dataserver["<<cnt<<"]:"<<hostname<<" channel:"<<chan<<std::endl;
            EXECUTE_CHAOS_API(api_proxy::data_service::DeleteDS,3000,ss.str());
            EXECUTE_CHAOS_API(api_proxy::data_service::NewDS,3000,ss.str(),hostname,chan);

        }
    }

    CMultiTypeDataArrayWrapper* us=mdsconf.getVectorValue("us");
    if(us){
        for(int cnt=0;(us!=NULL)&&(cnt<us->size());cnt++){
            std::auto_ptr<CDataWrapper> usw(us->getCDataWrapperElementAtIndex(cnt));
            GET_CONFIG_STRING(usw,unit_server_alias);
            std::cout<<"* found us["<<cnt<<"]:"<<unit_server_alias<<std::endl;
            //GET_CHAOS_API_PTR(api_proxy::unit_server::NewUS)->execute(usname.c_str());
           //  EXECUTE_CHAOS_API(api_proxy::unit_server::DeleteUS,3000,unit_server_alias);
            try {
             EXECUTE_CHAOS_API(api_proxy::unit_server::NewUS,3000,unit_server_alias);
            } catch(CException e){
            	std::cout<<" warning:"<<" cannot create a new US:"<<unit_server_alias<<std::endl;
            }
             CMultiTypeDataArrayWrapper* cu_l=usw->getVectorValue("cu_desc");
             for(int cui=0;(cu_l !=NULL) && (cui<cu_l->size());cui++){
                 api_proxy::control_unit::SetInstanceDescriptionHelper cud;
                 std::auto_ptr<CDataWrapper> cuw(cu_l->getCDataWrapperElementAtIndex(cui));
                 GET_CONFIG_STRING(cuw,cu_id);
                 GET_CONFIG_STRING(cuw,cu_type);
                 GET_CONFIG_STRING(cuw,cu_param);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_load,true);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_init,true);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_start,true);
		 GET_CONFIG_DEFAULT_INT(cuw,storage_type,1);
		 GET_CONFIG_DEFAULT_INT(cuw,storage_ageing,3600*24);
                 std::cout<<"\t"<<cu_id<<","<<cu_type<<std::endl;
                 cud.auto_load=auto_load;
                 cud.auto_init=auto_init;
                 cud.auto_start=auto_start;
                 cud.load_parameter = cu_param;
                 cud.control_unit_uid=cu_id;
                 cud.unit_server_uid=unit_server_alias;
                 cud.control_unit_implementation=cu_type;
		 cud.history_ageing=storage_ageing;
		 cud.storage_type=(chaos::DataServiceNodeDefinitionType::DSStorageType)storage_type;
                 //EXECUTE_CHAOS_API(api_proxy::unit_server::ManageCUType,3000,unit_server_alias,cu_type,1);
                 EXECUTE_CHAOS_API(api_proxy::control_unit::DeleteInstance,3000,unit_server_alias,cu_id);
                 EXECUTE_CHAOS_API(api_proxy::control_unit::Delete,3000,cu_id);
                 EXECUTE_CHAOS_API(api_proxy::unit_server::ManageCUType,3000,unit_server_alias,cu_type,0);

                 // drivers
                 std::auto_ptr<CMultiTypeDataArrayWrapper> drv_l(cuw->getVectorValue("DriverDescription"));
                 for(int drv=0;(drv_l.get() !=NULL) && (drv<drv_l->size());drv++){
                     std::auto_ptr<CDataWrapper> drv_w(drv_l->getCDataWrapperElementAtIndex(drv));

                    GET_CONFIG_STRING(drv_w,DriverDescriptionName);
                    GET_CONFIG_STRING(drv_w,DriverDescriptionVersion);
                    GET_CONFIG_STRING(drv_w,DriverDescriptionInitParam);
                    cud.addDriverDescription(DriverDescriptionName,DriverDescriptionVersion,DriverDescriptionInitParam);
                 }
                 //attributes
                 std::auto_ptr<CMultiTypeDataArrayWrapper> attr_l(cuw->getVectorValue("AttrDesc"));
                 for(int attr=0;(attr_l.get() !=NULL) && (attr<attr_l->size());attr++){
                     std::auto_ptr<CDataWrapper> attr_w(attr_l->getCDataWrapperElementAtIndex(attr));

                    GET_CONFIG_STRING(attr_w,ds_attr_name);
                    GET_CONFIG_STRING(attr_w,ds_default_value);
                    GET_CONFIG_STRING(attr_w,ds_max_range);
                    GET_CONFIG_STRING(attr_w,ds_min_range);

                    cud.addAttributeConfig(ds_attr_name,ds_default_value,ds_max_range,ds_min_range);
                 }

                 EXECUTE_CHAOS_API(api_proxy::control_unit::SetInstanceDescription,3000,cud);
             }
        }
    }


    return 0;
}
Exemplo n.º 11
0
void StringHealtMetric::addMetricToCD(CDataWrapper& data) {
    data.addStringValue(name, value);
}
Exemplo n.º 12
0
void DoubleHealtMetric::addMetricToCD(CDataWrapper& data) {
    data.addDoubleValue(name, value);
}
Exemplo n.º 13
0
void Int64HealtMetric::addMetricToCD(CDataWrapper& data) {
    data.addInt64Value(name, value);
}
Exemplo n.º 14
0
void BoolHealtMetric::addMetricToCD(CDataWrapper& data) {
    data.addBoolValue(name.c_str(), value);
}