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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
|
/*****************************************************************
|
| Platinum - Service Action
|
| Copyright (c) 2004-2010, Plutinosoft, LLC.
| All rights reserved.
| http://www.plutinosoft.com
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of the GNU General Public License
| as published by the Free Software Foundation; either version 2
| of the License, or (at your option) any later version.
|
| OEMs, ISVs, VARs and other distributors that combine and
| distribute commercially licensed software with Platinum software
| and do not wish to distribute the source code for the commercially
| licensed software under version 2, or (at your option) any later
| version, of the GNU General Public License (the "GPL") must enter
| into a commercial license agreement with Plutinosoft, LLC.
| licensing@plutinosoft.com
|
| This program is distributed in the hope that it will be useful,
| but WITHOUT ANY WARRANTY; without even the implied warranty of
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
| GNU General Public License for more details.
|
| You should have received a copy of the GNU General Public License
| along with this program; see the file LICENSE.txt. If not, write to
| the Free Software Foundation, Inc.,
| 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
| http://www.gnu.org/licenses/gpl-2.0.html
|
****************************************************************/
/** @file
UPnP Service Action
*/
#ifndef _PLT_ACTION_H_
#define _PLT_ACTION_H_
/*----------------------------------------------------------------------
| includes
+---------------------------------------------------------------------*/
#include "Neptune.h"
#include "PltArgument.h"
#include "PltDeviceData.h"
/*----------------------------------------------------------------------
| forward declarations
+---------------------------------------------------------------------*/
class PLT_Service;
/*----------------------------------------------------------------------
| PLT_ActionDesc
+---------------------------------------------------------------------*/
/**
The PLT_ActionDesc class provides information about a UPnP Service given action.
This description has a name, a set of arguments and is associated to a service.
*/
class PLT_ActionDesc
{
public:
/**
Constructor
@param name the action name
@param service the UPnP service the action is associated with
*/
PLT_ActionDesc(const char* name, PLT_Service* service);
~PLT_ActionDesc();
/**
Return an array of arguments
@return array of arguments
*/
NPT_Array<PLT_ArgumentDesc*>& GetArgumentDescs() {
return m_ArgumentDescs;
}
/**
Return the action name.
@return action name.
*/
const NPT_String& GetName() const { return m_Name;}
/**
Look for an argument given a name.
@param name argument name
@return PLT_ArgumentDesc pointer
*/
PLT_ArgumentDesc* GetArgumentDesc(const char* name);
/**
Serialize action information to xml into an existing xml tree
@param node the xml Element to serialize action information
*/
NPT_Result GetSCPDXML(NPT_XmlElementNode* node);
/**
Return the service the action is associated with
*/
PLT_Service* GetService();
protected:
//members
NPT_String m_Name;
PLT_Service* m_Service;
NPT_Array<PLT_ArgumentDesc*> m_ArgumentDescs;
};
/*----------------------------------------------------------------------
| PLT_Action
+---------------------------------------------------------------------*/
/**
The PLT_Action class provides a mechanism to call or verify the validity of a
specific UPNP service action.
Given a service, a UPnP Control Point would use this class to serialize a soap
request. On the other side, a UPnP Device would use this class to verify
a soap request and the validity of the action arguments.
*/
class PLT_Action
{
public:
/**
Constructor
@param action_desc the action description
If you intend to send an action, you need to use the second constructor
and pass the root device of the device you wish to control.
*/
PLT_Action(PLT_ActionDesc& action_desc);
/**
Constructor
@param action_desc the action description
@param root_device a reference to the root device of the service the action
is associated with. This insures that the device won't be deleted if it goes
away while we're waiting for a response for this action. This is important because
we only keep a reference to the PLT_ActionDesc which is own by the service operated
by the device (or embedded device).
*/
PLT_Action(PLT_ActionDesc& action_desc, PLT_DeviceDataReference& root_device);
~PLT_Action();
/**
Return the action description
@return the action description
*/
PLT_ActionDesc& GetActionDesc() { return m_ActionDesc; }
/**
Retrieve the string value of an argument given an argument name.
@param name the argument name
@param value the string value to retrieve
@return error if the argument is not found or if the type does not correspond.
*/
NPT_Result GetArgumentValue(const char* name, NPT_String& value);
/**
Retrieve the value of an argument given an argument name.
@param name the argument name
@param value the unsigned int value to retrieve
@return error if the argument is not found or if the type does not correspond.
*/
NPT_Result GetArgumentValue(const char* name, NPT_UInt32& value);
/**
Retrieve the value of an argument given an argument name.
@param name the argument name
@param value the int value to retrieve
@return error if the argument is not found or if the type does not correspond.
*/
NPT_Result GetArgumentValue(const char* name, NPT_Int32& value);
/**
Retrieve the value of an argument given an argument name.
@param name the argument name
@param value the bool value to retrieve
@return error if the argument is not found or if the type does not correspond.
*/
NPT_Result GetArgumentValue(const char* name, bool& value);
/**
Verify a value is valid for a given argument.
@param name the argument name
@param value the value to verify
*/
NPT_Result VerifyArgumentValue(const char* name, const char* value);
/**
Verify that all required arguments are set.
@param input boolean indicating whether input or output parameters
should be verified
*/
NPT_Result VerifyArguments(bool input);
/**
Set the output argument value from the associated current state variable value.
@param name the state variable name
*/
NPT_Result SetArgumentOutFromStateVariable(const char* name);
/**
Set all the output argument values associated with state variables.
*/
NPT_Result SetArgumentsOutFromStateVariable();
/**
Set an argument value
@param name the argument name
@param value the argument value
*/
NPT_Result SetArgumentValue(const char* name, const char* value);
/**
Set the error code and description in case of failure.
@param code the code for the error
@param description a short description
*/
NPT_Result SetError(unsigned int code, const char* description);
/**
Return the error description and code for the failed action.
@param code optional pointer to receive the code
@return the error short description
*/
const char* GetError(unsigned int* code = NULL);
/**
Return the error code for the failed action.
@return the error code.
*/
unsigned int GetErrorCode();
/**
Called by a control point when serializing an action.
@param stream the stream to serialize the action to
*/
NPT_Result FormatSoapRequest(NPT_OutputStream& stream);
/**
Called by a device when serializing a response to an action.
@param stream the stream to serialize the action to
*/
NPT_Result FormatSoapResponse(NPT_OutputStream& stream);
/**
Helper method for a device to serialize an action invocation error.
@param code optional pointer to receive the code
@param desc the error short description
@param stream the stream to serialize to
*/
static NPT_Result FormatSoapError(unsigned int code,
NPT_String desc,
NPT_OutputStream& stream);
private:
// methods
NPT_Result SetArgumentOutFromStateVariable(PLT_ArgumentDesc* arg_desc);
PLT_Argument* GetArgument(const char* name);
protected:
// members
PLT_ActionDesc& m_ActionDesc;
PLT_Arguments m_Arguments;
unsigned int m_ErrorCode;
NPT_String m_ErrorDescription;
// keep reference of service root device to prevent it
// from being released during action lifetime
PLT_DeviceDataReference m_RootDevice;
};
typedef NPT_Reference<PLT_Action> PLT_ActionReference;
/*----------------------------------------------------------------------
| PLT_GetSCPDXMLIterator
+---------------------------------------------------------------------*/
/**
The PLT_GetSCPDXMLIterator class provides a recursive way to serialize
an SCPD into an xml tree.
*/
template <class T>
class PLT_GetSCPDXMLIterator
{
public:
PLT_GetSCPDXMLIterator<T>(NPT_XmlElementNode* node) :
m_Node(node) {}
NPT_Result operator()(T* const & data) const {
return data->GetSCPDXML(m_Node);
}
private:
NPT_XmlElementNode* m_Node;
};
/*----------------------------------------------------------------------
| PLT_ActionDescNameFinder
+---------------------------------------------------------------------*/
/**
The PLT_ActionDescNameFinder class provides a mechanism to find a PLT_ActionDesc
given a PLT_Service and an action name.
*/
class PLT_ActionDescNameFinder
{
public:
// methods
PLT_ActionDescNameFinder(PLT_Service* service, const char* name) :
m_Service(service), m_Name(name) {}
virtual ~PLT_ActionDescNameFinder() {}
bool operator()(const PLT_ActionDesc* const & action_desc) const {
return action_desc->GetName().Compare(m_Name, true) ? false : true;
}
private:
// members
PLT_Service* m_Service;
NPT_String m_Name;
};
#endif /* _PLT_ACTION_H_ */
|