IPC: Support older glib
[platform/core/security/vasum.git] / common / ipc / internals / signal-request.hpp
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
19 /**
20  * @file
21  * @author  Jan Olszak (j.olszak@samsung.com)
22  * @brief   Processor's request to send a signal
23  */
24
25 #ifndef COMMON_IPC_INTERNALS_SIGNAL_REQUEST_HPP
26 #define COMMON_IPC_INTERNALS_SIGNAL_REQUEST_HPP
27
28 #include "ipc/types.hpp"
29 #include "config/manager.hpp"
30 #include "logger/logger-scope.hpp"
31
32 namespace vasum {
33 namespace ipc {
34
35 class SignalRequest {
36 public:
37     SignalRequest(const SignalRequest&) = delete;
38     SignalRequest& operator=(const SignalRequest&) = delete;
39
40
41
42     template<typename SentDataType>
43     static std::shared_ptr<SignalRequest> create(const MethodID methodID,
44                                                  const FileDescriptor peerFD,
45                                                  const std::shared_ptr<SentDataType>& data);
46
47     MethodID methodID;
48     FileDescriptor peerFD;
49     MessageID messageID;
50     std::shared_ptr<void> data;
51     SerializeCallback serialize;
52
53 private:
54     SignalRequest(const MethodID methodID, const FileDescriptor peerFD)
55         : methodID(methodID),
56           peerFD(peerFD),
57           messageID(getNextMessageID())
58     {}
59
60 };
61
62 template<typename SentDataType>
63 std::shared_ptr<SignalRequest> SignalRequest::create(const MethodID methodID,
64                                                      const FileDescriptor peerFD,
65                                                      const std::shared_ptr<SentDataType>& data)
66 {
67     std::shared_ptr<SignalRequest> request(new SignalRequest(methodID, peerFD));
68
69     request->data = data;
70
71     request->serialize = [](const int fd, std::shared_ptr<void>& data)->void {
72         LOGS("Signal serialize, peerFD: " << fd);
73         config::saveToFD<SentDataType>(fd, *std::static_pointer_cast<SentDataType>(data));
74     };
75
76     return request;
77 }
78
79 } // namespace ipc
80 } // namespace vasum
81
82 #endif // COMMON_IPC_INTERNALS_SIGNAL_REQUEST_HPP