1 // OVLibrary.h: Interface header for dynamic loadable OV modules
2 //
3 // Copyright (c) 2004-2006 The OpenVanilla Project (http://openvanilla.org)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions
8 // are met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 //    notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 //    notice, this list of conditions and the following disclaimer in the
14 //    documentation and/or other materials provided with the distribution.
15 // 3. Neither the name of OpenVanilla nor the names of its contributors
16 //    may be used to endorse or promote products derived from this software
17 //    without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef __OVLibrary_h
32 #define __OVLibrary_h
33 
34 // as a dynamically-loadable library (be it .so, .DLL, .dylib or .bundle),
35 // we only need to export these three functions
36 
37 // extern "C" unsigned int OVGetLibraryVersion();
38 // extern "C" int OVInitializeLibrary(OVService* srv, const char* libpath);
39 // extern "C" OVModule *OVGetModuleFromLibrary(int idx);
40 
41 // wrapper macro for libraries that have exactly only one OVModule (IM/OF)
42 #define OV_SINGLE_MODULE_WRAPPER(classname) \
43     extern "C" unsigned int OVGetLibraryVersion() { return OV_VERSION; } \
44     extern "C" int OVInitializeLibrary(OVService*, const char*) { return 1; } \
45     extern "C" OVModule *OVGetModuleFromLibrary(int idx) {\
46         return (idx==0) ? new classname : NULL; \
47     }
48 
49 // below are used for most OV Loader implementations, not needed by any
50 // loadable library
51 
52 typedef unsigned int _OVGetLibraryVersion_t();
53 typedef int _OVInitializeLibrary_t(OVService *srv, const char *libpath);
54 typedef OVModule* _OVGetModuleFromLibrary_t(int);
55 
56 struct OVLoadedLibrary {
57     OVLoadedLibrary(_OVInitializeLibrary_t *i, _OVGetModuleFromLibrary_t *m) :
58         initialize(i), getModule(m) {}
59     _OVInitializeLibrary_t *initialize;
60     _OVGetModuleFromLibrary_t *getModule;
61 };
62 
63 #endif
64