wangzhengquan
2020-06-12 602442ecedf17800cddfdae188b05b40345cb011
service/netdisk_service.c
@@ -69,35 +69,37 @@
int work(Netdisk_DownloadRequest drequest) {
  Netdisk *netdisk = NULL;
  std::vector<std::string> files;
  int rv;
  char rmsg[MAXLINE];
  strcpy(rmsg, "success");
  Netdisk_LoginInfo loginInfo = loginStore.getLoginInfo(drequest.loginUUID);
  std::map<std::string, Netdisk *>::iterator userDeviceIter = userDeviceMap.find( drequest.loginUUID);
  if( userDeviceIter != userDeviceMap.end() ) {
     netdisk = userDeviceIter->second;
  }
  Netdisk_LoginInfo loginInfo = loginStore.getLoginInfo(drequest.loginUUID);
  if (netdisk == NULL) {
    netdisk = NetdiskFacotory::create(loginInfo.deviceType);
    if(netdisk != NULL) {
      userDeviceMap.insert({loginInfo.loginUUID, netdisk});
    } else {
      err_msg(0, "无法识别的设备类型: %s", loginInfo.deviceType.c_str());
      snprintf(rmsg, MAXLINE, "无法识别的设备类型: %s", loginInfo.deviceType.c_str());
    }
  }
  if ( (rv = netdisk->login(loginInfo)) != 0 ) {
    printf("下载登录失败\n");
    snprintf(rmsg, MAXLINE, "请重新登录");
  } else if ( (rv = netdisk->downloadByTime(drequest, &files) ) != 0) {
    snprintf(rmsg, MAXLINE, "下载失败");
  }
  std::vector<std::string> files;
  if ( (rv = netdisk->downloadByTime(drequest, &files) ) != 0) {
    printf("下载失败\n");
  }
  Json::Value response;
  Json::Value payload;
  response["rv"] = rv;
  response["code"] = rv;
  response["msg"] = rmsg;
  Json::Value filelist;
  for(std::string f : files) {
@@ -150,6 +152,7 @@
    }
    jsonreader.parse(buf, request);
    nng_free(buf, sz);
    std::string method = request["method"].asString();
    std::map<std::string, RequestHandleFun>::iterator handleFunIter = requestHandleFunMap.find(method);
@@ -160,15 +163,20 @@
      std::cerr << "Don't support " << method << std::endl;
    }
    
    nng_free(buf, sz);
  }
}
/**
 * 注册请求处理的方法
 */
void registRequestHandleFun() {
  requestHandleFunMap.insert({"login", handleLogin});
  requestHandleFunMap.insert({"logout", handleLogout});
  requestHandleFunMap.insert({"downloadByTime", handleDownloadByTimeAsync});
  requestHandleFunMap.insert({"getDeviceInfo", handleGetDeviceInfo});
}
void initThreadPool() {
  pthread_t tid;
@@ -178,15 +186,17 @@
int main()
{
  Netdisk_EnvConfig hcEnvConfig;
  hcEnvConfig.libpath = config.get("hclib");
  HCNetdisk::netdisk_init(&hcEnvConfig);
  //环境变量初始化
  WORKERS = config.getInt("workers");
  localUrl = config.get("local_url");
  remoteUrl = config.get("remote_url");
  //海康设备环境初始化
  Netdisk_EnvConfig hcEnvConfig;
  hcEnvConfig.libpath = config.get("hclib");
  HCNetdisk::netdisk_init(&hcEnvConfig);
  registRequestHandleFun();