Update wrt-plugins-common_0.3.60
[platform/framework/web/wrt-plugins-common.git] / src / plugins-installer / 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 #include <IObject.h>
26
27 namespace {
28 const char* SEPARATOR = ".";
29 const std::string GLOBAL_OBJECT_NAME = WrtPluginsApi::IObject::WINDOW_OBJECT();
30
31 std::string normalizeName(const std::string& objectName)
32 {
33     if (objectName.empty()) {
34         LogError("Normalize name, name size is 0");
35         return objectName;
36     }
37
38     if (!objectName.compare(0, GLOBAL_OBJECT_NAME.size(),
39                             GLOBAL_OBJECT_NAME)) {
40         return objectName;
41     }
42
43     //each object in storage has name started from $GLOBAL_OBJECT_NAME$
44     return GLOBAL_OBJECT_NAME + std::string(SEPARATOR) + objectName;
45 }
46
47 std::string normalizeName(const std::string& objectName,
48         const std::string& parentName)
49 {
50     if (objectName.empty() || parentName.empty()) {
51         LogError("Normalize name, name size or parent name size is 0");
52         return std::string();
53     }
54
55     std::string normalizedName;
56     normalizedName = normalizeName(parentName) +
57         std::string(SEPARATOR) + objectName;
58
59     return normalizedName;
60 }
61 }
62
63 PluginObjects::PluginObjects()
64 {
65     m_implemented = ObjectsPtr(new Objects());
66     m_dependent = ObjectsPtr(new Objects());
67 }
68
69 PluginObjects::ObjectsPtr PluginObjects::getImplementedObject() const
70 {
71     return m_implemented;
72 }
73
74 PluginObjects::ObjectsPtr PluginObjects::getDependentObjects() const
75 {
76     return m_dependent;
77 }
78
79 void PluginObjects::addObjects(const std::string& parentName,
80         const std::string& name)
81 {
82     LogDebug("\n Parent: "  << parentName
83              << "\n Name: " << name
84             << "\n After: Implemented: "  << normalizeName(name, parentName)
85              << "\n After Dependent: " << normalizeName(parentName)
86              );
87
88     addImplementedObject(normalizeName(name, parentName));
89     addDependentObject(normalizeName(parentName));
90 }
91
92 void PluginObjects::addDependentObject(const std::string& value)
93 {
94     if (!value.compare(GLOBAL_OBJECT_NAME)) {
95         //dont add dependency to GLOBAL_OBJECT
96         return;
97     }
98     m_dependent->insert(value);
99 }
100
101 bool PluginObjects::hasObject(const std::string& name) const
102 {
103     return m_implemented->find(name) != m_implemented->end();
104 }
105
106 void PluginObjects::addImplementedObject(const std::string& value)
107 {
108     m_implemented->insert(value);
109 }