115051a29814a49a5f94ec5c6dd915342838378c
[platform/core/security/security-manager.git] / src / client / client-offline.cpp
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *  Contact: Rafal Krypa <r.krypa@samsung.com>
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License
17  */
18 /*
19  * @file        client-offline.cpp
20  * @author      Rafal Krypa <r.krypa@samsung.com>
21  * @version     1.0
22  * @brief       Helper class for client "off-line" mode detection
23  */
24
25 #include <dpl/log/log.h>
26 #include "client-offline.h"
27
28 namespace SecurityManager {
29
30 ClientOffline::ClientOffline()
31 {
32     offlineMode = false;
33     serviceLock = nullptr;
34     try {
35         serviceLock = new SecurityManager::FileLocker(SecurityManager::SERVICE_LOCK_FILE, false);
36         offlineMode = serviceLock->Locked();
37     } catch (...) {
38         /* Ignore exceptions, assume on-line */
39     }
40
41     if (offlineMode)
42         LogInfo("Working in off-line mode.");
43     else
44         LogInfo("Working in on-line mode.");
45 }
46
47 ClientOffline::~ClientOffline()
48 {
49     if (serviceLock != nullptr)
50         delete serviceLock;
51 }
52
53 bool ClientOffline::isOffline(void)
54 {
55     return offlineMode;
56 }
57
58 } // namespace SecurityManager