2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIo_IpcCommonParamTraits.h
20 * @brief This is the header file for common param traits.
23 #ifndef _FIO_INTERNAL_IPC_COMMON_PARAM_TRAITS_H_
24 #define _FIO_INTERNAL_IPC_COMMON_PARAM_TRAITS_H_
27 #include <base/tuple.h>
28 #include <ipc/ipc_param_traits.h>
30 #include <FBaseString.h>
31 #include <FBaseByteBuffer.h>
32 #include <FBaseColArrayList.h>
33 #include <FBaseColHashMap.h>
34 #include <FBaseSysLog.h>
35 #include "FIo_IpcCommonDataTypes.h"
40 const static int IPC_OBJECT_TYPE_STRING = 0;
41 const static int IPC_OBJECT_TYPE_BYTE_BUFFER = 1;
44 struct ParamTraits <Tizen::Base::String>
46 typedef Tizen::Base::String param_type;
48 static void Write(Message* m, const param_type& p)
50 int len = (p.GetLength() + 1) * sizeof(wchar_t);
52 m->WriteBytes((void*) p.GetPointer(), (p.GetLength() + 1) * sizeof(wchar_t));
55 static bool Read(const Message* m, void** iter, param_type* r)
57 const char* pStr = null;
60 if (!m->ReadLength(iter, &len))
65 m->ReadBytes(iter, &pStr, len);
67 r->Append((wchar_t*) pStr);
72 static void Log(const param_type& p, std::string* l)
78 struct ParamTraits <Tizen::Base::ByteBuffer>
80 typedef Tizen::Base::ByteBuffer param_type;
82 static void Write(Message* m, const param_type& p)
84 int capacity = p.GetCapacity();
86 m->WriteInt(capacity);
87 m->WriteBytes((void*) p.GetPointer(), capacity);
88 m->WriteInt(p.GetLimit());
89 m->WriteInt(p.GetPosition());
92 static bool Read(const Message* m, void** iter, param_type* r)
94 const byte* pByte = null;
98 if (!m->ReadLength(iter, &capacity))
102 r->Construct(capacity);
104 m->ReadBytes(iter, (const char**)&pByte, capacity);
105 r->SetArray(pByte, 0, capacity);
107 m->ReadLength(iter, &value);
108 if (r->SetLimit(value) != E_SUCCESS)
113 m->ReadLength(iter, &value);
114 r->SetPosition(value);
119 static void Log(const param_type& p, std::string* l)
125 struct ParamTraits <Tizen::Base::Collection::ArrayList>
127 typedef Tizen::Base::Collection::ArrayList param_type;
129 static void Write(Message* m, const param_type& p)
131 int count = p.GetCount();
132 const Tizen::Base::String* pType = NULL;
134 WriteParam(m, count);
136 for (int i = 0; i < count; i++)
138 pType = dynamic_cast < const Tizen::Base::String* > (p.GetAt(i));
141 WriteParam(m, IPC_OBJECT_TYPE_STRING);
142 WriteParam(m, *pType);
146 WriteParam(m, IPC_OBJECT_TYPE_BYTE_BUFFER);
147 WriteParam(m, *(Tizen::Base::ByteBuffer*) p.GetAt(i));
152 static bool Read(const Message* m, void** iter, param_type* r)
154 Tizen::Base::String* pStr = null;
155 Tizen::Base::ByteBuffer* pBuffer = null;
159 if (!m->ReadLength(iter, &count))
166 for (int i = 0; i < count; i++)
168 m->ReadLength(iter, &type);
169 if (type == IPC_OBJECT_TYPE_STRING)
171 pStr = new Tizen::Base::String;
172 if (!ReadParam(m, iter, pStr))
181 pBuffer = new Tizen::Base::ByteBuffer;
182 if (!ReadParam(m, iter, pBuffer))
194 static void Log(const param_type& p, std::string* l)
200 struct ParamTraits <Tizen::Base::Collection::HashMap>
202 typedef Tizen::Base::Collection::HashMap param_type;
204 static void Write(Message* m, const param_type& p)
206 int count = p.GetCount();
207 const Tizen::Base::String* pType = NULL;
209 Tizen::Base::Collection::IList* pKeys = p.GetKeysN();
210 Tizen::Base::Collection::IList* pValues = p.GetValuesN();
212 WriteParam(m, count);
214 for (int i = 0; i < count; i++)
216 WriteParam(m, *(Tizen::Base::String*) pKeys->GetAt(i));
218 pType = dynamic_cast < const Tizen::Base::String* > (pValues->GetAt(i));
221 WriteParam(m, IPC_OBJECT_TYPE_STRING);
222 WriteParam(m, *pType);
226 WriteParam(m, IPC_OBJECT_TYPE_BYTE_BUFFER);
227 WriteParam(m, *(Tizen::Base::ByteBuffer*) pValues->GetAt(i));
235 static bool Read(const Message* m, void** iter, param_type* r)
237 Tizen::Base::String* pKey = null;
238 Tizen::Base::String* pStr = null;
239 Tizen::Base::ByteBuffer* pBuffer = null;
244 if (!m->ReadLength(iter, &count))
251 for (int i = 0; i < count; i++)
253 pKey = new Tizen::Base::String();
255 if (!ReadParam(m, iter, pKey))
261 m->ReadLength(iter, &type);
263 if (type == IPC_OBJECT_TYPE_STRING)
265 pStr = new Tizen::Base::String();
266 if (!ReadParam(m, iter, pStr))
273 r->Add(*pKey, *pStr);
277 pBuffer = new Tizen::Base::ByteBuffer();
278 if (!ReadParam(m, iter, pBuffer))
285 r->Add(*pKey, *pBuffer);
293 static void Log(const param_type& p, std::string* l)
299 struct ParamTraits <Tizen::Io::_IpcBuffer>
301 typedef Tizen::Io::_IpcBuffer param_type;
303 static void Write(Message* m, const param_type& p)
306 m->WriteBytes((void*) p.pBuffer, p.size);
309 static bool Read(const Message* m, void** iter, param_type* r)
311 const char* pBuffer = null;
313 if (!m->ReadLength(iter, &len))
318 m->ReadBytes(iter, &pBuffer, len);
321 r->pBuffer = malloc(len);
322 memcpy(r->pBuffer, pBuffer, len);
327 static void Log(const param_type& p, std::string* l)
334 #endif // _FIO_INTERNAL_CLIENT_CHANNEL_H_