• Main Page
  • Classes
  • Files
  • File List

nxclientlib.h

00001 /***************************************************************************
00002                                nxclientlib.h
00003                              -------------------
00004     begin                : Sat 22nd July 2006
00005     remove Qt dependency : Started June 2007
00006     modifications        : June-July 2007
00007     copyright            : (C) 2006 by George Wright
00008     modifications        : (C) 2007 Embedded Software Foundry Ltd. (U.K.)
00009                          :     Author: Sebastian James
00010                          : (C) 2008 Defuturo Ltd
00011                          :     Author: George Wright
00012     email                : seb@esfnet.co.uk, gwright@kde.org
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #ifndef _NXCLIENTLIB_H_
00025 #define _NXCLIENTLIB_H_
00026 
00027 #include <iostream>
00028 #include "nxsession.h"
00029 #include <list>
00030 #include "notQt.h"
00031 
00032 
00033 using namespace std;
00034 
00035 namespace nxcl {
00036 
00037     struct ProxyData {
00038         string id;
00039         int    display;
00040         string cookie;
00041         string proxyIP;
00042         bool   encrypted;
00043         int    port;
00044         string server;
00045     };
00046 
00052     class NXClientLibExternalCallbacks
00053     {
00054         public:
00055             NXClientLibExternalCallbacks () {}
00056             virtual ~NXClientLibExternalCallbacks () {}
00057             virtual void write (string msg) {}
00058             virtual void write (int num, string msg) {}
00059             virtual void error (string msg) {}
00060             virtual void debug (string msg) {}
00061             virtual void stdoutSignal (string msg) {}
00062             virtual void stderrSignal (string msg) {}
00063             virtual void stdinSignal (string msg) {}
00064             virtual void resumeSessionsSignal (list<NXResumeData>) {}
00065             virtual void noSessionsSignal (void) {}
00066             virtual void serverCapacitySignal (void) {}
00067             virtual void connectedSuccessfullySignal (void) {}
00068     };
00069 
00081     class NXClientLibBase 
00082     {
00083         public:
00084             NXClientLibBase() {}
00085             virtual ~NXClientLibBase() {}
00086 
00087             virtual void setIsFinished (bool status) {}
00088             virtual void processParseStdout (void) {}
00089             virtual void processParseStderr (void) {}
00090             virtual void loginFailed (void) {}
00091             virtual void readyproxy (void) {}
00092             virtual void doneAuth (void) {}
00093 
00100             NXClientLibExternalCallbacks * externalCallbacks;
00101     };
00102 
00107     class NXClientLibCallbacks : public notQProcessCallbacks,
00108         public NXSessionCallbacks
00109     {
00110         public:
00111             NXClientLibCallbacks();
00112             ~NXClientLibCallbacks();
00113 
00122             void startedSignal (string name);
00123             void errorSignal (int error);
00124             void processFinishedSignal (string name);
00125             void readyReadStandardOutputSignal (void);
00126             void readyReadStandardErrorSignal (void);
00128 
00132             void noSessionsSignal (void);
00133             void loginFailedSignal (void);
00134             void readyForProxySignal (void);
00135             void authenticatedSignal (void);
00136             void sessionsSignal (list<NXResumeData>);
00138 
00139 
00144             void setParent (NXClientLibBase * p) { this->parent = p; }
00145         private:
00146             NXClientLibBase * parent;
00147     };
00148 
00149     class NXClientLib : public NXClientLibBase
00150     {
00151         public:
00152             NXClientLib();
00153             ~NXClientLib();
00154 
00174             void invokeNXSSH (string publicKey = "supplied",
00175                     string serverHost = "",
00176                     bool encryption = true,
00177                     string key = "",
00178                     int port = 22);
00179 
00186             void write (string data);
00187 
00191             void setCustomPath(string path)
00192             {
00193                 this->customPath = path;
00194             }
00195             
00199             void allowSSHConnect (bool auth);
00200 
00204             void invokeProxy (void);
00205 
00213             string parseSSH (string message);
00214 
00220             //void checkSession (void);
00221 
00229             bool chooseResumable (int n); 
00230 
00239             bool terminateSession (int n);
00240 
00241             void runSession (void);
00242 
00243             void startX11 (string resolution, string name);
00244 
00245             bool needX11Probe (void)
00246             {
00247                 return x11Probe;
00248             }
00249             
00250             // public slots:
00252             void doneAuth (void);
00253             void loginFailed (void);
00254             
00255             void finished (void)
00256             {
00257                 dbgln ("Finishing up on signal"); this->isFinished = true;
00258             }
00259 
00260             void readyproxy (void)
00261             {
00262                 dbgln ("ready for nxproxy"); this->readyForProxy = true;
00263             }
00264 
00265             void reset (void);
00266             void processParseStdout (void);
00267             void processParseStderr (void);
00268 
00274             void requestConfirmation (string msg);
00276 
00277             // Accessors
00279 
00282             void setUsername (string& user)
00283             {
00284                 this->nxuser = user;
00285                 this->session.setUsername (this->nxuser);
00286             }
00287 
00291             void setPassword (string& pass)
00292             {
00293                 this->nxpass = pass;
00294                 this->session.setPassword (this->nxpass);
00295             }
00296 
00297             void setResolution (int x, int y)
00298             {
00299                 this->session.setResolution(x, y);
00300             }
00301 
00302             void setDepth (int depth)
00303             {
00304                 this->session.setDepth(depth);
00305             }
00306 
00307             void setRender (bool render)
00308             {
00309                 this->session.setRender(render);
00310             }
00311 
00312             void setSessionData (NXSessionData *);
00313 
00314             notQProcess* getNXSSHProcess (void)
00315             {
00316                 return this->nxsshProcess;
00317             }
00318 
00319             notQProcess* getNXProxyProcess (void)
00320             {
00321                 return this->nxproxyProcess;
00322             }
00323 
00324             notQProcess* getX11Process (void)
00325             {
00326                 return this->x11Process;
00327             }
00328 
00329             notQProcess* getNXAuthProcess (void)
00330             {
00331                 return this->nxauthProcess;
00332             }
00333 
00334             bool getIsFinished (void)
00335             {
00336                 return this->isFinished;
00337             }
00338 
00339             bool getReadyForProxy (void)
00340             {
00341                 return this->readyForProxy;
00342             }
00343 
00344             NXSession* getSession (void)
00345             {
00346                 return &this->session;
00347             }
00348 
00349             void setIsFinished (bool status)
00350             {
00351                 this->isFinished = status;
00352             }
00353 
00354             void setExternalCallbacks (NXClientLibExternalCallbacks * cb)
00355             {
00356                 this->externalCallbacks = cb;
00357             }
00358 
00359             bool getSessionRunning (void)
00360             {
00361                 return this->sessionRunning;
00362             }
00364 
00365         private:
00375             string getPath (string prog);
00376 
00380             string customPath;
00381 
00382             bool x11Probe;
00388             bool isFinished;
00392             bool readyForProxy;
00399             bool sessionRunning;
00403             bool password;
00404 
00405             // FIXME: I hold the actual data, and a pointer to the
00406             // data here. I tried to get rid of the pointer, and
00407             // modify main.cpp in ../nxcl and that didn't work
00408             // properly - I'm not sure why. I suppose I could get
00409             // rid of the objects here, and then call
00410             // pNxsshProcess = new notQProcess; in the
00411             // constructor...
00415             notQProcess* nxsshProcess;
00419             notQProcess* nxproxyProcess;
00423             notQProcess* x11Process;
00427             notQProcess* nxauthProcess;
00433             NXClientLibCallbacks callbacks;
00437             notQTemporaryFile *keyFile;
00441             NXSession session;
00447             ProxyData proxyData;
00451             string nxuser;
00455             string nxpass;
00456     };
00457 
00458 } // namespace
00459 #endif

Generated on Thu Sep 2 2010 11:40:11 for nxcl by  doxygen 1.7.1