You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
5.7 KiB
C++
189 lines
5.7 KiB
C++
/******************************************************************************
|
|
Copyright(C):2015~2018 hzleaper
|
|
FileName:LoadSpider.h
|
|
Author:zhikun wu
|
|
Email:zk.wu@hzleaper.com
|
|
Tools:vs2010 pc on company
|
|
Created:2015/04/27
|
|
History:27:4:2015 17:18
|
|
*******************************************************************************/
|
|
#ifndef __SPIDER_USING_H
|
|
#define __SPIDER_USING_H
|
|
|
|
#include "spider.h"
|
|
#include "DllLoader.h"
|
|
|
|
class CLoadSpider
|
|
{
|
|
public:
|
|
CLoadSpider(const char* dllPath);
|
|
CLoadSpider(const ZStringList& dllPaths);
|
|
~CLoadSpider(void);
|
|
|
|
ISpiderConnect* GetSpiderConnect(SPIDER_INI_SETTING* pSetting);
|
|
bool DelSpiderConnect(ISpiderConnect* pConn);
|
|
|
|
/*
|
|
bool InitSpider(const char* dllPath, const char* szCfgFile);
|
|
void FreeSpider();
|
|
void QueueString(const char* key, const char* value);
|
|
bool AppendCommand(void* pfunc, char* szFormatCmd);
|
|
char* RedisFormatCommand(const char *format, ...);
|
|
*/
|
|
private:
|
|
/*
|
|
ZReadWriteLock m_locker;
|
|
SPIDER_INI_SETTING m_setting;
|
|
ISpider* m_pSpider;
|
|
*/
|
|
CDllLoader<SPIDER_INI_SETTING*, ISpider*, ISpider*, void>* m_pLib;
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
inline ISpiderConnect* qspider_getredis(CLoadSpider* pDll
|
|
, const QString& szIp
|
|
, int nPort
|
|
, const QString& szUser
|
|
, const QString& szPassword)
|
|
{
|
|
QJsonObject jsonObj;
|
|
jsonObj.insert(SPIDER_JSON_KEY_REDIS_IP, szIp);
|
|
jsonObj.insert(SPIDER_JSON_KEY_REDIS_PORT, nPort);
|
|
jsonObj.insert(SPIDER_JSON_KEY_REDIS_USER, szUser);
|
|
jsonObj.insert(SPIDER_JSON_KEY_REDIS_PASSWORD, szPassword);
|
|
SPIDER_INI_SETTING setting;
|
|
memset(&setting, 0, sizeof(setting));
|
|
setting.spiderType = SPIDER_REDIS;
|
|
QJsonDocument jsonDoc(jsonObj);
|
|
QByteArray jsonText = jsonDoc.toJson();
|
|
setting.jsonText = jsonText.data();
|
|
return pDll->GetSpiderConnect(&setting);
|
|
}
|
|
|
|
inline ISpiderConnect* qspider_getsqlite(CLoadSpider* pDll
|
|
, const QString& szMainPath
|
|
, const QString& dbName
|
|
, const QString& dbRoot = NULL
|
|
, const QString& dbPassword = NULL
|
|
, const QString& szHttpUrl = NULL
|
|
, const QString& szHttpUser = NULL
|
|
, const QString& szHttpPassword = NULL)
|
|
{
|
|
if (NULL == pDll)
|
|
{
|
|
return NULL;
|
|
}
|
|
SPIDER_INI_SETTING setting;
|
|
memset(&setting, 0, sizeof(setting));
|
|
setting.spiderType = SPIDER_SQLITE;
|
|
QJsonObject jsonObj;
|
|
jsonObj.insert(SPIDER_JSON_KEY_MAIN_PATH, szMainPath);
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_NAME, dbName);
|
|
if (!dbRoot.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_ROOT, dbRoot);
|
|
}
|
|
if (!dbPassword.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_PASSWORD, dbPassword);
|
|
}
|
|
if (!szHttpUrl.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP, szHttpUrl);
|
|
if (!szHttpUser.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP_USER, szHttpUser);
|
|
}
|
|
if (!szHttpPassword.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP_PASSWORD, szHttpPassword);
|
|
}
|
|
}
|
|
QJsonDocument jsonDoc(jsonObj);
|
|
QByteArray jsonText = jsonDoc.toJson();
|
|
setting.jsonText = jsonText.data();
|
|
return pDll->GetSpiderConnect(&setting);
|
|
}
|
|
|
|
inline ISpiderConnect* qspider_getdataupload(CLoadSpider* pDll
|
|
, const QString& szMainPath
|
|
, const QString& dbName
|
|
, const QString& dbRoot = NULL
|
|
, const QString& dbPassword = NULL
|
|
, const QString& szHttpUrl = NULL
|
|
, const QString& szHttpUser = NULL
|
|
, const QString& szHttpPassword = NULL)
|
|
{
|
|
if (NULL == pDll)
|
|
{
|
|
return NULL;
|
|
}
|
|
SPIDER_INI_SETTING setting;
|
|
memset(&setting, 0, sizeof(setting));
|
|
setting.spiderType = SPIDER_DATA_UPLOAD;
|
|
QJsonObject jsonObj;
|
|
jsonObj.insert(SPIDER_JSON_KEY_MAIN_PATH, szMainPath);
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_NAME, dbName);
|
|
if (!dbRoot.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_ROOT, dbRoot);
|
|
}
|
|
if (!dbPassword.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_SQLITE_PASSWORD, dbPassword);
|
|
}
|
|
if (!szHttpUrl.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP, szHttpUrl);
|
|
if (!szHttpUser.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP_USER, szHttpUser);
|
|
}
|
|
if (!szHttpPassword.isEmpty())
|
|
{
|
|
jsonObj.insert(SPIDER_JSON_KEY_HTTP_PASSWORD, szHttpPassword);
|
|
}
|
|
}
|
|
QJsonDocument jsonDoc(jsonObj);
|
|
QByteArray jsonText = jsonDoc.toJson();
|
|
setting.jsonText = jsonText.data();
|
|
return pDll->GetSpiderConnect(&setting);
|
|
}
|
|
|
|
inline ISpiderConnect* qspider_gethttp(CLoadSpider* pDll)
|
|
{
|
|
if (NULL == pDll)
|
|
{
|
|
return NULL;
|
|
}
|
|
SPIDER_INI_SETTING setting;
|
|
memset(&setting, 0, sizeof(setting));
|
|
setting.spiderType = SPIDER_HTTP;
|
|
return pDll->GetSpiderConnect(&setting);
|
|
}
|
|
|
|
inline bool qspider_queuejson(ISpiderConnect* pSpider, const QString& key, const QJsonObject& json)
|
|
{
|
|
QByteArray szKey = key.toUtf8();
|
|
QByteArray szValue = QJsonDocument(json).toJson();
|
|
return pSpider->QueueString(szKey.data(), szValue.data());
|
|
}
|
|
|
|
inline bool qspider_queuestring(ISpiderConnect* pSpider, const QString& key, const QString& text)
|
|
{
|
|
QByteArray szKey = key.toUtf8();
|
|
QByteArray szValue = text.toUtf8();
|
|
return pSpider->QueueString(szKey.data(), szValue.data());
|
|
}
|
|
|
|
inline bool qspider_queuepicture(ISpiderConnect* pSpider, const QString& name, QImage& img, const QString& format)
|
|
{
|
|
QByteArray szName = name.toUtf8();
|
|
QByteArray szFormat = format.toUtf8();
|
|
return pSpider->QueuePicture(szName.data(), &img, szFormat.data());
|
|
}
|
|
|
|
#endif
|