1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "BundleResource.h"
26 #include "InternalTypes.h"
32 BundleResource::BundleResource()
34 m_pNotiReceiver = nullptr;
37 BundleResource::~BundleResource()
39 m_pNotiReceiver = nullptr;
42 void BundleResource::registerObserver(NotificationReceiver *pNotiReceiver)
44 m_pNotiReceiver = pNotiReceiver;
47 std::list< std::string > BundleResource::getAttributeNames()
49 std::list< std::string > ret;
50 for (RCSResourceAttributes::iterator it = m_resourceAttributes.begin();
51 it != m_resourceAttributes.end(); ++it)
53 ret.push_back(it->key());
58 RCSResourceAttributes &BundleResource::getAttributes()
60 return m_resourceAttributes;
63 void BundleResource::setAttributes(RCSResourceAttributes &attrs, bool notify)
65 for (RCSResourceAttributes::iterator it = attrs.begin(); it != attrs.end(); ++it)
67 OC_LOG_V(INFO, "BUNDLE_RESOUCE", "set attribute \(%s)'",
68 std::string(it->key() + "\', with " + it->value().toString()).c_str());
70 m_resourceAttributes[it->key()] = it->value();
73 if (notify && m_pNotiReceiver)
74 m_pNotiReceiver->onNotificationReceived(m_uri);
77 void BundleResource::setAttributes(RCSResourceAttributes &attrs)
79 setAttributes(attrs, false);
82 void BundleResource::setAttribute(const std::string &key,
83 RCSResourceAttributes::Value &&value, bool notify)
85 OC_LOG_V(INFO, "BUNDLE_RESOUCE", "set attribute \(%s)'", std::string(key + "\', with " +
86 value.toString()).c_str());
88 m_resourceAttributes[key] = value;
90 if (notify && m_pNotiReceiver)
91 m_pNotiReceiver->onNotificationReceived(m_uri);
94 void BundleResource::setAttribute(const std::string &key, RCSResourceAttributes::Value &&value)
96 setAttribute(key, std::move(value), true);
99 RCSResourceAttributes::Value BundleResource::getAttribute(const std::string &key)
101 OC_LOG_V(INFO, "BUNDLE_RESOUCE", "get attribute \'(%s)" , std::string(key + "\'").c_str());
103 return m_resourceAttributes.at(key);