00001 #include "ace/Dynamic_Service_Base.h"
00002 #include "ace/ACE.h"
00003 #include "ace/Service_Config.h"
00004 #include "ace/Service_Repository.h"
00005 #include "ace/Service_Types.h"
00006 #include "ace/Log_Msg.h"
00007
00008
00009 ACE_RCSID (ace,
00010 Dynamic_Service_Base,
00011 "$Id: Dynamic_Service_Base.cpp 80826 2008-03-04 14:51:23Z wotte $")
00012
00013 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00014
00015
00016 void
00017 ACE_Dynamic_Service_Base::dump (void) const
00018 {
00019 #if defined (ACE_HAS_DUMP)
00020 ACE_TRACE ("ACE_Dynamic_Service_Base::dump");
00021
00022 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00023 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
00024 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00025 #endif
00026 }
00027
00028
00029
00030
00031 void *
00032 ACE_Dynamic_Service_Base::instance (const ACE_TCHAR *name, bool no_global)
00033 {
00034 ACE_TRACE ("ACE_Dynamic_Service_Base::instance");
00035 return instance (ACE_Service_Config::current (), name, no_global);
00036 }
00037
00038
00039
00040 const ACE_Service_Type *
00041 ACE_Dynamic_Service_Base::find_i (const ACE_Service_Gestalt* &repo,
00042 const ACE_TCHAR *name,
00043 bool no_global)
00044 {
00045 ACE_TRACE ("ACE_Dynamic_Service_Base::find_i");
00046 const ACE_Service_Type *svc_rec = 0;
00047
00048 ACE_Service_Gestalt* global = ACE_Service_Config::global ();
00049
00050 for ( ; (repo->find (name, &svc_rec) == -1) && !no_global; repo = global)
00051 {
00052
00053 if (repo == global)
00054 break;
00055 }
00056
00057 return svc_rec;
00058 }
00059
00060
00061
00062 void *
00063 ACE_Dynamic_Service_Base::instance (const ACE_Service_Gestalt* repo,
00064 const ACE_TCHAR *name,
00065 bool no_global)
00066 {
00067 ACE_TRACE ("ACE_Dynamic_Service_Base::instance");
00068
00069 void *obj = 0;
00070 const ACE_Service_Type_Impl *type = 0;
00071
00072 const ACE_Service_Gestalt* repo_found = repo;
00073 const ACE_Service_Type *svc_rec = find_i (repo_found, name, no_global);
00074 if (svc_rec != 0)
00075 {
00076 type = svc_rec->type ();
00077 if (type != 0)
00078 obj = type->object ();
00079 }
00080
00081 if (ACE::debug ())
00082 {
00083 ACE_Guard <ACE_Log_Msg> log_guard (*ACE_Log_Msg::instance ());
00084
00085 ACE_DEBUG ((LM_DEBUG,
00086 ACE_TEXT ("ACE (%P|%t) DSB::instance, repo=%@, name=%s")
00087 ACE_TEXT (" type=%@ => %@"),
00088 repo->repo_, name, type, obj));
00089
00090 if (repo->repo_ != repo_found->repo_)
00091 ACE_DEBUG ((LM_DEBUG,
00092 ACE_TEXT (" [in repo=%@]\n"),
00093 repo_found->repo_));
00094 else
00095 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
00096 }
00097
00098 return obj;
00099 }
00100
00101 ACE_END_VERSIONED_NAMESPACE_DECL