blob: ef0c94314563f3a77134ad0700b029452f3bf1b7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#ifndef DBANDROIDJSONCONNECTION_H
#define DBANDROIDJSONCONNECTION_H
#include "dbandroidmode.h"
#include "common/global.h"
#include "common/expiringcache.h"
#include "dbandroidconnection.h"
#include <QObject>
class DbAndroid;
class AdbManager;
class BlockingSocket;
class DbAndroidJsonConnection : public DbAndroidConnection
{
Q_OBJECT
public:
DbAndroidJsonConnection(DbAndroid* plugin, QObject *parent = 0);
~DbAndroidJsonConnection();
bool connectToAndroid(const DbAndroidUrl& url);
void disconnectFromAndroid();
bool isConnected() const;
QByteArray send(const QByteArray& data);
QString getDbName() const;
QStringList getDbList();
QStringList getAppList();
bool isAppOkay() const;
bool deleteDatabase(const QString& dbName);
ExecutionResult executeQuery(const QString& query);
private:
QJsonDocument wrapQueryInJson(const QString& query);
bool connectToNetwork();
bool connectToDevice();
bool connectToTcp(const QString& ip, int port);
void cleanUp();
QByteArray sendBytes(const QByteArray& data);
void handleSocketError();
void handleConnectionFailed();
QStringList handleDbListResult(const QByteArray& results);
bool handleStdResult(const QByteArray& results);
static QByteArray sizeToBytes(qint32 size);
static qint32 bytesToSize(const QByteArray& bytes);
static QVariant convertJsonValue(const QJsonValue& value);
DbAndroid* plugin = nullptr;
AdbManager* adbManager = nullptr;
BlockingSocket* socket = nullptr;
DbAndroidUrl dbUrl;
DbAndroidMode mode = DbAndroidMode::NETWORK;
bool connectedState = false;
static_char* PASS_RESPONSE_OK = "{\"result\":\"ok\"}";
static_char* PING_RESPONSE_OK = "{\"result\":\"pong\"}";
static_char* LIST_CMD = "{cmd:\"LIST\"}";
static_char* DELETE_DB_CMD = "{cmd:\"DELETE_DB\",db:\"%1\"}";
private slots:
void handlePossibleDisconnection();
};
#endif // DBANDROIDJSONCONNECTION_H
|