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

Service_Types.cpp

Go to the documentation of this file.
00001 #include "ace_pch.h"
00002 // $Id: Service_Types.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $
00003 
00004 #include "ace/Service_Types.h"
00005 #include "ace/Stream_Modules.h"
00006 #include "ace/Stream.h"
00007 
00008 ACE_RCSID(ace, Service_Types, "$Id: Service_Types.cpp,v 1.1.1.4.2.1 2003/03/13 19:44:22 chad Exp $")
00009 
00010 typedef ACE_Stream<ACE_SYNCH> MT_Stream;
00011 typedef ACE_Module<ACE_SYNCH> MT_Module;
00012 typedef ACE_Task<ACE_SYNCH> MT_Task;
00013 
00014 #if !defined (__ACE_INLINE__)
00015 #include "ace/Service_Types.i"
00016 #endif /* __ACE_INLINE__ */
00017 
00018 ACE_ALLOC_HOOK_DEFINE(ACE_Service_Type_Impl)
00019 
00020 void
00021 ACE_Service_Type_Impl::dump (void) const
00022 {
00023   ACE_TRACE ("ACE_Service_Type_Impl::dump");
00024 }
00025 
00026 ACE_Service_Type_Impl::ACE_Service_Type_Impl (void *so,
00027                                               const ACE_TCHAR *s_name,
00028                                               u_int f,
00029                                               ACE_Service_Object_Exterminator gobbler)
00030   : name_ (0),
00031     obj_ (so),
00032     gobbler_ (gobbler),
00033     flags_ (f)
00034 {
00035   ACE_TRACE ("ACE_Service_Type_Impl::ACE_Service_Type_Impl");
00036   this->name (s_name);
00037 }
00038 
00039 ACE_Service_Type_Impl::~ACE_Service_Type_Impl (void)
00040 {
00041   ACE_TRACE ("ACE_Service_Type_Impl::~ACE_Service_Type_Impl");
00042 
00043   // It's ok to call this, even though we may have already deleted it
00044   // in the fini() method since it would then be NULL.
00045   delete [] (ACE_TCHAR *) this->name_;
00046 }
00047 
00048 int
00049 ACE_Service_Type_Impl::fini (void) const
00050 {
00051   ACE_TRACE ("ACE_Service_Type_Impl::fini");
00052   if (ACE::debug ())
00053     ACE_DEBUG ((LM_DEBUG,
00054                 ACE_LIB_TEXT ("destroying %s, flags = %d\n"),
00055                 this->name_,
00056                 this->flags_));
00057 
00058   delete [] (ACE_TCHAR *) this->name_;
00059   ((ACE_Service_Type_Impl *) this)->name_ = 0;
00060 
00061   if (ACE_BIT_ENABLED (this->flags_,
00062                        ACE_Service_Type::DELETE_OBJ))
00063     {
00064       if (gobbler_ != 0)
00065         gobbler_ (this->object ());
00066       else
00067         // Cast to remove const-ness.
00068         operator delete ((void *) this->object ());
00069     }
00070 
00071   if (ACE_BIT_ENABLED (this->flags_,
00072                        ACE_Service_Type::DELETE_THIS))
00073     delete (ACE_Service_Type_Impl *) this;
00074 
00075   return 0;
00076 }
00077 
00078 ACE_Service_Object_Type::ACE_Service_Object_Type (void *so,
00079                                                   const ACE_TCHAR *s_name,
00080                                                   u_int f,
00081                                                   ACE_Service_Object_Exterminator gobbler)
00082   : ACE_Service_Type_Impl (so, s_name, f, gobbler)
00083 {
00084   ACE_TRACE ("ACE_Service_Object_Type::ACE_Service_Object_Type");
00085 }
00086 
00087 int
00088 ACE_Service_Object_Type::init (int argc, ACE_TCHAR *argv[]) const
00089 {
00090   ACE_TRACE ("ACE_Service_Object_Type::init");
00091 
00092   void *obj = this->object ();
00093   ACE_Service_Object *so = (ACE_Service_Object *) obj;
00094 
00095   if (so == 0)
00096     return -1;
00097   else
00098     return so->init (argc, argv);
00099 }
00100 
00101 ACE_ALLOC_HOOK_DEFINE(ACE_Module_Type)
00102 
00103 void
00104 ACE_Module_Type::dump (void) const
00105 {
00106   ACE_TRACE ("ACE_Module_Type::dump");
00107 }
00108 
00109 ACE_Module_Type::ACE_Module_Type (void *m,
00110                                   const ACE_TCHAR *m_name,
00111                                   u_int f)
00112   : ACE_Service_Type_Impl (m, m_name, f)
00113 {
00114   ACE_TRACE ("ACE_Module_Type::ACE_Module_Type");
00115 }
00116 
00117 int
00118 ACE_Module_Type::init (int argc, ACE_TCHAR *argv[]) const
00119 {
00120   ACE_TRACE ("ACE_Module_Type::init");
00121   void *obj = this->object ();
00122   MT_Module *mod = (MT_Module *) obj;
00123   MT_Task *reader = mod->reader ();
00124   MT_Task *writer = mod->writer ();
00125 
00126   if (reader->init (argc, argv) == -1
00127       || writer->init (argc, argv) == -1)
00128     return -1;
00129   else
00130     return 0;
00131 }
00132 
00133 int
00134 ACE_Module_Type::suspend (void) const
00135 {
00136   ACE_TRACE ("ACE_Module_Type::suspend");
00137   void *obj = this->object ();
00138   MT_Module *mod = (MT_Module *) obj;
00139   MT_Task *reader = mod->reader ();
00140   MT_Task *writer = mod->writer ();
00141 
00142   if (reader->suspend () == -1
00143       || writer->suspend () == -1)
00144     return -1;
00145   else
00146     return 0;
00147 }
00148 
00149 int
00150 ACE_Module_Type::resume (void) const
00151 {
00152   ACE_TRACE ("ACE_Module_Type::resume");
00153   void *obj = this->object ();
00154   MT_Module *mod = (MT_Module *) obj;
00155   MT_Task *reader = mod->reader ();
00156   MT_Task *writer = mod->writer ();
00157 
00158   if (reader->resume () == -1
00159       || writer->resume () == -1)
00160     return -1;
00161   else
00162     return 0;
00163 }
00164 
00165 // Note, these operations are somewhat too familiar with the
00166 // implementation of ACE_Module and ACE_Module::close...
00167 
00168 int
00169 ACE_Module_Type::fini (void) const
00170 {
00171   ACE_TRACE ("ACE_Module_Type::fini");
00172 
00173   void *obj = this->object ();
00174   MT_Module *mod = (MT_Module *) obj;
00175   MT_Task *reader = mod->reader ();
00176   MT_Task *writer = mod->writer ();
00177 
00178   if (reader != 0)
00179     reader->fini ();
00180 
00181   if (writer != 0)
00182     writer->fini ();
00183 
00184   // Close the module and delete the memory.
00185   mod->close (MT_Module::M_DELETE);
00186   return ACE_Service_Type_Impl::fini ();
00187 }
00188 
00189 int
00190 ACE_Module_Type::info (ACE_TCHAR **str, size_t len) const
00191 {
00192   ACE_TRACE ("ACE_Module_Type::info");
00193   ACE_TCHAR buf[BUFSIZ];
00194 
00195   ACE_OS::sprintf (buf,
00196                    ACE_LIB_TEXT ("%s\t %s"),
00197                    this->name (),
00198                    ACE_LIB_TEXT ("# ACE_Module\n"));
00199 
00200   if (*str == 0 && (*str = ACE_OS::strdup (buf)) == 0)
00201     return -1;
00202   else
00203     ACE_OS::strsncpy (*str, buf, len);
00204   return ACE_static_cast (int, ACE_OS_String::strlen (buf));
00205 }
00206 
00207 void
00208 ACE_Module_Type::link (ACE_Module_Type *n)
00209 {
00210   ACE_TRACE ("ACE_Module_Type::link");
00211   this->link_ = n;
00212 }
00213 
00214 ACE_Module_Type *
00215 ACE_Module_Type::link (void) const
00216 {
00217   ACE_TRACE ("ACE_Module_Type::link");
00218   return this->link_;
00219 }
00220 
00221 ACE_ALLOC_HOOK_DEFINE(ACE_Stream_Type)
00222 
00223 void
00224 ACE_Stream_Type::dump (void) const
00225 {
00226   ACE_TRACE ("ACE_Stream_Type::dump");
00227 }
00228 
00229 int
00230 ACE_Stream_Type::init (int, ACE_TCHAR *[]) const
00231 {
00232   ACE_TRACE ("ACE_Stream_Type::init");
00233   return 0;
00234 }
00235 
00236 int
00237 ACE_Stream_Type::suspend (void) const
00238 {
00239   ACE_TRACE ("ACE_Stream_Type::suspend");
00240 
00241   for (ACE_Module_Type *m = this->head_;
00242        m != 0;
00243        m = m->link ())
00244     m->suspend ();
00245 
00246   return 0;
00247 }
00248 
00249 int
00250 ACE_Stream_Type::resume (void) const
00251 {
00252   ACE_TRACE ("ACE_Stream_Type::resume");
00253 
00254   for (ACE_Module_Type *m = this->head_;
00255        m != 0;
00256        m = m->link ())
00257     m->resume ();
00258 
00259   return 0;
00260 }
00261 
00262 ACE_Stream_Type::ACE_Stream_Type (void *s,
00263                                   const ACE_TCHAR *s_name,
00264                                   u_int f)
00265   : ACE_Service_Type_Impl (s, s_name, f),
00266     head_ (0)
00267 {
00268   ACE_TRACE ("ACE_Stream_Type::ACE_Stream_Type");
00269 }
00270 
00271 int
00272 ACE_Stream_Type::info (ACE_TCHAR **str, size_t len) const
00273 {
00274   ACE_TRACE ("ACE_Stream_Type::info");
00275   ACE_TCHAR buf[BUFSIZ];
00276 
00277   ACE_OS::sprintf (buf,
00278                    ACE_LIB_TEXT ("%s\t %s"),
00279                    this->name (),
00280                    ACE_LIB_TEXT ("# STREAM\n"));
00281 
00282   if (*str == 0 && (*str = ACE_OS::strdup (buf)) == 0)
00283     return -1;
00284   else
00285     ACE_OS::strsncpy (*str, buf, len);
00286   return ACE_static_cast (int, ACE_OS_String::strlen (buf));
00287 }
00288 
00289 int
00290 ACE_Stream_Type::fini (void) const
00291 {
00292   ACE_TRACE ("ACE_Stream_Type::fini");
00293   void *obj = this->object ();
00294   MT_Stream *str = (MT_Stream *) obj;
00295 
00296   for (ACE_Module_Type *m = this->head_; m != 0; )
00297     {
00298       ACE_Module_Type *t = m->link ();
00299 
00300       // Final arg is an indication to *not* delete the Module.
00301       str->remove (m->name (),
00302                    MT_Module::M_DELETE_NONE);
00303 
00304       // Finalize the Module (this may delete it, but we don't really
00305       // care since we don't access it again).
00306       m->fini ();
00307       m = t;
00308     }
00309 
00310   str->close ();
00311   return ACE_Service_Type_Impl::fini ();
00312 }
00313 
00314 // Locate and remove <mod_name> from the ACE_Stream.
00315 
00316 int
00317 ACE_Stream_Type::remove (ACE_Module_Type *mod)
00318 {
00319   ACE_TRACE ("ACE_Stream_Type::remove");
00320 
00321   ACE_Module_Type *prev = 0;
00322   void *obj = this->object ();
00323   MT_Stream *str = (MT_Stream *) obj;
00324   int result = 0;
00325 
00326   for (ACE_Module_Type *m = this->head_; m != 0; )
00327     {
00328       // We need to do this first so we don't bomb out if we delete m!
00329       ACE_Module_Type *link = m->link ();
00330 
00331       if (m == mod)
00332         {
00333           if (prev == 0)
00334             this->head_ = link;
00335           else
00336             prev->link (link);
00337 
00338           // Final arg is an indication to *not* delete the Module.
00339           if (str->remove (m->name (),
00340                            MT_Module::M_DELETE_NONE) == -1)
00341             result = -1;
00342 
00343           // This call may end up deleting m, which is ok since we
00344           // don't access it again!
00345           m->fini ();
00346         }
00347       else
00348         prev = m;
00349 
00350       m = link;
00351     }
00352 
00353   return result;
00354 }
00355 
00356 int
00357 ACE_Stream_Type::push (ACE_Module_Type *new_module)
00358 {
00359   ACE_TRACE ("ACE_Stream_Type::push");
00360   void *obj = this->object ();
00361   MT_Stream *str = (MT_Stream *) obj;
00362 
00363   new_module->link (this->head_);
00364   this->head_ = new_module;
00365   obj = new_module->object ();
00366   return str->push ((MT_Module *) obj);
00367 }
00368 
00369 ACE_Module_Type *
00370 ACE_Stream_Type::find (const ACE_TCHAR *mod_name) const
00371 {
00372   ACE_TRACE ("ACE_Stream_Type::find");
00373 
00374   for (ACE_Module_Type *m = this->head_;
00375        m != 0;
00376        m = m->link ())
00377     if (ACE_OS::strcmp (m->name (), mod_name) == 0)
00378       return m;
00379 
00380   return 0;
00381 }
00382 
00383 int
00384 ACE_Service_Object_Type::fini (void) const
00385 {
00386   ACE_TRACE ("ACE_Service_Object_Type::fini");
00387 
00388   void *obj = this->object ();
00389 
00390   ACE_Service_Object *so = (ACE_Service_Object *) obj;
00391 
00392   if (so)
00393     {
00394       so->fini ();
00395 
00396 #if 0
00397       if (ACE_BIT_ENABLED (this->flags_,
00398                            ACE_Service_Type::DELETE_OBJ))
00399         delete so;
00400 #endif /* 1 */
00401     }
00402 
00403   return ACE_Service_Type_Impl::fini ();
00404 }
00405 /*
00406 #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
00407 template class ACE_Message_Queue<ACE_SYNCH>;
00408 template class ACE_Message_Queue_Iterator<ACE_SYNCH>;
00409 template class ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH>;
00410 template class ACE_Message_Queue_Factory<ACE_SYNCH>;
00411 template class ACE_Dynamic_Message_Queue<ACE_SYNCH>;
00412 template class ACE_Module<ACE_SYNCH>;
00413 template class ACE_Stream<ACE_SYNCH>;
00414 template class ACE_Stream_Head<ACE_SYNCH>;
00415 template class ACE_Stream_Tail<ACE_SYNCH>;
00416 template class ACE_Task<ACE_SYNCH>;
00417 template class ACE_Thru_Task<ACE_SYNCH>;
00418 
00419 // Even with threads, these ACE_NULL_SYNCH specializations are necessary.
00420 #if defined (ACE_HAS_THREADS)
00421   template class ACE_Message_Queue<ACE_NULL_SYNCH>;
00422   template class ACE_Message_Queue_Iterator<ACE_NULL_SYNCH>;
00423   template class ACE_Message_Queue_Reverse_Iterator<ACE_NULL_SYNCH>;
00424   template class ACE_Message_Queue_Factory<ACE_NULL_SYNCH>;
00425   template class ACE_Dynamic_Message_Queue<ACE_NULL_SYNCH>;
00426   template class ACE_Module<ACE_NULL_SYNCH>;
00427   template class ACE_Task<ACE_NULL_SYNCH>;
00428   template class ACE_Thru_Task<ACE_NULL_SYNCH>;
00429   #endif *//* ACE_HAS_THREADS */
00430 /*
00431 #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
00432 #pragma instantiate ACE_Message_Queue<ACE_SYNCH>
00433 #pragma instantiate ACE_Message_Queue_Iterator<ACE_SYNCH>
00434 #pragma instantiate ACE_Message_Queue_Reverse_Iterator<ACE_SYNCH>
00435 #pragma instantiate ACE_Message_Queue_Factory<ACE_SYNCH>
00436 #pragma instantiate ACE_Dynamic_Message_Queue<ACE_SYNCH>
00437 #pragma instantiate ACE_Module<ACE_SYNCH>
00438 #pragma instantiate ACE_Stream<ACE_SYNCH>
00439 #pragma instantiate ACE_Stream_Head<ACE_SYNCH>
00440 #pragma instantiate ACE_Stream_Tail<ACE_SYNCH>
00441 #pragma instantiate ACE_Task<ACE_SYNCH>
00442 #pragma instantiate ACE_Thru_Task<ACE_SYNCH>
00443 // Even with threads, these ACE_NULL_SYNCH specializations are necessary.
00444 #if defined (ACE_HAS_THREADS)
00445   #pragma instantiate ACE_Message_Queue<ACE_NULL_SYNCH>
00446   #pragma instantiate ACE_Message_Queue_Iterator<ACE_NULL_SYNCH>
00447   #pragma instantiate ACE_Message_Queue_Reverse_Iterator<ACE_NULL_SYNCH>
00448   #pragma instantiate ACE_Message_Queue_Factory<ACE_NULL_SYNCH>
00449   #pragma instantiate ACE_Dynamic_Message_Queue<ACE_NULL_SYNCH>
00450   #pragma instantiate ACE_Module<ACE_NULL_SYNCH>
00451   #pragma instantiate ACE_Task<ACE_NULL_SYNCH>
00452   #pragma instantiate ACE_Thru_Task<ACE_NULL_SYNCH>
00453   #endif *//* ACE_HAS_THREADS */
00454 //#else
00455 //#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

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