diff options
Diffstat (limited to 'ipc/proxy')
-rwxr-xr-x | ipc/proxy/include/ipc-callback-info.h | 48 | ||||
-rwxr-xr-x | ipc/proxy/include/ipc-proxy-main.h | 66 | ||||
-rwxr-xr-x | ipc/proxy/include/ipc-proxy-socket.h | 48 | ||||
-rwxr-xr-x | ipc/proxy/ipc-callback-info.cpp | 52 | ||||
-rwxr-xr-x | ipc/proxy/ipc-proxy-main.cpp | 199 | ||||
-rwxr-xr-x | ipc/proxy/ipc-proxy-socket.cpp | 161 |
6 files changed, 574 insertions, 0 deletions
diff --git a/ipc/proxy/include/ipc-callback-info.h b/ipc/proxy/include/ipc-callback-info.h new file mode 100755 index 0000000..0af5b7d --- /dev/null +++ b/ipc/proxy/include/ipc-callback-info.h @@ -0,0 +1,48 @@ +/* +* 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. +* +*/ + + +#ifndef _IPC_CALLBACK_INFO_H_ +#define _IPC_CALLBACK_INFO_H_ + + +class ipcEmailAPIInfo; + + +class ipcEmailCallbackInfo +{ +public: + ipcEmailCallbackInfo(); + virtual ~ipcEmailCallbackInfo(); + +private: + int m_nAPIID; + void *m_pfnCallBack; + +public: + bool SetValue(int m_nAPIID, void* a_pfnCallBack); + int GetAPIID(); + void* GetCallBack(); +}; + +#endif /* _IPC_CALLBACK_INFO_H_ */ + + diff --git a/ipc/proxy/include/ipc-proxy-main.h b/ipc/proxy/include/ipc-proxy-main.h new file mode 100755 index 0000000..268d2a2 --- /dev/null +++ b/ipc/proxy/include/ipc-proxy-main.h @@ -0,0 +1,66 @@ +/* +* 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. +* +*/ + + + +#ifndef _IPC_PROXY_MAIN_H_ +#define _IPC_PROXY_MAIN_H_ + +#include "ipc-library.h" +#include <pthread.h> +#include "cm-list.h" +#include "cm-sys-msg-queue.h" +#include "ipc-api-info.h" +#include "ipc-proxy-socket.h" +#include "ipc-callback-info.h" +#include "emf-mutex.h" + + +class ipcEmailProxyMain +{ +public: + ipcEmailProxyMain(); + virtual ~ipcEmailProxyMain(); + +private: + static ipcEmailProxyMain* s_pThis; + int m_nReference; + ipcEmailProxySocket *m_pSyncSocket; + bool m_bRecvStopFlag; + cmSysMsgQueue *m_pProxyMessageQ; + int m_nAPPID; + Mutex mx; + +private: + bool RegisterTask(ipcEmailAPIInfo *a_pApiInfo); + +public: + + static ipcEmailProxyMain* Instance(); + static void FreeInstance(); + int Initialize(); + int Finalize(); + bool ExecuteAPI(ipcEmailAPIInfo* pApi); + bool Dispatch(); + +}; +#endif/* _IPC_PROXY_MAIN_H_ */ + diff --git a/ipc/proxy/include/ipc-proxy-socket.h b/ipc/proxy/include/ipc-proxy-socket.h new file mode 100755 index 0000000..bcca207 --- /dev/null +++ b/ipc/proxy/include/ipc-proxy-socket.h @@ -0,0 +1,48 @@ +/* +* 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. +* +*/ + + + +#ifndef _IPC_PROXY_SOCKET_H_ +#define _IPC_PROXY_SOCKET_H_ +#include "ipc-socket.h" +#include "emf-dbglog.h" + +class ipcEmailProxySocket +{ + public: + ipcEmailProxySocket(); + virtual ~ipcEmailProxySocket(); + + private: + fd_set fds_read; + ipcEmailSocket *m_pSocket; + public: + int Start(); + bool End(); + int Send(char* pData , int a_nLen ); + int Recv(char** pData); + int GetSocketID(); +}; + +#endif /* _IPC_PROXY_SOCKET_H_ */ + + diff --git a/ipc/proxy/ipc-callback-info.cpp b/ipc/proxy/ipc-callback-info.cpp new file mode 100755 index 0000000..e89d22b --- /dev/null +++ b/ipc/proxy/ipc-callback-info.cpp @@ -0,0 +1,52 @@ +/* +* 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-callback-info.h" + +ipcEmailCallbackInfo::ipcEmailCallbackInfo() +{ + m_nAPIID = 0; + m_pfnCallBack = 0; +} + +ipcEmailCallbackInfo::~ipcEmailCallbackInfo() +{ +} + + +bool ipcEmailCallbackInfo::SetValue(int a_nAPIID, void* a_pfnCallBack) +{ + m_nAPIID = a_nAPIID; + m_pfnCallBack = a_pfnCallBack; + return true; +} + +int ipcEmailCallbackInfo::GetAPIID() +{ + return m_nAPIID; +} + +void* ipcEmailCallbackInfo::GetCallBack() +{ + return m_pfnCallBack; +} diff --git a/ipc/proxy/ipc-proxy-main.cpp b/ipc/proxy/ipc-proxy-main.cpp new file mode 100755 index 0000000..7490033 --- /dev/null +++ b/ipc/proxy/ipc-proxy-main.cpp @@ -0,0 +1,199 @@ +/* +* 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 <unistd.h> +#include "ipc-library-build.h" +#include "ipc-proxy-main.h" +#include "emf-types.h" + +ipcEmailProxyMain* ipcEmailProxyMain::s_pThis = NULL; + +ipcEmailProxyMain::ipcEmailProxyMain() : mx() +{ + EM_DEBUG_FUNC_BEGIN(); + m_pSyncSocket = NULL; + m_pProxyMessageQ = NULL; + m_bRecvStopFlag = false; + m_nReference = 0; + m_nAPPID = 0; + EM_DEBUG_FUNC_END(); +} + +ipcEmailProxyMain::~ipcEmailProxyMain() +{ + EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_FUNC_END(); +} + +ipcEmailProxyMain* ipcEmailProxyMain::Instance() +{ + EM_DEBUG_FUNC_BEGIN(); + if(s_pThis) + return s_pThis; + + s_pThis = new ipcEmailProxyMain(); + + EM_DEBUG_FUNC_END(); + return s_pThis; +} + +void ipcEmailProxyMain::FreeInstance() +{ + EM_DEBUG_FUNC_BEGIN(); + + if(s_pThis) { + s_pThis->Finalize(); + delete s_pThis; + s_pThis = NULL; + } + EM_DEBUG_FUNC_END(); +} + +int ipcEmailProxyMain::Initialize() +{ + EM_DEBUG_FUNC_BEGIN(); + + if (m_nReference > 0) { + EM_DEBUG_EXCEPTION("Already Initialized m_nReference[%d]", m_nReference); + return EMF_ERROR_NONE; + } + + m_nReference++; + + m_pSyncSocket = new ipcEmailProxySocket(); + + if(!m_pSyncSocket) { + EM_DEBUG_EXCEPTION("m_pSyncSocket == NULL"); + return EMF_ERROR_IPC_SOCKET_FAILURE; + } + + if( m_pSyncSocket->Start() != EMF_SUCCESS ) { + EM_DEBUG_EXCEPTION("Socket start FAILs"); + return EMF_ERROR_IPC_CONNECTION_FAILURE; + } + + EM_DEBUG_LOG("Socket ID : %x", m_pSyncSocket->GetSocketID()); + EM_DEBUG_FUNC_END(); + return EMF_ERROR_NONE; +} + +int ipcEmailProxyMain::Finalize() +{ + EM_DEBUG_FUNC_BEGIN(); + + if (--m_nReference > 0) { + EM_DEBUG_EXCEPTION("More than one reference m_nReference[%d]",m_nReference); + return EMF_ERROR_NONE; + } + + if(m_pSyncSocket) { + delete m_pSyncSocket; + m_pSyncSocket = NULL; + } + + if(m_pProxyMessageQ) { + delete m_pProxyMessageQ; + m_pProxyMessageQ = NULL; + } + EM_DEBUG_FUNC_END(); + return EMF_ERROR_NONE; +} + + +bool ipcEmailProxyMain::ExecuteAPI(ipcEmailAPIInfo* a_hAPI) +{ + EM_DEBUG_FUNC_BEGIN(); + + if(!a_hAPI) { + EM_DEBUG_EXCEPTION("Invalid Parameter"); + return false; + } + + int nRet; + char* pInStream = (char*)a_hAPI->GetStream(ePARAMETER_IN); + int nLength = a_hAPI->GetStreamLength(ePARAMETER_IN); + bool result = false; + int sending_bytes; + + mx.lock(); + sending_bytes = m_pSyncSocket->Send(pInStream, nLength); + mx.unlock(); + + EM_DEBUG_LOG("Proxy=>Stub Sending %dB.", sending_bytes); + + if( sending_bytes > 0 ) { +#ifdef IPCLIB_STREAM_TRACE_ON + int index; + for(index=0; index< nLength; index++) + EM_DEBUG_LOG("pInStream[index] : [%x]", pInStream[index]); +#endif + + char* ipc_buf = NULL; + + /* now waiting for response from email-service */ + mx.lock(); + nRet = m_pSyncSocket->Recv(&ipc_buf); + mx.unlock(); + EM_DEBUG_LOG("Recv length : %d", nRet); + + if (nRet > 0) + result = a_hAPI->ParseStream(ePARAMETER_OUT, ipc_buf); + else + result = false; + + if(ipc_buf) + delete []ipc_buf; + } + + EM_DEBUG_FUNC_END(); + return result; +} + +bool ipcEmailProxyMain::Dispatch() +{ + EM_DEBUG_FUNC_BEGIN(); + + unsigned char pStream[IPC_MSGQ_SIZE]; + + while(!m_bRecvStopFlag) { + memset(pStream, 0x00, sizeof(pStream)); + + if(m_pProxyMessageQ->MsgRcv(pStream, sizeof(pStream))>0) { + ipcEmailAPIInfo *pAPIInfo = new ipcEmailAPIInfo(); + int nAPIID = *((int*)pStream); + + pAPIInfo->SetAPIID(nAPIID); + pAPIInfo->ParseStream(ePARAMETER_OUT, pStream); + EM_DEBUG_LOG("Proxy Message Queue Recv [APIID=%x], [RecvLen=%d]", nAPIID, pAPIInfo->GetStreamLength(ePARAMETER_OUT)); + +#ifdef IPCLIB_STREAM_TRACE_ON + int index; + for(index=0; index< pAPIInfo->GetStreamLength(ePARAMETER_OUT); index++) + EM_DEBUG_LOG("[%x]", pStream[index]); +#endif + } + usleep(1000); + } + EM_DEBUG_FUNC_END(); + return false; +} diff --git a/ipc/proxy/ipc-proxy-socket.cpp b/ipc/proxy/ipc-proxy-socket.cpp new file mode 100755 index 0000000..44507a9 --- /dev/null +++ b/ipc/proxy/ipc-proxy-socket.cpp @@ -0,0 +1,161 @@ +/* +* 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 <unistd.h> +#include <sys/select.h> +#include "ipc-library-build.h" +#include "ipc-proxy-socket.h" + +ipcEmailProxySocket::ipcEmailProxySocket() +{ + EM_DEBUG_FUNC_BEGIN(); + memset(&fds_read, 0, sizeof(fd_set));/* CID = 17042 BU */ + m_pSocket = NULL; +} + +ipcEmailProxySocket::~ipcEmailProxySocket() +{ + EM_DEBUG_FUNC_BEGIN(); + End(); +} + +int ipcEmailProxySocket::Start() +{ + EM_DEBUG_FUNC_BEGIN(); + m_pSocket = new ipcEmailSocket(); + + if(m_pSocket) { + return m_pSocket->Connect(); + } + + return -1; +} + +bool ipcEmailProxySocket::End() +{ + EM_DEBUG_FUNC_BEGIN(); + EM_DEBUG_LOG("[IPCLib] ipcEmailProxySocket::End "); + + if(m_pSocket) { + m_pSocket->Close(); /* prevent 20071030 */ + delete(m_pSocket); + m_pSocket = NULL; + } + + return true; +} + +int ipcEmailProxySocket::Send(char* pData , int a_nLen) +{ + EM_DEBUG_FUNC_BEGIN(); + if(m_pSocket && m_pSocket->IsConnected()) { + return m_pSocket->Send(m_pSocket->GetSocketID(), pData, a_nLen); + } else { + EM_DEBUG_EXCEPTION("[IPCLib] ipcEmailProxySocket not connect"); + /* m_pSocket->Connect(); */ + return 0; + } +} + +int ipcEmailProxySocket::GetSocketID() +{ + EM_DEBUG_FUNC_BEGIN(); + if(m_pSocket) + return m_pSocket->GetSocketID(); + + return 0; +} + + +int ipcEmailProxySocket::Recv(char** pData) +{ + EM_DEBUG_FUNC_BEGIN(); + + + int nRecvLen = 0; + + if(m_pSocket /*&& m_pSocket->IsConnected()*/) + nRecvLen = m_pSocket->Recv(m_pSocket->GetSocketID(), pData); else { + EM_DEBUG_EXCEPTION("[IPCLib] m_pSocket[%p] is not available or disconnected", m_pSocket); + return 0; + } + + if( nRecvLen == 0 ) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv delete %x", m_pSocket->GetSocketID()); + m_pSocket->Close(); + } else if(nRecvLen == -1) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv error"); + } + + return nRecvLen; +/* + int ret_select; + fd_set fds_buf; + int nRecvLen = -2, timeout_count = 0; + struct timeval timeout; + + while(1) { + fds_buf = fds_read; + + FD_ZERO(&fds_buf); + + FD_SET(m_pSocket->GetSocketID(), &fds_buf); + timeout.tv_sec = 0; + timeout.tv_usec = 1000000; + ret_select = select(m_pSocket->GetSocketID()+1, &fds_buf, NULL, NULL, &timeout); + + if(ret_select == -1) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy select error"); + break; + } else if(ret_select == 0) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy select timeout"); + + if(timeout_count++ > 10) { + EM_DEBUG_EXCEPTION("[IPCLib] exit from select loop"); + break; + } + continue; + } + + if(FD_ISSET(m_pSocket->GetSocketID(), &fds_buf)) { + nRecvLen = m_pSocket->Recv(m_pSocket->GetSocketID(), pData); + if(nRecvLen > 0) { + EM_DEBUG_LOG("[IPCLib] Proxy Recv[fd = %x], [nRecvLen = %d]", m_pSocket->GetSocketID(), nRecvLen); + break; + } + else if(nRecvLen == 0) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv delete %x", m_pSocket->GetSocketID()); + m_pSocket->Close(); + break; + } + else if(nRecvLen == -1) { + EM_DEBUG_EXCEPTION("[IPCLib] Proxy Recv error"); + break; + } + } + + } +*/ + return nRecvLen; + +} |