pans
2017-08-07 58c513f0a3abb45359972112913619fa9d613c95
add RemoteServer(pthread) #todo add stop()

git-svn-id: http://192.168.1.226/svn/proxy@980 454eff88-639b-444f-9e54-f578c98de674
2个文件已修改
68 ■■■■■ 已修改文件
VisitFace/RtspNativeCodec/app/src/main/cpp/RemoteFunc.cpp 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/RemoteFunc.h 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/RemoteFunc.cpp
@@ -2,3 +2,48 @@
// Created by pansen on 2017/8/4.
//
#include "RemoteFunc.h"
#include <logger.h>
bool RemoteServer::start() {
    LOG_INFO << "server_thd::start" << LOG_ENDL;
    if(running == true){
        LOG_INFO << "The server_thd is already running" << LOG_ENDL;
        return false;
    }
    running = true;
    pthread_mutex_init(&mutexSerevr, NULL); // 初始化互斥对象,动态加锁,用于server
    int retServer = pthread_create(&server_thd, NULL, RemoteServer::rServer_thd, this);
    if(retServer != 0)
    {
        LOGP(ERROR, "server_thd_create: %s/n", strerror(retServer));
        running = false;
        return false;
    }
    return true;
}
void RemoteServer::stop() {
//    LOG_INFO << "server_thd::stop" << LOG_ENDL;
//    if (!running)
//        return;
//    running = false;
//    pthread_mutex_destroy(&mutexSerevr);
    //#todo
}
template <class T>
void *RemoteServer::rServer_thd(void *arg) {
    LOG_INFO << "RemoteServer::rServer_thd start" << LOG_ENDL;
    RemoteServer& rs = *(RemoteServer*)arg;
    capnp::EzRpcServer trpcServer(kj::heap<T>(),rs.host, rs.port);
    auto& serverLoop = trpcServer.getWaitScope();
    kj::NEVER_DONE.wait(serverLoop);
    LOG_INFO << "RemoteServer::rServer_thd stop" << LOG_ENDL;
}
VisitFace/RtspNativeCodec/app/src/main/cpp/RemoteFunc.h
@@ -6,13 +6,30 @@
#define RTSPNATIVECODEC_REMOTEFUNC_H
#include <iostream>
#include <capnp/ez-rpc.h>
#include "RemoteMethod.proto.h"
#include "CameraWrapperServer.h"
class RemoteFunc{
//::capnp::Capability::Server
template <class T> class RemoteServer{
public:
//    RemoteServer(std::string host, int port, capnp::EzRpcServer rpcServer) : rpcServer(rpcServer) {
//        this->rpcServer(kj::heap<T>(),host, port);
//                //.rpcServer(kj::heap<T>(),host, port);
//    };
    RemoteServer(std::string host,int port):host(host),port(port){};
    ~RemoteServer(){};
    bool start();
    void stop();
    bool running;
private:
    std::string host;
    int port;
    static void *rServer_thd(void *arg);
    pthread_t server_thd;
    pthread_mutex_t mutexSerevr;
};
#endif //RTSPNATIVECODEC_REMOTEFUNC_H