moab
|
00001 00016 #ifdef WIN32 00017 #ifdef _DEBUG 00018 // turn off warnings that say they debugging identifier has been truncated 00019 // this warning comes up when using some STL containers 00020 #pragma warning(disable : 4786) 00021 #endif 00022 #endif 00023 00024 #include "moab/Core.hpp" 00025 00026 #ifdef XPCOM_MB 00027 00028 #include "nsIGenericFactory.h" 00029 00030 // define constructor function for Core 00031 NS_GENERIC_FACTORY_CONSTRUCTOR(moab::Core) 00032 00033 // support for nsIClassInfo 00034 NS_DECL_CLASSINFO(moab::Core) 00035 00036 MB_EXPORT const char* MoabVersion(); 00037 MB_EXPORT void GetInterface(MBuuid& interface_requested, UnknownInterface** iface); 00038 MB_EXPORT void DeInitialize(); 00039 MB_EXPORT void ReleaseInterface(UnknownInterface* iface); 00040 00041 static const nsModuleComponentInfo components[] = 00042 { 00043 { "MOAB Interface", CORE_CID, CORE_CONTRACTID, CoreConstructor, 00044 NULL /* NULL if you dont need one */, 00045 NULL /* NULL if you dont need one */, 00046 NULL /* no factory destructor */, 00047 NS_CI_INTERFACE_GETTER_NAME(moab::Core), 00048 NULL /* no language helper */, 00049 &NS_CLASSINFO_NAME(moab::Core), 00050 0 00051 } 00052 }; 00053 00054 // implement NSGetModule() 00055 NS_IMPL_NSGETMODULE(moab::Core, components); 00056 00057 #endif 00058 00059 #ifndef WIN32 00060 #define MB_EXPORT extern "C" 00061 #else 00062 #define MB_EXPORT extern "C" __declspec(dllexport) 00063 #endif 00064 00065 #include <list> 00066 00067 namespace moab { 00068 00069 class ComponentFactory : public UnknownInterface 00070 { 00071 public: 00072 ComponentFactory(){} 00073 virtual ~ComponentFactory(){} 00074 // returns the interface requested from an object 00075 virtual int QueryInterface( const MBuuid&, 00076 UnknownInterface** ); 00077 // keep track of the objects this component factory creates 00078 static std::list<UnknownInterface*> objects_in_use; 00079 }; 00080 00081 // the list that keeps track of all the interfaces generated by this server 00082 std::list<UnknownInterface*> ComponentFactory::objects_in_use; 00083 00084 00085 // this QueryInterface function is supposed to create an instance of the object 00086 // that contains the interface requested 00087 // 00088 // note: the object is not the same as the interface, therefore 00089 // we ask the object for the interface that was requested 00090 // 00091 00092 int ComponentFactory::QueryInterface( const MBuuid& uuid, UnknownInterface** iface ) 00093 { 00094 // this is an unknown interface that was requested 00095 // if wanted, we could provide a default interface 00096 // if IDD_MBUnknown is specified 00097 if(uuid == IDD_MBUnknown) 00098 return 0; 00099 // IDD_MBVerde interface was requested 00100 // create an Verde object and have it return the interface 00101 // requested 00102 else if(uuid == IDD_MBCore) 00103 { 00104 Core* mdb = new Core; 00105 // if the object does not contain the interface requested, delete the object 00106 if(!mdb->QueryInterface(uuid, iface)) 00107 { 00108 delete mdb; 00109 return 0; 00110 } 00111 return 1; 00112 } 00113 else 00114 return 0; 00115 00116 } 00117 00118 // returns the interface version 00119 MB_EXPORT const char* MoabVersion() 00120 { 00121 return MB_INTERFACE_VERSION; 00122 } 00123 00124 00125 // Initialize function is accessed by the MBClient when asking for interfaces 00126 MB_EXPORT void GetInterface(MBuuid& interface_requested, UnknownInterface** iface) 00127 { 00128 // create an instance of our component factory 00129 ComponentFactory server; 00130 // ask the component factory to give us the interface we want 00131 server.QueryInterface(interface_requested, iface); 00132 // if the interface existed, put it on our list 00133 if(iface && *iface) 00134 ComponentFactory::objects_in_use.push_front(*iface); 00135 } 00136 00137 00138 // DeInitialize function is accessed by the MBClient when disconnecting from this library 00139 // this will clean everything up prior to a disconnection 00140 // from this library 00141 MB_EXPORT void DeInitialize() 00142 { 00143 // delete all instances of objects 00144 while(ComponentFactory::objects_in_use.size()) 00145 { 00146 UnknownInterface* iface = 00147 ComponentFactory::objects_in_use.front(); 00148 ComponentFactory::objects_in_use.pop_front(); 00149 if(iface) 00150 delete iface; 00151 } 00152 } 00153 00154 // ReleaseInterface function is accessed by the MBClient when deleting an interface 00155 00156 // ReleaseInterface will delete this interface 00157 MB_EXPORT void ReleaseInterface(UnknownInterface* iface) 00158 { 00159 if(!iface) 00160 return; 00161 // remove this object from our list and delete it 00162 ComponentFactory::objects_in_use.remove(iface); 00163 delete iface; 00164 } 00165 00166 } // namespace moab 00167 00168