summaryrefslogtreecommitdiff
path: root/ipc/stub/ipc-stub-main.cpp
blob: 454e6a03f4945c6b6b25d9e597a555c51563d77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
*  email-service
*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/



#include "ipc-stub-main.h"
#include "ipc-library.h"
#include "ipc-response-info.h"
#include "ipc-param-list.h"
#include "ipc-library-build.h"


ipcEmailStubMain* ipcEmailStubMain::s_pThis = NULL;

ipcEmailStubMain::ipcEmailStubMain()
{
	EM_DEBUG_FUNC_BEGIN();
	m_pfnAPIMapper = NULL;
	m_pStubSocket = NULL;
	m_pMsgSender = NULL;
	m_pResponseList = NULL;
	EM_DEBUG_FUNC_END();
}

ipcEmailStubMain::~ipcEmailStubMain()
{
	EM_DEBUG_FUNC_BEGIN();
	Finalize();
	EM_DEBUG_FUNC_END();
}


ipcEmailStubMain* ipcEmailStubMain::Instance()
{
	EM_DEBUG_FUNC_BEGIN();
	if(s_pThis)
		return s_pThis;

	s_pThis = new ipcEmailStubMain();	
	EM_DEBUG_FUNC_END();
	return s_pThis;
}

void ipcEmailStubMain::FreeInstance()
{
	EM_DEBUG_FUNC_BEGIN();
	if(s_pThis) {
		delete s_pThis;
		s_pThis = NULL;
	}
	EM_DEBUG_FUNC_END();
}

bool ipcEmailStubMain::Initialize(PFN_EXECUTE_API a_pfnAPIMapper)
{
	EM_DEBUG_FUNC_BEGIN();
	m_pfnAPIMapper = a_pfnAPIMapper;

	if(!a_pfnAPIMapper || m_pStubSocket) {
		EM_DEBUG_EXCEPTION("Invalid Param");
		return false;
	}

	m_pfnAPIMapper = a_pfnAPIMapper;

	m_pResponseList = new cmList();
	if(!m_pResponseList) {
		EM_DEBUG_EXCEPTION("m_pResponseList == NULL\n");
		return false;
	}

	m_pMsgSender = new cmSysMsgQueue(0);
	if(!m_pMsgSender) {
		EM_DEBUG_EXCEPTION("m_pMsgSender == NULL\n");
		return false;
	}
	m_pMsgSender->MsgCreate();

	m_pStubSocket = new ipcEmailStubSocket;
	
	if(m_pStubSocket) {
		return m_pStubSocket->Start();
	} else {
		EM_DEBUG_EXCEPTION("m_pStubSocket == NULL\n");
		return false;
	}
	EM_DEBUG_FUNC_END();
	return false;
}

bool ipcEmailStubMain::Finalize()
{
	EM_DEBUG_FUNC_BEGIN();

	if(m_pResponseList) {
		int nIndex;
		for(nIndex = 0; nIndex<m_pResponseList->GetCount(); nIndex++) {
			ipcEmailResponseInfo *pResponseInfo = (ipcEmailResponseInfo *)m_pResponseList->GetAt(nIndex);
			if(pResponseInfo)
				m_pResponseList->RemoveItem(pResponseInfo);
		}
		delete m_pResponseList;
	}
	if(m_pMsgSender) {
		m_pMsgSender->MsgDestroy();
		m_pMsgSender = NULL;
	}
	
	if(m_pStubSocket) {
		m_pStubSocket->End();
		delete m_pStubSocket;
		m_pStubSocket = NULL;
	}
	
	if(m_pfnAPIMapper)
		m_pfnAPIMapper = NULL;
		
	EM_DEBUG_FUNC_END();
	return true;
}

bool ipcEmailStubMain::ExecuteAPIProxyToStub(ipcEmailAPIInfo *a_pAPI)
{
	EM_DEBUG_FUNC_BEGIN();
	if(!m_pfnAPIMapper || !a_pAPI) {
		EM_DEBUG_EXCEPTION("Invalid Param");
		return false;
	}
	
	m_pfnAPIMapper(a_pAPI);
	EM_DEBUG_FUNC_END();
	return true;
}

bool ipcEmailStubMain::ExecuteAPIStubToProxy(ipcEmailAPIInfo *a_pAPI)
{
	EM_DEBUG_FUNC_BEGIN("a_pAPI [%p]", a_pAPI);
	EM_IF_NULL_RETURN_VALUE(a_pAPI, false);
	EM_DEBUG_LOG("APIID [%s], Response SockID [%d], APPID [%d]", EM_APIID_TO_STR(a_pAPI->GetAPIID()), a_pAPI->GetResponseID(), a_pAPI->GetAPPID());
	
	unsigned char* pStream = (unsigned char*)a_pAPI->GetStream(ePARAMETER_OUT);
	int nStreamLength = a_pAPI->GetStreamLength(ePARAMETER_OUT);
	EM_DEBUG_LOG("Data : %p, Data length : %dB",pStream, nStreamLength);
	EM_DEBUG_LOG("Stub => Proxy Sending %dB", nStreamLength);
	m_pStubSocket->Send(a_pAPI->GetResponseID(), pStream, nStreamLength);

#ifdef IPCLIB_STREAM_TRACE_ON
	int nIndex;
	for(nIndex=0; nIndex< nStreamLength; nIndex++)
		EM_DEBUG_LOG("pStream[nIndex] :[%d]", pStream[nIndex]);
#endif

	EM_DEBUG_FUNC_END();
	return true;
}

bool ipcEmailStubMain::SetResponseInfo( long a_nAPPID, long a_nAPIID)
{
	EM_DEBUG_FUNC_BEGIN("ResponseID [%d]", a_nAPPID);

	if(a_nAPPID <= 0)	
		return true;

	ipcEmailResponseInfo *pResponseInfo = new ipcEmailResponseInfo();
	if(pResponseInfo) {
		pResponseInfo->SetVaue(a_nAPPID, a_nAPIID);
		m_pResponseList->AddTail(pResponseInfo);
		return true;
	}
	EM_DEBUG_FUNC_END();
	return false;
}