|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: MessageDispatcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef MESSAGEDISPATCHER_H |
|
20 #define MESSAGEDISPATCHER_H |
|
21 |
|
22 #include <string> |
|
23 #include <memory> |
|
24 |
|
25 #include "javaosheaders.h" |
|
26 #include "javastorageentry.h" |
|
27 #include "javastorage.h" |
|
28 #include "javastoragemessage.h" |
|
29 |
|
30 namespace java |
|
31 { |
|
32 namespace comms |
|
33 { |
|
34 class CommsMessage; |
|
35 } // end namespace comms |
|
36 namespace storage |
|
37 { |
|
38 class JavaDataAccess; |
|
39 class StatementUtils; |
|
40 |
|
41 /** |
|
42 * MessageDispatcher takes care of message handling. It creates messages for |
|
43 * the storage and gives them for sending and construct response object from |
|
44 * the message response if needed. |
|
45 */ |
|
46 OS_NONSHARABLE_CLASS(MessageDispatcher) |
|
47 { |
|
48 friend class JavaStorageImpl; |
|
49 |
|
50 public: |
|
51 /** |
|
52 * Destructor. |
|
53 */ |
|
54 ~MessageDispatcher(); |
|
55 |
|
56 /** |
|
57 * CreateAndSendMessage for short storage statements. These are |
|
58 * transaction and connection handling requests. |
|
59 * |
|
60 * @param aMsgId message identifier. |
|
61 * @param aHeaders connection headers. |
|
62 * @param aStorageName storage name to be opened. This is used only when |
|
63 * connection is opened. |
|
64 * @return sessionID string if connection is opened, not used otherwise. |
|
65 * @throws JavaStorageException if unknown message id or error response |
|
66 * received from the storage. |
|
67 */ |
|
68 std::string createAndSendMessage( |
|
69 JavaStorageMessage::MessageIdentifier aMsgId, |
|
70 const std::string& aHeaders, |
|
71 const std::string& aStorageName |
|
72 ); |
|
73 |
|
74 /** |
|
75 * CreateAndSendMessage for storage statements. |
|
76 * |
|
77 * @param aMsgId message identifier. |
|
78 * @param aHeaders connection headers. |
|
79 * @param aTableName table where statement is executed. |
|
80 * @param aEntry Application entry holding statement data. It contains e.g. |
|
81 * entries written to storage table. |
|
82 * @return amount of removed storage entries. This is used only when data |
|
83 * is removed from the storage. |
|
84 * @throws JavaStorageException if unknown message id or error response |
|
85 * received from the storage. |
|
86 */ |
|
87 int createAndSendMessage( |
|
88 JavaStorageMessage::MessageIdentifier aMsgId, |
|
89 const std::string& aHeaders, |
|
90 const std::string& aTableName, |
|
91 const java::storage::JavaStorageApplicationEntry_t& aEntry |
|
92 ); |
|
93 |
|
94 /** |
|
95 * Handlesearch handles search statements. It creates SQL statement |
|
96 * out of entry, handles communication and constructs application list |
|
97 * from response. |
|
98 * |
|
99 * @param aMsgId message identifier. |
|
100 * @param aHeaders connection headers. |
|
101 * @param aTableName table where statement is executed. |
|
102 * @param aEntry Application entry holding statement data. It contains |
|
103 * search query data. |
|
104 * @param[out] aAppList response object. Each application represents one row. |
|
105 * @throws JavaStorageException if unknown message id, error response |
|
106 * received from the storage or invalid data structure detected. |
|
107 */ |
|
108 void handleSearch( |
|
109 JavaStorageMessage::MessageIdentifier aMsgId, |
|
110 const std::string& aHeaders, |
|
111 const std::string& aTableName, |
|
112 const java::storage::JavaStorageApplicationEntry_t& aEntry, |
|
113 JavaStorageApplicationList_t& aAppList |
|
114 ); |
|
115 |
|
116 /** |
|
117 * HandleUpdate hadles update statements. It creates SQL statement |
|
118 * out of entries and send it to storage for execution. |
|
119 * |
|
120 * @param aMsgId message identifier. |
|
121 * @param aHeaders connection headers. |
|
122 * @param aTableName table where statement is executed. |
|
123 * @param aUpdateEntry Application entry holding updated data. |
|
124 * @param aMatchEntry Application entry holding data to match content |
|
125 * to be updated. |
|
126 * @throws JavaStorageException if unknown message id or error response |
|
127 * received from the storage. |
|
128 */ |
|
129 void handleUpdate( |
|
130 JavaStorageMessage::MessageIdentifier aMsgId, |
|
131 const std::string& aHeaders, |
|
132 const std::string& aTableName, |
|
133 const JavaStorageApplicationEntry_t& aUpdateEntry, |
|
134 const JavaStorageApplicationEntry_t& aMatchEntry); |
|
135 |
|
136 private: |
|
137 /** |
|
138 * Private constructor. Creates data access object that is used to |
|
139 * communicate with the storage. |
|
140 */ |
|
141 MessageDispatcher(); |
|
142 |
|
143 /** |
|
144 * Populate single entry. If response contains more than one application |
|
145 * entries they are ignored. If response contains malformed entries |
|
146 * population is stopped and already populated valid entries are left |
|
147 * populated for a robustness sake. |
|
148 * |
|
149 * @param aReceivedMessage response message from the storage as wstring |
|
150 * representation. |
|
151 * @param[out] aEntry Application entry populated with response message |
|
152 * content. Entry is left empty if no entries found. |
|
153 */ |
|
154 void populateEntry(comms::CommsMessage& aReceivedMessage, |
|
155 JavaStorageApplicationEntry_t& aEntry); |
|
156 |
|
157 /** |
|
158 * Populate application list. If response contains malformed application |
|
159 * entries population is stopped and already populated valid entries are |
|
160 * left populated for a robustness sake. |
|
161 * |
|
162 * @param aReceivedMessage response message from the storage as wstring |
|
163 * representation. |
|
164 * @param[out] aAppList Application list populated with response message |
|
165 * content. List is left empty if no entries found. |
|
166 */ |
|
167 void populateEntry(comms::CommsMessage& aReceivedMessage, |
|
168 JavaStorageApplicationList_t& aAppList); |
|
169 |
|
170 /** |
|
171 * Create message header. |
|
172 * |
|
173 * @param aMsgId message identifier. |
|
174 * @param aHeaders current headers. |
|
175 */ |
|
176 void createHeader(int aMgsId, std::string& aHeaders); |
|
177 |
|
178 /** |
|
179 * Read error message from received message. |
|
180 * |
|
181 * @param aReceivedMessage received message. |
|
182 * @param[out] aErrMsg error message. |
|
183 */ |
|
184 void readErrorMessage(comms::CommsMessage& aReceivedMessage, |
|
185 std::string& aErrMsg); |
|
186 |
|
187 private: |
|
188 std::auto_ptr<JavaDataAccess> mDataAccess; |
|
189 std::auto_ptr<StatementUtils> mUtils; |
|
190 |
|
191 }; |
|
192 |
|
193 } // end namespace storage |
|
194 } // end namespace java |
|
195 |
|
196 #endif // MESSAGEDISPATCHER_H |
|
197 |