00001
#ifndef maciSimpleClient_H
00002
#define maciSimpleClient_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __cplusplus
00018
#error This is a C++ include file and cannot be used from plain C
00019
#endif
00020
00021
#include <acsutil.h>
00022
#include <maciExport.h>
00023
00024
#include <logging.h>
00025
00026
#include <maciS.h>
00027
#include <ace/SString.h>
00028
00029
#include "maciSimpleClientThreadHook.h"
00030
#include <ACSErrTypeCommon.h>
00031
#include <maciErrType.h>
00032
#include <ACSErrTypeCORBA.h>
00033
00034
#include <acsComponentSmartPtr.h>
00035
00036
namespace maci {
00037
00038
class SimpleClient;
00039
00040
00041
template<
typename T,
class H = SimpleClient>
00042 class ComponentSmartPtr :
public SmartPtr<T, H, Loki::RefCountedMTAdj<Loki::ObjectLevelLockable>::RefCountedMT,
00043 Loki::DisallowConversion, Loki::NoCheck, ComponentStorage, Loki::LOKI_DEFAULT_CONSTNESS> {
00044
public:
00045
00049 ComponentSmartPtr()
00050 {}
00051
00061 ComponentSmartPtr(H* h,
bool s, T* p)
00062 {
00063 setValues(h, s, p);
00064 }
00065
00066
00067 };
00068
00069
00077 class maci_EXPORT SimpleClient :
00078
public virtual POA_maci::Client,
00079
public virtual PortableServer::
RefCountServantBase
00080 {
00081
00082
public:
00083
00087 SimpleClient ();
00088
00092
virtual ~SimpleClient ();
00093
00098
int destroy();
00099
00104
int initCORBA(
int argc,
char * argv[]);
00105
00109 CORBA::ORB_ptr getORB();
00110
00115
int doneCORBA();
00116
00122
int login();
00123
00128
int logout();
00129
00141
int init(
int argc,
char *argv[]);
00142
00148
int run (ACE_Time_Value &tv
00149 );
00150
00155
int run ();
00156
00157
static void initThread(
const char * threadName);
00158
static void doneThread();
00159
00164 maci::Manager_ptr manager();
00165
00170 maci::Handle handle();
00171
00183 CORBA::Object_ptr getComponent(
const char *name,
const char *domain,
bool activate);
00184
00190 CORBA::Object_ptr get_object(
const char *name,
const char *domain,
bool activate)
00191 {
00192
return getComponent(name, domain, activate);
00193 }
00194
00195
00212
template<
class T>
00213 T* getComponent(
const char *name,
const char *domain,
bool activate);
00214
00222 CORBA::Object* getDynamicComponent(maci::ComponentSpec compSpec,
bool markAsDefault);
00223
00231
template<
class T>
00232 T* getDynamicComponent(maci::ComponentSpec compSpec,
bool markAsDefault);
00249
template<
class T>
00250
ComponentSmartPtr<T> getComponentSmartPtr(
const char *name,
const char *domain,
bool activate);
00251
00259
template<
class T>
00260
ComponentSmartPtr<T> getDynamicComponentSmartPtr(maci::ComponentSpec compSpec,
bool markAsDefault);
00266
template<
class T>
00267 T* get_object(
const char *name,
const char *domain,
bool activate)
00268 {
00269
return getComponent<T>(name, domain, activate);
00270 }
00271
00279 CORBA::Object* getComponentNonSticky(
const char *name);
00280
00289
template <
class T>
00290 T* getComponentNonSticky(
const char *name);
00291
00300
template <
class T>
00301
ComponentSmartPtr<T> getComponentNonStickySmartPtr(
const char *name);
00302
00310
long releaseComponent(
const char* name);
00311
00312
00313
00314
00315
00319
virtual char * name ();
00320
00325
virtual void disconnect ();
00326
00336 virtual ::maci::AuthenticationData * authenticate (
00337 ::maci::ExecutionId execution_id,
const char * question);
00338
00344
virtual void message (CORBA::Short type,
00345
const char * message
00346 );
00347
00354
virtual void taggedmessage (CORBA::Short type,
00355 CORBA::Short tag,
00356
const char * message
00357 );
00358
00363
virtual void components_available (
const maci::ComponentInfoSeq & cobs
00364 );
00365
00370
virtual void components_unavailable (
const maci::stringSeq & cob_names
00371 );
00372
00373
00382
virtual CORBA::Boolean ping ();
00383
00386 static LoggingProxy * getLoggerProxy()
00387 {
00388
return m_logger;
00389 }
00390
00393 static const char * getProcessName()
00394 {
00395
return m_processName.c_str();
00396 }
00397
00398
private:
00399
00401 maci::Manager_var m_manager;
00402
00404 maci::Handle m_handle;
00405
00407 bool m_initialized;
00408
00410 PortableServer::POA_var m_poaRoot;
00411
00413 PortableServer::POA_var m_poaPersistent;
00414
00416 PortableServer::POA_var m_poaTransient;
00417
00419 CORBA::ORB_var m_orb;
00420
00422 static LoggingProxy* m_logger;
00423
00425 static ACE_CString m_processName;
00426
00428 maci::SimpleClientThreadHook m_simpleClientThreadHook;
00429
00431 maci::ExecutionId m_executionId;
00432
00434 ACS::Time m_startTime;
00435 };
00436
00437
00438
00439
00440
00441
00442
00443
00444
template<
class T>
00445 T* SimpleClient::getComponent(
const char *name,
const char *domain,
bool activate)
00446 {
00447
if(!
m_initialized)
00448 {
00449 ACSErrTypeCommon::NotInitializedExImpl notInitEx( __FILE__, __LINE__,
00450
"maci::SimpleClient::getComponent<>");
00451 notInitEx.setName(
"SimpleClient");
00452 maciErrType::CannotGetComponentExImpl ex( notInitEx, __FILE__, __LINE__,
00453
"maci::SimpleClient::getComponent<>");
00454 name ? ex.setCURL(name) : ex.setCURL(
"NULL");
00455
throw ex;
00456 }
00457
00458
if(!name)
00459 {
00460 ACSErrTypeCommon::NullPointerExImpl nullEx(__FILE__, __LINE__,
00461
"maci::SimpleClient::getComponent<>");
00462 nullEx.setVariable(
"(parameter) name");
00463 maciErrType::CannotGetComponentExImpl ex(nullEx, __FILE__, __LINE__,
00464
"maci::SimpleClient::getComponent<>");
00465 ex.setCURL(
"NULL");
00466
throw ex;
00467 }
00468
00473
char *curl_str =
"curl://";
00474
00475 ACE_CString curl =
"";
00476
if(strncmp(name, curl_str, strlen(curl_str)) != 0 )
00477 {
00478 curl += curl_str;
00479
if (domain)
00480 curl += domain;
00481
00482 curl += ACE_CString(
"/");
00483 }
00484 curl += name;
00485
00486
ACS_SHORT_LOG((LM_DEBUG,
"Getting component: '%s'. Creating it...", curl.c_str()));
00487
00488
try
00489 {
00491 CORBA::Object_var obj =
manager()->get_service(
m_handle, curl.c_str(), activate);
00492 T* tmpRef = T::_narrow(obj);
00493
if (CORBA::is_nil(tmpRef))
00494 {
00495
releaseComponent(name);
00496 ACSErrTypeCORBA::NarrowFailedExImpl ex(__FILE__, __LINE__,
"maci::SimpleClient<>::getComponent");
00497 ex.setNarrowType(
typeid(T).
name());
00498
throw ex;
00499 }
00500
return tmpRef;
00501 }
00502
catch(maciErrType::NoPermissionEx &_ex)
00503 {
00504 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00505
"maci::SimpleClient::getComponent<>");
00506 ex.setCURL(name);
00507
throw ex;
00508 }
00509
catch(maciErrType::CannotGetComponentEx &_ex)
00510 {
00511 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00512
"maci::SimpleClient::getComponent<>");
00513 ex.setCURL(name);
00514
throw ex;
00515 }
00516
catch(maciErrType::ComponentNotAlreadyActivatedEx &_ex)
00517 {
00518 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00519
"maci::SimpleClient::getComponent<>");
00520 ex.setCURL(name);
00521
throw ex;
00522 }
00523
catch(maciErrType::ComponentConfigurationNotFoundEx &_ex)
00524 {
00525 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00526
"maci::SimpleClient::getComponent<>");
00527 ex.setCURL(name);
00528
throw ex;
00529 }
00530
catch (
ACSErr::ACSbaseExImpl &ex)
00531 {
00532 maciErrType::CannotGetComponentExImpl lex(ex, __FILE__, __LINE__,
00533
"maci::SimpleClient<T>::getComponent");
00534 lex.setCURL(name);
00535
throw lex;
00536 }
00537
catch( CORBA::SystemException &_ex )
00538 {
00539 ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(__FILE__, __LINE__,
00540
"maci::SimpleClient::getComponent<>");
00541 corbaProblemEx.setMinor(_ex.minor());
00542 corbaProblemEx.setCompletionStatus(_ex.completed());
00543 corbaProblemEx.setInfo(_ex._info().c_str());
00544 maciErrType::CannotGetComponentExImpl ex(corbaProblemEx, __FILE__, __LINE__,
00545
"maci::SimpleClient::getComponent<>");
00546 ex.setCURL(name);
00547
throw ex;
00548 }
00549
catch(...)
00550 {
00551 ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
00552
"maci::SimpleClient::getComponent<>");
00553 maciErrType::CannotGetComponentExImpl ex(uex, __FILE__, __LINE__,
00554
"maci::SimpleClient::getComponent<>");
00555 ex.setCURL(name);
00556
throw ex;
00557 }
00558 }
00559
00560
00561
00562
00563
template<
class T>
00564 ComponentSmartPtr<T> SimpleClient::getComponentSmartPtr(
const char *name,
const char *domain,
bool activate)
00565 {
00566
return ComponentSmartPtr<T>(
this,
true, this->getComponent<T>(name, domain, activate));
00567 }
00568
00569
00570
00571
template<
class T>
00572 ComponentSmartPtr<T> SimpleClient::getDynamicComponentSmartPtr(maci::ComponentSpec compSpec,
bool markAsDefault)
00573 {
00574
return ComponentSmartPtr<T>(
this,
true, this->getDynamicComponent<T>(compSpec,markAsDefault));
00575 }
00576
00577
00578
00579
00580
00581
00582
template<
class T>
00583 T* SimpleClient::getDynamicComponent(maci::ComponentSpec compSpec,
bool markAsDefault)
00584 {
00585
00586
00587
00588
00589
00590
00591 ComponentInfo_var cInfo;
00592
ACS_TRACE(
"maci::SimpleClient<>::getDynamicComponent");
00593
try
00594 {
00595 cInfo =
m_manager->get_dynamic_component(
m_handle,
00596 compSpec,
00597 markAsDefault);
00598 CORBA::Object_var obj = cInfo->reference;
00599
if (CORBA::is_nil(obj.in()))
00600 {
00601 ACSErrTypeCORBA::CORBAReferenceNilExImpl ex(__FILE__, __LINE__,
00602
"maci::SimpleClient<>::getDynamicComponent");
00603 ex.setVariable(
"cInfo->reference");
00604
throw ex;
00605 }
00606
00607
00608 T* tmpRef = T::_narrow(obj);
00609
if(CORBA::is_nil(tmpRef))
00610 { ACSErrTypeCORBA::NarrowFailedExImpl ex(__FILE__, __LINE__,
"maci::SimpleClient<>::getDynamicComponent");
00611
00612
throw ex;
00613 }
00614
return tmpRef;
00615
00616 }
00617
catch (maciErrType::NoPermissionEx &ex)
00618 {
00619 maciErrType::NoPermissionExImpl lex(ex, __FILE__, __LINE__,
00620
"maci::SimpleClient<>::getDynamicComponent");
00621
throw lex;
00622 }
00623
catch (maciErrType::IncompleteComponentSpecEx &ex)
00624 {
00625 maciErrType::IncompleteComponentSpecExImpl lex(ex, __FILE__, __LINE__,
00626
"maci::SimpleClient<>::getDynamicComponent");
00627 lex.setCURL(compSpec.component_name.in());
00628
throw lex;
00629 }
00630
catch (maciErrType::InvalidComponentSpecEx &ex)
00631 {
00632 maciErrType::InvalidComponentSpecExImpl lex(ex, __FILE__, __LINE__,
00633
"maci::SimpleClient<>::getDynamicComponent");
00634
throw lex;
00635 }
00636
catch (maciErrType::ComponentSpecIncompatibleWithActiveComponentEx &ex)
00637 {
00638 maciErrType::ComponentSpecIncompatibleWithActiveComponentExImpl lex(ex, __FILE__, __LINE__,
00639
"maci::SimpleClient<>::getDynamicComponent");
00640 lex.setCURL(compSpec.component_name.in());
00641
throw lex;
00642 }
00643
catch (maciErrType::CannotGetComponentEx &ex)
00644 {
00645 maciErrType::CannotGetComponentExImpl lex(ex, __FILE__, __LINE__,
00646
"maci::SimpleClient<>::getDynamicComponent");
00647 lex.setCURL(compSpec.component_name.in());
00648
throw lex;
00649 }
00650
catch(
ACSErr::ACSbaseExImpl &ex)
00651 {
00652 maciErrType::CannotGetComponentExImpl lex(ex, __FILE__, __LINE__,
00653
"maci::SimpleClient<>::getDynamicComponent");
00654 lex.setCURL(compSpec.component_name.in());
00655
throw lex;
00656 }
00657
catch( CORBA::SystemException &ex )
00658 {
00659 ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(__FILE__, __LINE__,
00660
"maci::SimpleClient<>::getDynamicComponent");
00661 corbaProblemEx.setMinor(ex.minor());
00662 corbaProblemEx.setCompletionStatus(ex.completed());
00663 corbaProblemEx.setInfo(ex._info().c_str());
00664
00665 maciErrType::CannotGetComponentExImpl lex(corbaProblemEx, __FILE__, __LINE__,
00666
"maci::SimpleClient<>::getDynamicComponent");
00667 lex.setCURL(compSpec.component_name.in());
00668
throw lex;
00669 }
00670
catch (...)
00671 {
00672 ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
00673
"maci::SimpleClient<>::getDynamicComponent");
00674 maciErrType::CannotGetComponentExImpl lex(uex, __FILE__, __LINE__,
00675
"maci::SimpleClient<>::getDynamicComponent");
00676 lex.setCURL(compSpec.component_name.in());
00677
throw lex;
00678 }
00679 }
00680
00681
00682
00683
00684
00685
template<
class T>
00686 T* SimpleClient::getComponentNonSticky(
const char *name)
00687 {
00688
if(!
m_initialized)
00689 {
00690 ACSErrTypeCommon::NotInitializedExImpl notInitEx( __FILE__, __LINE__,
00691
"maci::SimpleClient::getComponentNonSticky<>");
00692 notInitEx.setName(
"SimpleClient");
00693 maciErrType::CannotGetComponentExImpl ex( notInitEx, __FILE__, __LINE__,
00694
"maci::SimpleClient::getComponentNonSticky<>");
00695 name ? ex.setCURL(name) : ex.setCURL(
"NULL");
00696
throw ex;
00697 }
00698
00699
if(!name)
00700 {
00701 ACSErrTypeCommon::NullPointerExImpl nullEx(__FILE__, __LINE__,
00702
"maci::SimpleClient::getComponentNonSticky<>");
00703 nullEx.setVariable(
"(parameter) name");
00704 maciErrType::CannotGetComponentExImpl ex(nullEx, __FILE__, __LINE__,
00705
"maci::SimpleClient::getComponentNonSticky<>");
00706 ex.setCURL(
"NULL");
00707
throw ex;
00708 }
00709
00710
ACS_SHORT_LOG((LM_DEBUG,
"Getting component non sticky: '%s'. Creating it...", name));
00711
00712
try
00713 {
00714 CORBA::Object_var obj =
manager()->get_component_non_sticky(
m_handle, name);
00715 T* tmpRef = T::_narrow(obj);
00716
if (CORBA::is_nil(tmpRef))
00717 {
00718
00719 ACSErrTypeCORBA::NarrowFailedExImpl ex(__FILE__, __LINE__,
"maci::SimpleClient<>::getComponentNonSticky");
00720 ex.setNarrowType(
typeid(T).
name());
00721
throw ex;
00722 }
00723
return tmpRef;
00724 }
00725
catch(maciErrType::NoPermissionEx &_ex)
00726 {
00727 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00728
"maci::SimpleClient::getComponentNonSticky<>");
00729 ex.setCURL(name);
00730
throw ex;
00731 }
00732
catch(maciErrType::CannotGetComponentEx &_ex)
00733 {
00734 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00735
"maci::SimpleClient::getComponentNonSticky<>");
00736 ex.setCURL(name);
00737
throw ex;
00738 }
00739
catch(maciErrType::ComponentNotAlreadyActivatedEx &_ex)
00740 {
00741 maciErrType::CannotGetComponentExImpl ex(_ex, __FILE__, __LINE__,
00742
"maci::SimpleClient::getComponentNonSticky<>");
00743 ex.setCURL(name);
00744
throw ex;
00745 }
00746
catch (
ACSErr::ACSbaseExImpl &ex)
00747 {
00748 maciErrType::CannotGetComponentExImpl lex(ex, __FILE__, __LINE__,
00749
"maci::SimpleClient<>::getComponentNonSticky");
00750 lex.setCURL(name);
00751
throw lex;
00752 }
00753
catch( CORBA::SystemException &_ex )
00754 {
00755 ACSErrTypeCommon::CORBAProblemExImpl corbaProblemEx(__FILE__, __LINE__,
00756
"maci::SimpleClient::getComponentNonSticky<>");
00757 corbaProblemEx.setMinor(_ex.minor());
00758 corbaProblemEx.setCompletionStatus(_ex.completed());
00759 corbaProblemEx.setInfo(_ex._info().c_str());
00760 maciErrType::CannotGetComponentExImpl ex(corbaProblemEx, __FILE__, __LINE__,
00761
"maci::SimpleClient::getComponent<>");
00762 ex.setCURL(name);
00763
throw ex;
00764 }
00765
catch(...)
00766 {
00767 ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__,
00768
"maci::SimpleClient::getComponentNonSticky<>");
00769 maciErrType::CannotGetComponentExImpl ex(uex, __FILE__, __LINE__,
00770
"maci::SimpleClient::getComponentNonSticky<>");
00771 ex.setCURL(name);
00772
throw ex;
00773 }
00774 }
00775
00776
00777
00778
00779
template<
class T>
00780 ComponentSmartPtr<T> SimpleClient::getComponentNonStickySmartPtr(
const char *name)
00781 {
00782
return ComponentSmartPtr<T>(
this,
false, this->getComponentNonSticky<T>(name));
00783 }
00784
00785 };
00786
00787
#endif