void Adapter::enableIndications( CMPIIndicationMI* mi, const CMPIContext* context) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Ignore request if indications already enabled. if (adapter->_indications_enabled) return; adapter->_indications_enabled = true; // Invoke the provider: Enable_Indications_Status status = adapter->enable_indications( _indication_proc, adapter); switch (status) { case ENABLE_INDICATIONS_OK: break; case ENABLE_INDICATIONS_FAILED: break; } }
void Adapter::disableIndications( CMPIIndicationMI* mi, const CMPIContext* context) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Ignore if indications are not enabled. if (!adapter->_indications_enabled) return; // Invoke the provider: Disable_Indications_Status status = adapter->disable_indications(); switch (status) { case DISABLE_INDICATIONS_OK: break; case DISABLE_INDICATIONS_FAILED: break; } adapter->_indications_enabled = false; }
Adapter *Agent::addAdapter (const string & aDeviceName, const string & aHost, const unsigned int aPort, bool aStart, int aLegacyTimeout ) { Adapter *adapter = new Adapter(aDeviceName, aHost, aPort, aLegacyTimeout); adapter->setAgent(*this); mAdapters.push_back(adapter); Device *dev = mDeviceMap[aDeviceName]; if ( ( dev != NULL ) && dev->mAvailabilityAdded ) { adapter->setAutoAvailable(true); } if ( aStart ) { adapter->start( ); } return adapter; }
void XMLConfigReader::getAdaptersFromXML(TiXmlElement* ruleEngineElm, RuleEngine *engine) { for (TiXmlElement* adapterElm = ruleEngineElm->FirstChildElement("adapter"); adapterElm != NULL; adapterElm = adapterElm->NextSiblingElement("adapter")) { TiXmlElement* conditionElm = adapterElm->FirstChildElement("rule"); if(conditionElm != NULL){ std::string rule = std::string(conditionElm->GetText()); int delimiterLoc = rule.find(":"); Adapter *adapter = new Adapter(new Rule(rule.substr(0, delimiterLoc), rule.substr(delimiterLoc + 1, rule.length()).at(0))); for (TiXmlElement* actionElm = adapterElm->FirstChildElement("action"); actionElm != NULL; actionElm = actionElm->NextSiblingElement("action")) { std::string actionTxt = std::string(actionElm->GetText()); if(actionTxt == "ADD"){ adapter->addAction(ADD); } else if(actionTxt == "DEL"){ adapter->addAction(DEL); } else if(actionTxt == "MOD"){ adapter->addAction(MOD); } else if(actionTxt == "SHF"){ adapter->addAction(SHF); } else { std::cerr << "Action: " << actionTxt << " not defined!!" << std::endl; } } engine->addAdapter(adapter); } } }
static void Adapter_addJoin( Adapter adp, ZnkStr ans, const StrListHandle str_list, size_t begin, size_t end, const char* connector, size_t connector_leng, size_t expect_elem_leng ) { const size_t num = adp->size_( str_list ); end = Znk_MIN( num, end ); if( end > begin ){ size_t idx; DECIDE_STRLENG( connector_leng, connector ); /* おおまかな予想予約サイズ */ ZnkBfr_reserve( ans, ZnkBfr_size(ans) + ( expect_elem_leng + connector_leng ) * (end-begin) ); /*** * ZnkStr_add, あるいは ZnkStr_appendで十分高速である. * これらを使わずに工夫を凝らしたとしてもほとんど差はない. */ for( idx=begin; idx<end-1; ++idx ){ ZnkStr_add( ans, adp->at_( str_list, idx ) ); ZnkStr_append( ans, connector, connector_leng ); } ZnkStr_add( ans, adp->at_( str_list, end-1 ) ); } }
//Removed thread support! uint64 Adapter::_timer(void* arg) { TRACE; // This function is called when the Scheduler's timer proc expires. It // invokes the provider's timer() method(). Adapter* adapter = (Adapter*)arg; Auto_RMutex auto_lock(adapter->_lock); uint64 timeout = 0; Timer_Status status = adapter->timer(timeout); switch (status) { case TIMER_CANCEL: return 0; case TIMER_RESCHEDULE: // Convert to microseconds. return timeout * 1000; } // Unreachable! return 0; }
int main(int argc, const char * argv[]) { Adapter* ad = new Adapter(); ad->render(); return 0; }
int main(int, char **) { // create an adapter object and call one of its functions Adapter adapter; adapter.DoSomething(42); return 0; }
int main(int argc, char **argv) { Adaptee *ade = new Adaptee(); Adapter *apt = new Adapter(ade); apt->Request(); return 0; }
void Decorator::writeSolution( const Epetra_Vector &soln, const double time, const bool overlapped) { Adapter *adapter = Adapter::get(); if (adapter) adapter->update(this->timestep++, time, *this, soln); discretization->writeSolution(soln, time, overlapped); }
Adapter * Agent::addAdapter( const string& device, const string& host, const unsigned int port ) { Adapter *adapter = new Adapter(device, host, port); adapter->setAgent(*this); return adapter; }
inline void WriteAdapter(Adapter& v, F f) { m_jsutil.StartArray(); for (size_t i = 0, size = v.size(); i < size; i++) { WriteValue(f()); v.pop(); } m_jsutil.EndArray(); }
CMPIStatus Adapter::associators( CMPIAssociationMI* mi, const CMPIContext* context, const CMPIResult* result, const CMPIObjectPath* cmpi_op, const char* assoc_class_, const char* result_class_, const char* role_, const char* result_role_, const char** properties) { TRACE; const char* assoc_class = assoc_class_ ? assoc_class_ : ""; const char* result_class = result_class_ ? result_class_ : ""; const char* role = role_ ? role_ : ""; const char* result_role = result_role_ ? result_role_ : ""; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); CIMPLE_ASSERT(strcasecmp(assoc_class, adapter->_mc->name) == 0); // Lookup meta class for cmpi_op (not the same as the provider class). const Meta_Class* mc = adapter->_find_meta_class(class_name(cmpi_op)); if (!mc) CMReturn(CMPI_RC_ERR_INVALID_CLASS); // Convert to CIMPLE reference: Instance* cimple_ref = 0; CMPIrc rc = make_cimple_reference(mc, cmpi_op, cimple_ref); Destroyer<Instance> cimple_ref_d(cimple_ref); if (rc != CMPI_RC_OK) CMReturn(rc); // Invoke the provider: associators::Data data = { adapter->broker, context, result, name_space(cmpi_op), properties, CMPI_RC_OK }; Enum_Associator_Names_Status status = adapter->enum_associator_names( cimple_ref, result_class, role, result_role, associators::_proc, &data); CMReturn(CMPI_RC_OK); }
void PhysicsNeuralModule::AddAdapter(std::string strXml, bool bDoNotInit) { CStdXml oXml; oXml.Deserialize(strXml); oXml.FindElement("Root"); oXml.FindChildElement("Adapter"); Adapter *lpAdapter = LoadAdapter(oXml); if(!bDoNotInit) lpAdapter->Initialize(); }
int main( int argc, char* argv[] ) { #if CLASS Adaptee* ade = new Adaptee(); Adapter* adt = new Adapter(); adt->Request(); #else Adaptee* ade = new Adaptee(); Adapter* adt = new Adapter( ade ); adt->Request(); #endif return 0; }
void ConfigTest::testLegacyTimeout() { istringstream str("Devices = ../samples/test_config.xml\n" "LegacyTimeout = 2000\n"); mConfig->loadConfig(str); Agent *agent = mConfig->getAgent(); CPPUNIT_ASSERT(agent); Device *device = agent->getDevices()[0]; Adapter *adapter = device->mAdapters[0]; CPPUNIT_ASSERT_EQUAL(2000, adapter->getLegacyTimeout()); }
CMPIStatus Adapter::enumInstanceNames( CMPIInstanceMI* mi, const CMPIContext* context, const CMPIResult* result, const CMPIObjectPath* cmpi_op) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Convert to CIMPLE reference: const Meta_Class* mc = adapter->_mc; Instance* cimple_ref = 0; CMPIrc rc = make_cimple_reference(mc, cmpi_op, cimple_ref); if (rc != CMPI_RC_OK) CMReturn(rc); Destroyer<Instance> cimple_ref_d(cimple_ref); // Nullify non-key properties (this is a reference). nullify_non_keys(cimple_ref); // Invoke provider: const char* ns = name_space(cmpi_op); enum_instance_names::Data data = { adapter->broker, result, ns, CMPI_RC_OK }; Enum_Instances_Status status = adapter->enum_instances(cimple_ref, enum_instance_names::_proc, &data); switch (status) { case ENUM_INSTANCES_OK: CMReturnDone(result); CMReturn(CMPI_RC_OK); case ENUM_INSTANCES_FAILED: CMReturn(CMPI_RC_ERR_FAILED); } // Unreachable! CMReturn(CMPI_RC_OK); }
CMPIStatus Adapter::enumInstances( CMPIInstanceMI* mi, const CMPIContext* context, const CMPIResult* result, const CMPIObjectPath* cmpi_op, const char** properties) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Convert to CIMPLE reference: const Meta_Class* mc = adapter->_mc; Instance* cimple_ref = 0; CMPIrc rc = make_cimple_reference(mc, cmpi_op, cimple_ref); Destroyer<Instance> cimple_ref_d(cimple_ref); if (rc != CMPI_RC_OK) CMReturn(rc); // Filter properties: if (properties) filter_properties(cimple_ref, properties); // Invoke provider: enum_instances::Data data = { adapter->broker, result, cmpi_op, properties, CMPI_RC_OK }; Enum_Instances_Status status = adapter->enum_instances(cimple_ref, enum_instances::_proc, &data); switch (status) { case ENUM_INSTANCES_OK: break; case ENUM_INSTANCES_FAILED: CMReturn(CMPI_RC_ERR_FAILED); } CMReturnDone(result); CMReturn(CMPI_RC_OK); }
void operator() (Adapter const& va) const { double label_x, label_y, z = 0; va.rewind(0); for (unsigned cmd; (cmd = va.vertex(&label_x, &label_y)) != SEG_END; ) { if (cmd != SEG_CLOSE) { prj_trans_.backward(label_x, label_y, z); tr_.forward(&label_x, &label_y); points_.emplace_back(label_x, label_y); } } }
void ConfigTest::testIgnoreTimestamps() { istringstream str("Devices = ../samples/test_config.xml\n" "IgnoreTimestamps = true\n"); mConfig->loadConfig(str); Agent *agent = mConfig->getAgent(); CPPUNIT_ASSERT(agent); Device *device = agent->getDevices()[0]; Adapter *adapter = device->mAdapters[0]; CPPUNIT_ASSERT(adapter->isIgnoringTimestamps()); }
void operator() (Adapter const& va) { double x,y,z = 0; unsigned cmd = SEG_END; va.rewind(0); while ((cmd = va.vertex(&x, &y)) != mapnik::SEG_END) { if (cmd == SEG_CLOSE) continue; prj_trans_.backward(x, y, z); common_.t_.forward(&x, &y); el_.init(x, y, rx_, ry_, el_.num_steps()); ras_.add_path(el_); agg::render_scanlines(ras_, sl_, ren_); } }
const VampPluginDescriptor * vampGetPluginDescriptor(unsigned int version, unsigned int index) { if (version < 1) return 0; // Return a different plugin adaptor's descriptor for each index, // and return 0 for the first index after you run out of plugins. // (That's how the host finds out how many plugins are in this // library.) switch (index) { case 0: return timeAdapter.getDescriptor(); case 1: return freqAdapter.getDescriptor(); default: return 0; } }
void ConfigTest::testDevice() { istringstream str("Devices = ../samples/test_config.xml\n"); mConfig->loadConfig(str); Agent *agent = mConfig->getAgent(); CPPUNIT_ASSERT(agent); Device *device = agent->getDevices()[0]; Adapter *adapter = device->mAdapters[0]; CPPUNIT_ASSERT_EQUAL((string) "LinuxCNC", device->getName()); CPPUNIT_ASSERT(!adapter->isDupChecking()); CPPUNIT_ASSERT(!adapter->isAutoAvailable()); CPPUNIT_ASSERT(!adapter->isIgnoringTimestamps()); CPPUNIT_ASSERT(device->mPreserveUuid); }
CMPIStatus Adapter::modifyInstance( CMPIInstanceMI* mi, const CMPIContext* context, const CMPIResult* result, const CMPIObjectPath* cmpi_op, const CMPIInstance* cmpi_inst, const char** properties) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Create CIMPLE instance: const Meta_Class* mc = adapter->_mc; Instance* cimple_inst = 0; CMPIrc rc = make_cimple_instance(mc, cmpi_inst, cimple_inst); if (rc != CMPI_RC_OK) CMReturn(rc); Destroyer<Instance> cmpi_inst_d(cimple_inst); // Invoke the provider: Modify_Instance_Status status = adapter->modify_instance(cimple_inst); switch (status) { case MODIFY_INSTANCE_OK: CMReturnObjectPath(result, cmpi_op); CMReturnDone(result); CMReturn(CMPI_RC_OK); case MODIFY_INSTANCE_NOT_FOUND: CMReturn(CMPI_RC_ERR_NOT_FOUND); case MODIFY_INSTANCE_UNSUPPORTED: CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } CMReturn(CMPI_RC_OK); }
void MessageRouter::handleMessages( Adapter& adapter) { bool handledMessage = false; // Get the first available message. const Message* message = adapter.getMessage(); if (message) { Logger::logDebug("MessageRouter::handleMessages: Got message " + toString(message->getMessageId()) + ".\n"); } while (message) { MessageHandler* handler = getHandler(message->getDestination()); if (!handler) { Logger::logDebug("Failed to handle message " + toString(message->getMessageId()) + ". No handler specified for destination \"" + message->getDestination() + "\"\n"); } else { // Allow the handler to handle the message. handledMessage = handler->handleMessage(*message); if (!handledMessage) { Logger::logDebug("Component \"" + handler->getId() + "\" failed to handle message " + toString(message->getMessageId()) + ". Unsupported message.\n"); } } // Free up the memory from the handled message. delete message; // Get the next available message. message = adapter.getMessage(); if (message) { Logger::logDebug("MessageRouter::handleMessages: Got message " + toString(message->getMessageId()) + ".\n"); } } }
void collector(Adapter & adp, std::ostream & os) { static TimeSpec zero(true); static TimeSpec to_sleep(1,0); while(true) { TimeSpec now; clock_gettime(CLOCK_REALTIME,&now.time_point_); os << now.time_point_.tv_sec<< "\t" << adp.get_request_c() << endl; // BOOST_LOG_TRIVIAL(debug) << now.time_point_.tv_sec<< "\t" << adp.get_request_c() << endl; adp.set_request_c(0); if(nanosleep(&to_sleep.time_point_,NULL)) { BOOST_LOG_TRIVIAL(warning) << "nanosleep failed." << endl; } } }
void ConfigTest::testAdapter() { istringstream str("Devices = ../samples/test_config.xml\n" "Adapters { LinuxCNC { \n" "Port = 23\n" "Host = 10.211.55.1\n" "FilterDuplicates = true\n" "AutoAvailable = true\n" "IgnoreTimestamps = true\n" "PreserveUUID = true\n" "LegacyTimeout = 2000\n" "} }\n"); mConfig->loadConfig(str); Agent *agent = mConfig->getAgent(); CPPUNIT_ASSERT(agent); Device *device = agent->getDevices()[0]; Adapter *adapter = device->mAdapters[0]; CPPUNIT_ASSERT_EQUAL(23, (int) adapter->getPort()); CPPUNIT_ASSERT_EQUAL((string) "10.211.55.1", adapter->getServer()); CPPUNIT_ASSERT(adapter->isDupChecking()); CPPUNIT_ASSERT(adapter->isAutoAvailable()); CPPUNIT_ASSERT(adapter->isIgnoringTimestamps()); CPPUNIT_ASSERT_EQUAL(2000, adapter->getLegacyTimeout()); CPPUNIT_ASSERT(device->mPreserveUuid); }
/*** * str.size は 2以上、chset.size は 2以上、 * 複雑なケースのみを前提として処理する. */ Znk_INLINE void Adapter_splitCSet_core( Adapter adp, StrListHandle ans_list, const char* str, size_t str_leng, const char* chset, size_t chset_leng, size_t expect_size ) { size_t idx; size_t begin = 0; adp->reserve_( ans_list, adp->size_(ans_list) + expect_size ); while( true ){ /*** * chset を読み飛ばす処理. */ begin = ZnkS_lfind_one_not_of( str, begin, str_leng, chset, chset_leng ); if( begin >= str_leng || begin == Znk_NPOS ){ return; } /* strの終端に達した場合 */ /*** * 次にchsetが現れる場所(拾うべきトークンの最終文字位置+1)を求める. * str[begin] 自体はchsetでないことは、直前のZnkS_lfind_one_not_ofにより * 保証されている. */ idx = ZnkS_lfind_one_of( str, begin, str_leng, chset, chset_leng ); if( idx >= str_leng || idx == Znk_NPOS ){ /* * 結局最後までWS文字は見つからなかった場合. * begin より残り全部が一つのトークンとなる. **/ if( begin < str_leng ){ adp->push_bk_( ans_list, str + begin, str_leng - begin ); } break; } /*** * トークンの範囲確定. ans_listへ追加. * * str[begin] 自体はchsetでないことが保証されており * かつ idxは ZnkS_lfind_one_of の結果であるため、必ず idx > begin が成り立つはず. * つまり token_size = idx - begin > 0 */ adp->push_bk_( ans_list, str + begin, idx - begin ); begin = idx + 1; /* 残り */ } }
CMPIStatus Adapter::deleteInstance( CMPIInstanceMI* mi, const CMPIContext* context, const CMPIResult* result, const CMPIObjectPath* cmpi_op) { TRACE; _context_tls.set((void*)context); Adapter* adapter = (Adapter*)mi->hdl; Auto_RMutex auto_lock(adapter->_lock); // Convert to CIMPLE reference: const Meta_Class* mc = adapter->_mc; Instance* cimple_ref = 0; CMPIrc rc = make_cimple_reference(mc, cmpi_op, cimple_ref); Destroyer<Instance> cimple_ref_d(cimple_ref); if (rc != CMPI_RC_OK) CMReturn(rc); // Invoke provider: Delete_Instance_Status status = adapter->delete_instance(cimple_ref); switch (status) { case DELETE_INSTANCE_OK: break; case DELETE_INSTANCE_NOT_FOUND: CMReturn(CMPI_RC_ERR_NOT_FOUND); case DELETE_INSTANCE_UNSUPPORTED: CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); } CMReturnDone(result); CMReturn(CMPI_RC_OK); }
bool MessageRouter::sendMessage( const Message& message) { bool sentMessage = false; // Retrieve the adapter. Adapter* adapter = getAdapter(message.getDestination()); if (adapter == 0) { Logger::logDebug("Failed to send " + toString(message.getMessageId()) + ". No adapter specified for destination \"" + message.getDestination() + "\"\n"); } else { // Send the message over the adapter. sentMessage = adapter->sendMessage(message); } }