kandy

atcommand.h

00001 /*
00002     This file is part of Kandy.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 #ifndef ATCOMMAND_H
00025 #define ATCOMMAND_H
00026 
00027 #include <tqstring.h>
00028 #include <tqstringlist.h>
00029 #include <tqptrlist.h>
00030 
00031 class ATParameter {
00032   public:
00033     ATParameter();
00034     ATParameter(const TQString &value,const TQString &name="",
00035                 bool userInput=false);
00036 
00037     void setName(const TQString &name) { mName = name; }
00038     TQString name() const { return mName; }
00039     void setValue(const TQString &value) { mValue = value; }
00040     TQString value() const { return mValue; }
00041     void setUserInput(bool userInput) { mUserInput = userInput; }
00042     bool userInput() const { return mUserInput; }
00043 
00044   private:
00045     TQString mName;
00046     TQString mValue;
00047     bool mUserInput;
00048 };
00049 
00053 // TODO: emit a signal, when the command was executed.
00054 class ATCommand {
00055   public:
00056     ATCommand();
00057     ATCommand(const TQString &cmdString);
00058     ATCommand(const TQString &cmdName,const TQString &cmdString,
00059               bool hexOutput=false);
00060     virtual ~ATCommand();
00061 
00062     void setCmdName(const TQString &);
00063     TQString cmdName();
00064 
00065     void setCmdString(const TQString &);
00066     TQString cmdString();
00067 
00068     TQString cmd();
00069 
00070     TQString id();
00071 
00072     void setHexOutput(bool);
00073     bool hexOutput();
00074 
00075     TQString processOutput(const TQString &);
00076     TQString processOutput();
00077 
00078     void setResultString(const TQString &);
00079     TQString resultString();
00080     TQString resultField(int index);
00081     TQPtrList<TQStringList> *resultFields();
00082 
00083     void addParameter(ATParameter *);
00084     void clearParameters();
00085     TQPtrList<ATParameter> parameters();
00086 
00087     void setParameter(int index,const TQString &value);
00088     void setParameter(int index,int value);
00089 
00090     void setAutoDelete(bool autoDelete) { mAutoDelete = autoDelete; }
00091     bool autoDelete() { return mAutoDelete; }
00092 
00093   private:
00094     void construct();
00095     void setResultFields(TQString fieldsString);
00096     void extractParameters();
00097 
00098     TQString mCmdName;
00099     TQString mCmdString;
00100     TQString mId;
00101     bool mHexOutput;
00102 
00103     TQString mResultString;
00104     TQPtrList<TQStringList> mResultFieldsList;
00105 
00106     TQPtrList<ATParameter> mParameters;
00107 
00108     bool mAutoDelete;
00109 };
00110 
00111 #endif