/* Copyright © 2003, Russell C. Hay All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: i. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ii. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. iii. Neither the name of the dead[protocol]society nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "stl.h" #include "action.h" action::action() : m_id(-1) , m_int_params(0) , m_str_params(0) , m_fd(-1) { } action::action(int id) : m_id(id) , m_int_params(0) , m_str_params(0) , m_fd(-1) { } action::~action() { } void action::SetActionType(int id) { if (id < g_actionname_count) m_id = id; } int action::GetActionType() { return m_id; } char *action::GetActionName() { if (m_id >= g_actionname_count) return "INVALID ACTION"; else return g_actionnames[m_id-1]; } void action::SetActionFileDesc(int id) { m_fd = id; } int action::GetActionFileDesc() { return m_fd; } int action::AddActionParam(int name, const int value) { if (m_int_params == 0) { InitIntParams(name+1); if (m_int_params == 0) return -1; } if (name >= m_int_params->capacity()) { m_int_params->resize(name+1, -1); } (*m_int_params)[name] = value; return 0; } int action::AddActionParam(int name, const char *value) { if (m_str_params == 0) { InitStrParams(name+1); if (m_str_params == 0) return -1; } if (name >= m_str_params->capacity()) { m_str_params->resize(name+1); } (*m_str_params)[name] = strdup(value); return 0; } int action::GetActionParamInt(int name) { if (name > m_int_params->capacity()) return -1; else return (*m_int_params)[name]; } const char *action::GetActionParamChar(int name) { if (name > m_str_params->capacity()) return ""; else return (*m_str_params)[name]; } void action::InitIntParams(int size) { m_int_params = new action_int_param(size, -1); } void action::InitStrParams(int size) { m_str_params = new action_string_param(size); } void action::DumpParams() { if (m_int_params != 0) { action_int_param::iterator iter; int i = 0; for(iter = m_int_params->begin(); iter != m_int_params->end(); iter++) { if (*iter!=-1) { printf("\tAction Parameter %d: %d\n", i, *iter); } i++; } } if (m_str_params != 0) { action_string_param::iterator iter; int i = 0; for(iter = m_str_params->begin(); iter != m_str_params->end(); iter++) { if ((*iter)==0) { printf("\tAction Parameter %d: '%s'\n", i, *iter); } i++; } } } char *action::g_actionnames[] = { "Device Reset", "Cursor Back", "Cursor Forward", "Cursor Home", "Device Status", "Key Notify On", "Key Notify Off", "Parse Error", "Horizontal Graph", "Vertical Graph", "Priority Mode Start", "Priority Mode Stop", "GPO", "Cursor", "BigInt", "Out", "Clear Display", "Quit" }; int action::g_actionname_count = sizeof(action::g_actionnames) / sizeof(char *) +1;