Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dbus-method-result-builder.hpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Contact: Jan Olszak (j.olszak@samsung.com)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
17 */
18 
26 #ifndef COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
27 #define COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
28 
29 #include "config.hpp"
30 
32 
33 #include "dbus/connection.hpp"
35 
36 #include <memory>
37 #include <functional>
38 
39 namespace vasum {
40 namespace api {
41 
42 const std::string DBUS_CONNECTION_PREFIX = "dbus://";
43 
44 template<typename Data>
46 public:
47  DbusMethodResultBuilder(const ::dbus::MethodResultBuilder::Pointer& methodResultBuilderPtr);
49 
50 private:
51  void setImpl(const std::shared_ptr<void>& data) override;
52  void setVoid() override;
53  void setError(const std::string& name, const std::string& message) override;
54  std::string getID() const override;
55 
57  std::function<GVariant*(std::shared_ptr<void>)> mSerialize;
58 };
59 
60 template<typename Data>
61 DbusMethodResultBuilder<Data>::DbusMethodResultBuilder(const ::dbus::MethodResultBuilder::Pointer& methodResultBuilderPtr)
62  : mMethodResultBuilderPtr(methodResultBuilderPtr)
63 {
64  mSerialize = [](const std::shared_ptr<void> data)->GVariant* {
65  return cargo::saveToGVariant(*std::static_pointer_cast<Data>(data));
66  };
67 }
68 
69 template<typename Data>
70 void DbusMethodResultBuilder<Data>::setImpl(const std::shared_ptr<void>& data)
71 {
72  GVariant* parameters = mSerialize(data);
73  mMethodResultBuilderPtr->set(parameters);
74 }
75 
76 template<typename Data>
78 {
79  mMethodResultBuilderPtr->setVoid();
80 }
81 
82 template<typename Data>
83 void DbusMethodResultBuilder<Data>::setError(const std::string& name, const std::string& message)
84 {
85  mMethodResultBuilderPtr->setError(name, message);
86 }
87 
88 template<typename Data>
90 {
91  return DBUS_CONNECTION_PREFIX + mMethodResultBuilderPtr->getPeerName();
92 }
93 
94 } // namespace result
95 } // namespace vasum
96 
97 #endif // COMMON_RESULT_DBUS_METHOD_RESULT_BUILDER_HPP
::dbus::MethodResultBuilder::Pointer mMethodResultBuilderPtr
Definition: dbus-method-result-builder.hpp:56
std::string getID() const override
Definition: dbus-method-result-builder.hpp:89
const std::string DBUS_CONNECTION_PREFIX
Definition: dbus-method-result-builder.hpp:42
Definition: dbus-method-result-builder.hpp:45
Configuration file for the code.
~DbusMethodResultBuilder()
Definition: dbus-method-result-builder.hpp:48
Dbus connection class.
An interface used to set a result to a method call.
Definition: method-result-builder.hpp:39
char data[368]
Definition: initctl.cpp:41
void setImpl(const std::shared_ptr< void > &data) override
Definition: dbus-method-result-builder.hpp:70
GVariant * saveToGVariant(const Cargo &visitable)
Saves the visitable in a GVariant.
Definition: cargo-gvariant.hpp:58
std::function< GVariant *(std::shared_ptr< void >)> mSerialize
Definition: dbus-method-result-builder.hpp:57
void setError(const std::string &name, const std::string &message) override
Definition: dbus-method-result-builder.hpp:83
DbusMethodResultBuilder(const ::dbus::MethodResultBuilder::Pointer &methodResultBuilderPtr)
Definition: dbus-method-result-builder.hpp:61
std::shared_ptr< MethodResultBuilder > Pointer
Definition: connection.hpp:47
void setVoid() override
Definition: dbus-method-result-builder.hpp:77
Interface for result builders.