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@1826: #include fp@1142: using namespace std; fp@1142: fp@1826: #include "../master/ioctl.h" fp@1826: fp@1826: class MasterDevice; 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@1834: /** Constructor with char * parameter. */ fp@1834: CommandException( fp@1834: const string &msg /**< Message. */ fp@1834: ): runtime_error(msg) {} fp@1834: 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@1826: typedef list MasterIndexList; fp@1869: void setMasters(const string &); fp@1869: MasterIndexList getMasterIndices() const; fp@1870: unsigned int getSingleMasterIndex() const; fp@1869: 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@2010: fp@2010: void setAliases(const string &); fp@2010: void setPositions(const string &); fp@2010: fp@2010: void setDomains(const string &); fp@2010: typedef list DomainIndexList; fp@2010: DomainIndexList getDomainIndices() const; fp@2010: fp@1166: void setDataType(const string &); fp@1166: const string &getDataType() const; fp@2010: fp@2529: void setEmergency(bool); fp@2529: bool getEmergency() const; fp@2529: fp@1804: void setForce(bool); fp@1804: bool getForce() const; fp@2010: fp@1804: void setOutputFile(const string &); fp@1804: const string &getOutputFile() const; fp@1142: fp@2436: void setSkin(const string &); fp@2436: const string &getSkin() const; fp@2436: fp@1142: bool matchesSubstr(const string &) const; fp@1142: bool matchesAbbrev(const string &) const; fp@1142: fp@1968: virtual string helpString(const string &) const = 0; fp@1142: fp@1142: typedef vector StringVector; fp@1826: virtual void execute(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@1834: void throwCommandException(const string &) 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@2453: DomainList selectedDomains(MasterDevice &, const ec_ioctl_master_t &); fp@2529: int emergencySlave() const; fp@1151: fp@1146: static string alStateString(uint8_t); fp@1142: fp@1142: private: fp@1804: string name; fp@1142: string briefDesc; fp@1869: string masters; fp@1142: Verbosity verbosity; fp@2010: string aliases; fp@2010: string positions; fp@2010: string domains; fp@1804: string dataType; fp@2529: bool emergency; fp@1804: bool force; fp@1804: string outputFile; fp@2436: string skin; 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@1166: inline const string &Command::getDataType() const fp@1166: { fp@1166: return dataType; fp@1166: } fp@1166: fp@1166: /****************************************************************************/ fp@1166: fp@2529: inline bool Command::getEmergency() const fp@2529: { fp@2529: return emergency; fp@2529: } fp@2529: fp@2529: /****************************************************************************/ fp@2529: 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@2436: inline const string &Command::getSkin() const fp@2436: { fp@2436: return skin; fp@2436: } fp@2436: fp@2436: /****************************************************************************/ fp@2436: fp@1142: #endif