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 <FBaseColHashMap.h>
33 #include <FBaseSysLog.h>
34 #include "FIo_IpcCommonDataTypes.h"
39 const static int IPC_OBJECT_TYPE_STRING = 0;
40 const static int IPC_OBJECT_TYPE_BYTE_BUFFER = 1;
43 struct ParamTraits <Tizen::Base::String>
45 typedef Tizen::Base::String param_type;
47 static void Write(Message* m, const param_type& p)
49 int len = (p.GetLength() + 1) * sizeof(wchar_t);
51 m->WriteBytes((void*) p.GetPointer(), (p.GetLength() + 1) * sizeof(wchar_t));
54 static bool Read(const Message* m, void** iter, param_type* r)
56 const char* pStr = null;
59 if (!m->ReadLength(iter, &len))
64 m->ReadBytes(iter, &pStr, len);
66 r->Append((wchar_t*) pStr);
71 static void Log(const param_type& p, std::string* l)
77 struct ParamTraits <Tizen::Base::ByteBuffer>
79 typedef Tizen::Base::ByteBuffer param_type;
81 static void Write(Message* m, const param_type& p)
83 int capacity = p.GetCapacity();
85 m->WriteInt(capacity);
86 m->WriteBytes((void*) p.GetPointer(), capacity);
87 m->WriteInt(p.GetLimit());
88 m->WriteInt(p.GetPosition());
91 static bool Read(const Message* m, void** iter, param_type* r)
93 const byte* pByte = null;
97 if (!m->ReadLength(iter, &capacity))
101 r->Construct(capacity);
103 m->ReadBytes(iter, (const char**)&pByte, capacity);
104 r->SetArray(pByte, 0, capacity);
106 m->ReadLength(iter, &value);
107 if (r->SetLimit(value) != E_SUCCESS)
112 m->ReadLength(iter, &value);
113 r->SetPosition(value);
118 static void Log(const param_type& p, std::string* l)
124 struct ParamTraits <Tizen::Base::Collection::ArrayList>
126 typedef Tizen::Base::Collection::ArrayList param_type;
128 static void Write(Message* m, const param_type& p)
130 int count = p.GetCount();
131 const Tizen::Base::String* pType = NULL;
133 WriteParam(m, count);
135 for (int i = 0; i < count; i++)
137 pType = dynamic_cast < const Tizen::Base::String* > (p.GetAt(i));
140 WriteParam(m, IPC_OBJECT_TYPE_STRING);
141 WriteParam(m, *pType);
145 WriteParam(m, IPC_OBJECT_TYPE_BYTE_BUFFER);
146 WriteParam(m, *(Tizen::Base::ByteBuffer*) p.GetAt(i));
151 static bool Read(const Message* m, void** iter, param_type* r)
153 Tizen::Base::String* pStr = null;
154 Tizen::Base::ByteBuffer* pBuffer = null;
158 if (!m->ReadLength(iter, &count))
165 for (int i = 0; i < count; i++)
167 m->ReadLength(iter, &type);
168 if (type == IPC_OBJECT_TYPE_STRING)
170 pStr = new Tizen::Base::String;
171 if (!ReadParam(m, iter, pStr))
180 pBuffer = new Tizen::Base::ByteBuffer;
181 if (!ReadParam(m, iter, pBuffer))
193 static void Log(const param_type& p, std::string* l)
199 struct ParamTraits <Tizen::Base::Collection::HashMap>
201 typedef Tizen::Base::Collection::HashMap param_type;
203 static void Write(Message* m, const param_type& p)
205 int count = p.GetCount();
206 const Tizen::Base::String* pType = NULL;
208 Tizen::Base::Collection::IList* pKeys = p.GetKeysN();
209 Tizen::Base::Collection::IList* pValues = p.GetValuesN();
211 WriteParam(m, count);
213 for (int i = 0; i < count; i++)
215 WriteParam(m, *(Tizen::Base::String*) pKeys->GetAt(i));
217 pType = dynamic_cast < const Tizen::Base::String* > (pValues->GetAt(i));
220 WriteParam(m, IPC_OBJECT_TYPE_STRING);
221 WriteParam(m, *pType);
225 WriteParam(m, IPC_OBJECT_TYPE_BYTE_BUFFER);
226 WriteParam(m, *(Tizen::Base::ByteBuffer*) pValues->GetAt(i));
234 static bool Read(const Message* m, void** iter, param_type* r)
236 Tizen::Base::String* pKey = null;
237 Tizen::Base::String* pStr = null;
238 Tizen::Base::ByteBuffer* pBuffer = null;
243 if (!m->ReadLength(iter, &count))
250 for (int i = 0; i < count; i++)
252 pKey = new Tizen::Base::String();
254 if (!ReadParam(m, iter, pKey))
260 m->ReadLength(iter, &type);
262 if (type == IPC_OBJECT_TYPE_STRING)
264 pStr = new Tizen::Base::String();
265 if (!ReadParam(m, iter, pStr))
272 r->Add(*pKey, *pStr);
276 pBuffer = new Tizen::Base::ByteBuffer();
277 if (!ReadParam(m, iter, pBuffer))
284 r->Add(*pKey, *pBuffer);
292 static void Log(const param_type& p, std::string* l)
298 struct ParamTraits <Tizen::Io::_IpcBuffer>
300 typedef Tizen::Io::_IpcBuffer param_type;
302 static void Write(Message* m, const param_type& p)
305 m->WriteBytes((void*) p.pBuffer, p.size);
308 static bool Read(const Message* m, void** iter, param_type* r)
310 const char* pBuffer = null;
312 if (!m->ReadLength(iter, &len))
317 m->ReadBytes(iter, &pBuffer, len);
320 r->pBuffer = malloc(len);
321 memcpy(r->pBuffer, pBuffer, len);
326 static void Log(const param_type& p, std::string* l)
333 #endif // _FIO_INTERNAL_CLIENT_CHANNEL_H_