tizen beta release
[framework/web/wrt-installer.git] / src / jobs / plugin_install / plugin_objects.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file    plugin_objects.h
18  * @author  Grzegorz Krawczyk (g.krawczyk@samgsung.com)
19  * @version
20  * @brief
21  */
22 #include <string>
23 #include <dpl/log/log.h>
24 #include "plugin_objects.h"
25
26 namespace {
27 const char* SEPARATOR = ".";
28 const std::string GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
29
30 std::string normalizeName(const std::string& objectName)
31 {
32     if (objectName.empty()) {
33         LogError("Normalize name, name size is 0");
34         return objectName;
35     }
36
37     if (!objectName.compare(0, GLOBAL_OBJECT_NAME.size(),
38                             GLOBAL_OBJECT_NAME)) {
39         return objectName;
40     }
41
42     //each object in storage has name started from $GLOBAL_OBJECT_NAME$
43     return GLOBAL_OBJECT_NAME + std::string(SEPARATOR) + objectName;
44 }
45
46 std::string normalizeName(const std::string& objectName,
47         const std::string& parentName)
48 {
49     if (objectName.empty() || parentName.empty()) {
50         LogError("Normalize name, name size or parent name size is 0");
51         return std::string();
52     }
53
54     std::string normalizedName;
55     normalizedName = normalizeName(parentName) +
56         std::string(SEPARATOR) + objectName;
57
58     return normalizedName;
59 }
60 }
61
62 PluginObjects::PluginObjects()
63 {
64     m_implemented = ObjectsPtr(new Objects());
65     m_dependent = ObjectsPtr(new Objects());
66 }
67
68 PluginObjects::ObjectsPtr PluginObjects::getImplementedObject() const
69 {
70     return m_implemented;
71 }
72
73 PluginObjects::ObjectsPtr PluginObjects::getDependentObjects() const
74 {
75     return m_dependent;
76 }
77
78 void PluginObjects::addObjects(const std::string& parentName,
79         const std::string& name)
80 {
81     addImplementedObject(normalizeName(name, parentName));
82     addDependentObject(normalizeName(parentName));
83 }
84
85 void PluginObjects::addDependentObject(const std::string& value)
86 {
87     if (!value.compare(GLOBAL_OBJECT_NAME)) {
88         //dont add dependency to GLOBAL_OBJECT
89         return;
90     }
91     m_dependent->insert(value);
92 }
93
94 bool PluginObjects::hasObject(const std::string& name) const
95 {
96     return m_implemented->find(name) != m_implemented->end();
97 }
98
99 void PluginObjects::addImplementedObject(const std::string& value)
100 {
101     m_implemented->insert(value);
102 }