Exemplo n.º 1
0
int main (int argc, char **argv)
{
  ACS_SHORT_LOG ((LM_INFO, "Init maciLogConfigTestClient..."));
  SimpleClient client;
  MACI_TEST::LogConfigTestClass_ptr comp;
    if (client.init(argc,argv) == 0)
	{
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}
  try
    {
	comp = client.getComponent<MACI_TEST::LogConfigTestClass>("MACI_LOG_CONFIG",0,true);

	comp->log_all();


        client.releaseComponent ("MACI_LOG_CONFIG");
    	client.logout();

    }
  catch ( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION(ex, "main");
    }

  ACS_SHORT_LOG ((LM_INFO, "Exiting maciLogConfigTestClient..."));
  return 0;

} /* end main() */
Exemplo n.º 2
0
int main(int argc, char *argv[]) {

	SimpleClient client;
	if( client.init(argc, argv) == 0 ) {
		cerr << "Cannot initialize client, not continuing" << endl;
		return 1;
	}
	client.login();

	try {

		ACS_SHORT_LOG((LM_INFO,"Obtaining reference to NEWCONFIG_RECEIVER"));
		bulkdata::BulkDataReceiver_var receiver = client.getComponent<bulkdata::BulkDataReceiver>("NEWCONFIG_RECEIVER", 0, true);
	
		// This stream is not configuredon the CDB, will use a default configuration
		ACS_SHORT_LOG((LM_INFO,"Opening stream 'no_existing_stream' (not in CDB)"));
		receiver->openReceiverStream("no_existing_stream");
	
		// This is configured on the CDB, cool
		ACS_SHORT_LOG((LM_INFO,"Opening stream 'Name1' (in CDB)"));
		receiver->openReceiverStream("Name1");
		sleep(2);

		// Open the rest of the receivers
		ACS_SHORT_LOG((LM_INFO,"Opening all remaining streams (namely, Name7)"));
		receiver->openReceiver();
	
		// now sleep a little bit
		ACS_SHORT_LOG((LM_INFO,"Sleeping 10 seconds"));
		ACE_OS::sleep(10);
	
		// and close the receivers
	
		// woops, this doesn't exist
		ACS_SHORT_LOG((LM_INFO,"Closing stream 'name12'"));
		receiver->closeReceiverStream("name12");
	
		// This was the one we wanted to close before
		ACS_SHORT_LOG((LM_INFO,"Closing stream 'Name1'"));
		receiver->closeReceiverStream("Name1");
		ACS_SHORT_LOG((LM_INFO,"Closing stream 'no_existing_stream' (but now it does exist)"));
		receiver->closeReceiverStream("no_existing_stream");
	
		// close the rest
		ACS_SHORT_LOG((LM_INFO,"Closing remaining streams"));
		receiver->closeReceiver();

		// Close receiver
		client.releaseComponent("NEWCONFIG_RECEIVER");

	} catch(maciErrType::CannotGetComponentExImpl &ex) {
		cerr << "Cannot get component '" << ex.getCURL() << "'. Reason: " << ex.getReason() << endl;
	} catch(...) {
		cerr << "Unexpected exception while running test code" << endl;
		client.logout();
	}
}
Exemplo n.º 3
0
/** @cond
*/
int main(int argc, char* argv[])
{
    MOUNT_ACS::Mount_var mount;
    BACIThreadManager threadManager;   // The thread manager is used to manage the thread
    ThreadParamStruct param; // The parameter for the thread

    // Check the arguments in the command line
	if (argc<2) {
		std::cerr<<"Usage: "<<argv[0]<<" component azimuth elevation <options>\n";
		return -1;
	}

	double destAz, destEl;
	if (sscanf(argv[2],"%lf",&destAz)+sscanf(argv[3],"%lf",&destEl)!=2) {
		std::cerr<<"Format error in azimuth and/or elevation"<<std::endl;
		std::cerr<<"Usage: "<<argv[0]<<" component azimuth elevation <options>\n";
		return -1;
	}

	// Create the SimpleClient object
	SimpleClient mountClient;

	// Init the client
	if (mountClient.init(argc,argv)==0) {
		// Error initing
		ACS_SHORT_LOG((LM_ERROR,"Error initing the client"));
		return -1;
	} else {
		ACS_SHORT_LOG((LM_INFO,"SimpleClient built"));
	}

	// Login the client
	if (mountClient.login()==0) {
		//Error
		ACS_SHORT_LOG((LM_ERROR,"Error logging in the client"));
		return -1;
	} else {
		ACS_SHORT_LOG((LM_INFO,"Client logged in"));
	}

	try
	    {
	    // Get the component
	    ACS_SHORT_LOG((LM_INFO,"Getting component %s",argv[1]));
	    mount = mountClient.getComponent<MOUNT_ACS::Mount>(argv[1], 0, true);
	    }
	catch(maciErrType::CannotGetComponentExImpl &_ex)
	    {
	    _ex.log();
	    return -1;
	    }

	param.mount=mount.ptr();
	param.az=destAz;
	param.el=destEl;

	char logStr[128];
	sprintf(logStr,"Commanded position az=%lf, el=%lf",destAz,destEl);
	ACS_SHORT_LOG((LM_INFO,logStr));

	// Start the thread to read the position of the antenna
	ACS_SHORT_LOG((LM_INFO,"Starting the thread"));
	BACIThread* thread_p = threadManager.create("Position thread",    //Name of the new thread
		(void *)worker,    //Function to run inside the thread
		static_cast<void *>(&param));    //the single parameter

	if (thread_p==NULL)  {
		ACS_SHORT_LOG((LM_ERROR,"Error in spawning thread"));
	}
        thread_p->resume();

	// The thread will run for 30 secs so we wait until it finishes
	// There are better (and safer) solution to wait instead of a simple wait
	// but... this is the faster one!
	sleep(40);

	// End of computation: begin to clean up

	// Stop all the threads
	ACS_SHORT_LOG((LM_INFO,"Terminating the thread"));
	threadManager.terminateAll();

	// Release the component
	try
	    {
	    ACS_SHORT_LOG((LM_INFO,"Releasing %s",argv[1]));
	    mountClient.releaseComponent(argv[1]);
	    }
	catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	    {
	    _ex.log();
	    return -1;
	    }

	// logout the client
	try
	    {
	    ACS_SHORT_LOG((LM_INFO,"Logging out"));
	    mountClient.logout();
	    }
	catch (...)
	    {
	    ACS_SHORT_LOG((LM_ERROR,"Error logging out the simple client object"));
	    ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
							    "main");
	    uex.log();
	    return -1;
	    }//try-catch

	ACS_SHORT_LOG((LM_INFO,"Done"));

	return 0;
}
Exemplo n.º 4
0
/** @cond
*/
int main(int argc, char *argv[])
{
    SimpleClient client;
    acsexmplHelloWorld::HelloWorld_var foo;

// Creates and initializes the SimpleClient object

    if (client.init(argc,argv) == 0)
    {
        return -1;
    }
    else
    {
        //Must log into manager before we can really do anything
        client.login();
    }

    try
    {
        //Get the specific component we have requested on the command-line
        foo = client.getComponent<acsexmplHelloWorld::HelloWorld>(argv[1], 0, true);
    }
    catch(maciErrType::CannotGetComponentExImpl &_ex)
    {
        _ex.log();
        return -1;
    }


    //Call the displayMessage() method existing in the interface for HelloWorld
    foo->displayMessage();

    try
    {
        foo->badMethod();
    }
    catch(ACSErrTypeCommon::UnknownEx &ex)
    {
        ACSErrTypeCommon::UnknownExImpl badMethodEx(ex);
        badMethodEx.log();
        ACS::Time timeStamp = badMethodEx.getTimeStamp();
        ACE_CString tString = getStringifiedUTC(timeStamp);
        ACS_DEBUG_PARAM(argv[0], "Time of the exception: %s\n", tString.c_str());
    }

    //We release our component and logout from manager
    try
    {
        client.releaseComponent(argv[1]);
    }
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
    {
        _ex.log();
        return -1;
    }

    client.logout();

    //Sleep for 3 sec to allow everytihng to cleanup and stablize
    ACE_OS::sleep(3);
    return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    // Checks command-line arguments.
    if (argc < 2)
	{
	ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
	return -1;
	}
    else
	{
	ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
	}
    
    //Creates and initializes the SimpleClient object
    SimpleClient client;
    if (client.init(argc,argv) == 0)
	{
	ACE_DEBUG((LM_DEBUG,"Cannot init client"));
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}

    try
	{
	//List all components of type "*Mount*" the Manager knows of. 
	ACS_SHORT_LOG((LM_INFO, "Listing all components of type *Mount*"));
	maci::HandleSeq seq;
	//See the doxygen documentation for maci.idl to understand what these parameters
	//are.
	maci::ComponentInfoSeq_var components = client.manager()->get_component_info(client.handle(), 
										     seq, 
										     "*", 
										     "*Mount*", 
										     false);
	
	for (CORBA::ULong i = static_cast<CORBA::ULong>(0); i < components->length(); i++)
	    {
	    //just print out all known mount components
	    ACS_SHORT_LOG((LM_INFO,"%s (%s)", components[i].name.in(), components[i].type.in()));
	    }
	
	// Now get the specific component we have requested from the command-line
	ACS_SHORT_LOG((LM_INFO, "Getting component: %s", argv[1]));

	//getComponent can throw an exception if it fails
	MOUNT_ACS::Mount_var mount = client.getComponent<MOUNT_ACS::Mount>(argv[1], 0, true);
	
	
	//Prints the descriptor of the requested component
	ACS_SHORT_LOG((LM_DEBUG, "Requesting descriptor()... "));
	ACS::CharacteristicComponentDesc_var descriptor = mount->descriptor();
	ACS_SHORT_LOG((LM_DEBUG, "Got descriptor()."));
	ACS_SHORT_LOG((LM_INFO,"Descriptor:"));
	ACS_SHORT_LOG((LM_INFO,"\tname: %s", descriptor->name.in()));
	
	//Get the reference to the  actAz double property
	ACS_SHORT_LOG((LM_INFO, "Getting component property: %s:actAz", argv[1]));
	ACS::ROdouble_var actAz = mount->actAz();
	    
	if (actAz.ptr() != ACS::ROdouble::_nil())
	    {
	    //Get the current value of the property synchronously
	    ACSErr::Completion_var completion;
	    CORBA::Double val = actAz->get_sync(completion.out());
	    ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
	    
	    
	    //Create the CBdouble property
	    ACS_SHORT_LOG((LM_INFO, "Trying to narrow CB for actAz... "));
	    MyCBdouble myCallback("actAz");
	    //Activate it as a CORBA object
	    ACS::CBdouble_var cb = myCallback._this(); 
	    ACS_SHORT_LOG((LM_INFO, "OK"));
	    
	    //Invoke the asynchronous method.
	    ACS_SHORT_LOG((LM_INFO, "Call get_async for actAz..."));
	    ACS::CBDescIn desc;
	    actAz->get_async(cb.in(), desc);    //returns control immediately
	    
	    //Here some other useful things should be done
	    //while the asyncrhonous reply comes
	    //...
	    //...
	    //...
	    
	    //Enter main loop and stays there for a fixed amount of time (1s)
	    //This is done to give the asynchronous method a chance to finish.
	    ACE_Time_Value tv(1);
	    client.run(tv);
	    }//if
	}
    catch(maciErrType::CannotGetComponentExImpl &_ex) // can be thrown by getComponent<..>(...)
	{
	_ex.log();
	return -1;
	}
    catch( CORBA::SystemException &_ex ) // can be thrown by get_component_info
	{
	ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(__FILE__, __LINE__,
							    "main");
	corbaProblemEx.setMinor(_ex.minor());
	corbaProblemEx.setCompletionStatus(_ex.completed());
	corbaProblemEx.setInfo(_ex._info().c_str());
	corbaProblemEx.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}//try-catch
  
    //Another try section where we release our component and logout from the Manager
    try
	{
	ACS_SHORT_LOG((LM_INFO,"Releasing..."));
	client.releaseComponent( argv[1]);	
	client.logout();
	}
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}//try-catch
    
    
    //sleep for 3 sec to allow everytihng to cleanup and stabilize
    //so that the tests can be determinitstic.
    ACE_OS::sleep(3);   
    return 0;
}
Exemplo n.º 6
0
/*
 * Main procedure
 */
int main(int argc, char *argv[])
{
    //Checks command-line arguments.
    if (argc < 2)
	{
	ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
	return -1;
	}
    else
	{
	ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
	}

    //Creates and initializes the SimpleClient object
    SimpleClient client;    
    if (client.init(argc,argv) == 0)
	{
	ACE_DEBUG((LM_DEBUG,"Cannot init client"));
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}

    //Create an instance of our user-defined callback class
    MyCBdouble myCallback("refTemp");

    try
	{
	//Get the specific component we have requested on the command-line
	FRIDGE::FridgeControl_var fridge = client.getComponent<FRIDGE::FridgeControl>(argv[1], 0, true);
	    
	//Get one of the component's BACI properties
	ACS::RWdouble_var refTemperature = fridge->refTemperature();
	
	if (refTemperature.ptr() != ACS::RWdouble::_nil())
	    {
	    ACSErr::Completion_var completion;
	    
	    //Just synchronously reading the value of refTemp
	    CORBA::Double val = refTemperature->get_sync(completion.out());
	    ACS_SHORT_LOG((LM_INFO,"Value: %f", val));
	    
	    //Activate the callback as a CORBA object
	    ACS::CBdouble_var cb = myCallback._this();
	    ACS_SHORT_LOG((LM_INFO, "OK"));
	    
	    ACS::CBDescIn desc;
	    desc.id_tag = 2;
	    ACS_SHORT_LOG((LM_INFO, "Trying to create monitor for refTemperature..."));

	    //Create the actual monitor
	    ACS::Monitordouble_var md = refTemperature->create_monitor(cb.in(), desc);
	    if (md.ptr() != ACS::Monitordouble::_nil())
		{
		ACS_SHORT_LOG((LM_INFO, "OK"));
		//Set the timer trigger to one second.
		md->set_timer_trigger(10000000);
		}
	    else
		{
		ACS_SHORT_LOG((LM_INFO, "Failed"));
		}

	    //Give the callback some time to run.
	    ACE_Time_Value time(20);
	    client.run(time);
	    
	    //Must explicitly destroy the callback before exiting
	    md->destroy();
	    //Give the callback time to be really destroyed
	    ACE_OS::sleep(15);
	    }
	}
    catch(maciErrType::CannotGetComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}//try-catch
        
    try
	{
	//Must release components and logout from manager	
	ACS_SHORT_LOG((LM_INFO,"Releasing..."));
	client.releaseComponent(argv[1]);
	client.logout();
	}
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							    "main");
	uex.log();
	return -1;
	}//try-catch
  
    // sleep for 3 sec.
    ACE_OS::sleep(3);
    return 0;
}
/** @cond
*/    
int main(int argc, char *argv[]) 
{
    //Checks command-line arguments
    if (argc < 2)
	{
	ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
	return -1;
	}
    else
	{
	ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
	}
    
    //Creates and initialyses the SimpleClient object
    SimpleClient client;
    if (client.init(argc,argv) == 0)
	{
	ACE_DEBUG((LM_DEBUG,"Cannot init client"));
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}
    
    try
	{
	//Gets from manager the reference to the requested component.
	//Pay special attention that this reference is just a generic
	//CORBA object at this point.
	ACS_SHORT_LOG((LM_INFO, "Looking for Object '%s' ", argv[1]));
        CORBA::Object_var obj =  client.getComponent(argv[1], 0 , true);
	
	//Get the stringified IOR of the component.  The IOR of CORBA objects
	//can be considered to be a unique "phone number" used to access CORBA
	//servants.
	ACS_SHORT_LOG((LM_INFO, "Getting stringified IOR"));
	CORBA::String_var mior = client.getORB()->object_to_string(obj.in());    
	
	//Print the IOR to standard out
	u_int result;         
	ACS_SHORT_LOG ((LM_INFO, "IOR for %s is: %s", argv[1], mior.in()));
	result = ACE_OS::printf ("%s", mior.in());
	}
    catch(maciErrType::CannotGetComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	
	uex.log();
	return -1;
	}

    //Normally you would not want to have separate try sections for releasing
    //the components and logging out from manager.  This is a very special case 
    //since we do not know ahead of time what will be released.  In other words,
    //argv[1] could technically be "manager" which would end up raising a 
    //no-permission exception.  To get around this just use separate try/catch 
    //sections and ignore no-permission exceptions.
    try
	{
	//All clients must cleanly release objects they activate!
	client.releaseComponent(argv[1]);
	}
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}
    
    try
	{
	if (client.logout() == 0)
	    {
	    ACS_SHORT_LOG ((LM_INFO, "Cannot logout"));
	    return -1;
	    }
	}
    catch(...)
	{
	ACS_SHORT_LOG((LM_ERROR, "Exception caught"));
	return -1;
	}    
    
    ACS_SHORT_LOG((LM_INFO,"The end!"));
    return 0;
}
Exemplo n.º 8
0
/** @cond
*/    
int main(int argc, char *argv[])
{   
    //Checks command-line arguments.
    if (argc < 2)
	{
	ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
	return -1;
	}
    else
	{
	ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
	}

    //Creates and initializes the SimpleClient object
    SimpleClient client;
    if (client.init(argc,argv) == 0)
	{
	ACE_DEBUG((LM_DEBUG,"Cannot init client"));
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}

    try
	{
	//Get the specific component we have requested on the command-line
	FRIDGE::FridgeControl_var fridge = client.getComponent<FRIDGE::FridgeControl>(argv[1], 0, true);
	
	//Run whatever supported command the end-user has specified
	//from the command-line
	if(strcmp(argv[2],"ON") == 0)    // Command ON
	    {
	    ACS_SHORT_LOG((LM_INFO, "ON"));
	    fridge->on();
	    }
	else if(strcmp(argv[2],"OFF") == 0)    // Command OFF
	    {
	    ACS_SHORT_LOG((LM_INFO, "OFF"));
	    fridge->off();
	    }
	else if(strcmp(argv[2],"OPEN") == 0)    // Command OPEN
	    {
	    ACS_SHORT_LOG((LM_INFO, "OPEN"));
	    fridge->open();
	    }
	else if(strcmp(argv[2],"CLOSE") == 0)    // Command CLOSE
	    {
	    ACS_SHORT_LOG((LM_INFO, "CLOSE"));
	    fridge->close();
	    }
	else
	    {
	    // User specified some non-existant command
	    ACS_SHORT_LOG((LM_INFO, "Unknown command"));
	    }
	}
    catch(maciErrType::CannotGetComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}
    
    try
	{
	//Release the component and log out from manager.
	ACS_SHORT_LOG((LM_INFO,"Releasing..."));
	client.releaseComponent(argv[1]);
	client.logout();
	}
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	}//try-catch
       
    // sleep for 3 sec.
    ACE_OS::sleep(3);
    return 0;
}