|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * This file contains the headers of the Data and ParameterList classes. |
|
16 */ |
|
17 |
|
18 #ifndef COMMON_H |
|
19 #define COMMON_H |
|
20 |
|
21 #pragma warning ( disable : 4786 ) |
|
22 |
|
23 #include <windows.h> |
|
24 |
|
25 //********************************************************************************** |
|
26 // Class Data |
|
27 // |
|
28 // This class provides data encapsulattion for DataGateway |
|
29 //********************************************************************************** |
|
30 |
|
31 class Data |
|
32 { |
|
33 public: |
|
34 //type of data |
|
35 enum DataType { EEmpty = 0, EControl, EError, EData }; |
|
36 public: |
|
37 Data(const void* data_in = NULL, DWORD length = 0, DataType type = EEmpty); |
|
38 Data(const void* data_in, DWORD length, DWORD offset, DataType type); |
|
39 Data(const Data& d); |
|
40 virtual ~Data(); |
|
41 /* |
|
42 * returns data in Data object given parameter |
|
43 */ |
|
44 virtual void* GetData(void* data_out = NULL) const; |
|
45 /* |
|
46 * returns length of data |
|
47 */ |
|
48 virtual DWORD GetLength() const; |
|
49 /* |
|
50 * returns type of data |
|
51 * can be one of the following: EEmpty, EControl, EError, EData |
|
52 */ |
|
53 DataType GetType() const; |
|
54 /* |
|
55 * This method copies up to length bytes from given data object to class member data object |
|
56 */ |
|
57 bool SetData(const void* data_in, DWORD length, DataType type); |
|
58 /* |
|
59 * This method copies up to length bytes(starting from offset) from given data object to class member data object |
|
60 */ |
|
61 bool SetData(const void* data_in, DWORD length, DWORD offset, DataType type); |
|
62 Data& operator=(const Data& data); |
|
63 /* |
|
64 * Used to combine different messages into one. |
|
65 * This method appends new data at the end of already excisting data. |
|
66 * If new data isn't same type as excisting data it isn't appended. |
|
67 * Returns bool value of whether the method has succeeded to append the data or not. |
|
68 */ |
|
69 virtual bool AppendData(Data* aData); |
|
70 /* |
|
71 * This method is used to free data and set data type to EEmpty |
|
72 */ |
|
73 void FreeData(); |
|
74 private: |
|
75 //actual data |
|
76 void* m_pData; |
|
77 //length of data |
|
78 DWORD m_dwLength; |
|
79 //type of data |
|
80 DataType m_Type; |
|
81 }; |
|
82 |
|
83 const BYTE ControlPhonePowered = 0x01; |
|
84 |
|
85 const Data CtrlMessagePhonePowered((void*)&ControlPhonePowered, 1, 0, Data::EControl); |
|
86 |
|
87 const BYTE ErrorSendingData = 0x81; |
|
88 |
|
89 const Data ErrorMessageSendingData((void*)&ErrorSendingData, 1, 0, Data::EError); |
|
90 |
|
91 #define CREATE_CONTROL_MESSAGE(str) new Data( (str), strlen(str)+1, Data::EControl) |
|
92 |
|
93 //********************************************************************************** |
|
94 // Class ParameterList |
|
95 // |
|
96 //********************************************************************************** |
|
97 |
|
98 #include <map> |
|
99 #include <string> |
|
100 |
|
101 using namespace std; |
|
102 |
|
103 class ParameterList |
|
104 { |
|
105 public: |
|
106 void Add(const string& key, const void* value); |
|
107 const void* Get(const string& key); |
|
108 ParameterList(); |
|
109 ~ParameterList(); |
|
110 private: |
|
111 map<const string,const void*> m_Map; |
|
112 }; |
|
113 |
|
114 #endif |
|
115 |
|
116 // End of the file |