kodi
PltAction.h
Go to the documentation of this file.
1 /*****************************************************************
2 |
3 | Platinum - Service Action
4 |
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
6 | All rights reserved.
7 | http://www.plutinosoft.com
8 |
9 | This program is free software; you can redistribute it and/or
10 | modify it under the terms of the GNU General Public License
11 | as published by the Free Software Foundation; either version 2
12 | of the License, or (at your option) any later version.
13 |
14 | OEMs, ISVs, VARs and other distributors that combine and
15 | distribute commercially licensed software with Platinum software
16 | and do not wish to distribute the source code for the commercially
17 | licensed software under version 2, or (at your option) any later
18 | version, of the GNU General Public License (the "GPL") must enter
19 | into a commercial license agreement with Plutinosoft, LLC.
20 | licensing@plutinosoft.com
21 |
22 | This program is distributed in the hope that it will be useful,
23 | but WITHOUT ANY WARRANTY; without even the implied warranty of
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 | GNU General Public License for more details.
26 |
27 | You should have received a copy of the GNU General Public License
28 | along with this program; see the file LICENSE.txt. If not, write to
29 | the Free Software Foundation, Inc.,
30 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 | http://www.gnu.org/licenses/gpl-2.0.html
32 |
33 ****************************************************************/
34 
39 #ifndef _PLT_ACTION_H_
40 #define _PLT_ACTION_H_
41 
42 /*----------------------------------------------------------------------
43 | includes
44 +---------------------------------------------------------------------*/
45 #include "Neptune.h"
46 #include "PltArgument.h"
47 #include "PltDeviceData.h"
48 
49 /*----------------------------------------------------------------------
50 | forward declarations
51 +---------------------------------------------------------------------*/
52 class PLT_Service;
53 
54 /*----------------------------------------------------------------------
55 | PLT_ActionDesc
56 +---------------------------------------------------------------------*/
62 {
63 public:
69  PLT_ActionDesc(const char* name, PLT_Service* service);
70  ~PLT_ActionDesc();
71 
77  return m_ArgumentDescs;
78  }
79 
84  const NPT_String& GetName() const { return m_Name;}
85 
91  PLT_ArgumentDesc* GetArgumentDesc(const char* name);
92 
97  NPT_Result GetSCPDXML(NPT_XmlElementNode* node);
98 
103 
104 protected:
105  //members
106  NPT_String m_Name;
107  PLT_Service* m_Service;
108  NPT_Array<PLT_ArgumentDesc*> m_ArgumentDescs;
109 };
110 
111 /*----------------------------------------------------------------------
112 | PLT_Action
113 +---------------------------------------------------------------------*/
122 {
123 public:
130  PLT_Action(PLT_ActionDesc& action_desc);
131 
141  PLT_Action(PLT_ActionDesc& action_desc, PLT_DeviceDataReference& root_device);
142  ~PLT_Action();
143 
148  PLT_ActionDesc& GetActionDesc() { return m_ActionDesc; }
149 
156  NPT_Result GetArgumentValue(const char* name, NPT_String& value);
157 
164  NPT_Result GetArgumentValue(const char* name, NPT_UInt32& value);
165 
172  NPT_Result GetArgumentValue(const char* name, NPT_Int32& value);
173 
180  NPT_Result GetArgumentValue(const char* name, bool& value);
181 
187  NPT_Result VerifyArgumentValue(const char* name, const char* value);
188 
194  NPT_Result VerifyArguments(bool input);
195 
200  NPT_Result SetArgumentOutFromStateVariable(const char* name);
201 
205  NPT_Result SetArgumentsOutFromStateVariable();
206 
212  NPT_Result SetArgumentValue(const char* name, const char* value);
213 
219  NPT_Result SetError(unsigned int code, const char* description);
220 
226  const char* GetError(unsigned int* code = NULL);
227 
232  unsigned int GetErrorCode();
233 
238  NPT_Result FormatSoapRequest(NPT_OutputStream& stream);
239 
244  NPT_Result FormatSoapResponse(NPT_OutputStream& stream);
245 
252  static NPT_Result FormatSoapError(unsigned int code,
253  NPT_String desc,
254  NPT_OutputStream& stream);
255 
256 private:
257  // methods
258  NPT_Result SetArgumentOutFromStateVariable(PLT_ArgumentDesc* arg_desc);
259  PLT_Argument* GetArgument(const char* name);
260 
261 protected:
262  // members
263  PLT_ActionDesc& m_ActionDesc;
264  PLT_Arguments m_Arguments;
265  unsigned int m_ErrorCode;
266  NPT_String m_ErrorDescription;
267 
268  // keep reference of service root device to prevent it
269  // from being released during action lifetime
270  PLT_DeviceDataReference m_RootDevice;
271 };
272 
274 
275 /*----------------------------------------------------------------------
276 | PLT_GetSCPDXMLIterator
277 +---------------------------------------------------------------------*/
282 template <class T>
284 {
285 public:
287  m_Node(node) {}
288 
289  NPT_Result operator()(T* const & data) const {
290  return data->GetSCPDXML(m_Node);
291  }
292 
293 private:
294  NPT_XmlElementNode* m_Node;
295 };
296 
297 /*----------------------------------------------------------------------
298 | PLT_ActionDescNameFinder
299 +---------------------------------------------------------------------*/
305 {
306 public:
307  // methods
308  PLT_ActionDescNameFinder(const char* name) :
309  m_Name(name) {}
310  virtual ~PLT_ActionDescNameFinder() {}
311 
312  bool operator()(const PLT_ActionDesc* const & action_desc) const {
313  return action_desc->GetName().Compare(m_Name, true) ? false : true;
314  }
315 
316 private:
317  // members
318  NPT_String m_Name;
319 };
320 
321 #endif /* _PLT_ACTION_H_ */
const NPT_String & GetName() const
Return the action name.
Definition: PltAction.h:84
The PLT_Argument class provides a mechanism to set or verify the validity of a specific UPNP service ...
Definition: PltArgument.h:99
PLT_ArgumentDesc * GetArgumentDesc(const char *name)
Look for an argument given a name.
Definition: PltAction.cpp:97
Definition: NptXml.h:172
PLT_ActionDesc & GetActionDesc()
Return the action description.
Definition: PltAction.h:148
The PLT_ActionDesc class provides information about a UPnP Service given action.
Definition: PltAction.h:61
UPnP Service Action Argument.
Definition: NptArray.h:54
PLT_Service * GetService()
Return the service the action is associated with.
Definition: PltAction.cpp:88
The PLT_ArgumentDesc class provides information about a given argument of a UPnP Service given action...
Definition: PltArgument.h:64
UPnP Service.
Definition: PltService.h:67
PLT_ActionDesc(const char *name, PLT_Service *service)
Constructor.
Definition: PltAction.cpp:49
Definition: NptStreams.h:92
The PLT_GetSCPDXMLIterator class provides a recursive way to serialize an SCPD into an xml tree...
Definition: PltAction.h:283
NPT_Array< PLT_ArgumentDesc * > & GetArgumentDescs()
Return an array of arguments.
Definition: PltAction.h:76
Definition: inftrees.h:24
The PLT_ActionDescNameFinder class provides a mechanism to find a PLT_ActionDesc given an action name...
Definition: PltAction.h:304
The PLT_Action class provides a mechanism to call or verify the validity of a specific UPNP service a...
Definition: PltAction.h:121
UPnP Device information.
NPT_Result GetSCPDXML(NPT_XmlElementNode *node)
Serialize action information to xml into an existing xml tree.
Definition: PltAction.cpp:67
Definition: NptStrings.h:57