Extract the detection into separate class for easy re-use in client library.
The detection method will get additional logic soon, so having it in one
place will be useful.
Change-Id: I561b582eb044bf8f6aa71f090d790c00b7bb3273
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
SET(CLIENT_SOURCES
${CLIENT_PATH}/client-security-manager.cpp
${CLIENT_PATH}/client-common.cpp
+ ${CLIENT_PATH}/client-offline.cpp
)
ADD_LIBRARY(${TARGET_CLIENT} SHARED ${CLIENT_SOURCES})
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Rafal Krypa <r.krypa@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
+ */
+/*
+ * @file client-offline.cpp
+ * @author Rafal Krypa <r.krypa@samsung.com>
+ * @version 1.0
+ * @brief Helper class for client "off-line" mode detection
+ */
+
+#include <dpl/log/log.h>
+#include "client-offline.h"
+
+namespace SecurityManager {
+
+ClientOffline::ClientOffline()
+{
+ offlineMode = false;
+ serviceLock = nullptr;
+ try {
+ serviceLock = new SecurityManager::FileLocker(SecurityManager::SERVICE_LOCK_FILE, false);
+ offlineMode = serviceLock->Locked();
+ } catch (...) {
+ /* Ignore exceptions, assume on-line */
+ }
+
+ if (offlineMode)
+ LogInfo("Working in off-line mode.");
+ else
+ LogInfo("Working in on-line mode.");
+}
+
+ClientOffline::~ClientOffline()
+{
+ if (serviceLock != nullptr)
+ delete serviceLock;
+}
+
+bool ClientOffline::isOffline(void)
+{
+ return offlineMode;
+}
+
+} // namespace SecurityManager
#include <client-common.h>
#include <protocols.h>
#include <service_impl.h>
-#include <file-lock.h>
-
#include <security-manager.h>
+#include <client-offline.h>
+
/**
* Mapping of lib_retcode error codes to theirs strings equivalents
if (p_req->appId.empty() || p_req->pkgId.empty())
return SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE;
- bool offlineMode;
int retval;
-
- try {
- SecurityManager::FileLocker serviceLock(SecurityManager::SERVICE_LOCK_FILE);
- if ((offlineMode = serviceLock.Locked())) {
- LogInfo("Working in offline mode.");
- retval = SecurityManager::ServiceImpl::appInstall(*p_req, geteuid());
- }
- } catch (const SecurityManager::FileLocker::Exception::Base &e) {
- offlineMode = false;
- }
- if (!offlineMode) {
+ ClientOffline offlineMode;
+ if (offlineMode.isOffline()) {
+ retval = SecurityManager::ServiceImpl::appInstall(*p_req, geteuid());
+ } else {
MessageBuffer send, recv;
//put data into buffer
int security_manager_user_add(const user_req *p_req)
{
using namespace SecurityManager;
- bool offlineMode;
- MessageBuffer send, recv;
if (!p_req)
return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+
return try_catch([&] {
int retval;
- try {
- SecurityManager::FileLocker serviceLock(SecurityManager::SERVICE_LOCK_FILE);
- if ((offlineMode = serviceLock.Locked())) {
- LogInfo("Working in offline mode.");
- retval = SecurityManager::ServiceImpl::userAdd(p_req->uid, p_req->utype, geteuid());
- }
- } catch (const SecurityManager::FileLocker::Exception::Base &e) {
- offlineMode = false;
- }
- if (!offlineMode) {
+ ClientOffline offlineMode;
+ if (offlineMode.isOffline()) {
+ retval = SecurityManager::ServiceImpl::userAdd(p_req->uid, p_req->utype, geteuid());
+ } else {
+ MessageBuffer send, recv;
//server is working
//put data into buffer
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Rafal Krypa <r.krypa@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
+ */
+/*
+ * @file client-common.h
+ * @author Rafal Krypa <r.krypa@samsung.com>
+ * @version 1.0
+ * @brief Helper class for client "off-line" mode detection
+ */
+
+#ifndef _SECURITY_MANAGER_OFFLINE_
+#define _SECURITY_MANAGER_OFFLINE_
+
+#include <file-lock.h>
+
+namespace SecurityManager {
+
+class ClientOffline {
+public:
+ ClientOffline();
+ ~ClientOffline();
+ bool isOffline(void);
+
+private:
+ bool offlineMode;
+ SecurityManager::FileLocker *serviceLock;
+};
+
+} // namespace SecurityManager
+
+#endif // _SECURITY_MANAGER_OFFLINE_