f19af43ee9ba17de271ea7ff67a19ca8e8638256
[tpot/pegasus/.git] / src / Pegasus / DynListener / ConsumerManager.h
1 //%2005////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
18 // 
19 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
22 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Heather Sterling (hsterl@us.ibm.com)
31 //
32 // Modified By: 
33 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 #ifndef Pegasus_ConsumerManager_h
37 #define Pegasus_ConsumerManager_h
38
39 #include <Pegasus/Common/Config.h>
40 #include <Pegasus/Common/HashTable.h>
41 #include <Pegasus/Common/OptionManager.h>
42 #include <Pegasus/Common/ArrayInternal.h>
43 #include <Pegasus/Common/CIMInstance.h>
44 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
45 #include <Pegasus/Common/System.h>
46 #include <Pegasus/DynListener/Linkage.h>
47
48 #include "ConsumerModule.h"
49 #include "DynamicConsumer.h"
50
51 PEGASUS_NAMESPACE_BEGIN
52
53 /** The ConsumerManager class is responsible for managing all of the consumers.  It is also responsible for
54  *  synchronizing consumer operations.
55  */
56
57 class PEGASUS_DYNLISTENER_LINKAGE ConsumerManager
58 {
59 public:
60
61     ConsumerManager(const String& consumerDir, const String& consumerConfigDir, Boolean enableConsumerUnload, Uint32 idleTimeout);
62
63     virtual ~ConsumerManager();
64
65     String getConsumerDir();
66
67     String getConsumerConfigDir();
68
69     Boolean getEnableConsumerUnload();
70
71     Uint32 getIdleTimeout();
72
73     Boolean hasLoadedConsumers();
74
75     Boolean hasActiveConsumers();
76
77     DynamicConsumer* getConsumer(const String& consumerName);
78
79     void unloadConsumer(const String& consumerName);
80
81     void unloadAllConsumers();
82
83     void unloadIdleConsumers();
84
85 private:
86
87     typedef HashTable<String, DynamicConsumer *, EqualFunc<String>,  HashFunc<String> > ConsumerTable;
88
89     typedef HashTable<String, ConsumerModule *, EqualFunc<String>, HashFunc<String> > ModuleTable;
90
91     //consumer queue
92     ConsumerTable _consumers;
93     Mutex _consumerTableMutex;
94
95     //consumer module queue
96     ModuleTable _modules;
97     Mutex _moduleTableMutex;
98
99     //config properties
100     String _consumerDir;
101     String _consumerConfigDir;
102     Boolean _enableConsumerUnload;
103     Uint32 _idleTimeout; //ms
104     Boolean _forceShutdown;
105
106         //ATTN: Bugzilla 3765 - Uncomment when OptionManager has a reset capability
107         //OptionManager _optionMgr;
108
109     //global thread pool
110     ThreadPool* _thread_pool;
111
112     //worker thread
113     static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL _worker_routine(void *param);
114
115
116     //methods
117
118     ConsumerModule* _lookupModule(const String & moduleFileName);
119  
120     String _getConsumerLibraryName(const String & consumerName);
121
122     void _initConsumer(const String& consumerName, DynamicConsumer* consumer);
123
124     void _unloadConsumers(Array<DynamicConsumer*> consumersToUnload);
125
126     void _init();
127
128     Array<IndicationDispatchEvent> _deserializeOutstandingIndications(const String& consumerName);
129
130     void _serializeOutstandingIndications(const String& consumerName, Array<IndicationDispatchEvent> indications);
131
132 };
133
134 PEGASUS_NAMESPACE_END
135
136 #endif /* Pegasus_ConsumerManager_h */
137
138
139