1 /*------------------------------------------------------------------------------
2 Name: SocketDriverFactory.h
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 Comment: The factory for the client driver for the SOCKET protocol
6 ------------------------------------------------------------------------------*/
7 #ifndef _CLIENT_PROTOCOL_SOCKET_SOCKETDRIVERFACTORY
8 #define _CLIENT_PROTOCOL_SOCKET_SOCKETDRIVERFACTORY
9
10 #include <util/xmlBlasterDef.h>
11 #include <client/protocol/socket/SocketDriver.h>
12 #include <util/objman.h> // for managed objects
13
14 namespace org {
15 namespace xmlBlaster {
16 namespace client {
17 namespace protocol {
18 namespace socket {
19
20 typedef std::pair<SocketDriver*, int> DriverEntry;
21 typedef std::map<org::xmlBlaster::util::Global*, DriverEntry> DriversMap;
22
23 /**
24 * Factory used to create instances of SocketDriver objects. It currently is a singleton class and has for
25 * that reason private constructors, destructor and assignment operator.
26 * To get a reference to the singleton instance you must invoke getFactory(...).
27 */
28 class Dll_Export SocketDriverFactory
29 {
30 friend SocketDriverFactory& getFactory(org::xmlBlaster::util::Global& global);
31
32 // required for the managed objects
33 friend class Object_Lifetime_Manager;
34 friend class ManagedObject;
35
36 private:
37 const std::string ME;
38 DriversMap drivers_; //< the std::map containing all drivers created by this factory
39 org::xmlBlaster::util::thread::Mutex getterMutex_; //< the mutex used for creating/deleting SocketDriver instances
40
41 static SocketDriverFactory* factory_;
42
43 /** Not used here */
44 void run();
45
46 SocketDriverFactory(org::xmlBlaster::util::Global& global);
47
48 SocketDriverFactory(const SocketDriverFactory& factory);
49 SocketDriverFactory& operator =(const SocketDriverFactory& factory);
50
51 public:
52 ~SocketDriverFactory(); // Should be private, VC7 is ok with private, g++ 3.3 does not like it
53
54 /**
55 */
56 static SocketDriverFactory& getFactory(org::xmlBlaster::util::Global& global);
57
58 /**
59 * gets an instance of a socket driver with the specified name.
60 */
61 SocketDriver& getDriverInstance(org::xmlBlaster::util::Global* global);
62
63 /**
64 * Kills the driver instance with the given name. Note that if you invoked getDriverInstance several
65 * times with the same global object, you just decrement the internal reference counter. When the reference
66 * counter reaches zero, the driver is really destroyed.
67 */
68 int killDriverInstance(org::xmlBlaster::util::Global* global);
69
70 };
71
72 }}}}} // namespaces
73
74 #endif
syntax highlighted by Code2HTML, v. 0.9.1