MRCI/src/cmd_proc.h

145 lines
4.2 KiB
C
Raw Normal View History

Major upgrade and module interface changes Made some major changes to the project to facilitate a lighter code base and the must flexible module interface possible. -the mutli-process architecture now operate at the command object level so each command now operate in it's own process instead of a single process handling multiple command objects. -each module is now an independent application that will now tell the session object all of the commands it can run via named pipe. during command execution, it will run the requested command object also running io with the session object via named pipe. with this change, it is now possible for modules to be developed in different versions or QT or entirely different languages. the only requirement is the need to support named pipes. shared memory segments is also a nice to have but not needed. -clients can now run multiple instances of the same command via changes to the protocol. mrci frames will now include a branch id along with the command id. the branch id can be used by clients to differentiate the io between instances of the same command. -the command states are longer controlled by a single object. it will now be up to the command object (internal/exterenal) to send an IDLE frame to the client to notify it that the command has finished. the session object will still track if the command is in idle state or not but not directly control it. -must async commands now use binary formatted data instead of TEXT as a way to reduce overhead. -all command objects can now send async commands. it is no longer limited to just internal commands, however; the data of these async commands are verified by session in some way to prevent host crashing due to malformed data. -changed up the database structure to rely more on user ids, channel ids and removed all foreign keys pointing to user names, channel names and sub-channel names. also removed the groups table altogether. instead, the host rank is now directly attached to the user data in the users table. -changed the query object to now support the INNER JOIN SQL clause. this change was needed to support the new database structure. -version negotiation is now one-way via tcp connection or module interface. the host will make it's own verion numner known to the client connected via tcp or the module connected via named pipe. it will now be entirely up to the client or module to decide if they support the host. another change in this regard is the removal of the import rev for the modules. compatibility for modules shall now use just the host verion. -removed ls_cmds and cmd_info. the NEW_CMD frame now carries all information about the command (cmd_id, cmd_name, summery, io and full_description) so it is now possible for the clients to display the command documentation instead of the host. Documentation for the internal commands were updated to reflect the changes but all other documentation will need to be updated in the near future.
2019-11-08 22:06:09 -05:00
#ifndef CMD_PROC_H
#define CMD_PROC_H
// This file is part of MRCI.
// MRCI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// MRCI is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with MRCI under the LICENSE.md file. If not, see
// <http://www.gnu.org/licenses/>.
#include "common.h"
class ModProcess : public QProcess
{
Q_OBJECT
private:
QHash<QString, quint32> cmdRanks;
QHash<QString, QStringList> *modCmdNames;
QHash<quint16, QString> *cmdUniqueNames;
QHash<quint16, QString> *cmdRealNames;
QHash<quint16, QString> *cmdAppById;
QList<quint16> *cmdIds;
IdleTimer *idleTimer;
quint16 genCmdId();
QString makeCmdUnique(const QString &name);
bool allowCmdLoad(const QString &cmdName);
protected:
QString pipeName;
QString fullPipe;
QString sesMemKey;
QString hostMemKey;
quint8 ipcTypeId;
quint32 ipcDataSize;
quint32 hostRank;
quint32 flags;
QLocalServer *ipcServ;
QLocalSocket *ipcSocket;
virtual void onReady();
virtual void onFailToStart();
virtual void onDataFromProc(quint8 typeId, const QByteArray &data);
void cleanupPipe();
void wrIpcFrame(quint8 typeId, const QByteArray &data);
bool startProc(const QStringList &args);
bool isCmdLoaded(const QString &name);
bool openPipe();
protected slots:
virtual void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
virtual void rdFromStdErr();
virtual void rdFromStdOut();
void rdFromIPC();
void newIPCLink();
void ipcDisconnected();
void err(QProcess::ProcessError error);
public:
explicit ModProcess(const QString &app, const QString &memSes, const QString &memHos, const QString &pipe, QObject *parent = nullptr);
void setSessionParams(QHash<quint16, QString> *uniqueNames,
QHash<quint16, QString> *realNames,
QHash<quint16, QString> *appById,
QHash<QString, QStringList> *namesForMod,
QList<quint16> *ids,
quint32 rnk);
bool loadPublicCmds();
bool loadUserCmds();
bool loadExemptCmds();
signals:
void cmdUnloaded(quint16 cmdId);
void dataToClient(quint32 cmdId, const QByteArray &data, quint8 typeId);
};
//----------------------------
class CmdProcess : public ModProcess
{
Q_OBJECT
private:
quint32 cmdId;
QString cmdName;
bool cmdIdle;
QSharedMemory *sesMem;
char *sessionId;
char *openWritableSubChs;
void onReady();
void onFailToStart();
void onFinished(int exitCode, QProcess::ExitStatus exitStatus);
void onDataFromProc(quint8 typeId, const QByteArray &data);
bool validAsync(quint16 async, const QByteArray &data, QTextStream &errMsg);
private slots:
void killCmd();
void rdFromStdErr();
void rdFromStdOut();
public slots:
void killCmd16(quint16 id16);
void killCmd32(quint32 id32);
public:
explicit CmdProcess(quint32 id, const QString &cmd, const QString &modApp, const QString &memSes, const QString &memHos, const QString &pipe, QObject *parent = nullptr);
void dataFromSession(quint32 id, const QByteArray &data, quint8 dType);
void setSessionParams(QSharedMemory *mem, char *sesId, char *wrableSubChs);
bool startCmdProc();
signals:
void cmdProcFinished(quint32 id);
void cmdProcReady(quint32 id, CmdProcess *obj);
void pubIPC(quint16 cmdId, const QByteArray &data);
void privIPC(quint16 cmdId, const QByteArray &data);
void pubIPCWithFeedBack(quint16 cmdId, const QByteArray &data);
};
#endif // CMD_PROC_H