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 FShell_LockManagerProxy.cpp
19 * @brief This is the implementation for the _LockManagerProxy.cpp class.
24 #include <unique_ptr.h>
25 #include <FBaseErrors.h>
26 #include <FBaseSysLog.h>
28 #include <FIo_IpcClient.h>
30 #include "FShell_LockManagerIpcMessages.h"
31 #include "FShell_LockManagerProxy.h"
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Shell;
39 const char IPC_SERVER_NAME[] = "osp.shell.ipcserver.lockmanager";
42 namespace Tizen { namespace Shell
45 _LockManagerProxy* _LockManagerProxy::__pTheInstance = null;
47 _LockManagerProxy::_LockManagerProxy(void)
52 _LockManagerProxy::~_LockManagerProxy(void)
57 _LockManagerProxy::InitSingleton(void)
59 std::unique_ptr<_LockManagerProxy> pInst(new (std::nothrow) _LockManagerProxy());
60 SysTryReturnVoidResult(NID_SHELL, pInst, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
62 result r = pInst->Construct();
63 SysTryReturnVoidResult(NID_SHELL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
65 __pTheInstance = pInst.release();
66 std::atexit(DestroySingleton);
70 _LockManagerProxy::DestroySingleton(void)
72 delete __pTheInstance;
76 _LockManagerProxy::GetInstance(void)
78 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
79 if (__pTheInstance == null)
82 pthread_once(&onceBlock, InitSingleton);
83 result r = GetLastResult();
86 onceBlock = PTHREAD_ONCE_INIT;
89 return __pTheInstance;
93 _LockManagerProxy::Construct(void)
95 SysLog(NID_SHELL, "Enter.");
97 __pIpcClient = new (std::nothrow) _IpcClient();
98 SysTryReturnResult(NID_SHELL, __pIpcClient != null, E_OUT_OF_MEMORY, "_IpcClient creation failed.");
100 const int MAX_TRY_COUNT = 5;
101 const int TRY_SLEEP_TIME = 250;
106 result r = __pIpcClient->Construct(IPC_SERVER_NAME);
109 SysLog(NID_APP, "Succeeded in connecting service(%s)", IPC_SERVER_NAME);
113 SysTryReturn(NID_APP, count < MAX_TRY_COUNT, E_SYSTEM, r, "[%s] Failed to connect service.(%s)", GetErrorMessage(r), IPC_SERVER_NAME);
116 Tizen::Base::Runtime::Thread::Sleep(TRY_SLEEP_TIME);
119 SysLog(NID_SHELL, "Exit.");
124 _LockManagerProxy::Unlock(void)
126 SysTryReturnResult(NID_APP, __pIpcClient != null, E_INVALID_STATE, "__pIpcClient instance must not be null.");
128 result response = E_SUCCESS;
130 std::auto_ptr<IPC::Message> pMsg (new (std::nothrow) LockManager_Unlock(&response));
131 result r = __pIpcClient->SendRequest(*pMsg.get());
132 SysTryReturnResult(NID_APP, !IsFailed(r), r, "SendRequest is failed.");