| 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 <cstdint> |
| 12 |
#include <memory> |
| 13 |
#include <string> |
| 14 |
#include <utility> |
| 15 |
#include <vector> |
| 16 |
|
| 17 |
class CEvent; |
| 18 |
|
| 19 |
namespace KODI |
| 20 |
{ |
| 21 |
namespace MESSAGING |
| 22 |
{ |
| 23 |
|
| 24 |
class CApplicationMessenger; |
| 25 |
|
| 26 |
class ThreadMessage |
| 27 |
{ |
| 28 |
friend CApplicationMessenger; |
| 29 |
public: |
| 30 |
ThreadMessage() |
| 31 |
: ThreadMessage{ 0, -1, -1, nullptr } |
| 32 |
{ |
| 33 |
} |
| 34 |
|
| 35 |
explicit ThreadMessage(uint32_t messageId) |
| 36 |
: ThreadMessage{ messageId, -1, -1, nullptr } |
| 37 |
{ |
| 38 |
} |
| 39 |
|
| 40 |
ThreadMessage(uint32_t messageId, int64_t p3) |
| 41 |
: ThreadMessage{ messageId, -1, -1, nullptr, p3 } |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
ThreadMessage(uint32_t messageId, int p1, int p2, void* payload, int64_t p3 = 0) |
| 46 |
: dwMessage{ messageId } |
| 47 |
, param1{ p1 } |
| 48 |
, param2{ p2 } |
| 49 |
, param3{ p3 } |
| 50 |
, lpVoid{ payload } |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
ThreadMessage(uint32_t messageId, |
| 55 |
int p1, |
| 56 |
int p2, |
| 57 |
void* payload, |
| 58 |
std::string param, |
| 59 |
std::vector<std::string> vecParams) |
| 60 |
: dwMessage{messageId}, |
| 61 |
param1{p1}, |
| 62 |
param2{p2}, |
| 63 |
param3{0}, |
| 64 |
lpVoid{payload}, |
| 65 |
strParam(std::move(param)), |
| 66 |
params(std::move(vecParams)) |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
ThreadMessage(const ThreadMessage& other) = default; |
| 71 |
|
| 72 |
ThreadMessage(ThreadMessage&& other) noexcept |
| 73 |
: dwMessage(other.dwMessage), |
| 74 |
param1(other.param1), |
| 75 |
param2(other.param2), |
| 76 |
param3(other.param3), |
| 77 |
lpVoid(other.lpVoid), |
| 78 |
strParam(std::move(other.strParam)), |
| 79 |
params(std::move(other.params)), |
| 80 |
waitEvent(std::move(other.waitEvent)), |
| 81 |
result(std::move(other.result)) |
| 82 |
{ |
| 83 |
} |
| 84 |
|
| 85 |
ThreadMessage& operator=(const ThreadMessage& other) |
| 86 |
{ |
| 87 |
if (this == &other) |
| 88 |
return *this; |
| 89 |
dwMessage = other.dwMessage; |
| 90 |
param1 = other.param1; |
| 91 |
param2 = other.param2; |
| 92 |
param3 = other.param3; |
| 93 |
lpVoid = other.lpVoid; |
| 94 |
strParam = other.strParam; |
| 95 |
params = other.params; |
| 96 |
waitEvent = other.waitEvent; |
| 97 |
result = other.result; |
| 98 |
return *this; |
| 99 |
} |
| 100 |
|
| 101 |
ThreadMessage& operator=(ThreadMessage&& other) noexcept |
| 102 |
{ |
| 103 |
if (this == &other) |
| 104 |
return *this; |
| 105 |
dwMessage = other.dwMessage; |
| 106 |
param1 = other.param1; |
| 107 |
param2 = other.param2; |
| 108 |
param3 = other.param3; |
| 109 |
lpVoid = other.lpVoid; |
| 110 |
strParam = std::move(other.strParam); |
| 111 |
params = std::move(other.params); |
| 112 |
waitEvent = std::move(other.waitEvent); |
| 113 |
result = std::move(other.result); |
| 114 |
return *this; |
| 115 |
} |
| 116 |
|
| 117 |
uint32_t dwMessage; |
| 118 |
int param1; |
| 119 |
int param2; |
| 120 |
int64_t param3; |
| 121 |
void* lpVoid; |
| 122 |
std::string strParam; |
| 123 |
std::vector<std::string> params; |
| 124 |
|
| 125 |
/*! |
| 126 |
* \brief set the message return value, will only be returned when |
| 127 |
* the message is sent using SendMsg |
| 128 |
* \param [in] res the return value or a result status code that is returned to the caller |
| 129 |
*/ |
| 130 |
void SetResult(int res) const |
| 131 |
{ |
| 132 |
//On posted messages result will be zero, since they can't |
| 133 |
//retrieve the response we silently ignore this to let message |
| 134 |
//handlers not have to worry about it |
| 135 |
if (result) |
| 136 |
*result = res; |
| 137 |
} |
| 138 |
protected: |
| 139 |
std::shared_ptr<CEvent> waitEvent; |
| 140 |
std::shared_ptr<int> result; |
| 141 |
}; |
| 142 |
} |
| 143 |
} |