|
1 /* |
|
2 * Copyright (c) 2008 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: DriveObserverMessages |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef DRIVEOBSERVERMESSAGES_H |
|
19 #define DRIVEOBSERVERMESSAGES_H |
|
20 |
|
21 #include "logger.h" |
|
22 #include "comms.h" |
|
23 #include "commsmessage.h" |
|
24 |
|
25 #include "driveutilities.h" |
|
26 |
|
27 using java::comms::CommsMessage; |
|
28 |
|
29 namespace java |
|
30 { |
|
31 namespace fileutils |
|
32 { |
|
33 const int DRIVEOBSERVER_MSG_SUBSCRIBE_EVENTS = 1; |
|
34 const int DRIVEOBSERVER_MSG_UNSUBSCRIBE_EVENTS = 2; |
|
35 const int DRIVEOBSERVER_MSG_DRIVE_CHANGED_EVENT = 3; |
|
36 const int DRIVEOBSERVER_MSG_GETDRIVES_REQUEST = 4; |
|
37 const int DRIVEOBSERVER_MSG_GETDRIVES_RESULT = 5; |
|
38 |
|
39 const int DRIVEOBSERER_GET_DRIVES_ALL = 1; |
|
40 const int DRIVEOBSERER_GET_DRIVES_ACCESIBLE = 2; |
|
41 |
|
42 inline void setSubscribeParams(CommsMessage& aMessage, int moduleId) |
|
43 { |
|
44 aMessage.setMessageId(DRIVEOBSERVER_MSG_SUBSCRIBE_EVENTS); |
|
45 aMessage.setModuleId(java::comms::PLUGIN_ID_DRIVE_OBSERVER_NATIVE_C); |
|
46 aMessage << moduleId; |
|
47 } |
|
48 inline void getSubscribeParams(CommsMessage& aMessage, int& moduleId) |
|
49 { |
|
50 if (aMessage.getMessageId() == DRIVEOBSERVER_MSG_SUBSCRIBE_EVENTS) |
|
51 { |
|
52 aMessage >> moduleId; |
|
53 } |
|
54 else |
|
55 { |
|
56 moduleId = 0; |
|
57 } |
|
58 } |
|
59 |
|
60 inline void setUnsubscribeMessage(CommsMessage& aMessage, int moduleId) |
|
61 { |
|
62 aMessage.setMessageId(DRIVEOBSERVER_MSG_UNSUBSCRIBE_EVENTS); |
|
63 aMessage.setModuleId(java::comms::PLUGIN_ID_DRIVE_OBSERVER_NATIVE_C); |
|
64 aMessage << moduleId; |
|
65 } |
|
66 |
|
67 inline void getUnsubscribeParams(CommsMessage& aMessage, int& moduleId) |
|
68 { |
|
69 if (aMessage.getMessageId() == DRIVEOBSERVER_MSG_UNSUBSCRIBE_EVENTS) |
|
70 { |
|
71 aMessage >> moduleId; |
|
72 } |
|
73 else |
|
74 { |
|
75 ELOG2(EJavaFile, "wrong messageId was %d expecting %d", |
|
76 aMessage.getMessageId(), DRIVEOBSERVER_MSG_UNSUBSCRIBE_EVENTS); |
|
77 moduleId = 0; |
|
78 } |
|
79 } |
|
80 |
|
81 inline void appendDriveInfo(CommsMessage& aMessage, const driveInfo& aDriveInfo) |
|
82 { |
|
83 aMessage << aDriveInfo.iRootPath; |
|
84 aMessage << (aDriveInfo.iIsPresent ? 1 : 0); |
|
85 aMessage << (aDriveInfo.iIsRemovable ? 1 : 0); |
|
86 aMessage << (aDriveInfo.iIsLocal ? 1 : 0); |
|
87 aMessage << (aDriveInfo.iIsReadOnly ? 1 : 0); |
|
88 aMessage << (int) aDriveInfo.iId; |
|
89 aMessage << (aDriveInfo.iIsExternallyMountable ? 1 : 0); |
|
90 } |
|
91 |
|
92 inline void extractDriveInfo(CommsMessage& aMessage, driveInfo& aDriveInfo) |
|
93 { |
|
94 aMessage >> aDriveInfo.iRootPath; |
|
95 |
|
96 int tempInt = 0; |
|
97 aMessage >> tempInt; |
|
98 aDriveInfo.iIsPresent = (tempInt == 1 ? true : false); |
|
99 |
|
100 aMessage >> tempInt; |
|
101 aDriveInfo.iIsRemovable = (tempInt == 1 ? true : false); |
|
102 |
|
103 aMessage >> tempInt; |
|
104 aDriveInfo.iIsLocal = (tempInt == 1 ? true : false); |
|
105 |
|
106 aMessage >> tempInt; |
|
107 aDriveInfo.iIsReadOnly = (tempInt == 1 ? true : false); |
|
108 |
|
109 aMessage >> tempInt; |
|
110 aDriveInfo.iId = tempInt; |
|
111 aMessage >> tempInt; |
|
112 aDriveInfo.iIsExternallyMountable = (tempInt == 1 ? true : false); |
|
113 } |
|
114 |
|
115 inline void setDriveChangedParams(CommsMessage& aMessage, |
|
116 int aReceiver, |
|
117 int aModuleId, |
|
118 int aOperation, |
|
119 const driveInfo& aDriveInfo) |
|
120 { |
|
121 aMessage.setMessageId(DRIVEOBSERVER_MSG_DRIVE_CHANGED_EVENT); |
|
122 aMessage.setReceiver(aReceiver); |
|
123 aMessage.setModuleId(aModuleId); |
|
124 aMessage << aOperation; |
|
125 appendDriveInfo(aMessage, aDriveInfo); |
|
126 } |
|
127 |
|
128 inline void getDriveChangedParams(CommsMessage& aMessage, int& aOperation, |
|
129 driveInfo& aDriveInfo) |
|
130 { |
|
131 if (aMessage.getMessageId() == DRIVEOBSERVER_MSG_DRIVE_CHANGED_EVENT) |
|
132 { |
|
133 aMessage >> aOperation; |
|
134 extractDriveInfo(aMessage, aDriveInfo); |
|
135 } |
|
136 else |
|
137 { |
|
138 ELOG2(EJavaFile, "wrong messageId was %d expecting %d", |
|
139 aMessage.getMessageId(), DRIVEOBSERVER_MSG_DRIVE_CHANGED_EVENT); |
|
140 } |
|
141 } |
|
142 |
|
143 inline void setGetDrivesParams(CommsMessage& aMessage, const int& aDriveTypes) |
|
144 { |
|
145 aMessage.setMessageId(DRIVEOBSERVER_MSG_GETDRIVES_REQUEST); |
|
146 aMessage.setModuleId(java::comms::PLUGIN_ID_DRIVE_OBSERVER_NATIVE_C); |
|
147 aMessage << aDriveTypes; |
|
148 } |
|
149 |
|
150 inline void getGetDrivesParams(CommsMessage& aMessage, int& aDriveTypes) |
|
151 { |
|
152 if (aMessage.getMessageId() == DRIVEOBSERVER_MSG_GETDRIVES_REQUEST) |
|
153 { |
|
154 aMessage >> aDriveTypes; |
|
155 } |
|
156 else |
|
157 { |
|
158 ELOG2(EJavaFile, "wrong messageId was %d expecting %d", |
|
159 aMessage.getMessageId(), DRIVEOBSERVER_MSG_GETDRIVES_REQUEST); |
|
160 } |
|
161 } |
|
162 |
|
163 inline void setGetDrivesResultParams(CommsMessage& aMessage, |
|
164 const driveInfos& aDriveInfos) |
|
165 { |
|
166 aMessage.setMessageId(DRIVEOBSERVER_MSG_GETDRIVES_RESULT); |
|
167 aMessage.setModuleId(java::comms::PLUGIN_ID_DRIVE_OBSERVER_NATIVE_C); |
|
168 int numOfDrives = aDriveInfos.size(); |
|
169 aMessage << numOfDrives; |
|
170 for (int i = 0 ; i < numOfDrives ; i++) |
|
171 { |
|
172 appendDriveInfo(aMessage, aDriveInfos[i]); |
|
173 } |
|
174 } |
|
175 |
|
176 inline void getGetDrivesResultParams(CommsMessage& aMessage, |
|
177 driveInfos& aDriveInfos) |
|
178 { |
|
179 aDriveInfos.clear(); |
|
180 |
|
181 if (aMessage.getMessageId() == DRIVEOBSERVER_MSG_GETDRIVES_RESULT) |
|
182 { |
|
183 int numOfDrives = 0; |
|
184 aMessage >> numOfDrives; |
|
185 if (numOfDrives > 0) |
|
186 { |
|
187 driveInfo di; |
|
188 for (int i = 0 ; i < numOfDrives ; i++) |
|
189 { |
|
190 extractDriveInfo(aMessage, di); |
|
191 aDriveInfos.push_back(di); |
|
192 } |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 ELOG2(EJavaFile, "wrong messageId was %d expecting %d", |
|
198 aMessage.getMessageId(), DRIVEOBSERVER_MSG_GETDRIVES_RESULT); |
|
199 } |
|
200 } |
|
201 |
|
202 } // namespace fileutils |
|
203 } // namespace java |
|
204 #endif // DRIVEOBSERVERMESSAGES_H |