ACE initialization

xiaoxiao2021-03-06  15

ACE initialization

ACE_INIT_ACE

Class ACE_EXPORT ACE_INIT_ACE

{

PUBLIC:

/ **

* This class implements initialization and shut down ACE, each ACE program only needs to call it.

* @Return Returns 0 on success, -1 on five, and 1 if it had already been

* Called.

* /

Static int init (void);

/ **

l Turn off the ACE library service, each ACE program only needs to call it.

L * @return returns 0 on success, -1 on five, and 1 if it had already been

* Called.

* /

Static int fini (void);

Private:

/ ** Reference

* Counter to match / calls. must inccess it;

* Must Decrement It. THEN DOES NOTING UNIL IT

* REACHES 0.

* /

Static unsigned int init_fini_count_;

}

CPP implementation file

int

ACE_INIT_ACE :: init (void)

{

/ / Do not use ACE_TRACE, because Object_manager has not been instantiated

// ACE_TRACE ("ACE_INIT_ACE :: Init");

init_fini_count_;

// initialize the statically instance object using the ACE_Object_manager static instance object

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)

/ / When the count is 0, use the ACE_Object_manager static instance object clearance

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 Static Object Management Macro Definition

ACE_HAS_NONSTATIC_OBJECT_MANAGER

Look at the macro definition of the macro, at the beginning, there is no macro defined non-static object management. Next is the definition ace_main_Object_manager macro, he is just to simplify.

# IF defined (ACE_HAS_NONSTATIC_OBJECT_MANAGER) &&! Defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_Object_manager)

# Ix! 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 ()" said ACE_OBJECT_MANAGER instantiates on the stack in the main function.

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

// If you do not define ace_main_object_manager, then define it

# Ix! Defined (ace_main_object_manager)

// The macro here is to define two static object instances.

# Define ace_main_Object_manager /

ACE_OS_OBJECT_MANAGER ACE_OS_OBJECT_MANAGER; /

ACE_OBJECT_MANAGER ACE_OBJECT_MANAGER;

# Endif / *! ACE_MAIN_OBJECT_MANAGER * /

// This is another macro for the PSOS operating system, ignores it

# If defined (ACE_PSOSIM)

// psosim root lacks the standard argc, argv commnd 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 Return Type As

// Name of the entry point.

# Define main /

ACE_MAIN_I (int, char * []); / * Forward decaration * / /

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 * / /} /

Other macro definition Win23

# Define main /

ACE_MAIN_I (int, char * []); / * Forward decaration * / /

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" * / /

} /

So the main function in Console's program

Embedding the following two objects

Main ()

{

ACE_OS_OBJECT_MANAGER ACE_OS_OBJECT_MANAGER;

ACE_OBJECT_MANAGER ACE_OBJECT_MANAGER;

.

}

转载请注明原文地址:https://www.9cbs.com/read-46025.html

New Post(0)