Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / service / scene-manager / src / SceneCollection.cpp
1 //******************************************************************
2 //
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "SceneCollection.h"
22
23 #include "SceneCollectionResource.h"
24
25 namespace OIC
26 {
27     namespace Service
28     {
29         SceneCollection::SceneCollection(
30                 const SceneCollectionResource::Ptr& sceneCollectionResource) :
31                 m_sceneCollectionResource(sceneCollectionResource) {}
32
33         Scene::Ptr SceneCollection::addNewScene(const std::string& sceneName)
34         {
35             if(sceneName.empty())
36             {
37                 throw RCSInvalidParameterException("Scene name is an empty string");
38             }
39
40             m_sceneCollectionResource->addScene(sceneName);
41
42             return Scene::Ptr(new Scene(sceneName, m_sceneCollectionResource));
43         }
44
45         std::unordered_map< std::string, Scene::Ptr > SceneCollection::getScenes() const
46         {
47             std::unordered_map< std::string, Scene::Ptr > scenes;
48
49             for(const auto &it : m_sceneCollectionResource->getSceneValues())
50             {
51                 Scene::Ptr scenePtr(new Scene(it, m_sceneCollectionResource));
52                 scenes.insert(std::pair< std::string, Scene::Ptr >(it, scenePtr));
53             }
54             return scenes;
55         }
56
57         Scene::Ptr SceneCollection::getScene(const std::string& sceneName) const
58         {
59             auto sceneValues = m_sceneCollectionResource->getSceneValues();
60             auto it = std::find(sceneValues.begin(), sceneValues.end(), sceneName);
61             if(it == sceneValues.end())
62             {
63                 throw RCSInvalidParameterException("Scene Name is Invalid!");
64             }
65             return Scene::Ptr(new Scene(sceneName, m_sceneCollectionResource));
66         }
67
68         void SceneCollection::setName(const std::string& name)
69         {
70             m_sceneCollectionResource->setName(name);
71         }
72
73         std::string SceneCollection::getName() const
74         {
75             return m_sceneCollectionResource->getName();
76         }
77
78         std::string SceneCollection::getId() const
79         {
80             return m_sceneCollectionResource->getId();
81         }
82
83     } /* namespace Service */
84 } /* namespace OIC */
85