xbmc
ThreadMessage.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include <memory>
12 #include <string>
13 #include <utility>
14 #include <vector>
15 
16 class CEvent;
17 
18 namespace KODI
19 {
20 namespace MESSAGING
21 {
22 
23 class CApplicationMessenger;
24 
26 {
27  friend CApplicationMessenger;
28 public:
30  : ThreadMessage{ 0, -1, -1, nullptr }
31  {
32  }
33 
34  explicit ThreadMessage(uint32_t messageId)
35  : ThreadMessage{ messageId, -1, -1, nullptr }
36  {
37  }
38 
39  ThreadMessage(uint32_t messageId, int64_t p3)
40  : ThreadMessage{ messageId, -1, -1, nullptr, p3 }
41  {
42  }
43 
44  ThreadMessage(uint32_t messageId, int p1, int p2, void* payload, int64_t p3 = 0)
45  : dwMessage{ messageId }
46  , param1{ p1 }
47  , param2{ p2 }
48  , param3{ p3 }
49  , lpVoid{ payload }
50  {
51  }
52 
53  ThreadMessage(uint32_t messageId,
54  int p1,
55  int p2,
56  void* payload,
57  std::string param,
58  std::vector<std::string> vecParams)
59  : dwMessage{messageId},
60  param1{p1},
61  param2{p2},
62  param3{0},
63  lpVoid{payload},
64  strParam(std::move(param)),
65  params(std::move(vecParams))
66  {
67  }
68 
69  ThreadMessage(const ThreadMessage& other) = default;
70 
71  ThreadMessage(ThreadMessage&& other) noexcept
72  : dwMessage(other.dwMessage),
73  param1(other.param1),
74  param2(other.param2),
75  param3(other.param3),
76  lpVoid(other.lpVoid),
77  strParam(std::move(other.strParam)),
78  params(std::move(other.params)),
79  waitEvent(std::move(other.waitEvent)),
80  result(std::move(other.result))
81  {
82  }
83 
84  ThreadMessage& operator=(const ThreadMessage& other)
85  {
86  if (this == &other)
87  return *this;
88  dwMessage = other.dwMessage;
89  param1 = other.param1;
90  param2 = other.param2;
91  param3 = other.param3;
92  lpVoid = other.lpVoid;
93  strParam = other.strParam;
94  params = other.params;
95  waitEvent = other.waitEvent;
96  result = other.result;
97  return *this;
98  }
99 
100  ThreadMessage& operator=(ThreadMessage&& other) noexcept
101  {
102  if (this == &other)
103  return *this;
104  dwMessage = other.dwMessage;
105  param1 = other.param1;
106  param2 = other.param2;
107  param3 = other.param3;
108  lpVoid = other.lpVoid;
109  strParam = std::move(other.strParam);
110  params = std::move(other.params);
111  waitEvent = std::move(other.waitEvent);
112  result = std::move(other.result);
113  return *this;
114  }
115 
116  uint32_t dwMessage;
117  int param1;
118  int param2;
119  int64_t param3;
120  void* lpVoid;
121  std::string strParam;
122  std::vector<std::string> params;
123 
129  void SetResult(int res) const
130  {
131  //On posted messages result will be zero, since they can't
132  //retrieve the response we silently ignore this to let message
133  //handlers not have to worry about it
134  if (result)
135  *result = res;
136  }
137 protected:
138  std::shared_ptr<CEvent> waitEvent;
139  std::shared_ptr<int> result;
140 };
141 }
142 }
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: ThreadMessage.h:25
void SetResult(int res) const
set the message return value, will only be returned when the message is sent using SendMsg ...
Definition: ThreadMessage.h:129
Controller configuration window.
Definition: AudioDecoder.h:18
This implements a simple message dispatcher/router for Kodi.
Definition: ApplicationMessenger.h:226