|
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 headers of HtiMessage class. |
|
16 */ |
|
17 #ifndef __HTI_MSG__ |
|
18 #define __HTI_MSG__ |
|
19 |
|
20 #include <windows.h> |
|
21 |
|
22 static const DWORD HTI_SYSTEM_SERVICE_UID = 0x1020DEB6; |
|
23 |
|
24 const int KMsgServiceNameOffset = 0; |
|
25 const int KHtiMsgServiceUidLen = 4; |
|
26 const int KMsgBodySizeLen = 4; |
|
27 const int KMsgBodySizeOffset = KMsgServiceNameOffset + KHtiMsgServiceUidLen; |
|
28 const int KMsgVersionOffset = KMsgBodySizeOffset+KMsgBodySizeLen; |
|
29 const int KMsgPriorityOffset = KMsgVersionOffset+1; |
|
30 const int KMsgWrapFlagOffset = KMsgPriorityOffset+1; |
|
31 const int KMsgExtSizeOffset = KMsgWrapFlagOffset+1; |
|
32 const int KMsgCrcOffset = KMsgExtSizeOffset+1; //two bytes field |
|
33 const int KMsgExtOffset = KMsgCrcOffset+2; |
|
34 const int KMsgHeaderMinSize = KMsgExtOffset; |
|
35 |
|
36 const BYTE KDefaultVersion = 1; |
|
37 |
|
38 //error message |
|
39 const int HtiErrCodeOffset = 1; |
|
40 const int HtiServiceErrCodeOffset = HtiErrCodeOffset + 1; |
|
41 const int HtiErrServiceUidOffset = HtiServiceErrCodeOffset + 4; |
|
42 const int HtiErrDescrOffset = HtiErrServiceUidOffset + 4; |
|
43 |
|
44 class HtiMessage |
|
45 { |
|
46 public: |
|
47 /** |
|
48 * Creates HTIMessage using given parameters and message body |
|
49 */ |
|
50 HtiMessage(DWORD serviceId, void* body, DWORD len, BYTE priority=0); |
|
51 |
|
52 /** |
|
53 * Creates HTIMessage parsing ready HTI message (with header) |
|
54 * message may contain only message beginning but should include valid |
|
55 * HTI header (see CheckValidHtiHeader()) |
|
56 * The rest of message can be added using AddToBody() |
|
57 */ |
|
58 HtiMessage(void* message, DWORD len); |
|
59 |
|
60 /** |
|
61 * Destructor |
|
62 */ |
|
63 ~HtiMessage(); |
|
64 |
|
65 /** |
|
66 * Add body parts if HTIMessage was constructed with incomplete data |
|
67 * Returns number of added bytes. |
|
68 */ |
|
69 DWORD AddToBody(void* data, DWORD len); |
|
70 |
|
71 inline bool IsMessageComplete(); |
|
72 inline int Reminder(); |
|
73 |
|
74 /** |
|
75 * Returns whole HTI message including header |
|
76 */ |
|
77 void* HtiData(); |
|
78 |
|
79 /** |
|
80 * |
|
81 */ |
|
82 DWORD HtiDataSize(); |
|
83 |
|
84 DWORD GetBodySize(); |
|
85 DWORD GetExtSize(); |
|
86 void* GetBody(); |
|
87 DWORD GetServiceUID(); |
|
88 |
|
89 /** |
|
90 * Attemt to read HTI header in provided data. |
|
91 * Pointer should reference to data at least MinHeaderSize() size. |
|
92 */ |
|
93 static bool CheckValidHtiHeader(void* header); |
|
94 |
|
95 /** |
|
96 * |
|
97 */ |
|
98 static DWORD ExtractMsgSizeFromHeader(void* header); |
|
99 |
|
100 /** |
|
101 * Returns minimal HTI message header |
|
102 */ |
|
103 static int MinHeaderSize(); |
|
104 |
|
105 //buit-in support for default error messages |
|
106 static HtiMessage* CreateErrorMessage(int errorCode, const char* errDescr); |
|
107 |
|
108 bool IsErrorMessage(); |
|
109 int HtiErrorCode(); |
|
110 int ServiceErrorCode(); |
|
111 char* ErrorDescription(); |
|
112 int ErrorServiceUid(); |
|
113 |
|
114 protected: |
|
115 int GetBodyStart(); |
|
116 |
|
117 DWORD m_Size; //size of whole message (inc. header) |
|
118 BYTE* m_Message; //whole message (inc. header) |
|
119 |
|
120 /** |
|
121 * Number of bytes left to copy to m_Message |
|
122 * Used when constructing message from data packages |
|
123 */ |
|
124 DWORD m_MessageReminderSize; |
|
125 //temp string for err descr with 0-ending |
|
126 char* m_ErrDescr; |
|
127 }; |
|
128 |
|
129 inline bool HtiMessage::IsMessageComplete(){return m_MessageReminderSize==0;} |
|
130 inline int HtiMessage::Reminder(){return m_MessageReminderSize;} |
|
131 |
|
132 #endif // |