fp@1142: /***************************************************************************** fp@1142: * fp@1363: * $Id$ fp@1363: * fp@1363: * Copyright (C) 2006-2009 Florian Pose, Ingenieurgemeinschaft IgH fp@1363: * fp@1363: * This file is part of the IgH EtherCAT Master. fp@1363: * fp@1363: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@1363: * modify it under the terms of the GNU General Public License version 2, as fp@1363: * published by the Free Software Foundation. fp@1363: * fp@1363: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@1363: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@1363: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@1363: * Public License for more details. fp@1363: * fp@1363: * You should have received a copy of the GNU General Public License along fp@1363: * with the IgH EtherCAT Master; if not, write to the Free Software fp@1363: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@1363: * fp@1363: * --- fp@1363: * fp@1363: * The license mentioned above concerns the source code only. Using the fp@1363: * EtherCAT technology and brand is only permitted in compliance with the fp@1363: * industrial property and similar rights of Beckhoff Automation GmbH. fp@1142: * fp@1142: ****************************************************************************/ fp@1142: fp@1142: #ifndef __COMMAND_H__ fp@1142: #define __COMMAND_H__ fp@1142: fp@1142: #include fp@1142: #include fp@1151: #include fp@1142: using namespace std; fp@1142: fp@1142: #include "MasterDevice.h" fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class InvalidUsageException: fp@1142: public runtime_error fp@1142: { fp@1142: friend class Command; fp@1142: fp@1142: protected: fp@1142: /** Constructor with stringstream parameter. */ fp@1142: InvalidUsageException( fp@1142: const stringstream &s /**< Message. */ fp@1142: ): runtime_error(s.str()) {} fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class CommandException: fp@1142: public runtime_error fp@1142: { fp@1142: friend class Command; fp@1142: fp@1142: protected: fp@1142: /** Constructor with stringstream parameter. */ fp@1142: CommandException( fp@1142: const stringstream &s /**< Message. */ fp@1142: ): runtime_error(s.str()) {} fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: class Command fp@1142: { fp@1142: public: fp@1142: Command(const string &, const string &); fp@1804: virtual ~Command(); fp@1142: fp@1151: const string &getName() const; fp@1151: const string &getBriefDescription() const; fp@1151: fp@1142: enum Verbosity { fp@1142: Quiet, fp@1142: Normal, fp@1142: Verbose fp@1142: }; fp@1142: void setVerbosity(Verbosity); fp@1804: Verbosity getVerbosity() const; fp@1151: void setAlias(int); fp@1151: int getAlias() const; fp@1151: void setPosition(int); fp@1151: int getPosition() const; fp@1166: void setDomain(int); fp@1166: int getDomain() const; fp@1166: void setDataType(const string &); fp@1166: const string &getDataType() const; fp@1804: void setForce(bool); fp@1804: bool getForce() const; fp@1804: void setOutputFile(const string &); fp@1804: const string &getOutputFile() const; fp@1142: fp@1142: bool matchesSubstr(const string &) const; fp@1142: bool matchesAbbrev(const string &) const; fp@1142: fp@1142: virtual string helpString() const = 0; fp@1142: fp@1142: typedef vector StringVector; fp@1142: virtual void execute(MasterDevice &, const StringVector &) = 0; fp@1142: fp@1144: static string numericInfo(); fp@1144: fp@1142: protected: fp@1804: enum {BreakAfterBytes = 16}; fp@1151: fp@1155: void throwInvalidUsageException(const stringstream &) const; fp@1155: void throwCommandException(const stringstream &) const; fp@1155: void throwSingleSlaveRequired(unsigned int) const; fp@1142: fp@1151: typedef list SlaveList; fp@1151: SlaveList selectedSlaves(MasterDevice &); fp@1156: typedef list ConfigList; fp@1156: ConfigList selectedConfigs(MasterDevice &); fp@1166: typedef list DomainList; fp@1166: DomainList selectedDomains(MasterDevice &); fp@1151: fp@1146: static string alStateString(uint8_t); fp@1142: fp@1142: private: fp@1804: string name; fp@1142: string briefDesc; fp@1142: Verbosity verbosity; fp@1151: int alias; fp@1151: int position; fp@1804: int domain; fp@1804: string dataType; fp@1804: bool force; fp@1804: string outputFile; fp@1142: fp@1142: Command(); fp@1142: }; fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline const string &Command::getName() const fp@1142: { fp@1142: return name; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline const string &Command::getBriefDescription() const fp@1142: { fp@1142: return briefDesc; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1142: inline Command::Verbosity Command::getVerbosity() const fp@1142: { fp@1142: return verbosity; fp@1142: } fp@1142: fp@1142: /****************************************************************************/ fp@1142: fp@1151: inline int Command::getAlias() const fp@1151: { fp@1151: return alias; fp@1151: } fp@1151: fp@1151: /****************************************************************************/ fp@1151: fp@1151: inline int Command::getPosition() const fp@1151: { fp@1151: return position; fp@1151: } fp@1151: fp@1151: /****************************************************************************/ fp@1151: fp@1166: inline int Command::getDomain() const fp@1166: { fp@1166: return domain; fp@1166: } fp@1166: fp@1166: /****************************************************************************/ fp@1166: fp@1166: inline const string &Command::getDataType() const fp@1166: { fp@1166: return dataType; fp@1166: } fp@1166: fp@1166: /****************************************************************************/ fp@1166: fp@1166: inline bool Command::getForce() const fp@1166: { fp@1166: return force; fp@1166: } fp@1166: fp@1166: /****************************************************************************/ fp@1166: fp@1335: inline const string &Command::getOutputFile() const fp@1335: { fp@1335: return outputFile; fp@1335: } fp@1335: fp@1335: /****************************************************************************/ fp@1335: fp@1142: #endif