コード例 #1
0
/**
 * The thread to read the actual azimuth and elevation
 * The reads are synchronous
 *
 */
static void
worker(void *threadParam_p) {

	if (threadParam_p==NULL) {
		ACS_SHORT_LOG((LM_ERROR,"Invalid parameter for thread!"));
		return;
	}

	//Get access to the BACI thread this function is being executed from
    BACIThreadParameter *baciParameter_p = static_cast<BACIThreadParameter *>(threadParam_p);
    BACIThread *myself_p = baciParameter_p->getBACIThread();

	// Init the thread
    if (BACIThread::InitThread != 0)  {
		BACIThread::InitThread("Position thread");
	}

    ACS_SHORT_LOG((LM_INFO,"Thread started with name %s",myself_p->getName().c_str()));

    // Get the struct from the parameter
    ThreadParamStruct* param=(ThreadParamStruct*)baciParameter_p->getParameter();

    // Get the reference to the actAz property of the mount
    ACS::ROdouble_var actAz = param->mount->actAz();
    if (CORBA::is_nil(actAz)) {
    	ACS_SHORT_LOG((LM_ERROR,"ERROR getting actAz"));
    	return;
    }

    // Get the reference to the actEl property of the mount
    ACS::ROdouble_var actEl = param->mount->actEl();
    if (CORBA::is_nil(actEl)) {
    	ACS_SHORT_LOG((LM_ERROR,"ERROR getting actEl"));
    	return;
    }

    // The az (azimuth) and el (elevation) are declared here
    // but they are both updated in the callback
	double az,el;
	ACSErr::Completion_var completion;

	// Create the structs for the async calls to read the values of az
	AsyncCBdouble azCallback("actAz",&az);
	ACS::CBdouble_var actAz_CB = azCallback._this();
	ACS::CBDescIn actAzDescIn;
	// Create the structs for the async calls to read the values of az
	AsyncCBdouble elCallback("actEl",&el);
	ACS::CBdouble_var actEl_CB = elCallback._this();
	ACS::CBDescIn actElDescIn;

	// Create the callback for the objfix method
	AsyncMethodCBvoid objfixCB("objfix");
	ACS::CBvoid_var objfix_CB = objfixCB._this();
	ACS::CBDescIn objfixDescIn;

	// Times handshaking is not yet implemented so
	// we do not really need to fill these fields
	//objfixDescIn.normal_timeout=10000000;
	//objfixDescIn.negotiable_timeout=5000000;

	CORBA::Double newAz=(CORBA::Double)param->az;
	CORBA::Double newEl=(CORBA::Double)param->el;

	ACS_SHORT_LOG((LM_INFO,"Calling the asynchronous objfix"))

	param->mount->objfix(newAz,newEl,objfix_CB.in(),objfixDescIn);

	while(myself_p->check() == true) {

		if(myself_p->isSuspended() == false) {
			ACS_SHORT_LOG((LM_INFO,"Calling the async methods to read Az and El"))
			actAz->get_async(actAz_CB.in(),actAzDescIn);
			actEl->get_async(actEl_CB.in(),actElDescIn);
		} else {
			myself_p->sleep();
		}

		sleep(1);
	}

	ACS_SHORT_LOG((LM_INFO,"Exiting thread"))
	sleep(5);
	if (BACIThread::DoneThread != 0) {
		BACIThread::DoneThread();
	}

    delete baciParameter_p;
    myself_p->setStopped();
}
コード例 #2
0
ファイル: acsexmplClient.cpp プロジェクト: ACS-Community/ACS
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;
}