Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
signal-request.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 
25 #ifndef CARGO_IPC_INTERNALS_SIGNAL_REQUEST_HPP
26 #define CARGO_IPC_INTERNALS_SIGNAL_REQUEST_HPP
27 
28 #include "cargo-ipc/types.hpp"
29 #include "cargo-fd/fdstore.hpp"
30 #include "logger/logger-scope.hpp"
31 
32 namespace cargo {
33 namespace ipc {
34 
36 public:
37  SignalRequest(const SignalRequest&) = delete;
38  SignalRequest& operator=(const SignalRequest&) = delete;
39 
40  template<typename SentDataType>
41  static std::shared_ptr<SignalRequest> create(const MethodID methodID,
42  const PeerID& peerID,
43  const std::shared_ptr<SentDataType>& data);
44 
48  std::shared_ptr<void> data;
50 
51 private:
52  SignalRequest(const MethodID methodID, const PeerID& peerID)
53  : methodID(methodID),
54  peerID(peerID),
56  {}
57 
58 };
59 
60 template<typename SentDataType>
61 std::shared_ptr<SignalRequest> SignalRequest::create(const MethodID methodID,
62  const PeerID& peerID,
63  const std::shared_ptr<SentDataType>& data)
64 {
65  std::shared_ptr<SignalRequest> request(new SignalRequest(methodID, peerID));
66 
67  request->data = data;
68 
69  request->serialize = [](const int fd, std::shared_ptr<void>& data)->void {
70  LOGS("Signal serialize, peerID: " << fd);
71  cargo::saveToFD<SentDataType>(fd, *std::static_pointer_cast<SentDataType>(data));
72  };
73 
74  return request;
75 }
76 
77 } // namespace ipc
78 } // namespace cargo
79 
80 #endif // CARGO_IPC_INTERNALS_SIGNAL_REQUEST_HPP
#define LOGS(MSG)
Automatically create LoggerScope object which logs at the construction and destruction.
Definition: logger-scope.hpp:78
std::string PeerID
Definition: types.hpp:45
SignalRequest & operator=(const SignalRequest &)=delete
SignalRequest(const MethodID methodID, const PeerID &peerID)
Definition: signal-request.hpp:52
Definition: signal-request.hpp:35
MethodID methodID
Definition: signal-request.hpp:45
Types definitions.
MessageID getNextMessageID()
Generate an unique message id.
Definition: types.cpp:46
char data[368]
Definition: initctl.cpp:41
static std::shared_ptr< SignalRequest > create(const MethodID methodID, const PeerID &peerID, const std::shared_ptr< SentDataType > &data)
Definition: signal-request.hpp:61
PeerID peerID
Definition: signal-request.hpp:46
std::shared_ptr< void > data
Definition: signal-request.hpp:48
unsigned int MethodID
Definition: types.hpp:43
std::function< void(cargo::ipc::FileDescriptor fd, std::shared_ptr< void > &data)> SerializeCallback
Generic function type used as callback for serializing and saving serialized data to the descriptor...
Definition: types.hpp:64
SignalRequest(const SignalRequest &)=delete
MessageID messageID
Definition: signal-request.hpp:47
Declaration of a class for writing and reading data from a file descriptor.
SerializeCallback serialize
Definition: signal-request.hpp:49
std::string MessageID
Definition: types.hpp:44
Scope logger class declaration.