ACE_Service_Gestalt Class Reference

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

#include <Service_Gestalt.h>

Collaboration diagram for ACE_Service_Gestalt:

Collaboration graph
[legend]
List of all members.

Public Types

 MAX_SERVICES = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE
enum  { MAX_SERVICES = ACE_DEFAULT_SERVICE_REPOSITORY_SIZE }

Public Member Functions

 ACE_Service_Gestalt (size_t size=1024, bool svc_repo_is_owned=true, bool no_static_svcs=true)
 ~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, bool ignore_static_svcs=true, bool ignore_default_svc_conf_file=false, bool ignore_debug_flag=false)
int open (int argc, ACE_TCHAR *argv[], 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 is_opened (void)
int process_directive (const ACE_TCHAR directive[])
int process_directive (const ACE_Static_Svc_Descriptor &ssd, bool force_replace=false)
 Process one static service definition.
int process_file (const ACE_TCHAR file[])
int find (const ACE_TCHAR name[], const ACE_Service_Type **srp=0, bool ignore_suspended=true) const
 Searches for a service object declaration in the local repo, only.
int parse_args (int, ACE_TCHAR *argv[])
int process_directives (bool ignore_default_svc_conf_file)
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.
ACE_Service_Repositorycurrent_service_repository (void)
 Get the current ACE_Service_Repository held by this object.

Static Public Member Functions

static void intrusive_add_ref (ACE_Service_Gestalt *)
static void intrusive_remove_ref (ACE_Service_Gestalt *)

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

int parse_args_i (int, ACE_TCHAR *argv[], bool &ignore_default_svc_conf_file)
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 <svc_conf_file_queue_> if necessary.
int load_static_svcs (void)
int process_commandline_directives (void)
int process_directive_i (const ACE_Static_Svc_Descriptor &ssd, bool force_replace=false)
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 *)
 Captures a list of the direcives processed (explicitely) for this Gestalt so that services can be replicated in other repositories upon their first initialization.
int init_i (void)

Protected Attributes

bool svc_repo_is_owned_
size_t svc_repo_size_
int is_opened_
const ACE_TCHARlogger_key_
bool 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_
ACE_Atomic_Op< ACE_SYNCH_MUTEX,
long > 
refcnt_
 Support for intrusive reference counting.

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
class ACE_Service_Config_Guard

Classes

struct  Processed_Static_Svc

Detailed Description

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

The Gestalt embodies the concept of configuration context. On one hand, it is a flat namespace, where names correspond to a Service Object instance. A Gestalt owns the Service Repository instance, which in turn owns the Service Object instances.

Another aspect of a Gestalt is its responsibility for record-keeping and accounting for the meta-data, necessary for locating, removing or instantiating a service.

A repository underlies an instance of a gestalt and its lifetime may or may not be bounded by the lifetime of the gestalt, that owns it. This feature is important for the derived classes and the Service Config in particular.

Definition at line 70 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 396 of file Service_Gestalt.h.

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

Definition at line 399 of file Service_Gestalt.h.

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

Definition at line 390 of file Service_Gestalt.h.

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

Definition at line 393 of file Service_Gestalt.h.

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

Definition at line 385 of file Service_Gestalt.h.

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

Definition at line 386 of file Service_Gestalt.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
MAX_SERVICES 

Definition at line 80 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 = 1024,
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 211 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE::debug(), and LM_DEBUG.

00214   : svc_repo_is_owned_ (svc_repo_is_owned)
00215   , svc_repo_size_ (size)
00216   , is_opened_ (0)
00217   , logger_key_ (ACE_DEFAULT_LOGGER_KEY)
00218   , no_static_svcs_ (no_static_svcs)
00219   , svc_queue_ (0)
00220   , svc_conf_file_queue_ (0)
00221   , repo_ (0)
00222   , static_svcs_ (0)
00223   , processed_static_svcs_ (0)
00224   , refcnt_ (0)
00225 {
00226   (void)this->init_i ();
00227 
00228 #ifndef ACE_NLOGGING
00229   if (ACE::debug ())
00230     ACE_DEBUG ((LM_DEBUG,
00231                 ACE_TEXT ("ACE (%P|%t) SG::ctor - this = %@, pss = %@\n"),
00232                 this, this->processed_static_svcs_));
00233 #endif
00234 }

ACE_Service_Gestalt::~ACE_Service_Gestalt ( void   ) 

Perform user-specified close activities and remove dynamic memory.

Definition at line 173 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), ACE::debug(), LM_DEBUG, ACE_Unbounded_Set_Ex_Iterator< T, C >::next(), processed_static_svcs_, repo_, static_svcs_, and svc_conf_file_queue_.

00174 {
00175 
00176   if (this->svc_repo_is_owned_)
00177     delete this->repo_;
00178 
00179   this->repo_ =0;
00180 
00181   delete this->static_svcs_;
00182   this->static_svcs_ = 0;
00183 
00184   // Delete the dynamically allocated static_svcs instance.
00185 #ifndef ACE_NLOGGING
00186   if (ACE::debug ())
00187     ACE_DEBUG ((LM_DEBUG,
00188                 ACE_TEXT ("ACE (%P|%t) SG::~SG - this=%@, pss = %@\n"),
00189                 this, this->processed_static_svcs_));
00190 #endif
00191 
00192   if (this->processed_static_svcs_ &&
00193       !this->processed_static_svcs_->is_empty())
00194     {
00195       Processed_Static_Svc **pss = 0;
00196       for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00197            iter.next (pss) != 0;
00198            iter.advance ())
00199         {
00200           delete *pss;
00201         }
00202     }
00203 
00204   delete this->processed_static_svcs_;
00205   this->processed_static_svcs_ = 0;
00206 
00207   delete this->svc_conf_file_queue_;
00208   this->svc_conf_file_queue_ = 0;
00209 }


Member Function Documentation

void ACE_Service_Gestalt::add_processed_static_svc ( const ACE_Static_Svc_Descriptor assd  )  [protected]

Captures a list of the direcives processed (explicitely) for this Gestalt so that services can be replicated in other repositories upon their first initialization.

This is part of the mechanism ensuring distinct local instances for static service objects, loaded in another repository.

When process_directive(Static_Svc_Descriptor&) is called, it associates a service object with the Gestalt and makes the resource (a Service Object) local to the repository. This is but the first step in using such SO. The next is the "initialization" step. It is typicaly done through a "static" service configuration directive.

In contrast a "dynamic" directive, when processed through the overloaded process_directives(string) both creates the SO locally and initializes it, where the statics directive must first locate the SO and then calls the init() method. This means that durig the "static" initialization there's no specific information about the hosting repository and the gestalt must employ some lookup strategy to find it elsewhere.

Definition at line 378 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_NEW, ACE_TEXT, ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), ACE::debug(), LM_DEBUG, ACE_Static_Svc_Descriptor::name_, ACE_Unbounded_Set_Ex_Iterator< T, C >::next(), and ACE_OS::strcmp().

Referenced by process_directive().

00379 {
00380 
00381   /// When process_directive(Static_Svc_Descriptor&) is called, it
00382   /// associates a service object with the Gestalt and makes the
00383   /// resource (a Service Object) local to the repository. This is but
00384   /// the first step in using such SO. The next is the
00385   /// "initialization" step. It is typicaly done through a "static"
00386   /// service configuration directive.
00387   ///
00388   /// In contrast a "dynamic" directive, when processed through the
00389   /// overloaded process_directives(string) both creates the SO
00390   /// locally and initializes it, where the statics directive must
00391   /// first locate the SO and then calls the init() method. This means
00392   /// that durig the "static" initialization there's no specific
00393   /// information about the hosting repository and the gestalt must
00394   /// employ some lookup strategy to find it elsewhere.
00395 
00396   if (this->processed_static_svcs_ == 0)
00397     ACE_NEW (this->processed_static_svcs_,
00398              ACE_PROCESSED_STATIC_SVCS);
00399 
00400   Processed_Static_Svc **pss = 0;
00401   for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00402        iter.next (pss) != 0;
00403        iter.advance ())
00404     {
00405       if (ACE_OS::strcmp ((*pss)->name_, assd->name_) == 0)
00406         {
00407           (*pss)->assd_ = assd;
00408           return;
00409         }
00410     }
00411   Processed_Static_Svc *tmp = 0;
00412   ACE_NEW (tmp,Processed_Static_Svc(assd));
00413   this->processed_static_svcs_->insert(tmp);
00414 
00415   if (ACE::debug ())
00416     ACE_DEBUG ((LM_DEBUG,
00417                 ACE_TEXT ("ACE (%P|%t) SG::add_processed_static_svc, ")
00418                 ACE_TEXT ("repo=%@ - %s\n"),
00419                 this->repo_,
00420                 assd->name_));
00421 }

int ACE_Service_Gestalt::close ( void   ) 

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

Definition at line 1248 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TRACE, ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), ACE::debug(), LM_DEBUG, ACE_Unbounded_Set_Ex_Iterator< T, C >::next(), processed_static_svcs_, repo_, and svc_conf_file_queue_.

01249 {
01250   ACE_TRACE ("ACE_Service_Gestalt::close");
01251 
01252   if (!this->is_opened_ || --this->is_opened_ != 0)
01253     return 0;
01254 
01255   // Delete the list fo svc.conf files
01256   delete this->svc_conf_file_queue_;
01257   this->svc_conf_file_queue_ = 0;
01258 
01259   if (this->processed_static_svcs_ &&
01260       !this->processed_static_svcs_->is_empty())
01261     {
01262       Processed_Static_Svc **pss = 0;
01263       for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
01264            iter.next (pss) != 0;
01265            iter.advance ())
01266         {
01267           delete *pss;
01268         }
01269     }
01270   delete this->processed_static_svcs_;
01271   this->processed_static_svcs_ = 0;
01272 
01273 #ifndef ACE_NLOGGING
01274   if (ACE::debug ())
01275     ACE_DEBUG ((LM_DEBUG,
01276                 ACE_TEXT ("ACE (%P|%t) SG::close - complete this=%@, repo=%@, owned=%d\n"),
01277                 this, this->repo_, this->svc_repo_is_owned_));
01278 #endif
01279 
01280   if (this->svc_repo_is_owned_)
01281     delete this->repo_;
01282 
01283   this->repo_ = 0;
01284 
01285   return 0;
01286 } /* close () */

ACE_INLINE ACE_Service_Repository * ACE_Service_Gestalt::current_service_repository ( void   ) 

Get the current ACE_Service_Repository held by this object.

Definition at line 71 of file Service_Gestalt.inl.

References repo_.

00072 {
00073   return this->repo_;
00074 }

void ACE_Service_Gestalt::dump ( void   )  const

Dump the state of an object.

Definition at line 445 of file Service_Gestalt.cpp.

References ACE_TRACE.

00446 {
00447 #if defined (ACE_HAS_DUMP)
00448   ACE_TRACE ("ACE_Service_Gestalt::dump");
00449 #endif /* ACE_HAS_DUMP */
00450 }

ACE_INLINE int ACE_Service_Gestalt::find ( const ACE_TCHAR  name[],
const ACE_Service_Type **  srp = 0,
bool  ignore_suspended = true 
) const

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

Locate an entry with name in the table. If ignore_suspended 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 srp. If name is not found, -1 is returned. If name is found, but it is suspended and the caller wants to ignore suspended services a -2 is returned.

Definition at line 56 of file Service_Gestalt.inl.

References ACE_Service_Repository::find(), and repo_.

Referenced by ACE_Dynamic_Service_Base::find_i(), and initialize().

00059 {
00060   // Closing the gestalt will have disassociated it from the
00061   // repository. If the repository used to be owned by the gestalt, it
00062   // will also have been destroyed - so just check for repo_ before
00063   // doing anything with it.
00064   if (this->repo_ != 0)
00065     return this->repo_->find (name, srp, ignore_suspended);
00066 
00067   return 0;
00068 }

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

Definition at line 351 of file Service_Gestalt.cpp.

References ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), ACE_Unbounded_Set_Ex_Iterator< T, C >::next(), and ACE_OS::strcmp().

Referenced by initialize().

00352 {
00353   if (this->processed_static_svcs_ == 0 || name == 0)
00354     return 0;
00355 
00356   Processed_Static_Svc **pss = 0;
00357   for (ACE_PROCESSED_STATIC_SVCS_ITERATOR iter (*this->processed_static_svcs_);
00358        iter.next (pss) != 0;
00359        iter.advance ())
00360     {
00361       if (ACE_OS::strcmp ((*pss)->name_, name) == 0)
00362         return (*pss)->assd_;
00363     }
00364   return 0;
00365 }

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 323 of file Service_Gestalt.cpp.

References ACE_TRACE, ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), ACE_Unbounded_Set_Ex_Iterator< T, C >::next(), and ACE_OS::strcmp().

00325 {
00326   ACE_TRACE ("ACE_Service_Gestalt::find_static_svc_descriptor");
00327 
00328   if (this->static_svcs_ == 0)
00329     return -1;
00330 
00331   ACE_Static_Svc_Descriptor **ssdp = 0;
00332   for (ACE_STATIC_SVCS_ITERATOR iter ( *this->static_svcs_);
00333        iter.next (ssdp) != 0;
00334        iter.advance ())
00335     {
00336       if (ACE_OS::strcmp ((*ssdp)->name_, name) == 0)
00337         {
00338           if (ssd != 0)
00339             *ssd = *ssdp;
00340 
00341           return 0;
00342         }
00343     }
00344 
00345   return -1;
00346 }

int ACE_Service_Gestalt::init_i ( void   )  [protected]

Performs the common initialization tasks for a new or previously closed instance. Must not be virtual, as it is called from the constructor.

Definition at line 240 of file Service_Gestalt.cpp.

References ACE_DEFAULT_SVC_CONF, ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TEXT, ACE_Unbounded_Queue< T >::enqueue_tail(), ACE_OS::fclose(), ACE_OS::fopen(), init_svc_conf_file_queue(), ACE_Service_Repository::instance(), ACE_Unbounded_Queue< T >::is_empty(), LM_ERROR, repo_, and svc_conf_file_queue_.

00241 {
00242   // Only initialize the repo_ if (a) we are being constructed, or;
00243   // (b) we're being open()-ed, perhaps after previously having been
00244   // close()-ed. In both cases: repo_ == 0 and we need a repository.
00245   if (this->repo_ == 0)
00246     {
00247       if (this->svc_repo_is_owned_)
00248         {
00249           ACE_NEW_RETURN (this->repo_,
00250                           ACE_Service_Repository (this->svc_repo_size_),
00251                           -1);
00252         }
00253       else
00254         {
00255           this->repo_ =
00256             ACE_Service_Repository::instance (this->svc_repo_size_);
00257         }
00258     }
00259 
00260   if (init_svc_conf_file_queue () == -1)
00261     return -1;
00262 
00263   if ( svc_conf_file_queue_->is_empty ())
00264     {
00265       // Check if the default file exists before attempting to queue it
00266       // for processing
00267       FILE *fp = ACE_OS::fopen (ACE_DEFAULT_SVC_CONF,
00268                                 ACE_TEXT ("r"));
00269       bool skip_static_svcs = (fp == 0);
00270       if (fp != 0)
00271         ACE_OS::fclose (fp);
00272 
00273       if (!skip_static_svcs) {
00274         // Load the default "svc.conf" entry here if there weren't
00275         // overriding -f arguments in <parse_args>.
00276         if (svc_conf_file_queue_->enqueue_tail
00277             (ACE_TString (ACE_DEFAULT_SVC_CONF)) == -1)
00278           {
00279             ACE_ERROR_RETURN ((LM_ERROR,
00280                                ACE_TEXT ("%p\n"),
00281                                ACE_TEXT ("enqueuing ")
00282                                ACE_DEFAULT_SVC_CONF
00283                                ACE_TEXT(" file")),
00284                               -1);
00285           }
00286       }
00287     }
00288 
00289   return 0;
00290 }

int ACE_Service_Gestalt::init_svc_conf_file_queue ( void   )  [protected]

Initialize the <svc_conf_file_queue_> if necessary.

Definition at line 998 of file Service_Gestalt.cpp.

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

Referenced by init_i().

00999 {
01000   if (this->svc_conf_file_queue_ == 0)
01001     {
01002       ACE_SVC_QUEUE *tmp = 0;
01003       ACE_NEW_RETURN (tmp,
01004           ACE_SVC_QUEUE,
01005           -1);
01006       this->svc_conf_file_queue_ = tmp;
01007     }
01008 
01009 #ifndef ACE_NLOGGING
01010   if (ACE::debug ())
01011     ACE_DEBUG ((LM_DEBUG,
01012                 ACE_TEXT ("ACE (%P|%t) SG::init_svc_conf_file_queue ")
01013                 ACE_TEXT ("- this=%@, repo=%@\n"),
01014                 this, this->repo_));
01015 #endif
01016 
01017   return 0;
01018 
01019 } /* 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 ...

Definition at line 457 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR, ACE_ERROR_RETURN, ACE_TEXT, ACE_TRACE, ACE_ARGV_T< CHAR_TYPE >::argc(), ACE_ARGV_T< CHAR_TYPE >::argv(), ACE::debug(), 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(), repo_, and ACE_Service_Type::type().

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

int ACE_Service_Gestalt::initialize ( const ACE_Service_Type ,
const ACE_TCHAR parameters 
)

Dynamically link the shared object file and retrieve a pointer to the designated shared object in this file.

Deprecated:
Note:
This is error-prone in the presense of dynamic services, which in turn initialize their own static services. This method will allow those static services to register *before* the dynamic service that owns them. Upon finalization of the static services the process will typically crash, because the dynamic service's DLL may have been already released, together with the memory in which the static services reside. It may not crash, for instance, when the first static service to register is the same as the dynamic service being loaded. You should be so lucky!

Definition at line 617 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TRACE, ACE::debug(), initialize_i(), LM_DEBUG, LM_WARNING, ACE_Service_Type::name(), ACE_Service_Repository::remove(), and repo_.

00619 {
00620   ACE_TRACE ("ACE_Service_Gestalt::initialize");
00621 
00622   if (ACE::debug ())
00623     ACE_DEBUG ((LM_DEBUG,
00624                 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00625                 ACE_TEXT (" - looking up in the repo\n"),
00626                 this->repo_,
00627                 sr->name ()));
00628 
00629   ACE_Service_Type *srp = 0;
00630   if (this->repo_->find (sr->name (),
00631                          (const ACE_Service_Type **) &srp) >= 0)
00632     {
00633 #ifndef ACE_NLOGGING
00634       ACE_DEBUG ((LM_WARNING,
00635                   ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00636                   ACE_TEXT (" - removing a pre-existing namesake.\n"),
00637                   this->repo_,
00638                   sr->name ()));
00639 #endif
00640       this->repo_->remove (sr->name ());
00641     }
00642 
00643   return this->initialize_i (sr, parameters);
00644 
00645 }

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 522 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_TEXT, ACE_TRACE, ACE::debug(), ACE_Service_Repository::find(), initialize_i(), LM_DEBUG, LM_WARNING, ACE_Service_Repository::remove(), repo_, and ACE_Service_Type::type().

Referenced by ACE_Service_Config::initialize().

00524 {
00525   ACE_TRACE ("ACE_Service_Gestalt::initialize");
00526 
00527 #ifndef ACE_NLOGGING
00528   if (ACE::debug ())
00529     ACE_DEBUG ((LM_DEBUG,
00530                 ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s")
00531                 ACE_TEXT (" - looking up in the repo\n"),
00532                 this->repo_,
00533                 stf->name ()));
00534 #endif
00535 
00536   ACE_Service_Type *srp = 0;
00537   int const retv = this->repo_->find (stf->name (),
00538                                       (const ACE_Service_Type **) &srp);
00539 
00540   // If there is an active service already, remove it first
00541   // before it can be re-installed.
00542   if (retv >= 0)
00543     {
00544 #ifndef ACE_NLOGGING
00545       if (ACE::debug ())
00546         ACE_DEBUG ((LM_WARNING,
00547                     ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
00548                     ACE_TEXT (" name=%s - removing a pre-existing namesake.\n"),
00549                     this->repo_,
00550                     stf->name ()));
00551 #endif
00552       this->repo_->remove (stf->name ());
00553     }
00554 
00555   // If there is an inactive service by that name it may have been
00556   // either inactivated, or just a forward declaration for a service,
00557   // that is in the process of being initialized. If it is the latter,
00558   // then we have detected an attempt to initialize the same dynamic
00559   // service while still processing previous attempt. This can lock up
00560   // the process, because the ACE_DLL_Manager::open () is not
00561   // re-entrant - it uses a Singleton lock to serialize concurent
00562   // invocations. This use case must be handled here, because if the
00563   // DLL_Manager was re-entrant we would have entered an infinite
00564   // recursion here.
00565   if (retv == -2 && srp->type () == 0)
00566     ACE_ERROR_RETURN ((LM_WARNING,
00567                        ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,")
00568                        ACE_TEXT (" name=%s - forward-declared; ")
00569                        ACE_TEXT (" recursive initialization requests are")
00570                        ACE_TEXT (" ignored.\n"),
00571                        this->repo_,
00572                        stf->name ()),
00573                       -1);
00574 
00575   // Reserve a spot for the dynamic service by inserting an incomplete
00576   // service declaration, i.e. one that can not produce a service
00577   // object if asked (a forward declaration).  This declaration
00578   // ensures maintaining the proper partial ordering of the services
00579   // with respect to their finalization. For example, dependent static
00580   // services must be registered *after* the dynamic service that
00581   // loads them, so that their finalization is complete *before*
00582   // finalizing the dynamic service.
00583   ACE_Service_Type_Dynamic_Guard dummy (*this->repo_,
00584                                         stf->name ());
00585 
00586   // make_service_type() is doing the dynamic loading and also runs
00587   // any static initializers
00588   ACE_Auto_Ptr<ACE_Service_Type> tmp (stf->make_service_type (this));
00589 
00590   if (tmp.get () != 0 &&
00591       this->initialize_i (tmp.get (), parameters) == 0)
00592     {
00593       // All good. Tthe ACE_Service_Type instance is now owned by the
00594       // repository and we should make sure it is not destroyed upon
00595       // exit from this method.
00596       tmp.release ();
00597       return 0;
00598     }
00599 
00600   return -1;
00601 }

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

Dynamically link the shared object file and retrieve a pointer to the designated shared object in this file.

Definition at line 650 of file Service_Gestalt.cpp.

References ACE_ERROR_RETURN, ACE_TEXT, ACE_TRACE, ACE_ARGV_T< CHAR_TYPE >::argc(), ACE_ARGV_T< CHAR_TYPE >::argv(), ACE::debug(), ACE_Service_Type_Impl::init(), LM_WARNING, ACE_Service_Type::name(), ACE_Service_Repository::remove(), repo_, and ACE_Service_Type::type().

Referenced by initialize().

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

int ACE_Service_Gestalt::insert ( ACE_Static_Svc_Descriptor stsd  ) 

Queues a static service object descriptor which, during open() will be given to process_directive() to create the Service Object. Normally, only called from static initializers, prior to calling open() but loading a service from a DLL can cause it too.

Definition at line 430 of file Service_Gestalt.cpp.

References ACE_NEW_RETURN, ACE_Unbounded_Set_Ex< T, C >::insert(), and static_svcs_.

Referenced by ACE_Service_Config::insert().

00431 {
00432   if (this->static_svcs_ == 0)
00433     ACE_NEW_RETURN (this->static_svcs_,
00434                     ACE_STATIC_SVCS,
00435                     -1);
00436 
00437   return this->static_svcs_->insert (stsd);
00438 }

void ACE_Service_Gestalt::intrusive_add_ref ( ACE_Service_Gestalt  )  [static]

Definition at line 152 of file Service_Gestalt.cpp.

References ACE_ASSERT, and refcnt_.

00153 {
00154   if (g != 0)
00155     {
00156       ++g->refcnt_;
00157       ACE_ASSERT (g->refcnt_ > 0);
00158     }
00159 }

void ACE_Service_Gestalt::intrusive_remove_ref ( ACE_Service_Gestalt  )  [static]

Definition at line 162 of file Service_Gestalt.cpp.

References ACE_ASSERT, and refcnt_.

00163 {
00164   if (g != 0)
00165     {
00166       long tmp = --g->refcnt_;
00167       if (tmp <= 0)  delete g;
00168       ACE_ASSERT (tmp >= 0);
00169     }
00170 }

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 1101 of file Service_Gestalt.cpp.

References is_opened_.

01102 {
01103   return this->is_opened_;
01104 }

int ACE_Service_Gestalt::load_static_svcs ( void   )  [protected]

Add the default statically-linked services to the ACE_Service_Repository.

Definition at line 297 of file Service_Gestalt.cpp.

References ACE_TRACE, ACE_Unbounded_Set_Ex_Iterator< T, C >::advance(), and ACE_Unbounded_Set_Ex_Iterator< T, C >::next().

00298 {
00299   ACE_TRACE ("ACE_Service_Gestalt::load_static_svcs");
00300 
00301   if (this->static_svcs_ == 0)
00302     return 0; // Nothing to do
00303 
00304   ACE_Static_Svc_Descriptor **ssdp = 0;
00305   for (ACE_STATIC_SVCS_ITERATOR iter (*this->static_svcs_);
00306        iter.next (ssdp) != 0;
00307        iter.advance ())
00308     {
00309       ACE_Static_Svc_Descriptor *ssd = *ssdp;
00310 
00311       if (this->process_directive (*ssd, 1) == -1)
00312         return -1;
00313     }
00314   return 0;
00315 
00316 } /* load_static_svcs () */

ACE_INLINE int ACE_Service_Gestalt::open ( int  argc,
ACE_TCHAR argv[],
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 
)

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:

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 true then static services are not loaded, otherwise, they are loaded.
ignore_default_svc_conf_file If false then the svc.conf configuration file will be ignored.
ignore_debug_flag If false 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).

Definition at line 30 of file Service_Gestalt.inl.

References ACE_TRACE, no_static_svcs_, and open_i().

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

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,
bool  ignore_static_svcs = true,
bool  ignore_default_svc_conf_file = false,
bool  ignore_debug_flag = false 
)

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 true then static services are not loaded, otherwise, they are loaded. If ignore_default_svc_conf_file is true 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 true then the application is responsible for setting the <ACE_Log_Msg::priority_mask> appropriately.

Definition at line 13 of file Service_Gestalt.inl.

References 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]

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.

Definition at line 1023 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_LOG_MSG, ACE_TEXT, ACE_TRACE, ACE::debug(), ACE_Log_Msg::disable_debug_messages(), ACE_Log_Msg::enable_debug_messages(), LM_DEBUG, no_static_svcs_, ACE_Log_Msg::priority_mask(), ACE_Log_Msg::PROCESS, process_directives(), and ACE_Log_Msg::THREAD.

Referenced by open().

01028 {
01029   ACE_TRACE ("ACE_Service_Gestalt::open_i");
01030   int result = 0;
01031   ACE_Log_Msg *log_msg = ACE_LOG_MSG;
01032 
01033   no_static_svcs_ = ignore_static_svcs;
01034 
01035   // Record the current log setting upon entering this thread.
01036   u_long old_process_mask = log_msg->priority_mask
01037     (ACE_Log_Msg::PROCESS);
01038 
01039   u_long old_thread_mask = log_msg->priority_mask
01040     (ACE_Log_Msg::THREAD);
01041 
01042 #ifndef ACE_NLOGGING
01043   if (ACE::debug ())
01044     ACE_DEBUG ((LM_DEBUG,
01045                 ACE_TEXT ("ACE (%P|%t) SG::open_i - this=%@, ")
01046                 ACE_TEXT ("opened=%d, loadstatics=%d\n"),
01047                 this, this->is_opened_, this->no_static_svcs_));
01048 #endif
01049 
01050   // Guard against reentrant processing. For example,
01051   // if the singleton gestalt (ubergestalt) was already open,
01052   // do not open it again...
01053   if (this->is_opened_++ != 0)
01054     return 0;
01055 
01056   if (this->init_i () != 0)
01057     return -1;
01058 
01059   if (!ignore_debug_flag)
01060     {
01061       // If -d was included as a startup parameter, the user wants debug
01062       // information printed during service initialization.
01063       if (ACE::debug ())
01064         ACE_Log_Msg::enable_debug_messages ();
01065       else
01066         // The user has requested no debugging info.
01067         ACE_Log_Msg::disable_debug_messages ();
01068     }
01069 
01070   // See if we need to load the static services.
01071   if (this->no_static_svcs_ == 0
01072       && this->load_static_svcs () == -1)
01073     result = -1;
01074   else
01075     {
01076       if (this->process_commandline_directives () == -1)
01077         result = -1;
01078       else
01079         result = this->process_directives (ignore_default_svc_conf_file);
01080     }
01081 
01082 
01083   // Reset debugging back to the way it was when we came into
01084   // into <open_i>.
01085   {
01086     // Make sure to save/restore errno properly.
01087     ACE_Errno_Guard error (errno);
01088 
01089     if (!ignore_debug_flag)
01090       {
01091         log_msg->priority_mask (old_process_mask, ACE_Log_Msg::PROCESS);
01092         log_msg->priority_mask (old_thread_mask, ACE_Log_Msg::THREAD);
01093       }
01094   }
01095 
01096   return result;
01097 } /* 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 ACE_Service_Gestalt. Note that <argv[0]> is assumed to be the program name.

The arguments that are valid in a call to this method are

Definition at line 1137 of file Service_Gestalt.cpp.

References ACE_TRACE, and parse_args_i().

Referenced by ACE_Service_Config::parse_args().

01138 {
01139   ACE_TRACE ("ACE_Service_Gestalt::parse_args");
01140   bool unused_ignore_default_svc_conf = true;
01141   return parse_args_i (argc, argv, unused_ignore_default_svc_conf);
01142 }

int ACE_Service_Gestalt::parse_args_i ( int  ,
ACE_TCHAR argv[],
bool &  ignore_default_svc_conf_file 
) [protected]

Definition at line 1145 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_ERROR_RETURN, ACE_NEW_RETURN, ACE_TEXT, ACE_TRACE, ACE::debug(), ACE_OS::getopt(), LM_DEBUG, logger_key_, and no_static_svcs_.

Referenced by parse_args().

01148 {
01149   ACE_TRACE ("ACE_Service_Gestalt::parse_args_i");
01150   //FUZZ: disable check_for_lack_ACE_OS
01151   ACE_Get_Opt getopt (argc,
01152                       argv,
01153                       ACE_TEXT ("df:k:nyS:"),
01154                       1); // Start at argv[1].
01155   //FUZZ: enable check_for_lack_ACE_OS
01156 
01157   if (this->init_svc_conf_file_queue () == -1)
01158     return -1;
01159 
01160   //FUZZ: disable check_for_lack_ACE_OS
01161   for (int c; (argc != 0) && ((c = getopt ()) != -1); )
01162   //FUZZ: enable check_for_lack_ACE_OS
01163     switch (c)
01164       {
01165       case 'd':
01166         ACE::debug (1);
01167         break;
01168       case 'f':
01169         if (this->svc_conf_file_queue_->enqueue_tail (ACE_TString (getopt.opt_arg ())) == -1)
01170           ACE_ERROR_RETURN ((LM_ERROR,
01171                              ACE_TEXT ("%p\n"),
01172                              ACE_TEXT ("enqueue_tail")),
01173                             -1);
01174         ignore_default_svc_conf_file = true;
01175         break;
01176       case 'k':
01177         /*
01178          * @TODO: Is this always a static storage? Shouldn't we copy
01179          * & gain ownership of the value?
01180          */
01181         this->logger_key_ = getopt.opt_arg ();
01182         break;
01183       case 'n':
01184         this->no_static_svcs_ = 1;
01185         break;
01186       case 'y':
01187         this->no_static_svcs_ = 0;
01188         break;
01189       case 'S':
01190         if (this->svc_queue_ == 0)
01191           {
01192             ACE_NEW_RETURN (this->svc_queue_,
01193                             ACE_SVC_QUEUE,
01194                             -1);
01195           }
01196 
01197         if (this->svc_queue_->enqueue_tail (ACE_TString (getopt.opt_arg ())) == -1)
01198           ACE_ERROR_RETURN ((LM_ERROR,
01199                              ACE_TEXT ("%p\n"),
01200                              ACE_TEXT ("enqueue_tail")),
01201                             -1);
01202         break;
01203       default:
01204         if (ACE::debug ())
01205           ACE_DEBUG ((LM_DEBUG,
01206                       ACE_TEXT ("ACE (%P|%t) %c is not a ACE_Service_Config option\n"),
01207                       c));
01208       }
01209 
01210   return 0;
01211 } /* 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.

Definition at line 1107 of file Service_Gestalt.cpp.

References ACE_ERROR, ACE_TEXT, ACE_Unbounded_Queue_Iterator< T >::advance(), ACE_Unbounded_Queue_Iterator< T >::next(), and svc_queue_.

01108 {
01109   int result = 0;
01110   if (this->svc_queue_ != 0)
01111     {
01112       ACE_TString *sptr = 0;
01113       for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_queue_);
01114            iter.next (sptr) != 0;
01115            iter.advance ())
01116         {
01117           // Process just a single directive.
01118           if (this->process_directive ((sptr->fast_rep ())) != 0)
01119             {
01120               ACE_ERROR ((LM_ERROR,
01121                           ACE_TEXT ("ACE (%P|%t) %p\n"),
01122                           ACE_TEXT ("process_directive")));
01123               result = -1;
01124             }
01125         }
01126 
01127       delete this->svc_queue_;
01128       this->svc_queue_ = 0;
01129     }
01130 
01131   return result;
01132 
01133 } /* process_commandline_directives () */

int ACE_Service_Gestalt::process_directive ( const ACE_Static_Svc_Descriptor ssd,
bool  force_replace = false 
)

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'.

Definition at line 737 of file Service_Gestalt.cpp.

References add_processed_static_svc(), and process_directive_i().

00739 {
00740   int const result = process_directive_i (ssd, force_replace);
00741   if (result == 0)
00742     {
00743       this->add_processed_static_svc(&ssd);
00744     }
00745   return result;
00746 }

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.

Definition at line 956 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TRACE, ACE::debug(), LM_DEBUG, and process_directives_i().

Referenced by ACE_Service_Config::process_directive().

00957 {
00958   ACE_TRACE ("ACE_Service_Gestalt::process_directive");
00959 
00960 #ifndef ACE_NLOGGING
00961   if (ACE::debug ())
00962     ACE_DEBUG ((LM_DEBUG,
00963                 ACE_TEXT ("ACE (%P|%t) SG::process_directive, repo=%@ - %s\n"),
00964                 this->repo_,
00965                 directive));
00966 #endif
00967 
00968 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00969   ACE_UNUSED_ARG (directive);
00970 
00971   ACE_Svc_Conf_Param d (this, directive);
00972 
00973   return this->process_directives_i (&d);
00974 #else
00975   ACE_DLL dll;
00976 
00977   auto_ptr<ACE_XML_Svc_Conf>
00978     xml_svc_conf (this->get_xml_svc_conf (dll));
00979 
00980   if (xml_svc_conf.get () == 0)
00981     return -1;
00982 
00983   // Temporarily (for the duration of this call) make sure that *any* static
00984   // service registrations will happen with this instance. Such registrations
00985   // are possible as a side-effect of dynamically loading a DLL, which has
00986   // other static services registered. Thus this instance will own both the
00987   // DLL and those static services, which implies that their finalization
00988   // will be performed in the correct order, i.e. prior to finalizing the DLL
00989   ACE_Service_Config_Guard guard (this);
00990 
00991   return xml_svc_conf->parse_string (directive);
00992 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */
00993 
00994 } /* process_directive () */

int ACE_Service_Gestalt::process_directive_i ( const ACE_Static_Svc_Descriptor ssd,
bool  force_replace = false 
) [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 749 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_NEW_RETURN, ACE_TEXT, ACE_Static_Svc_Descriptor::active_, ACE_Static_Svc_Descriptor::alloc_, ACE_Service_Config::create_service_type_impl(), ACE::debug(), ACE_DLL::dll_name_, ACE_Static_Svc_Descriptor::flags_, ACE_Service_Repository::insert(), LM_DEBUG, ACE_Static_Svc_Descriptor::name_, repo_, and ACE_Static_Svc_Descriptor::type_.

Referenced by initialize(), and process_directive().

00751 {
00752   if (this->repo_ == 0)
00753     return -1;
00754 
00755   if (!force_replace)
00756     {
00757       if (this->repo_->find (ssd.name_, 0, 0) >= 0)
00758         {
00759           // The service is already there, just return
00760           return 0;
00761         }
00762     }
00763 
00764 
00765   ACE_Service_Object_Exterminator gobbler;
00766   void *sym = (ssd.alloc_)(&gobbler);
00767 
00768   ACE_Service_Type_Impl *stp =
00769     ACE_Service_Config::create_service_type_impl (ssd.name_,
00770                                                   ssd.type_,
00771                                                   sym,
00772                                                   ssd.flags_,
00773                                                   gobbler);
00774   if (stp == 0)
00775     return 0;
00776 
00777   ACE_Service_Type *service_type = 0;
00778 
00779   // This is just a temporary to force the compiler to use the right
00780   // constructor in ACE_Service_Type. Note that, in cases where we are
00781   // called from a static initializer which is part of a DLL, there is
00782   // not enough information about the actuall DLL in this context.
00783   ACE_DLL tmp_dll;
00784 
00785   ACE_NEW_RETURN (service_type,
00786                   ACE_Service_Type (ssd.name_,
00787                                     stp,
00788                                     tmp_dll,
00789                                     ssd.active_),
00790                   -1);
00791 
00792 #ifndef ACE_NLOGGING
00793   if (ACE::debug ())
00794     ACE_DEBUG ((LM_DEBUG,
00795                 ACE_TEXT ("ACE (%P|%t) SG::process_directive_i, ")
00796                 ACE_TEXT ("repo=%@ - %s, dll=%s, force=%d\n"),
00797                 this->repo_,
00798                 ssd.name_,
00799                 (tmp_dll.dll_name_ == 0) ? ACE_TEXT ("<null>") : tmp_dll.dll_name_,
00800                 force_replace));
00801 #endif
00802 
00803   return this->repo_->insert (service_type);
00804 }

int ACE_Service_Gestalt::process_directives ( bool  ignore_default_svc_conf_file  ) 

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

Definition at line 1218 of file Service_Gestalt.cpp.

References ACE_DEFAULT_SVC_CONF, ACE_TRACE, ACE_Unbounded_Queue_Iterator< T >::advance(), ACE_Unbounded_Queue_Iterator< T >::next(), and process_file().

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

01219 {
01220   ACE_TRACE ("ACE_Service_Gestalt::process_directives");
01221 
01222   if (this->svc_conf_file_queue_ == 0
01223       || this->svc_conf_file_queue_->is_empty ())
01224     return 0;
01225 
01226   ACE_TString *sptr = 0;
01227   ACE_TString default_svc_conf (ACE_DEFAULT_SVC_CONF);
01228 
01229   // Iterate through all the svc.conf files.
01230   for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_);
01231        iter.next (sptr) != 0;
01232        iter.advance ())
01233     {
01234       if (*sptr == default_svc_conf && ignore_default_svc_conf_file)
01235         continue;
01236 
01237       int result = this->process_file (sptr->fast_rep ());
01238       if (result < 0)
01239         return result;
01240     }
01241 
01242   return 0;
01243 
01244 } /* 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.

Definition at line 809 of file Service_Gestalt.cpp.

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

Referenced by process_directive(), and process_file().

00810 {
00811 #ifndef ACE_NLOGGING
00812   if (ACE::debug ())
00813     ACE_DEBUG ((LM_DEBUG,
00814                 ACE_TEXT ("ACE (%P|%t) SG::process_directives_i, ")
00815                 ACE_TEXT ("repo=%@ - %s\n"),
00816                 this->repo_,
00817                 (param->type == ACE_Svc_Conf_Param::SVC_CONF_FILE)
00818                 ? ACE_TEXT ("<from file>")
00819                 : param->source.directive));
00820 #endif
00821 
00822   // AC 970827 Skip the heap check because yacc allocates a buffer
00823   // here which will be reported as a memory leak for some reason.
00824   ACE_NO_HEAP_CHECK
00825 
00826   // Were we called in the context of the current instance?
00827   ACE_ASSERT (this == param->config);
00828 
00829   // Temporarily (for the duration of this call) make sure that *any*
00830   // static service registrations will happen with this instance. Such
00831   // registrations are possible as a side-effect of dynamically
00832   // loading a DLL, which has other static services registered. Thus
00833   // this instance will own both the DLL and those static services,
00834   // which implies that their finalization will be performed in the
00835   // correct order, i.e. prior to finalizing the DLL
00836   ACE_Service_Config_Guard guard (this);
00837 
00838   ::ace_yyparse (param);
00839 
00840   // This is a hack, better errors should be provided...
00841   if (param->yyerrno > 0)
00842     {
00843       // Always set the last error if ace_yyparse() fails.
00844       // Other code may use errno to determine the type
00845       // of problem that occurred from processing directives.
00846       ACE_OS::last_error (EINVAL);
00847       return param->yyerrno;
00848     }
00849   else
00850     return 0;
00851 }

int ACE_Service_Gestalt::process_file ( const ACE_TCHAR  file[]  ) 

Process a file containing a list of service configuration directives.

Definition at line 880 of file Service_Gestalt.cpp.

References ACE_DEBUG, ACE_TEXT, ACE_TRACE, ACE::debug(), ACE_OS::fclose(), ACE_OS::fopen(), LM_WARNING, process_directives_i(), and ACE_OS::stat().

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

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

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.

Definition at line 697 of file Service_Gestalt.cpp.

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

00698 {
00699   ACE_TRACE ("ACE_Service_Gestalt::remove");
00700   if (this->repo_ == 0)
00701     return -1;
00702 
00703   return this->repo_->remove (svc_name);
00704 }

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).

Definition at line 726 of file Service_Gestalt.cpp.

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

00727 {
00728   ACE_TRACE ("ACE_Service_Gestalt::resume");
00729   if (this->repo_ == 0)
00730     return -1;
00731 
00732   return this->repo_->resume (svc_name);
00733 }

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 <suspend> member function on the appropriate ACE_Service_Object. A service can be resumed later on by calling the <RESUME> member function...

Definition at line 713 of file Service_Gestalt.cpp.

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

00714 {
00715   ACE_TRACE ("ACE_Service_Gestalt::suspend");
00716   if (this->repo_ == 0)
00717     return -1;
00718 
00719   return this->repo_->suspend (svc_name);
00720 }


Friends And Related Function Documentation

friend class ACE_Dynamic_Service_Base [friend]

Definition at line 401 of file Service_Gestalt.h.

friend class ACE_Service_Config [friend]

Definition at line 403 of file Service_Gestalt.h.

friend class ACE_Service_Config_Guard [friend]

Definition at line 404 of file Service_Gestalt.h.

friend class ACE_Service_Object [friend]

Definition at line 402 of file Service_Gestalt.h.


Member Data Documentation

ACE_Service_Gestalt::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 181 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 <yyparse> 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 422 of file Service_Gestalt.h.

Referenced by is_opened().

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 426 of file Service_Gestalt.h.

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

bool ACE_Service_Gestalt::no_static_svcs_ [protected]

Should we avoid loading the static services?

Definition at line 429 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 448 of file Service_Gestalt.h.

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

ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> ACE_Service_Gestalt::refcnt_ [protected]

Support for intrusive reference counting.

Definition at line 451 of file Service_Gestalt.h.

Referenced by intrusive_add_ref(), and intrusive_remove_ref().

ACE_Service_Repository* ACE_Service_Gestalt::repo_ [protected]

The service repository to hold the services.

Definition at line 440 of file Service_Gestalt.h.

Referenced by ACE_Service_Config_Guard::ACE_Service_Config_Guard(), close(), current_service_repository(), find(), init_i(), initialize(), initialize_i(), ACE_Dynamic_Service_Base::instance(), process_directive_i(), remove(), resume(), suspend(), and ~ACE_Service_Gestalt().

ACE_STATIC_SVCS* ACE_Service_Gestalt::static_svcs_ [protected]

Repository of statically linked services.

Definition at line 443 of file Service_Gestalt.h.

Referenced by insert(), 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 437 of file Service_Gestalt.h.

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

ACE_SVC_QUEUE* ACE_Service_Gestalt::svc_queue_ [protected]

Queue of services specified on the command-line.

Definition at line 432 of file Service_Gestalt.h.

Referenced by 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?

Definition at line 410 of file Service_Gestalt.h.

size_t ACE_Service_Gestalt::svc_repo_size_ [protected]

Repository size is necessary, so that we can close (which may destroy the repository instance), and then re-open again.

Definition at line 414 of file Service_Gestalt.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:34 2010 for ACE by  doxygen 1.4.7