1 /*****************************************************************
3 | Platinum - Action Argument
5 | Copyright (c) 2004-2010, Plutinosoft, LLC.
7 | http://www.plutinosoft.com
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.
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
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.
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
33 ****************************************************************/
35 /*----------------------------------------------------------------------
37 +---------------------------------------------------------------------*/
38 #include "PltArgument.h"
39 #include "PltStateVariable.h"
40 #include "PltUtilities.h"
41 #include "PltAction.h"
43 NPT_SET_LOCAL_LOGGER("platinum.core.argument")
45 /*----------------------------------------------------------------------
46 | PLT_ArgumentDesc::PLT_ArgumentDesc
47 +---------------------------------------------------------------------*/
48 PLT_ArgumentDesc::PLT_ArgumentDesc(const char* name
,
50 const char* direction
,
51 PLT_StateVariable
* variable
,
55 m_Direction(direction
),
56 m_RelatedStateVariable(variable
),
57 m_HasReturnValue(has_ret
)
61 /*----------------------------------------------------------------------
62 | PLT_ArgumentDesc::GetSCPDXML
63 +---------------------------------------------------------------------*/
65 PLT_ArgumentDesc::GetSCPDXML(NPT_XmlElementNode
* node
)
67 NPT_XmlElementNode
* argument
= new NPT_XmlElementNode("argument");
68 NPT_CHECK_SEVERE(node
->AddChild(argument
));
69 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument
, "name", m_Name
));
70 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument
, "direction", m_Direction
));
71 NPT_CHECK_SEVERE(PLT_XmlHelper::AddChildText(argument
, "relatedStateVariable", m_RelatedStateVariable
->GetName()));
73 if (m_HasReturnValue
) {
74 NPT_CHECK_SEVERE(argument
->AddChild(new NPT_XmlElementNode("retval")));
80 /*----------------------------------------------------------------------
81 | PLT_Argument::CreateArgument
82 +---------------------------------------------------------------------*/
84 PLT_Argument::CreateArgument(PLT_ActionDesc
& action_desc
,
89 // reset output params first
92 PLT_ArgumentDesc
* arg_desc
= action_desc
.GetArgumentDesc(name
);
94 NPT_LOG_WARNING_2("Invalid argument %s for action %s",
96 (const char*)action_desc
.GetName());
97 return NPT_ERROR_NO_SUCH_NAME
;
101 PLT_Argument
* new_arg
= new PLT_Argument(*arg_desc
);
102 if (NPT_FAILED(res
= new_arg
->SetValue(value
))) {
105 NPT_LOG_WARNING_3("Invalid value of %s for argument %s of action %s",
108 (const char*)action_desc
.GetName());
116 /*----------------------------------------------------------------------
117 | PLT_Argument::PLT_Argument
118 +---------------------------------------------------------------------*/
119 PLT_Argument::PLT_Argument(PLT_ArgumentDesc
& arg_desc
) :
125 /*----------------------------------------------------------------------
126 | PLT_Argument::SetValue
127 +---------------------------------------------------------------------*/
129 PLT_Argument::SetValue(const char* value
)
131 NPT_CHECK_SEVERE(ValidateValue(value
));
137 /*----------------------------------------------------------------------
138 | PLT_Argument::GetValue
139 +---------------------------------------------------------------------*/
141 PLT_Argument::GetValue()
146 /*----------------------------------------------------------------------
147 | PLT_Argument::ValidateValue
148 +---------------------------------------------------------------------*/
150 PLT_Argument::ValidateValue(const char* value
)
152 if (m_ArgDesc
.GetRelatedStateVariable()) {
153 return m_ArgDesc
.GetRelatedStateVariable()->ValidateValue(value
);