Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Parse_Node.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 #include "ace/Parse_Node.h"
00003 
00004 #if (ACE_USES_CLASSIC_SVC_CONF == 1)
00005 
00006 #include "ace/Service_Config.h"
00007 #include "ace/Service_Repository.h"
00008 #include "ace/Task.h"
00009 
00010 #if !defined (__ACE_INLINE__)
00011 #include "ace/Parse_Node.i"
00012 #endif /* ____ */
00013 
00014 
00015 ACE_RCSID (ace,
00016            Parse_Node,
00017            "$Id: Parse_Node.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00018 
00019 
00020 ACE_ALLOC_HOOK_DEFINE (ACE_Stream_Node)
00021 
00022 // Provide the class hierarchy that defines the parse tree of Service
00023 // Nodes.
00024 
00025 
00026 void
00027 ACE_Stream_Node::dump (void) const
00028 {
00029   ACE_TRACE ("ACE_Stream_Node::dump");
00030 }
00031 
00032 void
00033 ACE_Stream_Node::apply (int & yyerrno)
00034 {
00035   ACE_TRACE ("ACE_Stream_Node::apply");
00036 
00037   if (ACE_Service_Config::initialize (this->node_->record (),
00038                                       this->node_->parameters ()) == -1)
00039     yyerrno++;
00040 
00041   if (ACE::debug ())
00042     ACE_DEBUG ((LM_DEBUG,
00043                 ACE_LIB_TEXT ("did stream on %s, error = %d\n"),
00044                 this->node_->name (),
00045                 yyerrno));
00046 }
00047 
00048 ACE_ALLOC_HOOK_DEFINE (ACE_Parse_Node)
00049 
00050 void
00051 ACE_Parse_Node::dump (void) const
00052 {
00053   ACE_TRACE ("ACE_Parse_Node::dump");
00054 }
00055 
00056 const ACE_TCHAR *
00057 ACE_Parse_Node::name (void) const
00058 {
00059   ACE_TRACE ("ACE_Parse_Node::name");
00060   return this->name_;
00061 }
00062 
00063 ACE_Parse_Node *
00064 ACE_Parse_Node::link (void) const
00065 {
00066   ACE_TRACE ("ACE_Parse_Node::link");
00067   return this->next_;
00068 }
00069 
00070 void
00071 ACE_Parse_Node::link (ACE_Parse_Node *n)
00072 {
00073   ACE_TRACE ("ACE_Parse_Node::link");
00074   this->next_ = n;
00075 }
00076 
00077 ACE_Stream_Node::ACE_Stream_Node (const ACE_Static_Node *str_ops,
00078                                   const ACE_Parse_Node *str_mods)
00079 #if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS)
00080   : ACE_Parse_Node (str_ops == 0 ? ACE_static_cast (ACE_TCHAR *,
00081                                                     ACE_LIB_TEXT ("<unknown>"))
00082                                  : ACE_static_cast (ACE_TCHAR *,
00083                                                     str_ops->name ())),
00084 #else
00085   : ACE_Parse_Node ((str_ops == 0 ? ACE_LIB_TEXT ("<unknown>") : str_ops->name ())),
00086 #endif /* defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
00087     node_ (str_ops),
00088     mods_ (str_mods)
00089 {
00090   ACE_TRACE ("ACE_Stream_Node::ACE_Stream_Node");
00091 }
00092 
00093 
00094 ACE_Stream_Node::~ACE_Stream_Node (void)
00095 {
00096   ACE_TRACE ("ACE_Stream_Node::~ACE_Stream_Node");
00097   ACE_Static_Node *n = ACE_const_cast (ACE_Static_Node *,
00098                                        this->node_);
00099   delete n;
00100   ACE_Parse_Node *m = ACE_const_cast (ACE_Parse_Node *,
00101                                       this->mods_);
00102   delete m;
00103 }
00104 
00105 ACE_Parse_Node::ACE_Parse_Node (void)
00106   : name_ (0),
00107     next_ (0)
00108 {
00109   ACE_TRACE ("ACE_Parse_Node::ACE_Parse_Node");
00110 }
00111 
00112 
00113 ACE_Parse_Node::ACE_Parse_Node (const ACE_TCHAR *nm)
00114   : name_ (ACE::strnew (nm)),
00115     next_ (0)
00116 {
00117   ACE_TRACE ("ACE_Parse_Node::ACE_Parse_Node");
00118 }
00119 
00120 void
00121 ACE_Parse_Node::print (void) const
00122 {
00123   ACE_TRACE ("ACE_Parse_Node::print");
00124 
00125   ACE_DEBUG ((LM_DEBUG,
00126               ACE_LIB_TEXT ("svc = %s\n"),
00127               this->name ()));
00128 
00129   if (this->next_)
00130     this->next_->print ();
00131 }
00132 
00133 
00134 ACE_Parse_Node::~ACE_Parse_Node (void)
00135 {
00136   ACE_TRACE ("ACE_Parse_Node::~ACE_Parse_Node");
00137   delete[] ACE_const_cast (ACE_TCHAR*, this->name_);
00138   delete this->next_;
00139 }
00140 
00141 ACE_ALLOC_HOOK_DEFINE (ACE_Suspend_Node)
00142 
00143 void
00144 ACE_Suspend_Node::dump (void) const
00145 {
00146   ACE_TRACE ("ACE_Suspend_Node::dump");
00147 }
00148 
00149 ACE_Suspend_Node::ACE_Suspend_Node (const ACE_TCHAR *name)
00150   : ACE_Parse_Node (name)
00151 {
00152   ACE_TRACE ("ACE_Suspend_Node::ACE_Suspend_Node");
00153 }
00154 
00155 ACE_ALLOC_HOOK_DEFINE (ACE_Resume_Node)
00156 
00157 void
00158 ACE_Resume_Node::dump (void) const
00159 {
00160   ACE_TRACE ("ACE_Resume_Node::dump");
00161 }
00162 
00163 ACE_Resume_Node::ACE_Resume_Node (const ACE_TCHAR *name)
00164   : ACE_Parse_Node (name)
00165 {
00166   ACE_TRACE ("ACE_Resume_Node::ACE_Resume_Node");
00167 }
00168 
00169 void
00170 ACE_Suspend_Node::apply (int & yyerrno)
00171 {
00172   ACE_TRACE ("ACE_Suspend_Node::apply");
00173 
00174   if (ACE_Service_Config::suspend (this->name ()) == -1)
00175     yyerrno++;
00176 
00177   if (ACE::debug ())
00178     ACE_DEBUG ((LM_DEBUG,
00179                 ACE_LIB_TEXT ("did suspend on %s, error = %d\n"),
00180                 this->name (),
00181                 yyerrno));
00182 }
00183 
00184 void
00185 ACE_Resume_Node::apply (int & yyerrno)
00186 {
00187   ACE_TRACE ("ACE_Resume_Node::apply");
00188   if (ACE_Service_Config::resume (this->name ()) == -1)
00189     yyerrno++;
00190 
00191   if (ACE::debug ())
00192     ACE_DEBUG ((LM_DEBUG,
00193                 ACE_LIB_TEXT ("did resume on %s, error = %d\n"),
00194                 this->name (),
00195                 yyerrno));
00196 }
00197 
00198 ACE_ALLOC_HOOK_DEFINE (ACE_Remove_Node)
00199 
00200 void
00201 ACE_Remove_Node::dump (void) const
00202 {
00203   ACE_TRACE ("ACE_Remove_Node::dump");
00204 }
00205 
00206 ACE_Remove_Node::ACE_Remove_Node (const ACE_TCHAR *name)
00207   : ACE_Parse_Node (name)
00208 {
00209   ACE_TRACE ("ACE_Remove_Node::ACE_Remove_Node");
00210 }
00211 
00212 void
00213 ACE_Remove_Node::apply (int & yyerrno)
00214 {
00215   ACE_TRACE ("ACE_Remove_Node::apply");
00216   if (ACE_Service_Config::remove (this->name ()) == -1)
00217     yyerrno++;
00218 
00219   if (ACE::debug ())
00220     ACE_DEBUG ((LM_DEBUG,
00221                 ACE_LIB_TEXT ("did remove on %s, error = %d\n"),
00222                 this->name (),
00223                 yyerrno));
00224 }
00225 
00226 ACE_Dynamic_Node::ACE_Dynamic_Node (const ACE_Service_Type *sr,
00227                                     ACE_TCHAR *parms)
00228   : ACE_Static_Node (sr->name (), parms),
00229     record_ (sr)
00230 {
00231   ACE_TRACE ("ACE_Dynamic_Node::ACE_Dynamic_Node");
00232 }
00233 
00234 const ACE_Service_Type *
00235 ACE_Dynamic_Node::record (void) const
00236 {
00237   ACE_TRACE ("ACE_Dynamic_Node::record");
00238   return this->record_;
00239 }
00240 
00241 void
00242 ACE_Dynamic_Node::apply (int & yyerrno)
00243 {
00244   ACE_TRACE ("ACE_Dynamic_Node::apply");
00245 
00246   if (ACE_Service_Config::initialize (this->record (),
00247                                       this->parameters ()) == -1)
00248     yyerrno++;
00249 
00250   if (ACE::debug ())
00251     ACE_DEBUG ((LM_DEBUG,
00252                 ACE_LIB_TEXT ("did dynamic on %s, error = %d\n"),
00253                 this->name (),
00254                 yyerrno));
00255 }
00256 
00257 ACE_ALLOC_HOOK_DEFINE (ACE_Dynamic_Node)
00258 
00259 void
00260 ACE_Dynamic_Node::dump (void) const
00261 {
00262   ACE_TRACE ("ACE_Dynamic_Node::dump");
00263 }
00264 
00265 ACE_Dynamic_Node::~ACE_Dynamic_Node (void)
00266 {
00267   ACE_TRACE ("ACE_Dynamic_Node::~ACE_Dynamic_Node");
00268 }
00269 
00270 ACE_ALLOC_HOOK_DEFINE (ACE_Static_Node)
00271 
00272 void
00273 ACE_Static_Node::dump (void) const
00274 {
00275   ACE_TRACE ("ACE_Static_Node::dump");
00276 }
00277 
00278 ACE_Static_Node::ACE_Static_Node (const ACE_TCHAR *nm,
00279                                   ACE_TCHAR *params)
00280   : ACE_Parse_Node (nm),
00281     parameters_ (ACE::strnew (params))
00282 {
00283   ACE_TRACE ("ACE_Static_Node::ACE_Static_Node");
00284 }
00285 
00286 const ACE_Service_Type *
00287 ACE_Static_Node::record (void) const
00288 {
00289   ACE_TRACE ("ACE_Static_Node::record");
00290   ACE_Service_Type *sr;
00291 
00292   if (ACE_Service_Repository::instance()->find
00293       (this->name (),
00294        (const ACE_Service_Type **) &sr) == -1)
00295     return 0;
00296   else
00297     return sr;
00298 }
00299 
00300 ACE_TCHAR *
00301 ACE_Static_Node::parameters (void) const
00302 {
00303   ACE_TRACE ("ACE_Static_Node::parameters");
00304   return this->parameters_;
00305 }
00306 
00307 void
00308 ACE_Static_Node::apply (int & yyerrno)
00309 {
00310   ACE_TRACE ("ACE_Static_Node::apply");
00311   if (ACE_Service_Config::initialize (this->name (),
00312                                       this->parameters ()) == -1)
00313     yyerrno++;
00314 
00315   if (ACE::debug ())
00316     ACE_DEBUG ((LM_DEBUG,
00317                 ACE_LIB_TEXT ("did static on %s, error = %d\n"),
00318                 this->name (),
00319                 yyerrno));
00320 }
00321 
00322 ACE_Static_Node::~ACE_Static_Node (void)
00323 {
00324   ACE_TRACE ("ACE_Static_Node::~ACE_Static_Node");
00325   delete[] this->parameters_;
00326 }
00327 
00328 ACE_ALLOC_HOOK_DEFINE (ACE_Location_Node)
00329 
00330 void
00331 ACE_Location_Node::dump (void) const
00332 {
00333   ACE_TRACE ("ACE_Location_Node::dump");
00334 }
00335 
00336 ACE_Location_Node::ACE_Location_Node (void)
00337   : pathname_ (0),
00338     symbol_ (0)
00339 {
00340   ACE_TRACE ("ACE_Location_Node::ACE_Location_Node");
00341 }
00342 
00343 ACE_Location_Node::~ACE_Location_Node (void)
00344 {
00345   ACE_TRACE ("ACE_Location_Node::~ACE_Location_Node");
00346 }
00347 
00348 const ACE_DLL &
00349 ACE_Location_Node::dll (void)
00350 {
00351   return this->dll_;
00352 }
00353 
00354 const ACE_TCHAR *
00355 ACE_Location_Node::pathname (void) const
00356 {
00357   ACE_TRACE ("ACE_Location_Node::pathname");
00358   return this->pathname_;
00359 }
00360 
00361 void
00362 ACE_Location_Node::pathname (const ACE_TCHAR *p)
00363 {
00364   ACE_TRACE ("ACE_Location_Node::pathname");
00365   this->pathname_ = p;
00366 }
00367 
00368 void
00369 ACE_Location_Node::set_symbol (void *s)
00370 {
00371   ACE_TRACE ("ACE_Location_Node::set_symbol");
00372   this->symbol_ = s;
00373 }
00374 
00375 int
00376 ACE_Location_Node::dispose (void) const
00377 {
00378   ACE_TRACE ("ACE_Location_Node::dispose");
00379   return this->must_delete_;
00380 }
00381 
00382 int
00383 ACE_Location_Node::open_dll (int & yyerrno)
00384 {
00385   ACE_TRACE ("ACE_Location_Node::open_dll");
00386 
00387   if (-1 == this->dll_.open (this->pathname ()))
00388     {
00389       yyerrno++;
00390 
00391       ACE_TCHAR *errmsg = this->dll_.error ();
00392       ACE_ERROR ((LM_ERROR,
00393                   ACE_LIB_TEXT ("ACE_DLL::open failed for %s: %s\n"),
00394                   this->pathname (),
00395                   errmsg ? errmsg : ACE_LIB_TEXT ("no error reported")));
00396       return -1;
00397     }
00398 
00399   return 0;
00400 
00401 }
00402 
00403 ACE_ALLOC_HOOK_DEFINE (ACE_Object_Node)
00404 
00405 void
00406 ACE_Object_Node::dump (void) const
00407 {
00408   ACE_TRACE ("ACE_Object_Node::dump");
00409 }
00410 
00411 ACE_Object_Node::ACE_Object_Node (const ACE_TCHAR *path,
00412                                   const ACE_TCHAR *obj_name)
00413   : object_name_ (ACE::strnew (obj_name))
00414 {
00415   ACE_TRACE ("ACE_Object_Node::ACE_Object_Node");
00416   this->pathname (ACE::strnew (path));
00417   this->must_delete_ = 0;
00418 }
00419 
00420 void *
00421 ACE_Object_Node::symbol (int & yyerrno,
00422                          ACE_Service_Object_Exterminator *)
00423 {
00424   ACE_TRACE ("ACE_Object_Node::symbol");
00425   if (this->open_dll (yyerrno) == 0)
00426     {
00427       ACE_TCHAR *object_name = ACE_const_cast (ACE_TCHAR *, this->object_name_);
00428 
00429       this->symbol_ = this->dll_.symbol (object_name);
00430       if (this->symbol_ == 0)
00431         {
00432           yyerrno++;
00433 
00434           ACE_TCHAR *errmsg = this->dll_.error ();
00435           ACE_ERROR ((LM_ERROR,
00436                       ACE_LIB_TEXT ("ACE_DLL::symbol failed for object %s: %s\n"),
00437                       object_name,
00438                       errmsg ? errmsg : ACE_LIB_TEXT ("no error reported")));
00439           return 0;
00440         }
00441 
00442       return this->symbol_;
00443     }
00444 
00445   return 0;
00446 }
00447 
00448 ACE_Object_Node::~ACE_Object_Node (void)
00449 {
00450   ACE_TRACE ("ACE_Object_Node::~ACE_Object_Node");
00451   delete[] ACE_const_cast (ACE_TCHAR *, this->object_name_);
00452 }
00453 
00454 ACE_ALLOC_HOOK_DEFINE (ACE_Function_Node)
00455 
00456 void
00457 ACE_Function_Node::dump (void) const
00458 {
00459   ACE_TRACE ("ACE_Function_Node::dump");
00460 }
00461 
00462 ACE_Function_Node::ACE_Function_Node (const ACE_TCHAR *path,
00463                                       const ACE_TCHAR *func_name)
00464   : function_name_ (ACE::strnew (func_name))
00465 {
00466   ACE_TRACE ("ACE_Function_Node::ACE_Function_Node");
00467   this->pathname (ACE::strnew (path));
00468   this->must_delete_ = 1;
00469 }
00470 
00471 void *
00472 ACE_Function_Node::symbol (int & yyerrno,
00473                            ACE_Service_Object_Exterminator *gobbler)
00474 {
00475   typedef ACE_Service_Object *(*ACE_Service_Factory_Ptr)
00476     (ACE_Service_Object_Exterminator *);
00477 
00478   ACE_TRACE ("ACE_Function_Node::symbol");
00479   if (this->open_dll (yyerrno) == 0)
00480     {
00481       ACE_Service_Factory_Ptr func = 0;
00482       this->symbol_ = 0;
00483 
00484       // Locate the factory function <function_name> in the shared
00485       // object.
00486       ACE_TCHAR *function_name = ACE_const_cast (ACE_TCHAR *,
00487                                                  this->function_name_);
00488       void *func_p = this->dll_.symbol (function_name);
00489       if (func_p == 0)
00490         {
00491           yyerrno++;
00492 
00493           if (this->symbol_ == 0)
00494             {
00495               yyerrno++;
00496 
00497               ACE_TCHAR *errmsg = this->dll_.error ();
00498               ACE_ERROR ((LM_ERROR,
00499                           ACE_LIB_TEXT ("ACE_DLL::symbol failed for function %s: %s\n"),
00500                           function_name,
00501                           errmsg ? errmsg :
00502                                    ACE_LIB_TEXT ("no error reported")));
00503               return 0;
00504             }
00505         }
00506       ptrdiff_t temp_p = ACE_reinterpret_cast (ptrdiff_t, func_p);
00507       func = ACE_reinterpret_cast (ACE_Service_Factory_Ptr, temp_p);
00508       // Invoke the factory function and record it's return value.
00509       this->symbol_ = (*func) (gobbler);
00510 
00511       if (this->symbol_ == 0)
00512         {
00513           yyerrno++;
00514           ACE_ERROR_RETURN ((LM_ERROR,
00515                              ACE_LIB_TEXT ("%p\n"),
00516                              this->function_name_),
00517                             0);
00518         }
00519     }
00520   return this->symbol_;
00521 }
00522 
00523 ACE_Function_Node::~ACE_Function_Node (void)
00524 {
00525   ACE_TRACE ("ACE_Function_Node::~ACE_Function_Node");
00526   delete[] ACE_const_cast (ACE_TCHAR *, function_name_);
00527   delete[] ACE_const_cast (ACE_TCHAR *, pathname_);
00528 }
00529 
00530 ACE_ALLOC_HOOK_DEFINE (ACE_Dummy_Node)
00531 
00532 void
00533 ACE_Dummy_Node::dump (void) const
00534 {
00535   ACE_TRACE ("ACE_Dummy_Node::dump");
00536 }
00537 
00538 ACE_Dummy_Node::ACE_Dummy_Node (const ACE_Static_Node *static_node,
00539                                 const ACE_Parse_Node *str_mods)
00540   : ACE_Parse_Node (static_node->name ()),
00541     node_ (static_node),
00542     mods_ (str_mods)
00543 {
00544   ACE_TRACE ("ACE_Dummy_Node::ACE_Dummy_Node");
00545 }
00546 
00547 void
00548 ACE_Dummy_Node::apply (int & yyerrno)
00549 {
00550   ACE_TRACE ("ACE_Dummy_Node::apply");
00551 
00552   if (ACE::debug ())
00553     ACE_DEBUG ((LM_DEBUG,
00554                 ACE_LIB_TEXT ("did operations on stream %s, error = %d\n"),
00555                 this->name (),
00556                 yyerrno));
00557 }
00558 
00559 ACE_Dummy_Node::~ACE_Dummy_Node (void)
00560 {
00561   ACE_TRACE ("ACE_Dummy_Node::~ACE_Dummy_Node");
00562   ACE_Static_Node *n = ACE_const_cast (ACE_Static_Node *,
00563                                        this->node_);
00564   delete n;
00565   ACE_Parse_Node *m = ACE_const_cast (ACE_Parse_Node *,
00566                                       this->mods_);
00567   delete m;
00568 }
00569 
00570 ACE_ALLOC_HOOK_DEFINE (ACE_Static_Function_Node)
00571 
00572 void
00573 ACE_Static_Function_Node::dump (void) const
00574 {
00575   ACE_TRACE ("ACE_Static_Function_Node::dump");
00576 }
00577 
00578 ACE_Static_Function_Node::ACE_Static_Function_Node (const ACE_TCHAR *func_name)
00579   : function_name_ (ACE::strnew (func_name))
00580 {
00581   ACE_TRACE ("ACE_Static_Function_Node::ACE_Static_Function_Node");
00582   this->must_delete_ = 1;
00583 }
00584 
00585 void *
00586 ACE_Static_Function_Node::symbol (int & yyerrno,
00587                                   ACE_Service_Object_Exterminator *gobbler)
00588 {
00589   ACE_TRACE ("ACE_Static_Function_Node::symbol");
00590 
00591   void *(*func)(ACE_Service_Object_Exterminator *) = 0;
00592   this->symbol_ = 0;
00593 
00594   // Locate the factory function <function_name> in the statically
00595   // linked svcs.
00596 
00597   ACE_Static_Svc_Descriptor **ssdp = 0;
00598   ACE_STATIC_SVCS &svcs = *ACE_Service_Config::static_svcs ();
00599   ACE_TCHAR *function_name = ACE_const_cast (ACE_TCHAR *, this->function_name_);
00600 
00601   for (ACE_STATIC_SVCS_ITERATOR iter (svcs);
00602        iter.next (ssdp) != 0;
00603        iter.advance ())
00604     {
00605       ACE_Static_Svc_Descriptor *ssd = *ssdp;
00606       if (ACE_OS::strcmp (ssd->name_,
00607                           function_name) == 0)
00608         func = (void *(*)(ACE_Service_Object_Exterminator*)) ssd->alloc_;
00609     }
00610 
00611   if (func == 0)
00612     {
00613       yyerrno++;
00614 
00615       if (this->symbol_ == 0)
00616         {
00617           yyerrno++;
00618 
00619           ACE_ERROR_RETURN ((LM_ERROR,
00620                              ACE_LIB_TEXT ("no static service registered for function %s\n"),
00621                              function_name),
00622                              0);
00623         }
00624     }
00625 
00626   // Invoke the factory function and record it's return value.
00627   this->symbol_ = (*func) (gobbler);
00628 
00629   if (this->symbol_ == 0)
00630     {
00631       yyerrno++;
00632       ACE_ERROR_RETURN ((LM_ERROR,
00633                          ACE_LIB_TEXT ("%p\n"),
00634                          this->function_name_),
00635                         0);
00636     }
00637 
00638   return this->symbol_;
00639 }
00640 
00641 ACE_Static_Function_Node::~ACE_Static_Function_Node (void)
00642 {
00643   ACE_TRACE ("ACE_Static_Function_Node::~ACE_Static_Function_Node");
00644   delete[] ACE_const_cast (ACE_TCHAR *, this->function_name_);
00645 }
00646 
00647 #endif /* ACE_USES_CLASSIC_SVC_CONF == 1 */

Generated on Mon Jun 16 11:20:47 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002