123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- #pragma once
- #include <QString>
- #include <QObject>
- #include <QLibrary>
- #include <QDateTime>
- #include <QMutex>
- #include <QWaitCondition>
- #include "threadcontroller.h"
- #define LH_HTTPAPI_SUCC 0
- #define LHAPI_BUFFER_SIZE_NEW 2048000
- #define LHAPI_BUFFER_SIZE_ARY 4096
- extern int g_nHttpTimeOut;
- enum enDBOperatorType
- {
- EDBOT_Select = 1,
- EDBOT_Update,
- EDBOT_Delete,
- EDBOT_Insert,
- EDBOT_Procedure,
- EDBOT_Batch,
- EDBOT_BatchTransAction
- };
- class lhhttpapi : public QObject
- {
- Q_OBJECT
- public:
- typedef int (*FunDBInit)(const char* lpUrl);
- typedef int (*FunDBLogin)(const char *pLocalIP, const char *pSerid, const char* CType, char *pszUserToken, int nSize);
- typedef int (*FunDBGetServerList)(char *pszList, int nSize);
- typedef int (*FunDBGetServerInfo)(const char* pSerid, const char* pszUserToken, char* pServerInfo, int nSize);
- typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize);
- typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParam, char *strRet, int nSize);
- typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
- typedef int (*FunSetHttpTimeOut)(int nTimeout);
-
- typedef int64_t (*FunDoGetHttpFileSize)(const char *pszHttpAddr);
-
- typedef int64_t (*FunDoGetHttpFileContent)(const char* pHttpAddr, char *pszContent, int nSize);
-
- typedef int (*FunDoWord2Pyjc)(const char* pszWord, char *pszContent, int nSize);
-
- typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
- typedef int (*FunDoUploadFtpFileContent)(const char* pszFileContent, int size, const char* pszFtpFilePath);
-
- typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
- typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
- typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
-
- typedef int (*FunDoGetDBInfo)(const char* strSerid, const char* strtoken, char* pDBInfo, int nsize);
- public:
- explicit lhhttpapi(QObject *parent = nullptr);
- ~lhhttpapi();
- public:
- QLibrary *m_pQLib;
- FunDBInit fnDBInit;
- FunDBLogin fnDBLogin;
- FunDBGetServerList fnDBGettServerList;
- FunDBGetChannelList fnDBGetChannelList;
- FunDBGetServerInfo fnDBGetServerInfo;
- FunSetHttpTimeOut fnSetHttpTimeOut;
- FunDoGetHttpFileSize fnGetHttpFileSize;
- FunDoGetHttpFileContent fnGetHttpFileContent;
- FunDoGetLastError fnGetLastError;
- FunDoWord2Pyjc fnDoWord2Pyjc;
- FunDoUploadFtpFile fnDoUploadFtpFile;
- FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
- FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
- FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
- FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
- FunDoGetDBInfo fnDoGetDBInfo;
- QMutex m_mutexWorkerDestroy;
- QWaitCondition m_Condition;
- FunDBDoInterface fnDBDoInterface;
- public:
- bool Load(QString file);
- bool UnLoad();
- int SetHttpTimeOut(int nTimeout);
- QString DoGetLastError(int *nErrorCode);
- QString GetServerID() const {return m_serID;}
- QString GetClientType() const {return m_clientType;}
- int DBQInit(QString strUrl);
- int DBQGetServerList(QString& serverList);
- int DBQGetServerInfo(const QString& serid, QString& serverInfo);
-
- int DBQLogin(QString LocalIP, QString Serid, QString CType, QString &strUserToken);
- int DBQDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = true);
- private slots:
- void OnWorkerFinished();
- private:
- QString m_token;
- QMutex m_mtx;
- QString m_serID;
- QString m_clientType;
- QTimer* m_tUpToken;
- };
- class DoInterfaceObject : public ThreadWorker
- {
- Q_OBJECT
- public:
- explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml);
- virtual ~DoInterfaceObject() override {}
- QString GetRetXML() const {return m_strRetXml;}
- int GetResult() const {return m_nResult;}
- public slots:
- void DoInit() override {}
- void DoWork() override;
- signals:
- void sig_WorkFinished();
- public:
- lhhttpapi *m_pApi;
- QString m_strToken;
- int m_nOperatorType;
- QString m_strParamXml;
- QString m_strRetXml;
- int m_nResult;
- };
|