Classified ads
tclWrapper.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013-2017.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 
22 #ifndef TCLWRAPPER_H
23 #define TCLWRAPPER_H
24 #include <QThread>
25 #include <QQueue>
26 #include "../mcontroller.h"
27 #include <tcl.h>
28 
29 class Model ;
30 class MController ;
31 class TclConsoleDialog ;
32 class TclCallbacks ;
33 
652 class TclWrapper : public QThread {
653  Q_OBJECT
654 public:
655  TclWrapper(Model& aModel,
656  MController& aController);
657 
661  ~TclWrapper() ;
668  void stopScript(bool aDeleteLater = false ) ;
669  void setScript(const QString& aScript) ;
673  const QString& currentProgram() const { return iTCLScript ; } ;
674  void showConsole() ;
681  void notifyOfContentReceived(const Hash& aHashOfContent,
682  const ProtocolItemType aTypeOfReceivedContent ) ;
683 public slots:
684  void run() ;
685 
686 signals:
691  const QString& aExplanation) ;
696  void consoleOutput(QString aOutput) ;
697 public slots:
698  void consoleClosed() ;
708  void evalScript(QString aScript,
709  QString* aMainWindowTitle = NULL ) ;
710 private: // methods
715  Tcl_Interp* initInterpreter() ;
720  bool initTk(Tcl_Interp* aInterp) ;
728  bool initExtensions(Tcl_Interp* aInterp) ;
729 
736  bool initProgram(Tcl_Interp* aInterp) ;
737 
754  static int listItemsCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
755 
762  static int getProfileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
763 
764 
771  static int getClassifiedAdCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
772 
773 
780  static int getProfileCommentCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
781 
782 
789  static int getBinaryFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
790 
806  static int getDbRecordCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
807 
808 
822  static int publishItemCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
826  static int sha1Cmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
830  static int storeTCLProgLocalDataCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
834  static int retrieveTCLProgLocalDataCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
840  static int saveFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
846  static int openFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
850  static int isProfileTrustedCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[]) ;
854  static int closeProc(
855  ClientData aInstanceData,
856  Tcl_Interp *aInterp);
860  static int inputProc(
861  ClientData aInstanceData,
862  char *aBuf,
863  int aBufSize,
864  int *aErrorCodePtr);
869  static int outputProc(
870  ClientData aInstanceData,
871  const char *aBuf,
872  int aToWrite,
873  int *aErrorCodePtr);
874 
875  static void watchProc(
876  ClientData instanceData,
877  int mask);
878  static int getHandleProc(
879  ClientData aInstanceData,
880  int aDirection,
881  ClientData *aHandlePtr);
882 
886  int outputProcImpl(
887  ClientData aInstanceData,
888  const char *aBuf,
889  int aToWrite,
890  int *aErrorCodePtr);
891 
900  void notifyInterpreterOfContentReceived( Tcl_Interp* aInterp ) ;
901 private: // these are not public
904  Tcl_Interp *iInterp ;
905  QString iTCLScript ;
906  bool iNeedsToRun ;
907  QByteArray iStdOutBuffer ;
908  bool iDeleteLater ;
910  QQueue<QString> iScriptQueue ;
912  QQueue<QPair<Hash, ProtocolItemType> > iAddedDataModelItems ;
914 } ;
915 #endif
void showConsole()
class for displaying tcl interpreter output
Definition: tclConsole.h:32
static int publishItemCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
bool iNeedsToRun
Definition: tclWrapper.h:906
static int getClassifiedAdCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
static int getProfileCommentCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
static int retrieveTCLProgLocalDataCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
void stopScript(bool aDeleteLater=false)
void evalScript(QString aScript, QString *aMainWindowTitle=NULL)
QString iMainWindowTitle
Definition: tclWrapper.h:911
static int outputProc(ClientData aInstanceData, const char *aBuf, int aToWrite, int *aErrorCodePtr)
static int getHandleProc(ClientData aInstanceData, int aDirection, ClientData *aHandlePtr)
QQueue< QPair< Hash, ProtocolItemType > > iAddedDataModelItems
Definition: tclWrapper.h:912
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:57
static int getBinaryFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
static void watchProc(ClientData instanceData, int mask)
ProtocolItemType
Definition: protocol.h:157
Class implementing TCL interpreter callbacks.
Definition: tclCallbacks.h:38
static int storeTCLProgLocalDataCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
void run()
Tcl_Interp * initInterpreter()
static int sha1Cmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
TclConsoleDialog * iConsole
Definition: tclWrapper.h:909
static int inputProc(ClientData aInstanceData, char *aBuf, int aBufSize, int *aErrorCodePtr)
TclWrapper(Model &aModel, MController &aController)
Model & iModel
Definition: tclWrapper.h:902
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
static int saveFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
QString iTCLScript
Definition: tclWrapper.h:905
bool initProgram(Tcl_Interp *aInterp)
M of the MVC pattern. Handles permanent storage.
Definition: model.h:50
static int openFileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
bool initExtensions(Tcl_Interp *aInterp)
static int closeProc(ClientData aInstanceData, Tcl_Interp *aInterp)
void setScript(const QString &aScript)
Tcl_Interp * iInterp
Definition: tclWrapper.h:904
void error(MController::CAErrorSituation aError, const QString &aExplanation)
bool initTk(Tcl_Interp *aInterp)
int outputProcImpl(ClientData aInstanceData, const char *aBuf, int aToWrite, int *aErrorCodePtr)
QByteArray iStdOutBuffer
Definition: tclWrapper.h:907
void notifyInterpreterOfContentReceived(Tcl_Interp *aInterp)
void consoleOutput(QString aOutput)
void consoleClosed()
Class providing TCL interpreter services.
Definition: tclWrapper.h:652
static int isProfileTrustedCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
const QString & currentProgram() const
Definition: tclWrapper.h:673
bool iDeleteLater
Definition: tclWrapper.h:908
void notifyOfContentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivedContent)
static int getDbRecordCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
static int listItemsCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])
QQueue< QString > iScriptQueue
Definition: tclWrapper.h:910
MController & iController
Definition: tclWrapper.h:903
TclCallbacks * iTclCallbacks
Definition: tclWrapper.h:913
static int getProfileCmd(ClientData aCData, Tcl_Interp *aInterp, int aObjc, Tcl_Obj *const aObjv[])