houxiao
2017-08-16 a188ad2e23ef190c8a044b17bc467fa3e2ae0ca5
VisitFace/RtspNativeCodec/app/src/main/cpp/RemoteFuncServer.cpp
@@ -1,32 +1,127 @@
//
// Created by pansen on 2017/8/4.
//
#include "RemoteFuncServer.h"
RtspFaceDetectClient rtspFaceDetectClient;
const RtspFaceDetectClient& getRtspFaceDetectClient(){
   return rtspFaceDetectClient;
}
//#todo
RtspFaceDetectClient::RtspFaceDetectClient():rpcClient("127.0.0.1",8111),
                           client(rpcClient.getMain<RtspFaceDetect>())
{}
void RtspFaceDetectClient::fireFaceCountListener(int cameraIndex, int faceCount){
        auto req = client.fireFaceCountListenerRequest();
        req.setCameraIndex(cameraIndex);
        req.setFaceCount(faceCount);
        auto send = req.send();
        send.wait(rpcClient.getWaitScope());
}
//#todo
::kj::Promise<void> RtspFaceViewImpl::RtspFaceViewImpl() {}
::kj::Promise<void> RtspFaceViewImpl::~RtspFaceViewImpl(){}
::kj::Promise<void> RtspFaceViewImpl::getFaceList(GetFaceListContext context) override{}
::kj::Promise<void> RtspFaceViewImpl::getFaceImages(GetFaceImagesContext context) override{}
::kj::Promise<void> RtspFaceViewImpl::setFaceLabel(SetFaceLabelContext context) override {}
//
// Created by pansen on 2017/8/4.
//
#include "AppConfig.h"
#include "RemoteFuncServer.h"
#include "RemoteFunc.h"
#include "RtspNativeCodecJNIServer.h"
#include <string>
#include <iostream>
using namespace std;
//#todo 修改服务线程构造参数传入方式
RemoteServer<RtspFaceViewImpl> remoteServer("192.168.1.94", 8112);
//RemoteServer<RtspFaceViewImpl> remoteServer("192.168.1.97", 8112);
static RtspFaceDetectClient* rtspFaceDetectClient = nullptr;
void startRemoteServer()
{
;
   AppConfig config;
   config.loadConfig("data/config.cfg");
    remoteServer.start();
//    //#todo 调用位置移动
//    try
//    {
//        RtspFaceDetectClient rtspFaceDetectClient = RtspFaceDetectClient();
//        RtspFaceDetect::Client& rClient = rtspFaceDetectClient.getClient();
//
//        auto& waitScope = rtspFaceDetectClient.getWaitScope();
//        auto  request = rClient.fireFaceCountListenerRequest();
//        auto sendAct = request.send();
//        sendAct.wait(waitScope);
//    }
//    catch (const kj::Exception& e)
//    {
//        cout << e.getDescription().cStr() << endl;
//        return;
//    }
    //#end
}
RtspFaceDetectClient * getRtspFaceDetectClient()
{
    if(rtspFaceDetectClient == nullptr)
        rtspFaceDetectClient = new RtspFaceDetectClient;
    return rtspFaceDetectClient;
}
//#todo 构造函数修改
RtspFaceDetectClient::RtspFaceDetectClient() :
        rpcClient(nullptr)
{
}
RtspFaceDetect::Client* RtspFaceDetectClient::getClient()
{
    LOG_INFO << "new client @ " << (int*)client << LOG_ENDL;
    if (client == nullptr) {
        LOG_INFO << "new client 2" << LOG_ENDL;
        try
        {
            client = new RtspFaceDetect::Client(getEzRpcClient()->getMain<RtspFaceDetect>());
        }
        catch (const kj::Exception& e)
        {
            LOG_ERROR << "new client error" << LOG_ENDL;
            delete client;
            client = nullptr;
            throw e;
        }
    }
    return client;
}
::kj::WaitScope &RtspFaceDetectClient::getWaitScope()
{
    return getEzRpcClient()->getWaitScope();
}
capnp::EzRpcClient * RtspFaceDetectClient::getEzRpcClient()
{
    if (rpcClient == nullptr) {
        try
        {
            //#todo ip test
            //rpcClient = new capnp::EzRpcClient("192.168.1.89", 8111);
            //client
           rpcClient = new capnp::EzRpcClient("192.168.1.97", 8111);
        }
        catch (const kj::Exception& e)
        {
            delete rpcClient;
            rpcClient = nullptr;
            throw e;
        }
    }
    return rpcClient;
}
::kj::Promise<void> RtspFaceViewImpl::getFaceList(GetFaceListContext context)
{
   auto results = context.getResults();
   remoteGetFaceList(context.getParams(), results);
   context.setResults(results);
    LOG_ERROR <<"getFaceList : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<< LOG_ENDL;
    return kj::READY_NOW;
}
::kj::Promise<void> RtspFaceViewImpl::getFaceImages(GetFaceImagesContext context)
{
   auto results = context.getResults();
   remoteGetFaceListImage(context.getParams(), results);
   context.setResults(results);
    LOG_ERROR <<"getFaceImages : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<< LOG_ENDL;
    return kj::READY_NOW;
}
::kj::Promise<void> RtspFaceViewImpl::setFaceLabel(SetFaceLabelContext context)
{
   auto results = context.getResults();
   remoteSetFaceLabel(context.getParams(), results);
   context.setResults(results);
    LOG_ERROR <<"setFaceLabel : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<< LOG_ENDL;
    return kj::READY_NOW;
}