#include <QCoreApplication>

#include <QDebug>

#include <functional>
#include <QTime>
#include <QtCore/qcommandlineoption.h>
#include <QtCore/qcommandlineparser.h>
#include <string.h>

#include "inputgatherclient.h"
#include "socketclient.h"
#include "ukuiinputgatherclient.h"
#include "testcommand.h"

void getEvent2(Event *event);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    if(!argv[1]){
        qDebug()<<"please input parse..."<<endl<<
                  "may be you can input parse  "<<"--help";
        return 0;
    }

    UKUIInputGatherClient inputGatherClient;
    testCommand testTool;
    QCommandLineParser parser;
    QCommandLineOption showHelpInfo("help","help info");
    QCommandLineOption showConnectServer("connectServer","show info for connect");
    QCommandLineOption showDebugEvents("debug-events","show info for events");
    QCommandLineOption callMethodRequest("call", "call method request");
    parser.addOption(showHelpInfo);
    parser.addOption(showConnectServer);
    parser.addOption(showDebugEvents);
    parser.addOption(callMethodRequest);
    parser.process(a);

    if(parser.isSet("help")){
        testTool.testCommandHelpStr();
        return 0;
    }
    if(parser.isSet("connectServer")){
        inputGatherClient.setEventCallBack(getEvent2);
        inputGatherClient.startToReceiveEvent();
        return 0;
    }
    if(parser.isSet("debug-events")){
        inputGatherClient.setEventCallBack(getEvent2);
        inputGatherClient.startToReceiveEvent();
    }
    if (parser.isSet("call")) {
        QString func = parser.positionalArguments().at(0);

        if (func == "libinputTabletSwitchState") {
            qDebug() << "libinputTabletSwitchState return:" << inputGatherClient.libinputTabletSwitchState();
            return 0;
        }
    }
    a.exec();
    return 0;
}


void getEvent2(Event *event)
{
    testCommand testTool;
    testTool.getEvent2(event);
}
