4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include "ipc-library-build.h"
26 #include "ipc-param-list.h"
29 ipcEmailParamList::ipcEmailParamList()
31 EM_DEBUG_FUNC_BEGIN();
36 ipcEmailParamList::~ipcEmailParamList()
38 EM_DEBUG_FUNC_BEGIN();
39 EM_SAFE_FREE(m_pbyteStream);
44 /* +----------------------------------------------------------------------------------------------------------+ */
45 /* | API ID(4B) | Resp. ID (4B) | Param Count(4B) | Param1 Len | Param1 Data | ... | ParamN Len | ParamN data | */
46 /* +----------------------------------------------------------------------------------------------------------+ */
47 bool ipcEmailParamList::ParseStream(void* a_pStreamData)
49 EM_DEBUG_FUNC_BEGIN();
50 long nParameterCount = ParseParameterCount(a_pStreamData);
51 if(nParameterCount <= 0) {
52 EM_DEBUG_EXCEPTION("There is no parameter. ");
56 unsigned char* pStream = (unsigned char*)a_pStreamData;
57 long nIndex, nParamLen, nPos = sizeof(long)*eSTREAM_DATA;
58 /* _pal_ITrace_IPCPrintF("[IPCLib] Parameter Count [%x] ", nParameterCount); */
60 for(nIndex = 0; nIndex < nParameterCount; nIndex++) {
61 /* unsigned char szLen[5] = {NULL,}; */
62 /* memcpy(szLen, pStream+nPos, sizeof(long)); */
63 /* nParamLen = *(long*)(szLen); */
66 memcpy(&nLen, pStream+nPos, sizeof(long));
68 EM_DEBUG_LOG("Parameter Length [%d] : %d ", nIndex, nParamLen);
69 nPos += sizeof(long); /* Move from length position to data position */
71 AddParam((void*)(pStream+nPos), nParamLen);
72 nPos += nParamLen; /* move to next parameter */
78 void* ipcEmailParamList::GetStream()
80 EM_DEBUG_FUNC_BEGIN();
84 int nStreamLen = GetStreamLength();
86 if ( nStreamLen > 0 ) {
87 m_pbyteStream = (unsigned char*) calloc(1, nStreamLen);
88 int nPos = sizeof(long)*eSTREAM_COUNT;
90 if ( nPos + (int)sizeof(m_nParamCount) > nStreamLen ) {
91 EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + sizeof(m_nParamCount));
92 EM_SAFE_FREE(m_pbyteStream);
96 memcpy((void*)(m_pbyteStream+nPos), (void*)&m_nParamCount, sizeof(m_nParamCount));
99 int nIndex = 0, nLength = 0;
101 /* check memory overflow */
102 for(nIndex=0; nIndex<m_nParamCount; nIndex++) {
103 nLength = m_lstParams[nIndex].GetLength();
104 if ( nLength <= 0 ) {
105 EM_DEBUG_EXCEPTION("nLength = %d", nIndex, nLength);
106 EM_SAFE_FREE(m_pbyteStream);
110 if ( nPos + (int)sizeof(long) > nStreamLen ) {
111 EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + sizeof(long));
112 EM_SAFE_FREE(m_pbyteStream);
115 memcpy((void*)(m_pbyteStream+nPos), (void*)&nLength, sizeof(long));
116 nPos += sizeof(long);
118 if ( nPos + nLength > nStreamLen ) {
119 EM_DEBUG_EXCEPTION("%d > nStreamLen", nPos + nLength);
120 EM_SAFE_FREE(m_pbyteStream);
124 memcpy((void*)(m_pbyteStream+nPos), (void*)m_lstParams[nIndex].GetData(), nLength);
127 return (void*)m_pbyteStream;
130 EM_DEBUG_EXCEPTION("failed.");
131 EM_SAFE_FREE(m_pbyteStream);
138 int ipcEmailParamList::GetStreamLength()
140 /* if(m_lstParams ) // prevent 20071030 : m_lstParams is array */ {
141 int nLength = sizeof(long)*eSTREAM_DATA; /* API ID, Response ID, Param count */
143 for(nIndex=0; nIndex<m_nParamCount; nIndex++) {
144 nLength += sizeof(long); /* Length size */
145 nLength += m_lstParams[nIndex].GetLength(); /* data size */
152 bool ipcEmailParamList::AddParam(void* a_pData, int a_nLen)
154 EM_DEBUG_FUNC_BEGIN();
156 if(m_lstParams[m_nParamCount].SetParam(a_pData, a_nLen)) {
158 EM_SAFE_FREE(m_pbyteStream);
166 void* ipcEmailParamList::GetParam(int a_nIndex)
168 EM_DEBUG_FUNC_BEGIN("a_nIndex [%d]", a_nIndex);
169 if(a_nIndex < 0 || a_nIndex >= m_nParamCount) {
170 EM_DEBUG_EXCEPTION("Index value is not valid ");
174 return (void*)m_lstParams[a_nIndex].GetData();
177 int ipcEmailParamList::GetParamLen(int a_nIndex)
179 EM_DEBUG_FUNC_BEGIN();
180 if(a_nIndex < 0 || a_nIndex >= m_nParamCount) {
181 EM_DEBUG_EXCEPTION("Index value is not valid ");
185 return m_lstParams[a_nIndex].GetLength();
188 int ipcEmailParamList::GetParamCount()
190 EM_DEBUG_FUNC_BEGIN("Paramter count [%d] ", m_nParamCount);
191 return m_nParamCount;
194 long ipcEmailParamList::ParseParameterCount(void *a_pStream)
196 EM_DEBUG_FUNC_BEGIN();
197 long *pParameterCountPostion = (long*)a_pStream + eSTREAM_COUNT;
199 return *pParameterCountPostion;