houxiao
2017-04-25 0e32d241f9ddd7e202879230585cb939dd3877b2
bug fix

git-svn-id: http://192.168.1.226/svn/proxy@545 454eff88-639b-444f-9e54-f578c98de674
1个文件已添加
6个文件已修改
122 ■■■■ 已修改文件
FaceServer/ev_proto.h 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/ev_server.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/ev_server.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/face_daemon_proto.h 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/main_face_daemon.cpp 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/make.sh 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/proto_hton_ntoh.cpp 73 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
FaceServer/ev_proto.h
@@ -56,6 +56,9 @@
    int16_t cmd;    // EVPCommand::EVPC
    uint32_t size;    // sizeof(EVPHeader)+sizeof(subcmd)
    
    void hton();
    void ntoh();
    EVPHeader() : _padding1(0), proto(EVPProto::EVPP__FIRST), cmd(EVPCommand::EVPC__FIRST), size(8)
    {}
};
@@ -63,12 +66,18 @@
struct EVP_Status
{
    int16_t status;
    void hton();
    void ntoh();
};
struct EVP_VariableBuffer
{
    int16_t type;
    uint8_t buff[0];
    void hton();
    void ntoh();
};
//#todo
FaceServer/ev_server.cpp
@@ -132,6 +132,7 @@
        }
        
        evpHeader = (EVPHeader*)headerBuff;
        evpHeader->ntoh();
        
        // check header
        if (evpHeader->proto <= EVPProto::EVPP__FIRST || evpHeader->proto >= EVPProto::EVPP__LAST || 
@@ -166,9 +167,10 @@
    do
    {
        readSize = bufferevent_read(bufev, client->recvbuff + client->recvbuff_end, client->recvbuff_max - client->recvbuff_end);
        client->read_times++;
        if (readSize == 0)
            break;
        else
            client->read_times++;
        client->recvbuff_end += readSize;
    } while (readSize > 0);
@@ -352,7 +354,9 @@
    EVPHeader* evpHeader = new (client.sendBuff) EVPHeader;
    evpHeader->cmd = EVPCommand::EVPC_STATUS;
    evpHeader->size = client.sendBuffSize;
    evpHeader->hton();
    
    EVP_Status* evpStatus = new (client.sendBuff + sizeof(EVPHeader)) EVP_Status;
    evpStatus->status = status;
    evpHeader->hton();
}
FaceServer/ev_server.h
@@ -9,7 +9,7 @@
#define SERVER_PORT 5432
#endif
#define REUSEADDR_ON 1
#define CLIENT_BUFFER_MAX 100*1024 // 100KB
#define CLIENT_BUFFER_MAX 1*1024*1024 // 1MB
#define CLIENT_READ_TIMES_MAX 100
#define CLIENT_MAX 100 // max count of clients connected //#todo not support
FaceServer/face_daemon_proto.h
@@ -31,8 +31,10 @@
    int16_t height;
    uint8_t buff[0];
    
    void hton();//#todo
    void hton();
    void ntoh();
};
//sizeof(FDP_Image)=10
struct FDP_FaceDetectPB
{
@@ -41,7 +43,8 @@
    FDP_FaceDetectPB(int32_t _db_id) : db_id(_db_id)
    {}
    
    void hton();//#todo
    void hton();
    void ntoh();
};
struct FDP_FaceDetectResult
@@ -52,7 +55,8 @@
    FDP_FaceDetectResult(int32_t _db_id, int32_t _st_id) : db_id(_db_id), st_id(_st_id)
    {}
    
    void hton();//#todo
    void hton();
    void ntoh();
};
#pragma pack()
FaceServer/main_face_daemon.cpp
@@ -107,6 +107,7 @@
{
    EVPHeader* evpHeader = (EVPHeader*)client.recvBuff;
    FDP_Image* fdpImage = (FDP_Image*)(client.recvBuff + sizeof(EVPHeader));
    fdpImage->ntoh();
    
    STFaceImage stfaceImg;
    stfaceImg.db_id = fdpImage->db_id;
@@ -116,13 +117,16 @@
    stfaceImg.size = evpHeader->size - sizeof(EVPHeader) - sizeof(FDP_Image);
    stfaceImg.buff = fdpImage->buff;
    
    //char imgfn[100 * 1024];
    //static int i = 0;
    //sprintf(imgfn, "IMG_%d_%d_w%d_h%d.rgb565", stfaceImg.db_id, ++i, stfaceImg.width, stfaceImg.height);
    //FILE * pFile = fopen(imgfn, "wb");
    //fwrite(stfaceImg.buff, sizeof(char), stfaceImg.size, pFile);
    //fclose(pFile);
    //pFile = nullptr;
    LOGP(DEBUG, "stfaceImg db_id=%d, mb_type=%d, width=%d, height=%d, size=%d",
        (int)stfaceImg.db_id, (int)stfaceImg.mb_type, (int)stfaceImg.width, (int)stfaceImg.height, (int)stfaceImg.size);
    char imgfn[100 * 1024];
    static int i = 0;
    sprintf(imgfn, "IMG_%d_%d_w%d_h%d.rgb565", stfaceImg.db_id, ++i, stfaceImg.width, stfaceImg.height);
    FILE * pFile = fopen(imgfn, "wb");
    fwrite(stfaceImg.buff, sizeof(char), stfaceImg.size, pFile);
    fclose(pFile);
    pFile = nullptr;
    
    fdr_vec_t result;
    FDP_FaceDetectResult fdrResult = g_STFaceCache.add(stfaceImg);
@@ -162,7 +166,7 @@
bool ev_dispatcher_proto_rawbin(EVClientStub& client)
{
    LOG_DEBUG << "ev_dispatcher_proto_pb" << LOG_ENDL;
    LOG_DEBUG << "ev_dispatcher_proto_rawbin" << LOG_ENDL;
    
    EVPHeader* evpHeader = (EVPHeader*)client.recvBuff;
    if (evpHeader->size != client.recvBuffSize)
FaceServer/make.sh
@@ -26,6 +26,7 @@
g++ $PIPELINE_BASE/Logger/src/logger.cc $CFLAGS $CPPFLAGS
g++ ev_server.cpp -DUSER_DEFINE_EVCLIENT_PROC $CFLAGS $CPPFLAGS
g++ proto_hton_ntoh.cpp $CFLAGS $CPPFLAGS
g++ $VISITFACE_BASE/PbFaceList.pb.cc $CFLAGS $CPPFLAGS
g++ main_face_daemon.cpp $CFLAGS $CPPFLAGS
g++ sample_face_search.cpp $CFLAGS $CPPFLAGS
@@ -38,6 +39,7 @@
g++ -g -std=c++11 \
  logger.o \
  ev_server.o \
  proto_hton_ntoh.o \
  PbFaceList.pb.o \
  main_face_daemon.o \
  sample_face_search.o \
FaceServer/proto_hton_ntoh.cpp
New file
@@ -0,0 +1,73 @@
#include "ev_proto.h"
#include "face_daemon_proto.h"
#include <netinet/in.h>
void EVPHeader::hton()
{
    cmd = htons(cmd);
    size = htonl(size);
}
void EVPHeader::ntoh()
{
    cmd = ntohs(cmd);
    size = ntohl(size);
}
void EVP_Status::hton()
{
    status = htons(status);
}
void EVP_Status::ntoh()
{
    status = ntohs(status);
}
void EVP_VariableBuffer::hton()
{
    type = htons(type);
}
void EVP_VariableBuffer::ntoh()
{
    type = ntohs(type);
}
void FDP_Image::hton()
{
    db_id = htonl(db_id);
    mb_type = htons(mb_type);
    width = htons(width);
    height = htons(height);
}
void FDP_Image::ntoh()
{
    db_id = ntohl(db_id);
    mb_type = ntohs(mb_type);
    width = ntohs(width);
    height = ntohs(height);
}
void FDP_FaceDetectPB::hton()
{
    db_id = htonl(db_id);
}
void FDP_FaceDetectPB::ntoh()
{
    db_id = ntohl(db_id);
}
void FDP_FaceDetectResult::hton()
{
    db_id = htonl(db_id);
    st_id = htonl(st_id);
}
void FDP_FaceDetectResult::ntoh()
{
    db_id = ntohl(db_id);
    st_id = ntohl(st_id);
}