ACE_Service_Gestalt Class Reference

Supplies common server operations for dynamic and static configuration of services. More...

#include <Service_Gestalt.h>

Inheritance diagram for ACE_Service_Gestalt:

Inheritance graph
[legend]
Collaboration diagram for ACE_Service_Gestalt:

Collaboration graph
[legend]
List of all members.

Public Types

enum  { MAX_SERVICES = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE }

Public Member Functions

 ACE_Service_Gestalt (size_t size, bool svc_repo_is_owned=true, bool no_static_svcs=true)
virtual ~ACE_Service_Gestalt (void)
void dump (void) const
 Dump the state of an object.

int open (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, int ignore_static_svcs=1, int ignore_default_svc_conf_file=0, int ignore_debug_flag=0)
int open (int argc, ACE_TCHAR *argv[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, int ignore_static_svcs=1, int ignore_default_svc_conf_file=0, int ignore_debug_flag=0)
int is_opened (void)
int process_directive (const ACE_TCHAR directive[])
int process_directive (const ACE_Static_Svc_Descriptor &ssd, int force_replace=0)
 Process one static service definition.

int process_file (const ACE_TCHAR file[])
int find (const ACE_TCHAR name[], const ACE_Service_Type **srp=0, int ignore_suspended=1) const
 Searches for a service object declaration in the local repo, only.

int parse_args (int, ACE_TCHAR *argv[])
int process_directives (void)
int close (void)
int insert (ACE_Static_Svc_Descriptor *stsd)
int initialize (const ACE_Service_Type_Factory *, const ACE_TCHAR *parameters)
int initialize (const ACE_Service_Type *, const ACE_TCHAR *parameters)
int initialize (const ACE_TCHAR *svc_name, const ACE_TCHAR *parameters)
 Initialize and activate a statically svc_name service.

int resume (const ACE_TCHAR svc_name[])
int suspend (const ACE_TCHAR svc_name[])
int remove (const ACE_TCHAR svc_name[])
int find_static_svc_descriptor (const ACE_TCHAR *name, ACE_Static_Svc_Descriptor **ssd=0) const
 Find a static service descriptor by name.


Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.


Protected Types

typedef ACE_Unbounded_Queue<
ACE_TString
ACE_SVC_QUEUE
typedef ACE_Unbounded_Queue_Iterator<
ACE_TString
ACE_SVC_QUEUE_ITERATOR
typedef ACE_Unbounded_Set<
ACE_Static_Svc_Descriptor * > 
ACE_STATIC_SVCS
typedef ACE_Unbounded_Set_Iterator<
ACE_Static_Svc_Descriptor * > 
ACE_STATIC_SVCS_ITERATOR
typedef ACE_Unbounded_Set<
Processed_Static_Svc * > 
ACE_PROCESSED_STATIC_SVCS
typedef ACE_Unbounded_Set_Iterator<
Processed_Static_Svc * > 
ACE_PROCESSED_STATIC_SVCS_ITERATOR

Protected Member Functions

virtual int parse_args_i (int, ACE_TCHAR *argv[])
virtual int open_i (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key=ACE_DEFAULT_LOGGER_KEY, bool ignore_static_svcs=true, bool ignore_default_svc_conf_file=false, bool ignore_debug_flag=false)
int init_svc_conf_file_queue (void)
 Initialize the if necessary.

int load_static_svcs (void)
int process_commandline_directives (void)
int process_directive_i (const ACE_Static_Svc_Descriptor &ssd, int force_replace=0)
int process_directives_i (ACE_Svc_Conf_Param *param)
int initialize_i (const ACE_Service_Type *sr, const ACE_TCHAR *parameters)
const ACE_Static_Svc_Descriptorfind_processed_static_svc (const ACE_TCHAR *)
void add_processed_static_svc (const ACE_Static_Svc_Descriptor *)

Protected Attributes

bool svc_repo_is_owned_
int is_opened_
const ACE_TCHARlogger_key_
int no_static_svcs_
 Should we avoid loading the static services?

ACE_SVC_QUEUEsvc_queue_
 Queue of services specified on the command-line.

ACE_SVC_QUEUEsvc_conf_file_queue_
ACE_Service_Repositoryrepo_
 The service repository to hold the services.

ACE_STATIC_SVCSstatic_svcs_
 Repository of statically linked services.

ACE_PROCESSED_STATIC_SVCSprocessed_static_svcs_

Private Member Functions

 ACE_Service_Gestalt (const ACE_Service_Gestalt &)
ACE_Service_Gestaltoperator= (const ACE_Service_Gestalt &)

Friends

class ACE_Dynamic_Service_Base
class ACE_Service_Object
class ACE_Service_Config_Guard

Detailed Description

Supplies common server operations for dynamic and static configuration of services.

Definition at line 47 of file Service_Gestalt.h.


Member Typedef Documentation

typedef ACE_Unbounded_Set<Processed_Static_Svc *> ACE_Service_Gestalt::ACE_PROCESSED_STATIC_SVCS [protected]
 

Definition at line 365 of file Service_Gestalt.h.

Referenced by add_processed_static_svc().

typedef ACE_Unbounded_Set_Iterator<Processed_Static_Svc *> ACE_Service_Gestalt::ACE_PROCESSED_STATIC_SVCS_ITERATOR [protected]
 

Definition at line 368 of file Service_Gestalt.h.

Referenced by add_processed_static_svc(), close(), find_processed_static_svc(), and ~ACE_Service_Gestalt().

typedef ACE_Unbounded_Set<ACE_Static_Svc_Descriptor *> ACE_Service_Gestalt::ACE_STATIC_SVCS [protected]
 

Definition at line 359 of file Service_Gestalt.h.

Referenced by ACE_Service_Gestalt().

typedef ACE_Unbounded_Set_Iterator<ACE_Static_Svc_Descriptor *> ACE_Service_Gestalt::ACE_STATIC_SVCS_ITERATOR [protected]
 

Definition at line 362 of file Service_Gestalt.h.

Referenced by find_static_svc_descriptor(), and load_static_svcs().

typedef ACE_Unbounded_Queue<ACE_TString> ACE_Service_Gestalt::ACE_SVC_QUEUE [protected]
 

Definition at line 354 of file Service_Gestalt.h.

Referenced by init_svc_conf_file_queue(), and parse_args_i().

typedef ACE_Unbounded_Queue_Iterator<ACE_TString> ACE_Service_Gestalt::ACE_SVC_QUEUE_ITERATOR [protected]
 

Definition at line 355 of file Service_Gestalt.h.

Referenced by process_commandline_directives(), and process_directives().


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
MAX_SERVICES 

Definition at line 57 of file Service_Gestalt.h.


Constructor & Destructor Documentation

ACE_Service_Gestalt::ACE_Service_Gestalt const ACE_Service_Gestalt  )  [private]
 

Not implemented to enforce no copying

ACE_Service_Gestalt::ACE_Service_Gestalt size_t  size,
bool  svc_repo_is_owned = true,
bool  no_static_svcs = true
 

Constructor either associates the instance with the process-wide singleton instance of ACE_Service_Repository, or creates and manages its own instance of the specified size.

Definition at line 229 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_DEFAULT_LOGGER_KEY, ACE_LIB_TEXT, ACE_NEW_NORETURN, ACE_STATIC_SVCS, ACE::debug(), ACE_Service_Repository::instance(), LM_DEBUG, and processed_static_svcs_.

00232   : svc_repo_is_owned_ (svc_repo_is_owned)
00233   , is_opened_ (0)
00234   , logger_key_ (ACE_DEFAULT_LOGGER_KEY)
00235   , no_static_svcs_ (no_static_svcs)
00236   , svc_queue_ (0)
00237   , svc_conf_file_queue_ (0)
00238 {
00239   if (svc_repo_is_owned)
00240     ACE_NEW_NORETURN (this->repo_,
00241                       ACE_Service_Repository (size));
00242   else
00243       this->repo_ =
00244         ACE_Service_Repository::instance (size);
00245 
00246   ACE_NEW_NORETURN (this->static_svcs_,
00247                     ACE_STATIC_SVCS);
00248 
00249   this->processed_static_svcs_ = 0;
00250 
00251   if (ACE::debug ())
00252     ACE_DEBUG ((LM_DEBUG,
00253                 ACE_LIB_TEXT ("(%P|%t) SG::ctor - this = %@, pss = %@\n"),
00254                 this, this->processed_static_svcs_));
00255 }

ACE_Service_Gestalt::~ACE_Service_Gestalt void   )  [virtual]
 

Perform user-specified close activities and remove dynamic memory.

Definition at line 202 of file Service_Gestalt.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_LIB_TEXT, ACE_PROCESSED_STATIC_SVCS_ITERATOR, ACE_Unbounded_Set_Iterator< T >::advance(), ACE::debug(), ACE_Unbounded_Set< T >::is_empty(), LM_DEBUG, ACE_Unbounded_Set_Iterator< T >::next(), processed_static_svcs_, static_svcs_, and svc_repo_is_owned_.

00203 {
00204   ACE_ASSERT (this->repo_ != 0);
00205 
00206   if (this->svc_repo_is_owned_)
00207     delete this->repo_;
00208   delete this->static_svcs_;
00209   // Delete the dynamically allocated static_svcs instance.
00210   if (ACE::debug ())
00211     ACE_DEBUG ((LM_DEBUG,
00212                 ACE_LIB_TEXT ("(%P|%t) SG::dtor - this=%@, pss = %@\n"),
00213                 this, this->processed_static_svcs_));
00214 
00215   if (this->processed_static_svcs_ &&
00216       !this->processed_static_svcs_->is_empty())
00217     {
00218       Processed_Static_Svc **pss = 0;
00219       for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00220            iter.next (pss) != 0;
00221            iter.advance ())
00222         {
00223           delete *pss;
00224         }
00225     }
00226   delete this->processed_static_svcs_;
00227 }


Member Function Documentation

void ACE_Service_Gestalt::add_processed_static_svc const ACE_Static_Svc_Descriptor  )  [protected]
 

Definition at line 328 of file Service_Gestalt.cpp.

References ACE_NEW, ACE_PROCESSED_STATIC_SVCS, ACE_PROCESSED_STATIC_SVCS_ITERATOR, ACE_Unbounded_Set_Iterator< T >::advance(), ACE_Unbounded_Set_Iterator< T >::next(), and ACE_OS::strcmp().

Referenced by process_directive().

00329 {
00330   if (this->processed_static_svcs_ == 0)
00331     ACE_NEW (this->processed_static_svcs_,
00332              ACE_PROCESSED_STATIC_SVCS);
00333 
00334   Processed_Static_Svc **pss = 0;
00335   for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00336        iter.next (pss) != 0;
00337        iter.advance ())
00338     {
00339       if (ACE_OS::strcmp ((*pss)->name_, assd->name_) == 0)
00340         {
00341           (*pss)->assd_ = assd;
00342           return;
00343         }
00344     }
00345   Processed_Static_Svc *tmp = 0;
00346   ACE_NEW (tmp,Processed_Static_Svc(assd));
00347   this->processed_static_svcs_->insert(tmp);
00348 }

int ACE_Service_Gestalt::close void   ) 
 

Tidy up and perform last rites when ACE_Service_Config is shut down. This method calls . Returns 0.

Reimplemented in ACE_Service_Config.

Definition at line 1211 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_PROCESSED_STATIC_SVCS_ITERATOR, ACE_TRACE, ACE_Unbounded_Set_Iterator< T >::advance(), ACE::debug(), ACE_Unbounded_Set< T >::is_empty(), is_opened_, LM_DEBUG, ACE_Unbounded_Set_Iterator< T >::next(), processed_static_svcs_, static_svcs_, and svc_conf_file_queue_.

Referenced by ACE_Service_Config::close().

01212 {
01213   ACE_TRACE ("ACE_Service_Gestalt::close");
01214 
01215   this->is_opened_--;
01216   if (this->is_opened_ > 0)
01217     return 0;
01218 
01219   // Delete the service repository.  All the objects inside the
01220   // service repository should already have been finalized.
01221   //  ACE_Service_Config::close_svcs ();
01222 
01223   // Delete the list fo svc.conf files
01224   delete this->svc_conf_file_queue_;
01225   this->svc_conf_file_queue_ = 0;
01226 
01227   // Delete the dynamically allocated static_svcs instance.
01228   if (ACE::debug ())
01229     ACE_DEBUG ((LM_DEBUG,
01230                 ACE_LIB_TEXT ("(%P|%t) SG::close - this=%@, repo=%@, pss = %@\n"),
01231                 this, this->repo_, this->processed_static_svcs_));
01232 
01233   delete this->static_svcs_;
01234   this->static_svcs_ = 0;
01235 
01236   if (this->processed_static_svcs_ &&
01237       !this->processed_static_svcs_->is_empty())
01238     {
01239       Processed_Static_Svc **pss = 0;
01240       for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
01241            iter.next (pss) != 0;
01242            iter.advance ())
01243         {
01244           delete *pss;
01245         }
01246     }
01247   delete this->processed_static_svcs_;
01248   this->processed_static_svcs_ = 0;
01249   if (ACE::debug ())
01250     ACE_DEBUG ((LM_DEBUG,
01251                 ACE_LIB_TEXT ("(%P|%t) SG::close - complete this=%@, repo=%@\n"),
01252                 this, this->repo_));
01253 
01254 
01255   return 0;
01256 
01257 } /* close () */

void ACE_Service_Gestalt::dump void   )  const
 

Dump the state of an object.

Reimplemented in ACE_Service_Config.

Definition at line 380 of file Service_Gestalt.cpp.

References ACE_TRACE.

00381 {
00382 #if defined (ACE_HAS_DUMP)
00383   ACE_TRACE ("ACE_Service_Gestalt::dump");
00384 #endif /* ACE_HAS_DUMP */
00385 }

ACE_INLINE int ACE_Service_Gestalt::find const ACE_TCHAR  name[],
const ACE_Service_Type **  srp = 0,
int  ignore_suspended = 1
const
 

Searches for a service object declaration in the local repo, only.

Locate an entry with in the table. If is set then only consider services marked as resumed. If the caller wants the located entry, pass back a pointer to the located entry via . If is not found, -1 is returned. If is found, but it is suspended and the caller wants to ignore suspended services a -2 is returned.

Definition at line 54 of file Service_Gestalt.inl.

References ACE_ASSERT, ACE_TCHAR, and ACE_Service_Repository::find().

Referenced by ACE_Dynamic_Service_Base::find_i(), and ACE_Static_Node::record().

00057 {
00058   ACE_ASSERT (this->repo_ != 0);
00059   return this->repo_->find (name, srp, ignore_suspended);
00060 }

const ACE_Static_Svc_Descriptor * ACE_Service_Gestalt::find_processed_static_svc const ACE_TCHAR  )  [protected]
 

Definition at line 313 of file Service_Gestalt.cpp.

References ACE_PROCESSED_STATIC_SVCS_ITERATOR, ACE_TCHAR, ACE_Unbounded_Set_Iterator< T >::advance(), ACE_Unbounded_Set_Iterator< T >::next(), and ACE_OS::strcmp().

Referenced by initialize().

00314 {
00315   Processed_Static_Svc **pss = 0;
00316   for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00317        iter.next (pss) != 0;
00318        iter.advance ())
00319     {
00320       if (ACE_OS::strcmp ((*pss)->name_, name) == 0)
00321         return (*pss)->assd_;
00322     }
00323   return 0;
00324 }

int ACE_Service_Gestalt::find_static_svc_descriptor const ACE_TCHAR name,
ACE_Static_Svc_Descriptor **  ssd = 0
const
 

Find a static service descriptor by name.

Using the supplied name, finds and (if needed) returns a pointer to a static service descriptor. Returns 0 for success and -1 for failure

Definition at line 287 of file Service_Gestalt.cpp.

References ACE_STATIC_SVCS_ITERATOR, ACE_TCHAR, ACE_TRACE, ACE_Unbounded_Set_Iterator< T >::advance(), ACE_Unbounded_Set_Iterator< T >::next(), static_svcs_, and ACE_OS::strcmp().

Referenced by ACE_Static_Function_Node::symbol().

00289 {
00290   ACE_TRACE ("ACE_Service_Gestalt::find_static_svc_descriptor");
00291 
00292   if (this->static_svcs_ == 0)
00293     return -1;
00294 
00295   ACE_Static_Svc_Descriptor **ssdp = 0;
00296   for (ACE_STATIC_SVCS_ITERATOR iter ( *this->static_svcs_);
00297        iter.next (ssdp) != 0;
00298        iter.advance ())
00299     {
00300       if (ACE_OS::strcmp ((*ssdp)->name_, name) == 0)
00301         {
00302           if (ssd != 0)
00303             *ssd = *ssdp;
00304 
00305           return 0;
00306         }
00307     }
00308 
00309   return -1;
00310 }

int ACE_Service_Gestalt::init_svc_conf_file_queue void   )  [protected]
 

Initialize the if necessary.

Definition at line 975 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_SVC_QUEUE, ACE::debug(), LM_DEBUG, and svc_conf_file_queue_.

Referenced by ACE_Service_Config::open_i(), and parse_args_i().

00976 {
00977   if (this->svc_conf_file_queue_ == 0)
00978     {
00979       ACE_SVC_QUEUE *tmp = 0;
00980       ACE_NEW_RETURN (tmp,
00981           ACE_SVC_QUEUE,
00982           -1);
00983       delete this->svc_conf_file_queue_;
00984       this->svc_conf_file_queue_ = tmp;
00985     }
00986 
00987   if (ACE::debug () > 1)
00988     ACE_DEBUG ((LM_DEBUG,
00989                 ACE_LIB_TEXT ("(%P|%t) SG::init_svc_conf_file_queue ")
00990                 ACE_LIB_TEXT ("- this=%@, repo=%@\n"),
00991                 this, this->repo_));
00992   return 0;
00993 
00994 } /* init_svc_conf_file_queue () */

int ACE_Service_Gestalt::initialize const ACE_TCHAR svc_name,
const ACE_TCHAR parameters
 

Initialize and activate a statically svc_name service.

If initialization fails ...

Reimplemented in ACE_Service_Config.

Definition at line 463 of file Service_Gestalt.cpp.

References ACE_ARGV, ACE_DEBUG, ACE_ERROR, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, ACE_ARGV_T< CHAR_TYPE >::argc(), ACE_ARGV_T< CHAR_TYPE >::argv(), ACE::debug(), ACE_Service_Repository::find(), find_processed_static_svc(), ACE_Service_Config::global(), ACE_Service_Type_Impl::init(), LM_DEBUG, LM_ERROR, process_directive_i(), ACE_Service_Repository::remove(), and ACE_Service_Type::type().

00465 {
00466   ACE_TRACE ("ACE_Service_Gestalt_Base::initialize (repo)");
00467   ACE_ARGV args (parameters);
00468 
00469 #ifndef ACE_NLOGGING
00470   if (ACE::debug () > 1)
00471     {
00472       ACE_DEBUG ((LM_DEBUG,
00473                   ACE_LIB_TEXT ("(%P|%t) SG::initialize - () repo=%@, ")
00474                   ACE_LIB_TEXT ("looking up static ")
00475                   ACE_LIB_TEXT ("service \'%s\' to initialize\n"),
00476                   this->repo_,
00477                   svc_name));
00478     }
00479 #endif
00480 
00481   const ACE_Service_Type *srp = 0;
00482   for (int i = 0; this->repo_->find (svc_name, &srp) == -1 && i < 2; i++)
00483     //  if (this->repo_->find (svc_name, &srp) == -1)
00484     {
00485       const ACE_Static_Svc_Descriptor *assd =
00486         ACE_Service_Config::global()->find_processed_static_svc(svc_name);
00487       if (assd != 0)
00488         {
00489           this->process_directive_i(*assd,0);
00490         }
00491       else
00492         {
00493           ACE_ERROR_RETURN ((LM_ERROR,
00494                              ACE_LIB_TEXT ("(%P|%t) SG::initialize - service \'%s\'")
00495                              ACE_LIB_TEXT (" was not located.\n"),
00496                              svc_name),
00497                             -1);
00498         }
00499     }
00500   if (srp == 0)
00501     ACE_ERROR_RETURN ((LM_ERROR,
00502                        ACE_LIB_TEXT ("(%P|%t) SG::initialize - service \'%s\'")
00503                        ACE_LIB_TEXT (" was not located.\n"),
00504                        svc_name),
00505                       -1);
00506 
00507   /// If initialization fails ...
00508   if (srp->type ()->init (args.argc (),
00509                           args.argv ()) == -1)
00510     {
00511       // ... report and remove this entry.
00512       ACE_ERROR ((LM_ERROR,
00513       ACE_LIB_TEXT ("(%P|%t) SG::initialize - static init of \'%s\'")
00514       ACE_LIB_TEXT (" failed (%p)\n"),
00515       svc_name));
00516       this->repo_->remove (svc_name);
00517       return -1;
00518     }
00519 
00520   // If everything is ok, activate it
00521   const_cast<ACE_Service_Type *>(srp)->active (1);
00522   return 0;
00523 }

int ACE_Service_Gestalt::initialize const ACE_Service_Type ,
const ACE_TCHAR parameters
 

Reimplemented in ACE_Service_Config.

Definition at line 627 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, ACE::debug(), ACE_Service_Repository::find(), initialize_i(), LM_DEBUG, LM_WARNING, and ACE_Service_Type::name().

00629 {
00630   ACE_TRACE ("ACE_Service_Gestalt::initialize");
00631 
00632   if (ACE::debug ())
00633     ACE_DEBUG ((LM_DEBUG,
00634                 ACE_LIB_TEXT ("(%P|%t) SG::initialize - looking up dynamic ")
00635                 ACE_LIB_TEXT (" service \'%s\' to initialize\n"),
00636                 sr->name ()));
00637 
00638   ACE_Service_Type *srp = 0;
00639   if (this->repo_->find (sr->name (),
00640                          (const ACE_Service_Type **) &srp) >= 0)
00641     ACE_ERROR_RETURN ((LM_WARNING,
00642                        ACE_LIB_TEXT ("(%P|%t) SG::initialize - \'%s\' ")
00643                        ACE_LIB_TEXT ("has already been installed. ")
00644                        ACE_LIB_TEXT ("Remove before reinstalling\n"),
00645                        sr->name ()),
00646                       0);
00647 
00648   return this->initialize_i (sr, parameters);
00649 
00650 }

int ACE_Service_Gestalt::initialize const ACE_Service_Type_Factory ,
const ACE_TCHAR parameters
 

Dynamically link the shared object file and retrieve a pointer to the designated shared object in this file. Also account for the possiblity to have static services registered when loading the DLL, by ensuring that the dynamic sevice is registered before any of its subordibnate static services. Thus avoiding any finalization order problems.

Definition at line 527 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, ACE::debug(), ACE_Service_Repository::find(), ACE_Auto_Basic_Ptr< X >::get(), initialize_i(), LM_DEBUG, LM_ERROR, LM_WARNING, ACE_Service_Type_Factory::make_service_type(), ACE_Service_Type_Factory::name(), ACE_Auto_Basic_Ptr< X >::release(), and ACE_Service_Type::type().

Referenced by ACE_Static_Node::apply(), ACE_Dynamic_Node::apply(), ACE_Stream_Node::apply(), and ACE_Service_Config::initialize().

00529 {
00530   ACE_TRACE ("ACE_Service_Gestalt::initialize");
00531 
00532 #ifndef ACE_NLOGGING
00533   if (ACE::debug () > 1)
00534     ACE_DEBUG ((LM_DEBUG,
00535                 ACE_LIB_TEXT ("(%P|%t) SG::initialize - repo=%@, looking up dynamic ")
00536                 ACE_LIB_TEXT ("service \'%s\' to initialize\n"),
00537                 this->repo_,
00538                 stf->name ()));
00539 #endif
00540 
00541   ACE_Service_Type *srp = 0;
00542   int const retv = this->repo_->find (stf->name (),
00543                                       (const ACE_Service_Type **) &srp);
00544 
00545   // If there is an active service already, it must first be removed,
00546   // before it could be re-installed.
00547   if (retv >= 0)
00548     {
00549 #ifndef ACE_NLOGGING
00550       if (ACE::debug ())
00551         ACE_ERROR_RETURN ((LM_WARNING,
00552                            ACE_LIB_TEXT ("(%P|%t) \'%s\' already installed.")
00553                            ACE_LIB_TEXT (" Must be removed before re-installing\n"),
00554                            stf->name ()),
00555                           0);
00556 #endif
00557         return 0;
00558     }
00559 
00560   // There is an inactive service by that name, so it may have been
00561   // either inactivated, or just a forward declaration for a service,
00562   // that is in the process of being loaded. If the latter, then we
00563   // have detected an attempt to initialize the same dynamic service
00564   // while still processing previous attempt. This can lock up the
00565   // process, because the ACE_DLL_Manager::open () is not re-entrant -
00566   // it uses a Singleton lock to serialize concurent invocations. This
00567   // use case must be handled here, because if the DLL_Manager was
00568   // re-entrant we would have entered an infinite recursion here.
00569   if (retv == -2 && srp->type () == 0)
00570     ACE_ERROR_RETURN ((LM_WARNING,
00571                        ACE_LIB_TEXT ("(%P|%t) \'%s\' has not been ")
00572                        ACE_LIB_TEXT ("completely defined. Recursive ")
00573                        ACE_LIB_TEXT ("initialization request while ")
00574                        ACE_LIB_TEXT ("already performing one.\n"),
00575                        stf->name ()),
00576                       -1);
00577 
00578   // Reserve a spot for the dynamic service by inserting an incomplete
00579   // service declaration, i.e. one that can not produce a service
00580   // object if asked.  Having this incomplete declaration works
00581   // similar to C++'s forward declaration to allow, in this case
00582   // proper partial ordering of the loaded services in respect to
00583   // their finalization. I.e. dependent static services must be
00584   // registered *after* the dynamic service that loads them, so that
00585   // their finalization is complete *before* finalizing the dynamic
00586   // service.
00587   ACE_Service_Type_Forward_Declaration_Guard dummy (this->repo_,
00588                                                     stf->name ());
00589 
00590   // make_service_type() is doing the dynamic loading and also runs
00591   // any static initializers
00592   ACE_Auto_Ptr<ACE_Service_Type> tmp (stf->make_service_type (this));
00593   if (tmp.get () != 0 &&
00594       this->initialize_i (tmp.get (), parameters) == 0)
00595     {
00596       // All good the ACE_Service_Type instance is now owned by the repository
00597       // and we should make sure it is not destroyed upon exit from this method.
00598       (void)tmp.release ();
00599       return 0;
00600     }
00601 
00602   // Something went wrong ...
00603 #ifndef ACE_NLOGGING
00604   if (ACE::debug ())
00605     ACE_ERROR_RETURN ((LM_ERROR,
00606                        ACE_LIB_TEXT ("(%P|%t) Error initializing %s: %m\n"),
00607                        stf->name()),
00608                       -1);
00609 #endif
00610 
00611   return -1;
00612 }

int ACE_Service_Gestalt::initialize_i const ACE_Service_Type sr,
const ACE_TCHAR parameters
[protected]
 

Definition at line 655 of file Service_Gestalt.cpp.

References ACE_ARGV, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, ACE_ARGV_T< CHAR_TYPE >::argc(), ACE_ARGV_T< CHAR_TYPE >::argv(), ACE::debug(), ACE_Service_Type_Impl::init(), ACE_Service_Repository::insert(), LM_ERROR, ACE_Service_Type::name(), ACE_Service_Repository::remove(), and ACE_Service_Type::type().

Referenced by initialize().

00657 {
00658   ACE_TRACE ("ACE_Service_Gestalt::initialize_i");
00659   ACE_ARGV args (parameters);
00660   if (sr->type ()->init (args.argc (),
00661                          args.argv ()) == -1)
00662     {
00663       // We just get ps to avoid having remove() delete it.
00664       ACE_Service_Type *ps = 0;
00665       this->repo_->remove (sr->name (), &ps);
00666 
00667 #ifndef ACE_NLOGGING
00668       if (ACE::debug ())
00669         ACE_ERROR_RETURN ((LM_ERROR,
00670                            ACE_LIB_TEXT ("(%P|%t) SG - initialize_i ")
00671                            ACE_LIB_TEXT ("failed for %s: %m\n"),
00672                            sr->name ()),
00673                           -1);
00674 #endif
00675       return -1;
00676     }
00677 
00678   if (this->repo_->insert (sr) == -1)
00679     {
00680 #ifndef ACE_NLOGGING
00681       if (ACE::debug ())
00682         ACE_ERROR_RETURN ((LM_ERROR,
00683                            ACE_LIB_TEXT ("(%P|%t) SG - repository insert ")
00684                            ACE_LIB_TEXT ("failed for %s: %m\n"),
00685                            sr->name ()),
00686                           -1);
00687 #endif
00688         return -1;
00689     }
00690 
00691   return 0;
00692 }

int ACE_Service_Gestalt::insert ACE_Static_Svc_Descriptor stsd  ) 
 

Reimplemented in ACE_Service_Config.

Definition at line 351 of file Service_Gestalt.cpp.

References ACE_Static_Svc_Descriptor::active_, ACE::debug(), ACE_OS::fprintf(), ACE_Unbounded_Set< T >::insert(), ACE_Static_Svc_Descriptor::name_, and static_svcs_.

Referenced by ACE_Service_Config::insert().

00352 {
00353   if (ACE::debug () > 1)
00354     {
00355       // If called during static initialization ACE_Log_Msg may not have
00356       // been initialized yet, so use printf intead.
00357       ACE_OS::fprintf (stderr,
00358            "// (%d|0) SG::insert"
00359            " repo=%p, name=%s - queuing a Static_Svc_Descriptor:"
00360            " active=%d, repo opened=%d.\n",
00361            ACE_OS::getpid (),
00362            this->repo_,
00363            stsd->name_,
00364            stsd->active_,
00365            this->is_opened_);
00366     }
00367 
00368   // Inserting a service after teh Gestalt has been opened makes it
00369   // impossible to activate it later. Perhaps open came too soon?
00370   //ACE_ASSERT (this->is_opened_ == 0);
00371 
00372   return this->static_svcs_->insert (stsd);
00373 }

int ACE_Service_Gestalt::is_opened void   ) 
 

Has it been opened? Returns the difference between the times open and close have been called on this instance

Definition at line 1069 of file Service_Gestalt.cpp.

References is_opened_.

01070 {
01071   return this->is_opened_;
01072 }

int ACE_Service_Gestalt::load_static_svcs void   )  [protected]
 

Add the default statically-linked services to the ACE_Service_Repository.

Reimplemented in ACE_Service_Config.

Definition at line 261 of file Service_Gestalt.cpp.

References ACE_STATIC_SVCS_ITERATOR, ACE_TRACE, ACE_Unbounded_Set_Iterator< T >::advance(), ACE_Unbounded_Set_Iterator< T >::next(), process_directive(), and static_svcs_.

Referenced by open_i().

00262 {
00263   ACE_TRACE ("ACE_Service_Gestalt::load_static_svcs");
00264 
00265   if (this->static_svcs_ == 0)
00266     return 0; // Nothing to do
00267 
00268   ACE_Static_Svc_Descriptor **ssdp = 0;
00269   for (ACE_STATIC_SVCS_ITERATOR iter (*this->static_svcs_);
00270        iter.next (ssdp) != 0;
00271        iter.advance ())
00272     {
00273       ACE_Static_Svc_Descriptor *ssd = *ssdp;
00274 
00275       if (this->process_directive (*ssd, 1) == -1)
00276         return -1;
00277     }
00278   return 0;
00279 
00280 } /* load_static_svcs () */

ACE_INLINE int ACE_Service_Gestalt::open int  argc,
ACE_TCHAR argv[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY,
int  ignore_static_svcs = 1,
int  ignore_default_svc_conf_file = 0,
int  ignore_debug_flag = 0
 

This is the primary entry point into the ACE_Service_Config (the constructor just handles simple initializations). It parses arguments passed in from argc and argv parameters. The arguments that are valid in a call to this method include:

  • '-b' Option to indicate that we should be a daemon. Note that when this option is used, the process will be daemonized before the service configuration file(s) are read. During daemonization, (on POSIX systems) the current directory will be changed to "/" so the caller should either fully specify the file names, or execute a chroot() to the appropriate directory.
    See also:
    ACE::daemonize().
  • '-d' Turn on debugging mode
  • '-f' Specifies a configuration file name other than the default svc.conf. Can be specified multiple times to use multiple files.
  • '-k' Specifies the rendezvous point to use for the ACE distributed logger.
  • '-y' Explicitly enables the use of static services. This flag overrides the ignore_static_svcs parameter value.
  • '-n' Explicitly disables the use of static services. This flag overrides the ignore_static_svcs parameter value.
  • '-p' Specifies a pathname which is used to store the process id.
  • '-s' Specifies a signal number other than SIGHUP to trigger reprocessing of the configuration file(s). Ignored for platforms that do not have POSIX signals, such as Windows.
  • '-S' Specifies a service directive string. Enclose the string in quotes and escape any embedded quotes with a backslash. This option specifies service directives without the need for a configuration file.

Parameters:
argc The number of commandline arguments.
argv The array with commandline arguments
logger_key Indicates where to write the logging output, which is typically either a STREAM pipe or a socket address.
ignore_static_svcs If 1 then static services are not loaded, otherwise, they are loaded.
ignore_default_svc_conf_file If non-0 then the svc.conf configuration file will be ignored.
ignore_debug_flag If non-0 then the application is responsible for setting the ACE_Log_Msg::priority_mask appropriately.
Return values:
-1 The configuration file is not found or cannot be opened (errno is set accordingly).
0 Success.
>0 The number of errors encountered while processing the service configuration file(s).

Reimplemented in ACE_Service_Config.

Definition at line 30 of file Service_Gestalt.inl.

References ACE_TCHAR, ACE_TRACE, no_static_svcs_, open_i(), and parse_args_i().

00036 {
00037   ACE_TRACE ("ACE_Service_Gestalt::open");
00038   this->no_static_svcs_ = ignore_static_svcs;
00039 
00040   if (this->parse_args_i (argc,
00041                           argv) == -1)
00042     return -1;
00043   else
00044     return this->open_i (argv == 0 ? 0 : argv[0],
00045                          logger_key,
00046                          ignore_static_svcs,
00047                          ignore_default_svc_conf,
00048                          ignore_debug_flag);
00049 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE int ACE_Service_Gestalt::open const ACE_TCHAR  program_name[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY,
int  ignore_static_svcs = 1,
int  ignore_default_svc_conf_file = 0,
int  ignore_debug_flag = 0
 

Performs an open without parsing command-line arguments. The logger_key indicates where to write the logging output, which is typically either a STREAM pipe or a socket address. If ignore_static_svcs is 1 then static services are not loaded, otherwise, they are loaded. If ignore_default_svc_conf_file is non-0 then the <svc.conf> configuration file will be ignored. Returns zero upon success, -1 if the file is not found or cannot be opened (errno is set accordingly), otherwise returns the number of errors encountered loading the services in the specified svc.conf configuration file. If ignore_debug_flag is non-0 then the application is responsible for setting the <ACE_Log_Msg::priority_mask> appropriately.

Reimplemented in ACE_Service_Config.

Definition at line 13 of file Service_Gestalt.inl.

References ACE_TCHAR, ACE_TRACE, no_static_svcs_, and open_i().

Referenced by ACE_Service_Config::open().

00018 {
00019   ACE_TRACE ("ACE_Service_Gestalt::open");
00020   this->no_static_svcs_ = ignore_static_svcs;
00021 
00022   return this->open_i (program_name,
00023                        logger_key,
00024                        ignore_static_svcs,
00025                        ignore_default_svc_conf,
00026                        ignore_debug_flag);
00027 }

int ACE_Service_Gestalt::open_i const ACE_TCHAR  program_name[],
const ACE_TCHAR logger_key = ACE_DEFAULT_LOGGER_KEY,
bool  ignore_static_svcs = true,
bool  ignore_default_svc_conf_file = false,
bool  ignore_debug_flag = false
[protected, virtual]
 

Performs an open without parsing command-line arguments. The logger_key indicates where to write the logging output, which is typically either a STREAM pipe or a socket address. If ignore_default_svc_conf_file is non-0 then the "svc.conf" file will be ignored. If ignore_debug_flag is non-0 then the application is responsible for setting the ACE_Log_Msg::priority_mask() appropriately. Returns number of errors that occurred on failure and 0 otherwise.

Reimplemented in ACE_Service_Config.

Definition at line 998 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LOG_MSG, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE::debug(), ACE_Log_Msg::disable_debug_messages(), ACE_Log_Msg::enable_debug_messages(), is_opened_, LM_DEBUG, load_static_svcs(), no_static_svcs_, ACE_Log_Msg::priority_mask(), process_commandline_directives(), and process_directives().

Referenced by open(), and ACE_Service_Config::open_i().

01003 {
01004   ACE_TRACE ("ACE_Service_Gestalt::open_i");
01005   int result = 0;
01006   ACE_Log_Msg *log_msg = ACE_LOG_MSG;
01007 
01008   // Record the current log setting upon entering this thread.
01009   u_long old_process_mask = log_msg->priority_mask
01010     (ACE_Log_Msg::PROCESS);
01011 
01012   u_long old_thread_mask = log_msg->priority_mask
01013     (ACE_Log_Msg::THREAD);
01014 
01015   if (ACE::debug ())
01016     ACE_DEBUG ((LM_DEBUG,
01017                 ACE_TEXT ("(%P|%t) SG::open_i - this=%@, ")
01018                 ACE_TEXT ("opened=%d, loadstatics=%d\n"),
01019                 this, this->is_opened_, this->no_static_svcs_));
01020 
01021   // Guard against reentrant processing. For example,
01022   // if the singleton gestalt (ubergestalt) was already open,
01023   // do not open it again...
01024   if (this->is_opened_++ != 0)
01025     return 0;
01026 
01027   if (ignore_debug_flag == 0)
01028     {
01029       // If -d was included as a startup parameter, the user wants debug
01030       // information printed during service initialization.
01031       if (ACE::debug ())
01032         ACE_Log_Msg::enable_debug_messages ();
01033       else
01034         // The user has requested no debugging info.
01035         ACE_Log_Msg::disable_debug_messages ();
01036     }
01037 
01038   // See if we need to load the static services.
01039   if (this->no_static_svcs_ == 0
01040       && this->load_static_svcs () == -1)
01041     result = -1;
01042   else
01043     {
01044       if (this->process_commandline_directives () == -1)
01045         result = -1;
01046       else
01047         result = this->process_directives ();
01048     }
01049 
01050 
01051   // Reset debugging back to the way it was when we came into
01052   // into <open_i>.
01053   {
01054     // Make sure to save/restore errno properly.
01055     ACE_Errno_Guard error (errno);
01056 
01057     if (ignore_debug_flag == 0)
01058       {
01059         log_msg->priority_mask (old_process_mask, ACE_Log_Msg::PROCESS);
01060         log_msg->priority_mask (old_thread_mask, ACE_Log_Msg::THREAD);
01061       }
01062   }
01063 
01064   return result;
01065 } /* open_i () */

ACE_Service_Gestalt& ACE_Service_Gestalt::operator= const ACE_Service_Gestalt  )  [private]
 

int ACE_Service_Gestalt::parse_args int  ,
ACE_TCHAR argv[]
 

Handle the command-line options intended for the . Note that <argv[0]> is assumed to be the program name. The arguments that are valid in a call to this method are

  • '-b' Option to indicate that we should be a daemon
  • '-d' Turn on debugging mode
  • '-f' Option to read in the list of svc.conf file names
  • '-k' Option to read a wide string where in the logger output can be written
  • '-y' Turn on the flag for a repository of statically linked services
  • '-n' Need not have a repository of statically linked services
  • '-S' Option to read in the list of services on the command-line Please observe the difference between options '-f' that looks for a list of files and here a list of services.

Reimplemented in ACE_Service_Config.

Definition at line 1105 of file Service_Gestalt.cpp.

References ACE_TCHAR, ACE_TRACE, and parse_args_i().

Referenced by ACE_Service_Config::parse_args().

01106 {
01107   ACE_TRACE ("ACE_Service_Gestalt::parse_args");
01108   return parse_args_i (argc, argv);
01109 }

int ACE_Service_Gestalt::parse_args_i int  ,
ACE_TCHAR argv[]
[protected, virtual]
 

Reimplemented in ACE_Service_Config.

Definition at line 1112 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_SVC_QUEUE, ACE_TCHAR, ACE_TRACE, ACE_TString, ACE::debug(), ACE_Unbounded_Queue< T >::enqueue_tail(), init_svc_conf_file_queue(), LM_DEBUG, LM_ERROR, no_static_svcs_, svc_conf_file_queue_, and svc_queue_.

Referenced by open(), parse_args(), and ACE_Service_Config::parse_args_i().

01113 {
01114   ACE_TRACE ("ACE_Service_Gestalt::parse_args_i");
01115   ACE_Get_Opt getopt (argc,
01116                       argv,
01117                       ACE_LIB_TEXT ("df:k:nyp:s:S:"),
01118                       1); // Start at argv[1].
01119 
01120   if (this->init_svc_conf_file_queue () == -1)
01121     return -1;
01122 
01123   for (int c; (c = getopt ()) != -1; )
01124     switch (c)
01125       {
01126       case 'd':
01127         ACE::debug (1);
01128         break;
01129       case 'f':
01130         if (this->svc_conf_file_queue_->enqueue_tail (ACE_TString (getopt.opt_arg ())) == -1)
01131           ACE_ERROR_RETURN ((LM_ERROR,
01132                              ACE_LIB_TEXT ("%p\n"),
01133                              ACE_LIB_TEXT ("enqueue_tail")),
01134                             -1);
01135         break;
01136       case 'k':
01137         /*
01138          * @TODO: Is this always a static storage? Shouldn't we copy
01139          * & gain ownership of the value?
01140          */
01141         this->logger_key_ = getopt.opt_arg ();
01142         break;
01143       case 'n':
01144         this->no_static_svcs_ = 1;
01145         break;
01146       case 'y':
01147         this->no_static_svcs_ = 0;
01148         break;
01149       case 'S':
01150         if (this->svc_queue_ == 0)
01151           {
01152             ACE_NEW_RETURN (this->svc_queue_,
01153                             ACE_SVC_QUEUE,
01154                             -1);
01155           }
01156 
01157         if (this->svc_queue_->enqueue_tail (ACE_TString (getopt.opt_arg ())) == -1)
01158           ACE_ERROR_RETURN ((LM_ERROR,
01159                              ACE_LIB_TEXT ("%p\n"),
01160                              ACE_LIB_TEXT ("enqueue_tail")),
01161                             -1);
01162         break;
01163       default:
01164         if (ACE::debug () > 0)
01165           ACE_DEBUG ((LM_DEBUG,
01166                       ACE_LIB_TEXT ("%c is not a ACE_Service_Config option\n"),
01167                       c));
01168       }
01169 
01170   return 0;
01171 } /* parse_args_i () */

int ACE_Service_Gestalt::process_commandline_directives void   )  [protected]
 

Process service configuration requests that were provided on the command-line. Returns the number of errors that occurred.

Reimplemented in ACE_Service_Config.

Definition at line 1075 of file Service_Gestalt.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_SVC_QUEUE_ITERATOR, ACE_TString, ACE_Unbounded_Queue_Iterator< T >::advance(), ACE_String_Base< CHAR >::fast_rep(), LM_ERROR, ACE_Unbounded_Queue_Iterator< T >::next(), process_directive(), and svc_queue_.

Referenced by open_i().

01076 {
01077   int result = 0;
01078   if (this->svc_queue_ != 0)
01079     {
01080       ACE_TString *sptr = 0;
01081       for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_queue_);
01082            iter.next (sptr) != 0;
01083            iter.advance ())
01084   {
01085     // Process just a single directive.
01086     if (this->process_directive ((sptr->fast_rep ())) != 0)
01087       {
01088         ACE_ERROR ((LM_ERROR,
01089         ACE_LIB_TEXT ("%p\n"),
01090         ACE_LIB_TEXT ("process_directive")));
01091         result = -1;
01092       }
01093   }
01094 
01095       delete this->svc_queue_;
01096       this->svc_queue_ = 0;
01097     }
01098 
01099   return result;
01100 
01101 } /* process_commandline_directives () */

int ACE_Service_Gestalt::process_directive const ACE_Static_Svc_Descriptor ssd,
int  force_replace = 0
 

Process one static service definition.

Load a new static service.

Parameters:
ssd Service descriptor, see the document of ACE_Static_Svc_Descriptor for more details.
force_replace If set the new service descriptor replaces any previous instance in the repository.
Returns:
Returns -1 if the service cannot be 'loaded'.

Reimplemented in ACE_Service_Config.

Definition at line 729 of file Service_Gestalt.cpp.

References add_processed_static_svc(), and process_directive_i().

00731 {
00732   int result = process_directive_i(ssd,force_replace);
00733   if (result == 0)
00734     {
00735       this->add_processed_static_svc(&ssd);
00736     }
00737   return result;
00738 }

int ACE_Service_Gestalt::process_directive const ACE_TCHAR  directive[]  ) 
 

Process one service configuration directive, which is passed as a string. Returns the number of errors that occurred.

Reimplemented in ACE_Service_Config.

Definition at line 941 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_TCHAR, ACE_TRACE, ACE::debug(), ACE_Auto_Basic_Ptr< X >::get(), LM_DEBUG, and process_directives_i().

Referenced by load_static_svcs(), process_commandline_directives(), and ACE_Service_Config::process_directive().

00942 {
00943   ACE_TRACE ("ACE_Service_Gestalt::process_directive");
00944 
00945   if (ACE::debug ())
00946     ACE_DEBUG ((LM_DEBUG,
00947                 ACE_LIB_TEXT ("(%P|%t) SG::process_directive, repo=%@ - %s\n"),
00948                 this->repo_,
00949                 directive));
00950 
00951 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00952   ACE_UNUSED_ARG (directive);
00953 
00954   ACE_Svc_Conf_Param d (this, directive);
00955 
00956   int result = this->process_directives_i (&d);
00957 
00958   return result;
00959 #else
00960   ACE_DLL dll;
00961 
00962   auto_ptr<ACE_XML_Svc_Conf>
00963     xml_svc_conf (this->get_xml_svc_conf (dll));
00964 
00965   if (xml_svc_conf.get () == 0)
00966     return -1;
00967 
00968   return xml_svc_conf->parse_string (directive);
00969 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00970 
00971 } /* process_directive () */

int ACE_Service_Gestalt::process_directive_i const ACE_Static_Svc_Descriptor ssd,
int  force_replace = 0
[protected]
 

Process a static directive without also inserting its descriptor the global table. This avoids multiple additions when processing directives in non-global gestalts.

Definition at line 741 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_NEW_RETURN, ACE_Service_Object_Exterminator, ACE_Static_Svc_Descriptor::active_, ACE_Static_Svc_Descriptor::alloc_, ACE_Service_Config::create_service_type_impl(), ACE::debug(), ACE_Service_Repository::find(), ACE_Static_Svc_Descriptor::flags_, ACE_Service_Repository::insert(), LM_DEBUG, ACE_Static_Svc_Descriptor::name_, and ACE_Static_Svc_Descriptor::type_.

Referenced by initialize(), and process_directive().

00743 {
00744 #ifndef ACE_NLOGGING
00745   if (ACE::debug () > 2)
00746     ACE_DEBUG ((LM_DEBUG,
00747                 ACE_LIB_TEXT ("(%P|%t) SG::process_directive, ")
00748                 ACE_LIB_TEXT ("repo=%@, replace=%d - %s\n"),
00749                 this->repo_,
00750                 force_replace,
00751                 ssd.name_));
00752 #endif
00753 
00754   if (!force_replace)
00755     {
00756       if (this->repo_->find (ssd.name_, 0, 0) >= 0)
00757         {
00758           // The service is already there, just return
00759           return 0;
00760         }
00761     }
00762 
00763   ACE_Service_Object_Exterminator gobbler;
00764   void *sym = (ssd.alloc_)(&gobbler);
00765 
00766   ACE_Service_Type_Impl *stp =
00767     ACE_Service_Config::create_service_type_impl (ssd.name_,
00768                                                   ssd.type_,
00769                                                   sym,
00770                                                   ssd.flags_,
00771                                                   gobbler);
00772   if (stp == 0)
00773     return 0;
00774 
00775 
00776   ACE_Service_Type *service_type;
00777 
00778   // This is just a temporary to force the compiler to use the right
00779   // constructor in ACE_Service_Type
00780   ACE_DLL tmp_dll;
00781 
00782   ACE_NEW_RETURN (service_type,
00783                   ACE_Service_Type (ssd.name_,
00784                                     stp,
00785                                     tmp_dll,
00786                                     ssd.active_),
00787                   -1);
00788 
00789   return this->repo_->insert (service_type);
00790 }

int ACE_Service_Gestalt::process_directives void   ) 
 

Process (or re-process) service configuration requests that are provided in the svc.conf file(s). Returns the number of errors that occurred.

Reimplemented in ACE_Service_Config.

Definition at line 1178 of file Service_Gestalt.cpp.

References ACE_SVC_QUEUE_ITERATOR, ACE_TRACE, ACE_TString, ACE_Unbounded_Queue_Iterator< T >::advance(), ACE_String_Base< CHAR >::fast_rep(), ACE_Unbounded_Queue_Iterator< T >::next(), process_file(), and svc_conf_file_queue_.

Referenced by open_i(), and ACE_Service_Config::process_directives().

01179 {
01180   ACE_TRACE ("ACE_Service_Gestalt::process_directives");
01181 
01182   int result = 0;
01183 
01184   if (this->svc_conf_file_queue_ != 0)
01185     {
01186       ACE_TString *sptr = 0;
01187 
01188       // Iterate through all the svc.conf files.
01189       for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_);
01190            iter.next (sptr) != 0;
01191            iter.advance ())
01192         {
01193           int r = this->process_file (sptr->fast_rep ());
01194 
01195           if (r < 0)
01196             {
01197               result = r;
01198               break;
01199             }
01200 
01201           result += r;
01202         }
01203     }
01204 
01205   return result;
01206 
01207 } /* process_directives () */

int ACE_Service_Gestalt::process_directives_i ACE_Svc_Conf_Param param  )  [protected]
 

This is the implementation function that process_directives() and process_directive() both call. Returns the number of errors that occurred.

Reimplemented in ACE_Service_Config.

Definition at line 795 of file Service_Gestalt.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_LIB_TEXT, ACE_NO_HEAP_CHECK, ACE_TEXT, ACE_Svc_Conf_Param::config, ACE::debug(), ACE_OS::last_error(), LM_DEBUG, ACE_Svc_Conf_Param::source, ACE_Svc_Conf_Param::type, and ACE_Svc_Conf_Param::yyerrno.

Referenced by process_directive(), and process_file().

00796 {
00797   // AC 970827 Skip the heap check because yacc allocates a buffer
00798   // here which will be reported as a memory leak for some reason.
00799   ACE_NO_HEAP_CHECK
00800 
00801     // Were we called in the context of the current instance?
00802     ACE_ASSERT (this == param->config);
00803 
00804   // Temporarily (for the duration of this call) make sure that *any* static
00805   // service registrations will happen with this instance. Such registrations
00806   // are possible as a side-effect of dynamically loading a DLL, which has
00807   // other static services registered. Thus this instance will own both the
00808   // DLL and those static services, which implies that their finalization
00809   // will be performed in the correct order, i.e. prior to finalizing the DLL
00810   ACE_Service_Config_Guard guard (this);
00811 
00812 #ifndef ACE_NLOGGING
00813   if (ACE::debug ())
00814     ACE_DEBUG ((LM_DEBUG,
00815                 ACE_LIB_TEXT ("(%P|%t) SG::process_directives_i, ")
00816                 ACE_LIB_TEXT ("repo=%@ - %s\n"),
00817                 this->repo_,
00818                 (param->type == ACE_Svc_Conf_Param::SVC_CONF_FILE)
00819     ? ACE_TEXT ("<from file>")
00820     : param->source.directive));
00821 #endif
00822 
00823   ::ace_yyparse (param);
00824 
00825   // This is a hack, better errors should be provided...
00826   if (param->yyerrno > 0)
00827     {
00828       if (ACE_OS::last_error () == 0)
00829         ACE_OS::last_error (EINVAL);
00830 
00831       return param->yyerrno;
00832     }
00833   else
00834     return 0;
00835 }

int ACE_Service_Gestalt::process_file const ACE_TCHAR  file[]  ) 
 

Process a file containing a list of service configuration directives.

Reimplemented in ACE_Service_Config.

Definition at line 866 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LIB_TEXT, ACE_stat, ACE_TCHAR, ACE_TEXT, ACE_TRACE, ACE::debug(), EPERM, ACE_OS::fclose(), ACE_Service_Repository::find(), ACE_OS::fopen(), ACE_Auto_Basic_Ptr< X >::get(), LM_ERROR, LM_WARNING, process_directives_i(), and ACE_OS::stat().

Referenced by process_directives().

00867 {
00868   ACE_TRACE ("ACE_Service_Gestalt::process_file");
00869 
00870   // To avoid recursive processing of the same file and the same repository
00871   // we maintain an implicit stack of dummy "services" named after the file
00872   // being processed. Anytime we have to open a new file, we then can check
00873   // to see if it is not already being processed by searching for a dummy
00874   // service with a matching name.
00875   if (this->repo_->find (file, 0, 0) >=0)
00876     {
00877       ACE_DEBUG ((LM_WARNING,
00878       ACE_TEXT ("(%P|%t) Configuration file %s has not finished")
00879       ACE_TEXT (" processing yet. Ignoring.\n"),
00880       file));
00881       return 0;
00882     }
00883 
00884   // Register a dummy service as a forward decl, using the file name as name.
00885   // The entry will be automaticaly removed once the thread exits this block.
00886   ACE_Service_Type_Forward_Declaration_Guard recursion_guard (this->repo_, file);
00887 
00888   /*
00889    * @TODO: Test with ACE_USES_CLASSIC_SVC_CONF turned off!
00890    */
00891 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00892   int result = 0;
00893 
00894   FILE *fp = ACE_OS::fopen (file,
00895                             ACE_LIB_TEXT ("r"));
00896 
00897   if (fp == 0)
00898     {
00899       // Invalid svc.conf file.  We'll report it here and break out of
00900       // the method.
00901       if (ACE::debug ())
00902         ACE_DEBUG ((LM_ERROR,
00903                     ACE_LIB_TEXT ("%p\n"),
00904                     file));
00905 
00906       // Use stat to find out if the file exists.  I didn't use access()
00907       // because stat is better supported on most non-unix platforms.
00908       ACE_stat exists;
00909       if (ACE_OS::stat (file, &exists) == 0)
00910         // If it exists, but we couldn't open it for reading then we
00911         // must not have permission to read it.
00912         errno = EPERM;
00913       else
00914         errno = ENOENT;
00915       result = -1;
00916     }
00917   else
00918     {
00919       ACE_Svc_Conf_Param f (this, fp);
00920 
00921       // Keep track of the number of errors.
00922       result = this->process_directives_i (&f);
00923 
00924       (void) ACE_OS::fclose (fp);
00925     }
00926   return result;
00927 #else
00928   ACE_DLL dll;
00929 
00930   auto_ptr<ACE_XML_Svc_Conf>
00931     xml_svc_conf (ACE_Service_Config::get_xml_svc_conf (dll));
00932 
00933   if (xml_svc_conf.get () == 0)
00934     return -1;
00935 
00936   return xml_svc_conf->parse_file (file);
00937 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00938 }

int ACE_Service_Gestalt::remove const ACE_TCHAR  svc_name[]  ) 
 

Totally remove svc_name from the daemon by removing it from the ACE_Reactor, and unlinking it if necessary.

Reimplemented in ACE_Service_Config.

Definition at line 698 of file Service_Gestalt.cpp.

References ACE_TCHAR, ACE_TRACE, and ACE_Service_Repository::remove().

Referenced by ACE_Remove_Node::apply().

00699 {
00700   ACE_TRACE ("ACE_Service_Gestalt::remove");
00701   return this->repo_->remove (svc_name);
00702 }

int ACE_Service_Gestalt::resume const ACE_TCHAR  svc_name[]  ) 
 

Resume a svc_name that was previously suspended or has not yet been resumed (e.g., a static service).

Reimplemented in ACE_Service_Config.

Definition at line 721 of file Service_Gestalt.cpp.

References ACE_TCHAR, ACE_TRACE, and ACE_Service_Repository::resume().

Referenced by ACE_Resume_Node::apply().

00722 {
00723   ACE_TRACE ("ACE_Service_Gestalt::resume");
00724   return this->repo_->resume (svc_name);
00725 }

int ACE_Service_Gestalt::suspend const ACE_TCHAR  svc_name[]  ) 
 

Suspend svc_name. Note that this will not unlink the service from the daemon if it was dynamically linked, it will mark it as being suspended in the Service Repository and call the member function on the appropriate . A service can be resumed later on by calling the member function...

Reimplemented in ACE_Service_Config.

Definition at line 711 of file Service_Gestalt.cpp.

References ACE_TCHAR, ACE_TRACE, and ACE_Service_Repository::suspend().

Referenced by ACE_Suspend_Node::apply().

00712 {
00713   ACE_TRACE ("ACE_Service_Gestalt::suspend");
00714   return this->repo_->suspend (svc_name);
00715 }


Friends And Related Function Documentation

friend class ACE_Dynamic_Service_Base [friend]
 

Definition at line 370 of file Service_Gestalt.h.

friend class ACE_Service_Config_Guard [friend]
 

Reimplemented in ACE_Service_Config.

Definition at line 372 of file Service_Gestalt.h.

friend class ACE_Service_Object [friend]
 

Definition at line 371 of file Service_Gestalt.h.


Member Data Documentation

ACE_Service_Gestalt::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Reimplemented in ACE_Service_Config.

Definition at line 158 of file Service_Gestalt.h.

int ACE_Service_Gestalt::is_opened_ [protected]
 

Keep track of the number of times the instance has been initialized (opened). "If so, we can't allow to be called since it's not reentrant" is the original motivation, but that does not seem to be the case anymore. This variable is incremented by the <ACE_Service_Gestalt::open> method and decremented by the <ACE_Service_Gestalt::close> method.

Definition at line 386 of file Service_Gestalt.h.

Referenced by close(), is_opened(), and open_i().

const ACE_TCHAR* ACE_Service_Gestalt::logger_key_ [protected]
 

Indicates where to write the logging output. This is typically either a STREAM pipe or a socket

Definition at line 390 of file Service_Gestalt.h.

int ACE_Service_Gestalt::no_static_svcs_ [protected]
 

Should we avoid loading the static services?

Definition at line 393 of file Service_Gestalt.h.

Referenced by open(), open_i(), and parse_args_i().

ACE_PROCESSED_STATIC_SVCS* ACE_Service_Gestalt::processed_static_svcs_ [protected]
 

Repository of statically linked services for which process directive was called, but the service is not already a member of the static_svcs_ list.

Definition at line 412 of file Service_Gestalt.h.

Referenced by ACE_Service_Gestalt(), close(), and ~ACE_Service_Gestalt().

ACE_Service_Repository* ACE_Service_Gestalt::repo_ [protected]
 

The service repository to hold the services.

Definition at line 404 of file Service_Gestalt.h.

Referenced by ACE_Service_Config_Guard::ACE_Service_Config_Guard(), and ACE_Dynamic_Service_Base::instance().

ACE_STATIC_SVCS* ACE_Service_Gestalt::static_svcs_ [protected]
 

Repository of statically linked services.

Definition at line 407 of file Service_Gestalt.h.

Referenced by close(), find_static_svc_descriptor(), insert(), load_static_svcs(), and ~ACE_Service_Gestalt().

ACE_SVC_QUEUE* ACE_Service_Gestalt::svc_conf_file_queue_ [protected]
 

Queue of svc.conf files specified on the command-line. @ This should probably be made to handle unicode filenames...

Definition at line 401 of file Service_Gestalt.h.

Referenced by close(), init_svc_conf_file_queue(), parse_args_i(), and process_directives().

ACE_SVC_QUEUE* ACE_Service_Gestalt::svc_queue_ [protected]
 

Queue of services specified on the command-line.

Definition at line 396 of file Service_Gestalt.h.

Referenced by parse_args_i(), and process_commandline_directives().

bool ACE_Service_Gestalt::svc_repo_is_owned_ [protected]
 

Do we own the service repository instance or have only been given a ptr to the singleton one?

Definition at line 378 of file Service_Gestalt.h.

Referenced by ~ACE_Service_Gestalt().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:29:06 2006 for ACE by doxygen 1.3.6