Bug 3324 - Extend ACE_TMAIN
Summary: Extend ACE_TMAIN
Status: NEW
Alias: None
Product: TAO
Classification: Unclassified
Component: Name Service (show other bugs)
Version: 1.6.5
Hardware: All Linux
: P3 normal
Assignee: Christoph Hofmann
URL:
Depends on:
Blocks:
 
Reported: 2008-05-13 03:05 CDT by Christoph Hofmann
Modified: 2008-06-18 04:59 CDT (History)
1 user (show)

See Also:


Attachments
possible solution (10.02 KB, patch)
2008-05-16 03:47 CDT, Christoph Hofmann
Details
possible solution as diff (1.39 KB, patch)
2008-05-16 03:49 CDT, Christoph Hofmann
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christoph Hofmann 2008-05-13 03:05:56 CDT
If ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER is set, the Naming Service does not work, because you have to call ACE::init and ACE::fini.

Here a possible solution for Naming_Server.cpp:

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    
//************************************************************************
// Patch: if ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER
//        we have to instantiate the Object_Manager
//************************************************************************     
#if defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER)
  (void)ACE::init();
  {   // Reason for this scope --> see at the end of this scope
#endif    
//************************************************************************
// Patch part 1 finished
//************************************************************************ 

  TAO_Naming_Service naming_service;

  // Stuff to insure that we're gracefully shut down...
  Naming_Svc_Shutdown killer (naming_service);
  Service_Shutdown kill_contractor(killer);

  if (naming_service.init (argc, argv) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT("Failed to start the Naming Service.\n")),
                      1);

  try
    {
      naming_service.run ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("NamingService");
      return 1;
    }

  naming_service.fini ();

//************************************************************************
// Patch: if ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER
//        we have to shut down ACE library services
//************************************************************************
#if defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER)
  }   // This scope is needed, that the things are cleaned up before ACE::fini()     
  (void)ACE::fini();
#endif
//************************************************************************
// Patch finished
//************************************************************************ 

  return 0;
}
Comment 1 Johnny Willemsen 2008-05-13 03:17:25 CDT
Why do you set this define at all? 
Comment 2 Christoph Hofmann 2008-05-13 03:48:25 CDT
We use a Xenomai patched Linux which shadows Posix threads within a co-scheduler. At least some versions of Xenomai require to register the main thread at this co scheduler prior to requesting services like mutexes. The Object Manager uses mutex services.
Comment 3 Johnny Willemsen 2008-05-13 03:55:59 CDT
Ok, but I don't think it is an option to change all thousands of executables in ACE/TAO to use your patch. I think you should check ace/OS_main.h/cpp, extend it with a special definition of main where ACE::init()/fini() are explicitly called, like on windows.
Comment 4 Christoph Hofmann 2008-05-14 02:52:23 CDT
I think it is no solution to extend ACE_TMAIN with ACE::init()/fini() because then again I have no control of ACE::init()/fini() in my applications.
Comment 5 Johnny Willemsen 2008-05-14 03:00:24 CDT
If you need control then I think you should make your own naming_service executable (or embed it into your process) instead of adding this to the core one. Seems to me that you also don't have control to the naming service when you do this
Comment 6 Christoph Hofmann 2008-05-14 04:41:14 CDT
No, I don't need the control in the Naming Service. I just want the Naming Service to run. But I want the control of ACE::init()/fini() in my application. To get this control I set ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER. And with this setting the Naming Service (and I think other services too) does not work. I think this is a bug.
Comment 7 Johnny Willemsen 2008-05-14 04:43:57 CDT
(In reply to comment #6)
> No, I don't need the control in the Naming Service. I just want the Naming
> Service to run. But I want the control of ACE::init()/fini() in my application.
> To get this control I set ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER. And
> with this setting the Naming Service (and I think other services too) does not
> work. I think this is a bug.
> 

The solution would be to redefine ACE_TMAIN so that we then call init()/fini() as part of main, doing this in each executable is not an option. But, you say that when we redefine ACE_TMAIN it gives again problems for you. So, we can put effort in redefining ACE_TMAIN but that seems only time consuming and not helping anyone
Comment 8 Christoph Hofmann 2008-05-14 07:23:01 CDT
Ok, new suggestion: Extend ACE_TMAIN and provide macros to add lines before ACE::init() and after ACE::fini().

Something like that:

# define ACE_TMAIN \
    ace_main_i (int, ACE_TCHAR *[]); /* forward declaration */ \
    int main (int argc, char *argv[]) { \
      int RetVal = 0; \
      ACE_Argv_Type_Converter wide_argv (argc, argv); \
#     if defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER) \
#       if defined (ACE_LINES_BEFORE_ACE_INIT) \
          ACE_LINES_BEFORE_ACE_INIT \
#       endif \
        (void)ACE::init(); \
        { \
#     endif \
        RetVal = ace_main_i (argc, wide_argv.get_TCHAR_argv ()); \
#     if defined (ACE_DOESNT_INSTANTIATE_NONSTATIC_OBJECT_MANAGER) \
        } \
        (void)ACE::fini(); \
#       if defined (ACE_LINES_AFTER_ACE_FINI) \
          ACE_LINES_AFTER_ACE_FINI \
#       endif \
#     endif \
      return RetVal \
    } \
    int ace_main_i
Comment 9 Johnny Willemsen 2008-05-14 07:36:11 CDT
Can you provide a unified diff based on x.6.4 that adds this? 
Comment 10 Johnny Willemsen 2008-05-15 08:46:30 CDT
back to reporter
Comment 11 Christoph Hofmann 2008-05-16 03:47:30 CDT
Created attachment 975 [details]
possible solution
Comment 12 Christoph Hofmann 2008-05-16 03:49:43 CDT
Created attachment 976 [details]
possible solution as diff