Atacama Large Millimeter Array ACS Training Developing a

  • Slides: 12
Download presentation
Atacama Large Millimeter Array ACS Training Developing a Client

Atacama Large Millimeter Array ACS Training Developing a Client

What files needs to be created? • C++ Implementation File SWC/LSO, October 2002 ACS

What files needs to be created? • C++ Implementation File SWC/LSO, October 2002 ACS Training 2

High-level ACS Client Concepts • Only one file needs to be created for a

High-level ACS Client Concepts • Only one file needs to be created for a client. • Need access to the IDL interface because we have no idea how this DO has been implemented. That is, we only have knowledge of the IDL interface within the client. • Need advance knowledge of what object instances are located in the CDB (although there are ways of getting around this…). SWC/LSO, October 2002 ACS Training 3

Sample C++ Implementation /** * This example shows a client that: * - logs

Sample C++ Implementation /** * This example shows a client that: * - logs into the Manager * - gets information on COBs * - takes one of them * - gets reference to a property * - reads it current value * - logs out of manager */ #include <vlt. Port. h> #include <acsutil. h> #include <maci. Simple. Client. h> #include <acsexmpl. Mount. C. h> // Note how a servant would include acsexmpl. Mount. S. h instead #include <baci. S. h> NAMESPACE_USE(maci); SWC/LSO, October 2002 // Use maci instead of baci for clients in general ACS Training 4

Sample C++ Implementation (continued) int main(int argc, char *argv[]) { /* Checks command line

Sample C++ Implementation (continued) int main(int argc, char *argv[]) { /* Checks command line arguments. We need the name of the MOUNT device to get in touch with. */ if (argc < 2) { ACS_SHORT_LOG((LM_INFO, "Usage: %s <Mount COB name> <options>", argv[0])); return -1; } /* Creates and initializes the Simple. Client object*/ Simple. Client client; if (client. init(argc, argv) == 0) { ACE_DEBUG((LM_DEBUG, "Cannot init client")); return -1; } SWC/LSO, October 2002 ACS Training 5

Sample C++ Implementation (continued) ACS_SHORT_LOG((LM_INFO, "Welcome to acsexmpl. Client!")); ACS_SHORT_LOG((LM_INFO, "Login into maci. Manager!"));

Sample C++ Implementation (continued) ACS_SHORT_LOG((LM_INFO, "Welcome to acsexmpl. Client!")); ACS_SHORT_LOG((LM_INFO, "Login into maci. Manager!")); client. login(); ACE_DECLARE_NEW_CORBA_ENV; ACE_TRY { /* List all DOs of type "*Mount*" the Manager knows of. */ ACS_SHORT_LOG((LM_INFO, "Listing all COBs of type *Mount*")); maci: : Handle. Seq seq; maci: : COBInfo. Seq_var cobs = client. manager()->get_COB_info(client. handle(), seq, "*", "*Mount*", false, ACE_TRY_ENV); ACE_TRY_CHECK; for (CORBA: : ULong i=0; i < cobs->length(); i++) { ACS_SHORT_LOG((LM_INFO, "%s (%s)", cobs[i]. name. in(), cobs[i]. type. in())); } SWC/LSO, October 2002 ACS Training 6

Sample C++ Implementation (continued) /* Now gets the specific DO we have requested on

Sample C++ Implementation (continued) /* Now gets the specific DO we have requested on the command line*/ ACS_SHORT_LOG((LM_INFO, "Getting COB: %s", argv[1])); CORBA: : Object_var obj = client. get_object(argv[1], 0, true); if (!CORBA: : is_nil(obj. in())) { MOUNT_ACS: : Mount_var mount = MOUNT_ACS: : Mount: : _narrow(obj. in(), ACE_TRY_ENV); ACE_TRY_CHECK; /*Prints the descriptor of the requested DO*/ ACS_SHORT_LOG((LM_DEBUG, "Requesting descriptor(). . . ")); ACS: : DODesc_var descriptor = mount->descriptor(ACE_TRY_ENV); ACE_TRY_CHECK; ACS_SHORT_LOG((LM_DEBUG, "Got descriptor(). ")); ACS_SHORT_LOG((LM_INFO, "Descriptor: ")); ACS_SHORT_LOG((LM_INFO, "tid: %d", descriptor->id)); ACS_SHORT_LOG((LM_INFO, "tname: %s", descriptor->name. in())); SWC/LSO, October 2002 ACS Training 7

Sample C++ Implementation (continued) /*Get the reference to the act. Az double property*/ ACS_SHORT_LOG((LM_INFO,

Sample C++ Implementation (continued) /*Get the reference to the act. Az double property*/ ACS_SHORT_LOG((LM_INFO, "Getting COB property: %s: act. Az", argv[1])); ACS: : ROdouble_var act. Az = mount->act. Az(ACE_TRY_ENV); ACE_TRY_CHECK; if (act. Az. ptr() != ACS: : ROdouble: : _nil()) { /*Get the current value of the property*/ ACS: : Completion_var completion; CORBA: : Double val = act. Az->get_sync(completion. out(), ACE_TRY_ENV); ACE_TRY_CHECK; ACS_SHORT_LOG((LM_INFO, "Value: %f", val)); } /* end if property reference OK */ } /* end if DO reference OK */ } /* end main try */ ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "main"); } ACE_ENDTRY; SWC/LSO, October 2002 ACS Training 8

Sample C++ Implementation (continued) /*Another try section where we release our COB and logout

Sample C++ Implementation (continued) /*Another try section where we release our COB and logout from the Manager*/ ACE_TRY_EX(try 2) { ACS_SHORT_LOG((LM_INFO, "Releasing. . . ")); client. manager()->release_COB(client. handle(), argv[1], ACE_TRY_ENV); ACE_TRY_CHECK_EX(try 2); client. logout(); } ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "main"); } ACE_ENDTRY; /*sleep for 3 sec to allow everything to cleanup and stabilize so that the tests can be deterministic. */ ACE_OS: : sleep(3); return 0; } SWC/LSO, October 2002 ACS Training 9

Low-level Client Concepts SWC/LSO, October 2002 ACS Training 10

Low-level Client Concepts SWC/LSO, October 2002 ACS Training 10

Other C++ Clients acsexmpl/ws/src/*Client*. cpp SWC/LSO, October 2002 ACS Training 11

Other C++ Clients acsexmpl/ws/src/*Client*. cpp SWC/LSO, October 2002 ACS Training 11

Questions about Clients? ? ? SWC/LSO, October 2002 ACS Training 12

Questions about Clients? ? ? SWC/LSO, October 2002 ACS Training 12