2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This file contains classes that implement WRT_INTERFACE.h interfaces,
19 * so that ACE could access WRT specific and other information during
20 * the decision making.
22 * @file attribute_.cpp
23 * @author Jaroslaw Osmanski (j.osmanski@samsung.com)
24 * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
25 * @author Ming Jin(ming79.jin@samsung.com)
27 * @brief Implementation file for attributes obtaining.
30 #include <dpl/exception.h>
39 #include <ace-dao-ro/AceDAOReadOnly.h>
40 #include <ace/WRT_INTERFACE.h>
42 #include <dpl/log/log.h>
43 #include <dpl/foreach.h>
44 #include <attribute_facade.h>
45 #include <ace/Request.h>
46 #include <simple_roaming_agent.h>
48 namespace // anonymous
50 typedef std::list<std::string> AttributeHandlerResponse;
52 typedef AttributeHandlerResponse (*AttributeHandler)(
53 const WidgetExecutionPhase &phase,
54 const WidgetHandle &widgetHandle);
55 typedef AttributeHandlerResponse (*ResourceAttributeHandler)(
56 const WidgetExecutionPhase &phase,
57 const WidgetHandle &widgetHandle,
58 const Request &request);
60 AttributeHandlerResponse AttributeClassHandler(const WidgetExecutionPhase & /*phase*/,
61 const WidgetHandle & /*widgetHandle*/)
63 AttributeHandlerResponse response;
64 response.push_back("widget");
68 AttributeHandlerResponse AttributeInstallUriHandler(
69 const WidgetExecutionPhase & /*phase*/,
70 const WidgetHandle &widgetHandle)
72 AttributeHandlerResponse response;
73 std::string value = AceDB::AceDAOReadOnly::getShareHref(widgetHandle);
75 response.push_back(value);
79 AttributeHandlerResponse AttributeVersionHandler(const WidgetExecutionPhase & /*phase*/,
80 const WidgetHandle &widgetHandle)
82 AttributeHandlerResponse response;
84 std::string value = AceDB::AceDAOReadOnly::getVersion(widgetHandle);
87 response.push_back(value);
93 AttributeHandlerResponse AttributeDistributorKeyCnHandler(
94 const WidgetExecutionPhase & /*phase*/,
95 const WidgetHandle &widgetHandle)
97 AttributeHandlerResponse response;
98 response = AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
99 AceDB::WidgetCertificateData::DISTRIBUTOR, AceDB::WidgetCertificateData::ENDENTITY);
103 AttributeHandlerResponse AttributeDistributorKeyFingerprintHandler(
104 const WidgetExecutionPhase & /*phase*/,
105 const WidgetHandle &widgetHandle)
107 AttributeHandlerResponse response;
108 response = AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
109 AceDB::WidgetCertificateData::DISTRIBUTOR, AceDB::WidgetCertificateData::ENDENTITY);
113 AttributeHandlerResponse AttributeDistributorKeyRootCnHandler(
114 const WidgetExecutionPhase & /*phase*/,
115 const WidgetHandle &widgetHandle)
117 AttributeHandlerResponse response;
118 response = AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
119 AceDB::WidgetCertificateData::DISTRIBUTOR, AceDB::WidgetCertificateData::ROOT);
123 AttributeHandlerResponse AttributeDistributorKeyRootFingerprintHandler(
124 const WidgetExecutionPhase & /*phase*/,
125 const WidgetHandle &widgetHandle)
127 AttributeHandlerResponse response;
128 response = AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
129 AceDB::WidgetCertificateData::DISTRIBUTOR, AceDB::WidgetCertificateData::ROOT);
133 AttributeHandlerResponse AttributeAuthorKeyCnHandler(
134 const WidgetExecutionPhase & /*phase*/,
135 const WidgetHandle &widgetHandle)
137 AttributeHandlerResponse response;
138 response = AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
139 AceDB::WidgetCertificateData::AUTHOR, AceDB::WidgetCertificateData::ENDENTITY);
143 AttributeHandlerResponse AttributeAuthorKeyFingerprintHandler(
144 const WidgetExecutionPhase & /*phase*/,
145 const WidgetHandle &widgetHandle)
147 AttributeHandlerResponse response;
148 response = AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
149 AceDB::WidgetCertificateData::AUTHOR, AceDB::WidgetCertificateData::ENDENTITY);
153 AttributeHandlerResponse AttributeAuthorKeyRootCnHandler(
154 const WidgetExecutionPhase & /*phase*/,
155 const WidgetHandle &widgetHandle)
157 AttributeHandlerResponse response;
158 response = AceDB::AceDAOReadOnly::getKeyCommonNameList(widgetHandle,
159 AceDB::WidgetCertificateData::AUTHOR, AceDB::WidgetCertificateData::ROOT);
163 AttributeHandlerResponse AttributeAuthorKeyRootFingerprintHandler(
164 const WidgetExecutionPhase & /*phase*/,
165 const WidgetHandle &widgetHandle)
167 AttributeHandlerResponse response;
168 response = AceDB::AceDAOReadOnly::getKeyFingerprints(widgetHandle,
169 AceDB::WidgetCertificateData::AUTHOR, AceDB::WidgetCertificateData::ROOT);
173 AttributeHandlerResponse AttributeNetworkAccessUriHandler(
174 const WidgetExecutionPhase & /*phase*/,
175 const WidgetHandle & /*widgetHandle*/)
177 AttributeHandlerResponse response;
181 AttributeHandlerResponse AttributeIdHandler(const WidgetExecutionPhase & /*phase*/,
182 const WidgetHandle &widgetHandle)
184 AttributeHandlerResponse response;
186 std::string wGUID = AceDB::AceDAOReadOnly::getGUID(widgetHandle);
188 if (!wGUID.empty()) {
189 response.push_back(wGUID);
194 AttributeHandlerResponse AttributeAuthorNameHandler(
195 const WidgetExecutionPhase & /*phase*/,
196 const WidgetHandle &widgetHandle)
198 AttributeHandlerResponse response;
200 std::string value = AceDB::AceDAOReadOnly::getAuthorName(widgetHandle);
202 if (!value.empty()) {
203 response.push_back(value);
209 AttributeHandlerResponse AttributeRoamingHandler(
210 const WidgetExecutionPhase &phase,
211 const WidgetHandle & /*widgetHandle*/)
213 AttributeHandlerResponse response;
215 if (WidgetExecutionPhase_WidgetInstall == phase) {
216 // TODO undetermind value
217 response.push_back(std::string(""));
218 } else if (SimpleRoamingAgentSingleton::Instance().IsRoamingOn()) {
219 response.push_back(std::string("true"));
221 response.push_back(std::string("false"));
227 AttributeHandlerResponse AttributeBearerTypeHandler(
228 const WidgetExecutionPhase & /*phase*/,
229 const WidgetHandle & /*widgetHandle*/)
231 AttributeHandlerResponse response;
233 std::string bearerName = "undefined-bearer-name";
235 if (bearerName.empty()) {
236 LogWarning("Bearer-type is NOT SET or empty");
238 response.push_back(bearerName);
244 struct AttributeHandlerContext
247 WidgetExecutionPhase allowedPhaseMask;
248 AttributeHandler handler;
252 const WidgetExecutionPhase WidgetExecutionPhase_All =
253 static_cast<WidgetExecutionPhase>(
254 WidgetExecutionPhase_WidgetInstall |
255 WidgetExecutionPhase_WidgetInstantiate |
256 WidgetExecutionPhase_WebkitBind |
257 WidgetExecutionPhase_Invoke);
258 const WidgetExecutionPhase WidgetExecutionPhase_NoWidgetInstall =
259 static_cast<WidgetExecutionPhase>(
260 WidgetExecutionPhase_WidgetInstantiate |
261 WidgetExecutionPhase_WebkitBind |
262 WidgetExecutionPhase_Invoke);
264 #define ALL_PHASE(name, handler) \
265 { # name, WidgetExecutionPhase_All, handler },
267 #define NO_INSTALL(name, handler) \
268 { # name, WidgetExecutionPhase_NoWidgetInstall, handler },
270 AttributeHandlerContext HANDLED_ATTRIBUTES_LIST[] = {
271 ALL_PHASE(Class, &AttributeClassHandler)
272 ALL_PHASE(install-uri, &AttributeInstallUriHandler)
273 ALL_PHASE(version, &AttributeVersionHandler)
274 ALL_PHASE(distributor-key-cn, &AttributeDistributorKeyCnHandler)
275 ALL_PHASE(distributor-key-fingerprint,
276 &AttributeDistributorKeyFingerprintHandler)
277 ALL_PHASE(distributor-key-root-cn,
278 &AttributeDistributorKeyRootCnHandler)
279 ALL_PHASE(distributor-key-root-fingerprint,
280 &AttributeDistributorKeyRootFingerprintHandler)
281 ALL_PHASE(author-key-cn, &AttributeAuthorKeyCnHandler)
282 ALL_PHASE(author-key-fingerprint, &AttributeAuthorKeyFingerprintHandler)
283 ALL_PHASE(author-key-root-cn, &AttributeAuthorKeyRootCnHandler)
284 ALL_PHASE(author-key-root-fingerprint,
285 &AttributeAuthorKeyRootFingerprintHandler)
286 ALL_PHASE(network-access-uri, &AttributeNetworkAccessUriHandler)
287 ALL_PHASE(id, &AttributeIdHandler)
288 // ALL_PHASE(name, &AttributeNameHandler)
289 // ALL_PHASE(widget-attr:name, &AttributeWidgetAttrNameHandler)
290 ALL_PHASE(author-name, &AttributeAuthorNameHandler)
291 /* Enviroment attributes*/
292 // NO_INSTALL(roaming, &AttributeRoamingHandler)
293 // NO_INSTALL(bearer-type, &AttributeBearerTypeHandler)
299 const size_t HANDLED_ATTRIBUTES_LIST_COUNT =
300 sizeof(HANDLED_ATTRIBUTES_LIST) / sizeof(HANDLED_ATTRIBUTES_LIST[0]);
303 class lambdaCollectionPusher
306 std::list<T>& m_collection;
307 lambdaCollectionPusher(std::list<T>& collection) : m_collection(collection)
310 void operator()(const T& element) const
312 m_collection.push_back(element);
316 AttributeHandlerResponse AttributeDeviceCapHandler(const WidgetExecutionPhase & /*phase*/,
317 const WidgetHandle & /*widgetHandle*/,
318 const Request &request)
320 AttributeHandlerResponse response;
322 Request::DeviceCapabilitySet capSet = request.getDeviceCapabilitySet();
323 LogDebug("device caps set contains");
326 LogDebug("-> " << *dc);
332 lambdaCollectionPusher<std::string>(response));
337 //class lambdaFeatureEquality :
338 // public std::binary_function<FeatureHandle, int, bool>
341 // bool operator()(const FeatureHandle& wFeature,
342 // const int& resurceId) const
344 // return wFeature == resurceId;
348 //class lambdaPushFeatureName :
349 // public std::binary_function<WidgetFeature, AttributeHandlerResponse, void>
351 // void operator()(const WidgetFeature& wFeature,
352 // AttributeHandlerResponse& response) const
354 // response.push_back(DPL::ToUTF8String(wFeature.name));
358 AttributeHandlerResponse AttributeApiFeatureHandler(
359 const WidgetExecutionPhase & /* phase */,
360 const WidgetHandle & /* widgetHandle */,
361 const Request & /* request */)
363 LogDebug("WAC 2.0 does not support api-feature and resource-id in policy.");
364 AttributeHandlerResponse response;
368 AttributeHandlerResponse AttributeFeatureInstallUriHandler(
369 const WidgetExecutionPhase & /* phase */,
370 const WidgetHandle & /* widgetHandle */,
371 const Request & /* request */)
373 LogDebug("WAC 2.0 does not support feature-install-uri is policy!");
374 AttributeHandlerResponse response;
378 AttributeHandlerResponse AttributeFeatureFeatureKeyCnHandler(
379 const WidgetExecutionPhase & /* phase */,
380 const WidgetHandle & /* widgetHandle */,
381 const Request & /* request */)
383 LogDebug("WAC 2.0 does not support feature-key-cn is policy!");
384 AttributeHandlerResponse response;
388 AttributeHandlerResponse AttributeFeatureKeyRootCnHandler(
389 const WidgetExecutionPhase & /* phase */,
390 const WidgetHandle & /* widgetHandle */,
391 const Request & /* request */)
393 LogDebug("WAC 2.0 does not support feature-key-root-cn is policy!");
394 AttributeHandlerResponse response;
398 AttributeHandlerResponse AttributeFeatureKeyRootFingerprintHandler(
399 const WidgetExecutionPhase & /* phase */,
400 const WidgetHandle & /* widgetHandle */,
401 const Request & /* request */)
403 LogDebug("WAC 2.0 does not support"
404 " feature-key-root-fingerprint is policy!");
405 AttributeHandlerResponse response;
409 struct ResourceAttributeHandlerContext
412 WidgetExecutionPhase allowedPhaseMask;
413 ResourceAttributeHandler handler;
416 #define ALL_PHASE(name, handler) \
417 { # name, WidgetExecutionPhase_All, handler },
419 ResourceAttributeHandlerContext HANDLED_RESOURCE_ATTRIBUTES_LIST[] = {
420 ALL_PHASE(device-cap, &AttributeDeviceCapHandler)
421 ALL_PHASE(api-feature, &AttributeApiFeatureHandler)
422 // For compatiblity with older policies we tread resource-id
423 // identically as api-feature
424 ALL_PHASE(resource-id, &AttributeApiFeatureHandler)
426 ALL_PHASE(feature-install-uri, &AttributeFeatureInstallUriHandler)
427 ALL_PHASE(feature-key-cn, &AttributeFeatureFeatureKeyCnHandler)
428 ALL_PHASE(feature-key-root-cn, &AttributeFeatureKeyRootCnHandler)
429 ALL_PHASE(feature-key-root-fingerprint,
430 &AttributeFeatureKeyRootFingerprintHandler)
435 const size_t HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT =
436 sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST) /
437 sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST[0]);
438 } // namespace anonymous
441 * class WebRuntimeImpl
443 int WebRuntimeImpl::getAttributesValuesLoop(const Request &request,
444 std::list<ATTRIBUTE>* attributes,
445 WidgetExecutionPhase executionPhase)
447 UNHANDLED_EXCEPTION_HANDLER_BEGIN
449 WidgetHandle widgetHandle = request.getWidgetHandle();
451 FOREACH(itr, *attributes)
453 // Get attribute name
454 std::string attribute = *itr->first;
456 // Search for attribute handler
457 bool attributeFound = false;
459 for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
460 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
461 // Check if execution phase is valid
462 if ((executionPhase &
463 HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
464 // Attribute found, but execution state
465 // forbids to execute handler
467 "Request for attribute: '" <<
468 attribute << "' which is supported " <<
469 "but forbidden at widget execution phase: "
473 // Execution phase allows handler
474 AttributeHandlerResponse attributeResponse =
475 (*HANDLED_ATTRIBUTES_LIST[i].handler)(
478 std::copy(attributeResponse.begin(),
479 attributeResponse.end(),
480 std::back_inserter(*itr->second));
483 attributeFound = true;
488 if (!attributeFound) {
489 LogWarning("Request for attribute: '" <<
490 attribute << "' which is not supported");
496 UNHANDLED_EXCEPTION_HANDLER_END
499 int WebRuntimeImpl::getAttributesValues(const Request &request,
500 std::list<ATTRIBUTE>* attributes)
502 UNHANDLED_EXCEPTION_HANDLER_BEGIN
504 // Get current execution state
505 WidgetExecutionPhase executionPhase =
506 request.getExecutionPhase();
508 return getAttributesValuesLoop(request, attributes, executionPhase);
510 UNHANDLED_EXCEPTION_HANDLER_END
513 std::string WebRuntimeImpl::getSessionId(const Request & /* request */)
516 LogError("Not implemented!");
520 WebRuntimeImpl::WebRuntimeImpl()
525 * class ResourceInformationImpl
528 int ResourceInformationImpl::getAttributesValuesLoop(const Request &request,
529 std::list<ATTRIBUTE>* attributes,
530 WidgetExecutionPhase executionPhase)
532 // Currently, we assume widgets have internal representation of integer IDs
533 WidgetHandle widgetHandle = request.getWidgetHandle();
534 //TODO add resource id string analyzys
535 FOREACH(itr, *attributes)
537 // Get attribute name
538 std::string attribute = *itr->first;
539 LogDebug("getting attribute value for: " << attribute);
540 FOREACH(aaa, *itr->second)
542 LogDebug("its value is: " << *aaa);
545 // Search for attribute handler
546 bool attributeFound = false;
548 for (size_t i = 0; i < HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT; ++i) {
549 if (HANDLED_RESOURCE_ATTRIBUTES_LIST[i].name == attribute) {
550 // Check if execution phase is valid
551 if ((executionPhase &
552 HANDLED_RESOURCE_ATTRIBUTES_LIST[i].allowedPhaseMask) ==
554 // Attribute found, but execution state
555 // forbids to execute handler
557 "Request for attribute: '" <<
559 "' which is supported but forbidden " <<
560 "at widget execution phase: " << executionPhase);
563 // Execution phase allows handler
564 AttributeHandlerResponse attributeResponse =
565 (*HANDLED_RESOURCE_ATTRIBUTES_LIST[i].handler)(
569 std::copy(attributeResponse.begin(),
570 attributeResponse.end(),
571 std::back_inserter(*itr->second));
573 std::ostringstream attributeResponseFull;
575 for (AttributeHandlerResponse::const_iterator
576 it = attributeResponse.begin();
577 it != attributeResponse.end(); ++it) {
578 attributeResponseFull <<
579 (it == attributeResponse.begin() ? "" : ", ") <<
583 LogDebug("Attribute(" << attribute << ") = " <<
584 attributeResponseFull.str());
587 attributeFound = true;
592 if (!attributeFound) {
593 LogWarning("Request for attribute: '" << attribute <<
594 "' which is not supported");
600 int ResourceInformationImpl::getAttributesValues(const Request &request,
601 std::list<ATTRIBUTE>* attributes)
603 UNHANDLED_EXCEPTION_HANDLER_BEGIN
605 // Get current execution state
606 WidgetExecutionPhase executionPhase =
607 request.getExecutionPhase();
608 return getAttributesValuesLoop(request, attributes, executionPhase);
610 UNHANDLED_EXCEPTION_HANDLER_END
613 ResourceInformationImpl::ResourceInformationImpl()
618 * class OperationSystemImpl
621 int OperationSystemImpl::getAttributesValues(const Request &request,
622 std::list<ATTRIBUTE>* attributes)
624 UNHANDLED_EXCEPTION_HANDLER_BEGIN
627 //GetExecution name without widget name
628 WidgetExecutionPhase executionPhase =
629 request.getExecutionPhase();
631 FOREACH(itr, *attributes)
633 // Get attribute name
634 std::string attribute = *itr->first;
636 // Search for attribute handler
637 bool attributeFound = false;
639 for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
640 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
641 // Check if execution phase is valid
642 if ((executionPhase &
643 HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
644 // Attribute found, but execution state forbids
645 // to execute handler
646 LogDebug("Request for attribute: '" << attribute <<
647 "' which is supported but forbidden at " <<
648 "widget execution phase: " << executionPhase);
651 // Execution phase allows handler
652 AttributeHandlerResponse attributeResponse =
653 (*HANDLED_ATTRIBUTES_LIST[i].handler)(
656 std::copy(attributeResponse.begin(),
657 attributeResponse.end(),
658 std::back_inserter(*itr->second));
660 std::ostringstream attributeResponseFull;
662 typedef AttributeHandlerResponse::const_iterator Iter;
663 FOREACH(it, attributeResponse)
665 attributeResponseFull <<
666 (it == attributeResponse.begin()
670 LogDebug("Attribute(" << attribute <<
671 ") = " << attributeResponseFull.str());
674 attributeFound = true;
679 if (!attributeFound) {
680 LogWarning("Request for attribute: '" << attribute <<
681 "' which is not supported");
687 UNHANDLED_EXCEPTION_HANDLER_END
690 OperationSystemImpl::OperationSystemImpl()
695 * end of class OperationSystemImpl
698 int FunctionParamImpl::getAttributesValues(const Request & /*request*/,
699 std::list<ATTRIBUTE> *attributes)
701 FOREACH(iter, *attributes)
703 std::string attributeName = *(iter->first);
705 ParamMap::const_iterator i;
706 std::pair<ParamMap::const_iterator, ParamMap::const_iterator> jj =
707 paramMap.equal_range(attributeName);
709 for (i = jj.first; i != jj.second; ++i) {
710 iter->second->push_back(i->second);
711 LogDebug("Attribute: " << attributeName << " Value: " <<