1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
* Copyright (C) 2012-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#pragma once
#include "IClient.h"
#include "ITransportLayer.h"
#include <map>
#include <string>
class CVariant;
class CVideoInfoTag;
namespace JSONRPC
{
/*!
\ingroup jsonrpc
\brief Possible statuc codes of a response
to a JSON-RPC request
*/
enum JSONRPC_STATUS
{
OK = 0,
ACK = -1,
InvalidRequest = -32600,
MethodNotFound = -32601,
InvalidParams = -32602,
InternalError = -32603,
ParseError = -32700,
//-32099..-32000 Reserved for implementation-defined server-errors.
BadPermission = -32099,
FailedToExecute = -32100
};
/*!
\brief Function pointer for JSON-RPC methods
*/
typedef JSONRPC_STATUS (*MethodCall) (const std::string &method, ITransportLayer *transport, IClient *client, const CVariant& parameterObject, CVariant &result);
/*!
\ingroup jsonrpc
\brief Permission categories for json rpc methods
A JSON-RPC method will only be called if the caller
has the correct permissions to execute the method.
The method call needs to be perfectly threadsafe.
*/
enum OperationPermission
{
ReadData = 0x1,
ControlPlayback = 0x2,
ControlNotify = 0x4,
ControlPower = 0x8,
UpdateData = 0x10,
RemoveData = 0x20,
Navigate = 0x40,
WriteFile = 0x80,
ControlSystem = 0x100,
ControlGUI = 0x200,
ManageAddon = 0x400,
ExecuteAddon = 0x800,
ControlPVR = 0x1000
};
const int OPERATION_PERMISSION_ALL = (ReadData | ControlPlayback | ControlNotify | ControlPower |
UpdateData | RemoveData | Navigate | WriteFile | ControlSystem |
ControlGUI | ManageAddon | ExecuteAddon | ControlPVR);
const int OPERATION_PERMISSION_NOTIFICATION = (ControlPlayback | ControlNotify | ControlPower | UpdateData |
RemoveData | Navigate | WriteFile | ControlSystem |
ControlGUI | ManageAddon | ExecuteAddon | ControlPVR);
/*!
\brief Returns a string representation for the
given OperationPermission
\param permission Specific OperationPermission
\return String representation of the given OperationPermission
*/
inline const char *PermissionToString(const OperationPermission &permission)
{
switch (permission)
{
case ReadData:
return "ReadData";
case ControlPlayback:
return "ControlPlayback";
case ControlNotify:
return "ControlNotify";
case ControlPower:
return "ControlPower";
case UpdateData:
return "UpdateData";
case RemoveData:
return "RemoveData";
case Navigate:
return "Navigate";
case WriteFile:
return "WriteFile";
case ControlSystem:
return "ControlSystem";
case ControlGUI:
return "ControlGUI";
case ManageAddon:
return "ManageAddon";
case ExecuteAddon:
return "ExecuteAddon";
case ControlPVR:
return "ControlPVR";
default:
return "Unknown";
}
}
/*!
\brief Returns a OperationPermission value for the given
string representation
\param permission String representation of the OperationPermission
\return OperationPermission value of the given string representation
*/
inline OperationPermission StringToPermission(const std::string& permission)
{
if (permission.compare("ControlPlayback") == 0)
return ControlPlayback;
if (permission.compare("ControlNotify") == 0)
return ControlNotify;
if (permission.compare("ControlPower") == 0)
return ControlPower;
if (permission.compare("UpdateData") == 0)
return UpdateData;
if (permission.compare("RemoveData") == 0)
return RemoveData;
if (permission.compare("Navigate") == 0)
return Navigate;
if (permission.compare("WriteFile") == 0)
return WriteFile;
if (permission.compare("ControlSystem") == 0)
return ControlSystem;
if (permission.compare("ControlGUI") == 0)
return ControlGUI;
if (permission.compare("ManageAddon") == 0)
return ManageAddon;
if (permission.compare("ExecuteAddon") == 0)
return ExecuteAddon;
if (permission.compare("ControlPVR") == 0)
return ControlPVR;
return ReadData;
}
class CJSONRPCUtils
{
public:
static void NotifyItemUpdated();
static void NotifyItemUpdated(const CVideoInfoTag& info,
const std::map<std::string, std::string>& artwork);
};
}
|