2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FIo_IpcCommonParamTraits.h
19 * @brief This is the header file for common param traits.
22 #ifndef _FIO_INTERNAL_IPC_COMMON_PARAM_TRAITS_H_
23 #define _FIO_INTERNAL_IPC_COMMON_PARAM_TRAITS_H_
26 #include <base/tuple.h>
27 #include <ipc/ipc_param_traits.h>
29 #include <FBaseString.h>
30 #include <FBaseByteBuffer.h>
31 #include <FBaseColArrayList.h>
32 #include <FBaseColArrayListT.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::ArrayListT<Tizen::Base::String> >
202 typedef Tizen::Base::Collection::ArrayListT<Tizen::Base::String> param_type;
204 static void Write(Message* m, const param_type& p)
206 int count = p.GetCount();
207 Tizen::Base::String str;
209 WriteParam(m, count);
211 for (int i = 0; i < count; i++)
218 static bool Read(const Message* m, void** iter, param_type* r)
220 Tizen::Base::String str;
223 if (!m->ReadLength(iter, &count))
230 for (int i = 0; i < count; i++)
232 if (!ReadParam(m, iter, &str))
242 static void Log(const param_type& p, std::string* l)
248 struct ParamTraits <Tizen::Base::Collection::HashMap>
250 typedef Tizen::Base::Collection::HashMap param_type;
252 static void Write(Message* m, const param_type& p)
254 int count = p.GetCount();
255 const Tizen::Base::String* pType = NULL;
257 Tizen::Base::Collection::IList* pKeys = p.GetKeysN();
258 Tizen::Base::Collection::IList* pValues = p.GetValuesN();
260 WriteParam(m, count);
262 for (int i = 0; i < count; i++)
264 WriteParam(m, *(Tizen::Base::String*) pKeys->GetAt(i));
266 pType = dynamic_cast < const Tizen::Base::String* > (pValues->GetAt(i));
269 WriteParam(m, IPC_OBJECT_TYPE_STRING);
270 WriteParam(m, *pType);
274 WriteParam(m, IPC_OBJECT_TYPE_BYTE_BUFFER);
275 WriteParam(m, *(Tizen::Base::ByteBuffer*) pValues->GetAt(i));
283 static bool Read(const Message* m, void** iter, param_type* r)
285 Tizen::Base::String* pKey = null;
286 Tizen::Base::String* pStr = null;
287 Tizen::Base::ByteBuffer* pBuffer = null;
292 if (!m->ReadLength(iter, &count))
299 for (int i = 0; i < count; i++)
301 pKey = new Tizen::Base::String();
303 if (!ReadParam(m, iter, pKey))
309 m->ReadLength(iter, &type);
311 if (type == IPC_OBJECT_TYPE_STRING)
313 pStr = new Tizen::Base::String();
314 if (!ReadParam(m, iter, pStr))
321 r->Add(*pKey, *pStr);
325 pBuffer = new Tizen::Base::ByteBuffer();
326 if (!ReadParam(m, iter, pBuffer))
333 r->Add(*pKey, *pBuffer);
341 static void Log(const param_type& p, std::string* l)
347 struct ParamTraits <Tizen::Io::_IpcBuffer>
349 typedef Tizen::Io::_IpcBuffer param_type;
351 static void Write(Message* m, const param_type& p)
354 m->WriteBytes((void*) p.pBuffer, p.size);
357 static bool Read(const Message* m, void** iter, param_type* r)
359 const char* pBuffer = null;
361 if (!m->ReadLength(iter, &len))
366 m->ReadBytes(iter, &pBuffer, len);
369 r->pBuffer = malloc(len);
370 memcpy(r->pBuffer, pBuffer, len);
375 static void Log(const param_type& p, std::string* l)
382 #endif // _FIO_INTERNAL_CLIENT_CHANNEL_H_