Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[ace-users] Using the ACE_Service_Object or ACE_Shared_Object

47 views
Skip to first unread message

Stephen Burke

unread,
Mar 9, 2010, 10:29:21 AM3/9/10
to ace-...@list.isis.vanderbilt.edu
To: ace-...@list.isis.vanderbilt.edu
Subject: Using the ACE_Service_Object or ACE_Shared_Object

ACE VERSION: 5.5.10

HOST MACHINE and OPERATING SYSTEM:
    WinXP SP3
    winsock.dll (v3.10.0.103)

COMPILER NAME AND VERSION (AND PATCHLEVEL): VS2005(VC8) v2.0.50727 SP2

THE $ACE_ROOT/ace/config.h FILE:
    We compile ACE in mingw first then with VS2005 in the same tree.
   
    /* we don't have a sys/statvfs.h file for msvc */
    #define ACE_LACKS_SYS_STATVFS_H
   
    /* platform supports ICMP over raw sockets */
    #define ACE_HAS_ICMP_SUPPORT 1
   
    /* add Ipv6 support */
    #define ACE_HAS_IPV6
   
    // Target Windows Server 2003, Windows XP */
    // This is because of compile errors on the mingw build of ace.
    // Consumers of ace that are being built with msvc will already
    // have this define set so use that
    #ifndef _WIN32_WINNT
    #  define _WIN32_WINNT 0x0501
    #endif
   
    /* Pull in the win32 configuration */
    #include "ace/config-win32.h"



BUILD METHOD USED: VS2005 project & sln

DOES THE PROBLEM AFFECT:
    OTHER:  The correct usage of ACE_Service_Object or ACE_Shared_Object


SYNOPSIS:
    I'd like to encapsulate all the gory details of dynamically
    loading dlls, calling functions from those dlls, and releasing
    them when they are done using ACE.  I'm not sure whether to use
    the ACE_Shared_Object or ACE_Service_Object.  I'm guessing I need
    the ACE_Shared_Object, but I couldn't find any details in any of
    the examples in the source distribution.  Could someone point me
    in the right direction to find some example code?

DESCRIPTION:
    The code below is basically what I want to mimic using the ACE
    classes.  I was able to build an ACE_Service_Object and
    implement its init, fini, & info classes.  That looks like it
    would work fine for me if I want to create a service & use it with
    the Reactor.  What if I just want to encapsulate some
    functionality in a dll, load it at runtime explicitly similar
    to calling dlopen & grabbing some exported functions & using
    those?
   
    void* handle = dlopen("./libdllbaseclass.so", RTLD_LAZY);
   
    DllBaseClass* (*create)();
    void (*destroy)(DllBaseClass*);
   
    create = (DllBaseClass* (*)())dlsym(handle, "create_object");
    destroy = (void (*)(DllBaseClass*))dlsym(handle, "destroy_object");
   
    DllBaseClass* myClass = (DllBaseClass*)create();
    myClass->DoSomething();
    destroy( myClass );

    I posted my question on StackOverflow as well & it's located
    here
    http://stackoverflow.com/questions/2405731/using-ace-service-object

Steve Huston

unread,
Mar 9, 2010, 11:26:33 AM3/9/10
to Stephen Burke, ace-...@list.isis.vanderbilt.edu
Thanks for the PROBLEM-REPORT-FORM.
 
(Also answered on stackoverflow...)
 
If all you need is to load, unload, and call some functions in a shared library, you could use the ACE_DLL class instead. That's what ACE_Shared_Object ends up using under the covers.
 
-Steve

--
Steve Huston, Riverace Corporation
Total Lifecycle Support for Your Networked Applications
http://www.riverace.com

Stephen Burke

unread,
Mar 9, 2010, 12:30:22 PM3/9/10
to Steve Huston, ace-...@list.isis.vanderbilt.edu
Thanks, that's exactly what I needed.  Can I use the ACE_FACTORY_DEFINE macro to define the entry point to the DLL?  I'm trying to do that with a class that isn't derived from ACE_Service_Object and running into compile issues.  I'm guessing I can't do that but is there a similar macro?

Steve

Douglas C. Schmidt

unread,
Mar 9, 2010, 5:42:18 PM3/9/10
to Stephen Burke, ace-...@list.isis.vanderbilt.edu

Hi Steve,

BTW, the ACE_DLL and ACE Service Configurator (which includes
ACE_Service_Object and ACE_Shared_Object) are described in Chapter 5 of
C++NPv2 <http://www.cs.wustl.edu/~schmidt/ACE/book2/>. There are
examples in ACE_ROOT/examples/C++NPv2/.

Thanks,

Doug

> _______________________________________________
> ace-users mailing list
> ace-...@list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/ace-users

Steve Huston

unread,
Mar 9, 2010, 5:48:18 PM3/9/10
to Stephen Burke, ace-...@list.isis.vanderbilt.edu
> Thanks, that's exactly what I needed.

Great! You're welcome.

> Can I use the ACE_FACTORY_DEFINE macro to define the entry point
> to the DLL?

I guess you could, but why? If you know the name of the function, you
can just use it.

> I'm trying to do that with a class that isn't derived from
> ACE_Service_Object and running into compile issues. I'm guessing
> I can't do that but is there a similar macro?

You'll need to use a C entrypoint (extern "C") to avoid the compiler
name mangling of a class/method name.

-Steve

Stephen Burke

unread,
Mar 9, 2010, 6:37:44 PM3/9/10
to Douglas C. Schmidt, ace-...@list.isis.vanderbilt.edu
Thanks for all the help, once I was pointed towards ACE_DLL, then I was able to find chapter 5 in C++NPv2 which helped me out a lot.  I made my class an ACE_Service_Object and then I load it with ACE_Service_Config::process_directive and grab the entry point with ACE_Dynamic_Service::instance.  This seems to work out for me. 

char const * const smc_service_directive = ACE_DYNAMIC_SERVICE_DIRECTIVE(
        "Smc",
        "smc_service",
        "_make_Smc",
        "");
   
int result = ACE_Service_Config::process_directive(smc_service_directive);
Smc * p_obj = ACE_Dynamic_Service<Smc>::instance("Smc");
p_obj->method1();

Steve

On Tue, Mar 9, 2010 at 4:42 PM, Douglas C. Schmidt <sch...@dre.vanderbilt.edu> wrote:

Hi Steve,

  BTW, the ACE_DLL and ACE Service Configurator (which includes
ACE_Service_Object and ACE_Shared_Object) are described in Chapter 5 of
C++NPv2 <http://www.cs.wustl.edu/~schmidt/ACE/book2/>.  There are
examples in ACE_ROOT/examples/C++NPv2/.

Thanks,

Doug

> Thanks, that's exactly what I needed.  Can I use the ACE_FACTORY_DEFINE macro
> to define the entry point to the DLL?  I'm trying to do that with a class that

> isn't derived from ACE_Service_Object and running into compile issues.  I'm
> guessing I can't do that but is there a similar macro?
>

Douglas C. Schmidt

unread,
Mar 9, 2010, 9:10:24 PM3/9/10
to Stephen Burke, ace-...@list.isis.vanderbilt.edu

hi Steve,

Cool, that sounds like a winner!!

doug

0 new messages