1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
5 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
6 | * the License. You may obtain a copy of the License at
|
---|
7 | * http://www.mozilla.org/MPL/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is Mozilla Transaction Manager.
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * Netscape Communications Corp.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2003
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | * John Gaunt <[email protected]>
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | #ifndef _tmTransactionManager_H_
|
---|
39 | #define _tmTransactionManager_H_
|
---|
40 |
|
---|
41 | #include "plhash.h"
|
---|
42 | #include "tmUtils.h"
|
---|
43 | #include "tmVector.h"
|
---|
44 | #include "tmIPCModule.h"
|
---|
45 |
|
---|
46 | // forward declarations
|
---|
47 | class tmQueue;
|
---|
48 | class tmClient;
|
---|
49 | class tmTransaction;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * This class manages the flow of messages from the IPC daemon (coming to
|
---|
53 | * it through the tmIPCModule) that ultimately come from a Transaction
|
---|
54 | * Service (TS) in a mozilla based client somewhere. The message is
|
---|
55 | * delivered to the proper queue, where it is dealt with.
|
---|
56 | *
|
---|
57 | * New queues get created here as clients request them.
|
---|
58 | */
|
---|
59 | class tmTransactionManager
|
---|
60 | {
|
---|
61 |
|
---|
62 | public:
|
---|
63 |
|
---|
64 | ////////////////////////////////////////////////////////////////////////////
|
---|
65 | // Constructor(s) & Destructor & Initializer
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * reclaim the memory allcoated during initialization
|
---|
69 | */
|
---|
70 | virtual ~tmTransactionManager();
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Set up the storage of the queues - initialize the vector
|
---|
74 | *
|
---|
75 | * @returns NS_OK if successful
|
---|
76 | * @returns -1 if initialization fails
|
---|
77 | */
|
---|
78 | PRInt32 Init();
|
---|
79 |
|
---|
80 | ////////////////////////////////////////////////////////////////////////////
|
---|
81 | // Public Member Functions
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Called from the tmIPCModule. Decide where to send the message and
|
---|
85 | * dispatch it.
|
---|
86 | */
|
---|
87 | void HandleTransaction(tmTransaction *aTrans);
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Called by the queues when they need to get a message back out to a
|
---|
91 | * client.
|
---|
92 | */
|
---|
93 | void SendTransaction(PRUint32 aDestClientIPCID, tmTransaction *aTrans) {
|
---|
94 | PR_ASSERT(aTrans);
|
---|
95 | tmIPCModule::SendMsg(aDestClientIPCID, aTrans);
|
---|
96 | }
|
---|
97 |
|
---|
98 | protected:
|
---|
99 |
|
---|
100 | ////////////////////////////////////////////////////////////////////////////
|
---|
101 | // Protected Member Functions
|
---|
102 |
|
---|
103 | // Queue management
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * @returns the queue indexed by the ID passed in, which could be nsnull
|
---|
107 | */
|
---|
108 | tmQueue* GetQueue(PRUint32 aQueueID) {
|
---|
109 | return (tmQueue*) mQueues[aQueueID];
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * @returns the queue with the name passed in
|
---|
114 | * @returns nsnull if there is no queue with that name
|
---|
115 | */
|
---|
116 | tmQueue* GetQueue(const char *aQueueName);
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * If all is successful a new queue with the name provided will be created,
|
---|
120 | * and added to the collection of queues. It will be initialized and ready
|
---|
121 | * to have transactions added.
|
---|
122 | *
|
---|
123 | * This doesn't check for the existance of a queue with this name. IF
|
---|
124 | * there is already a queue with this name then you will
|
---|
125 | * get that when using GetQueue(qName) and never get the new queue
|
---|
126 | * created here. A call to GetQueue(qID) will be able to get at the new
|
---|
127 | * queue, however you had better cache the ID.
|
---|
128 | *
|
---|
129 | * @returns -1 if the queue can't be created, or is not added
|
---|
130 | * @returns >= 0 if the queue was added successfully
|
---|
131 | */
|
---|
132 | PRInt32 AddQueue(const char *aQueueType);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | */
|
---|
136 | void RemoveQueue(PRUint32 aQueueID);
|
---|
137 |
|
---|
138 | ////////////////////////////////////////////////////////////////////////////
|
---|
139 | // Protected Member Variables
|
---|
140 |
|
---|
141 | tmVector mQueues;
|
---|
142 |
|
---|
143 | private:
|
---|
144 |
|
---|
145 | };
|
---|
146 |
|
---|
147 | #endif
|
---|