ACE初始化
ACE_Init_ACE
class ACE_Export ACE_Init_ACE
{
public:
/**
* 这个类实现了初始化和关闭ACE,每个ACE程序只需调用一次
* @return Returns 0 on success, -1 on failure, and 1 if it had already been
* called.
*/
static int init (void);
/**
l 关闭ACE库服务,每个ACE程序只需调用一次
l * @return Returns 0 on success, -1 on failure, and 1 if it had already been
* called.
*/
static int fini (void);
private:
/** 引用记数
* Counter to match <init()>/<fini()> calls. <init()> must increment it;
* <fini()> must decrement it. <fini()> then does nothing until it
* reaches 0.
*/
static unsigned int init_fini_count_;
};
CPP实现文件
int
ACE_Init_ACE::init (void)
{
// 不要使用ACE_TRACE, 因为Object_Manager 还没有实例化
// ACE_TRACE ("ACE_Init_ACE::init");
++init_fini_count_;
// 使用ACE_Object_Manager静态实例对象初始化
return ACE_Object_Manager::instance ()->init ();
}
int
ACE_Init_ACE::fini (void)
{
ACE_TRACE ("ACE_Init_ACE::fini");
if (init_fini_count_ > 0)
{
if (--init_fini_count_ == 0)
// 当记数为0,使用ACE_Object_Manager静态实例对象清除
return ACE_Object_Manager::instance ()->fini ();
else
// Wait for remaining fini () calls.
return 1;
}
else
// More ACE_Init_ACE::fini () calls than ACE_Init_ACE::init () calls. Bad
// application!
return -1;
}
ACE的静态对象管理宏定义
ACE_HAS_NONSTATIC_OBJECT_MANAGER
看看宏静态宏定义,一开始是没有定义非静态对象管理的宏,接下来是定义ACE_MAIN_OBJECT_MANAGER宏,他是只是为了简化而已。
# if defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) && !defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER)
# if !defined (ACE_HAS_MINIMAL_ACE_OS)
# include "ace/Object_Manager.h"
# endif /* ! ACE_HAS_MINIMAL_ACE_OS */
// Rename "main ()" on platforms that don't allow it to be called "main ()".
//这里说道ACE_Object_Manager在main函数里的栈上实例化。
// Also, create ACE_Object_Manager static instance(s) in "main ()".
// ACE_MAIN_OBJECT_MANAGER defines the ACE_Object_Manager(s) that will
// be instantiated on the stack of main (). Note that it is only used
// when compiling main (): its value does not affect the contents of
// ace/OS.o.
// 如果没有定义ACE_MAIN_OBJECT_MANAGER,那么定义它
# if !defined (ACE_MAIN_OBJECT_MANAGER)
// 这里的宏是定义两个静态对象实例
# define ACE_MAIN_OBJECT_MANAGER /
ACE_OS_Object_Manager ace_os_object_manager; /
ACE_Object_Manager ace_object_manager;
# endif /* ! ACE_MAIN_OBJECT_MANAGER */
// 这下面的是另一个针对PSOS操作系统的宏,不理它
# if defined (ACE_PSOSIM)
// PSOSIM root lacks the standard argc, argv command line parameters,
// create dummy argc and argv in the "real" main and pass to "user" main.
// NOTE: ACE_MAIN must be defined to give the return type as well as the
// name of the entry point.
# define main /
ace_main_i (int, char *[]); /* forward declaration */ /
ACE_MAIN () /* user's entry point, e.g., "main" w/out argc, argv */ /
{ /
int argc = 1; /* dummy arg count */ /
char *argv[] = {"psosim"}; /* dummy arg list */ /
ACE_MAIN_OBJECT_MANAGER /
int ret_val = -1; /* assume the worst */ /
if (ACE_PSOS_Time_t::init_simulator_time ()) /* init simulator time */ /
{ /
ACE_ERROR((LM_ERROR, "init_simulator_time failed/n")); /* report */ /
} /
else /
{ /
ret_val = ace_main_i (argc, argv); /* call user main, save result */ /
} /
ACE_OS::exit (ret_val); /* pass code to simulator exit */ /
} /
其他的宏定义WIN23的
# define main /
ace_main_i (int, char *[]); /* forward declaration */ /
int /
ACE_MAIN (int argc, char *argv[]) /* user's entry point, e.g., main */ /
{ /
ACE_MAIN_OBJECT_MANAGER /
return ace_main_i (argc, argv); /* what the user calls "main" */ /
} /
int /
ace_main_i
# if defined (ACE_WIN32)
# define wmain /
ace_main_i (int, ACE_TCHAR *[]); /* forward declaration */ /
int /
ACE_WMAIN (int argc, ACE_TCHAR *argv[]) /* user's entry point, e.g., main */ /
{ /
ACE_MAIN_OBJECT_MANAGER /
return ace_main_i (argc, argv); /* what the user calls "main" */ /
} /
所以console的程序里main函数
嵌入了下面两个对象
main()
{
ACE_OS_Object_Manager ace_os_object_manager;
ACE_Object_Manager ace_object_manager;
….
}