/******************************************************************************************* * main ********************************************************************************************/ int main(int argc, char* argv[]) { if (argc<2) { ACE_OS::printf ("usage: %s <object_name>\n", argv[0]); return -1; } try { ACE_CString g_strCmdLn; for (int i=argc-1; i>=0; i--) g_strCmdLn = ACE_CString(argv[i])+ " " + g_strCmdLn; if (g_strCmdLn.find("-ORBDottedDecimalAddresses")==ACE_CString::npos) g_strCmdLn += " -ORBDottedDecimalAddresses 1"; ACE_TCHAR **m_argv = argv; int m_argc = argc; ACE_OS::string_to_argv((ACE_TCHAR*)g_strCmdLn.c_str(), m_argc, m_argv); BACI_CORBA::InitCORBA(m_argc, m_argv); LoggingProxy EP_log (0, 0, 31, 0, 0, 1); LoggingProxy::init (&EP_log); /** * Get reference to a device */ char fileName[64]; sprintf(fileName, "file://%s.ior", argv[1]); CORBA::Object_var object = BACI_CORBA::getORB()->string_to_object (fileName); if (CORBA::is_nil(object.in())) { ACE_DEBUG ((LM_DEBUG, "Cannot get Object")); return -1; } // Try to narrow the object reference to a PowerSupply reference. ENUMPROP_TEST::enumpropTestDevice_var dev = ENUMPROP_TEST::enumpropTestDevice::_narrow (object.in ()); if (CORBA::is_nil(dev.in())) { ACS_SHORT_LOG((LM_DEBUG, "Failed to narrow enumnTestDevice ")); return 0; } ACS_SHORT_LOG((LM_DEBUG, "Device narrowed.")); //dev->off(); // Get current stat ENUMPROP_TEST::ROStates_var currentState = dev->currentState(); // get states description ACS::stringSeq_var description = currentState->statesDescription( ); AlarmCBpattern alarmCB (currentState.in()); ACS::Alarmpattern_var alarmCBObj = alarmCB._this(); ACS::CBDescIn desc; desc.id_tag = 1; ACS::Subscription_var monitor = currentState->new_subscription_AlarmEnum(alarmCBObj.in(), desc); // monitor->set_timer_trigger(10000000); SetterThread setterThread("setter thread", dev); setterThread.resume(); ACS_SHORT_LOG((LM_DEBUG, "(main thread) Going in main loop sleep...")); ACE_Time_Value tv(20); BACI_CORBA::getORB()->run(tv); ACS_SHORT_LOG((LM_DEBUG, "(main thread) Exit ... ")); monitor->destroy(); /* Allow time for the done() callback to come back */ BACI_CORBA::getORB()->run(tv); dev->serverShutdown(); ACS_SHORT_LOG((LM_INFO, "Exiting ....")); /*EP_log.flush(); LoggingProxy::done(); delete &EP_log;*/ BACI_CORBA::DoneCORBA(); } catch( CORBA::Exception &ex ) { ex._tao_print_exception("Error!"); return -1; } return 0; }
int main (int argc, char **argv) #endif { try { // create logging proxy LoggingProxy *m_logger = new LoggingProxy(0, 0, 31, 0); LoggingProxy::init(m_logger); LoggingProxy::ProcessName(argv[0]); LoggingProxy::ThreadName("main"); ACS_TEST_INIT_LOGGING; // // Initialysation of CORBA, POA and related CORBA internals // ACE_CString g_strCmdLn; for (int i=argc-1; i>=0; i--) g_strCmdLn = ACE_CString(argv[i])+ " " + g_strCmdLn; if (g_strCmdLn.find("-ORBDottedDecimalAddresses")==ACE_CString::npos) g_strCmdLn += " -ORBDottedDecimalAddresses 1"; ACE_TCHAR **m_argv = argv; int m_argc = argc; ACE_OS::string_to_argv((ACE_TCHAR*)g_strCmdLn.c_str(), m_argc, m_argv); BACI_CORBA::InitCORBA(m_argc, m_argv); std::string readIOR; int result = read_IOR_from_file ("BACIALARM", readIOR); if (result != 0) { ACS_SHORT_LOG((LM_ERROR, "Cannot read IOR from file")); return -1; } // Get an object reference from the argument string. CORBA::Object_var object = BACI_CORBA::getORB()->string_to_object (readIOR.c_str()); if (CORBA::is_nil(object.in())) { ACS_SHORT_LOG ((LM_DEBUG, "Cannot create OBJ from IOR")); return -1; } // Try to narrow the object reference to a BaciTestAlarmClass reference. BACI_TEST::BaciTestAlarmClass_var comp = BACI_TEST::BaciTestAlarmClass::_narrow(object.in()); CORBA::String_var ior = BACI_CORBA::getORB()->object_to_string (comp.in()); ACS_SHORT_LOG((LM_INFO,"baciTestAlarmClient: Connecting to: %s", ior.in())); /********************* pattern alarm subscription ******************/ ACS::ROpattern_var roPattern = comp->roPatternProperty(); ACS::RWpattern_var rwPattern = comp->rwPatternProperty(); //create an instance of our alarm class MyAlarmpattern macb("roPatternProperty"); //activate it as a CORBA object ACS::Alarmpattern_var acb = macb._this(); //create the actual BACI double alarm ACS::CBDescIn desc; ACS::Subscription_var alarmSub = roPattern->new_subscription_Alarm(acb.in(), desc); ACS_SHORT_LOG((LM_INFO,"Alarmpattern subscription created")); // create the thread WorkerThreadPattern threadPattern_p ("actionThreadPattern", comp, ThreadBase::defaultResponseTime, ThreadBase::defaultSleepTime*10 /*=1s*/); // by default threads that are not created using a thread manager are creatd suspended so we have to resume them!! threadPattern_p.resume(); //--------------------------------------------------------------- //Enter main loop and stays there for a fixed amount of time. Really we are //just allowing the thread we just created to run for awhile before exiting out //of this example. ACS_SHORT_LOG((LM_INFO,"baciTestAlarmClient: main thread, entering ORB loop to sleep...")); ACE_Time_Value tv(25); BACI_CORBA::getORB()->run(tv); //Must cleanly destroy the alarm ACS_SHORT_LOG((LM_INFO,"Alarm subscriptions deleted")); alarmSub->destroy(); ACS_SHORT_LOG((LM_INFO,"baciTestAlarmClient: main thread, shutting down...")); comp->shutdown(); sleep(10); BACI_CORBA::DoneCORBA(); // Delete the logger last. delete m_logger; } catch(CORBA::Exception &ex) { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"Error!"); return -1; } ACE_CHECK_RETURN (-1); // Wait for the servant to complete cleanup before exiting. sleep(2); return 0; } /* end main() */