Add a retry logic
[framework/appfw/message-port.git] / include / message-port-param-traits.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                message-port-param-traits.h
20  * @brief               This is the header file for message port param traits for IPC.
21  */
22
23 #ifndef _APPFW_MESSAGE_PORT_PARAM_TRAITS_H_
24 #define _APPFW_MESSAGE_PORT_PARAM_TRAITS_H_
25 #pragma once
26
27 #include <base/tuple.h>
28 #include <ipc/ipc_param_traits.h>
29
30 #include <bundle.h>
31
32 #include "message-port-data-types.h"
33
34 namespace IPC
35 {
36
37 template<>
38 struct ParamTraits <BundleBuffer>
39 {
40         typedef BundleBuffer param_type;
41
42         static void Write(Message* m, const param_type& p)
43         {
44                 int len = 0;
45                 bundle_raw* raw = NULL;
46                 bundle_encode_raw(p.b, &raw, &len);
47
48
49                 m->WriteInt(len);
50                 m->WriteBytes((const void*) raw, len);
51
52                 m->WriteInt(len);
53
54                 bundle_free_encoded_rawdata(&raw);
55         }
56
57         static bool Read(const Message* m, void** iter, param_type* r)
58         {
59                 int len = 0;
60                 const char* pBuffer = NULL;
61
62                 if (!m->ReadLength(iter, &len))
63                 {
64                         return false;
65                 }
66
67                 if (!m->ReadBytes(iter, &pBuffer, len))
68                 {
69                         return false;
70                 }
71
72                 if (!m->ReadLength(iter, &len))
73                 {
74                         return false;
75                 }
76
77                 if (pBuffer != NULL)
78                 {
79                         // Truncated
80                         ((char*)pBuffer)[len] = '\0';
81                 }
82                 else
83                 {
84                         return false;
85                 }
86
87                 r->b = bundle_decode_raw((const bundle_raw*)pBuffer, len);
88
89                 return true;
90         }
91
92         static void Log(const param_type& p, std::string* l)
93         {
94         }
95 };
96
97 }
98
99 #endif //_APPFW_MESSAGE_PORT_PARAM_TRAITS_H_