nugget_toolkit/client/utils.cpp
int callNosCmd(const char* body, const NosApp* app, const NosCmd* cmd) {
  auto req = cmd->request->New();
  auto res = cmd->reply->New();
  req->CopyFrom(*cmd->request);
  res->CopyFrom(*cmd->reply);

  auto num_fields = req->GetDescriptor()->field_count();
  if ((num_fields > 0) && !body) {
    printRequestDefinition(req);
    // return 3;
  }

  if (body) {
    auto status = JsonStringToMessage(body, req);
    if (status.ok()) {
      std::cout << "Request:" << endl;
      req->PrintDebugString();
      std::cout << endl;
    } else {
      std::cerr << "Json parsing issue: " << status << std::endl;
      return 1;
    }
  }

  // init the client
  NuggetClient client(CITADEL_DEV);
  uint32_t rv;

  client.Open();

  if (!client.IsOpen()) {
    std::cerr << "Error opening client " << CITADEL_DEV << std::endl;
    return 2;
  }

  // convert request to vector<uint8_t>
  std::string sreq;
  req->SerializeToString(&sreq);
  std::vector<uint8_t> vecreq(sreq.begin(), sreq.end());

  std::vector<uint8_t> vecres;
  vecres.resize(MAX_RESPONSE_SIZE);

  // call nos lib
  rv = client.CallApp(app->id, cmd->id, vecreq, &vecres);

  // print result
  std::string response_str(vecres.begin(), vecres.end());
  res->ParseFromString(response_str);
  std::cout << "Response:" << endl;
  res->PrintDebugString();

  // close the client
  client.Close();

  return rv;
}
/*
 * Send a command to a Citadel application. Takes a optional json string as
 * argument. Return the status code coming from nos library.
 */
Send a command to a Citadel application. Takes a optional json string as
argument. Return the status code coming from nos library.
Send a command to a Citadel application . Takes a optional json string as argument . Return the status code coming from nos library .
int callNosCmd(const char* body, const NosApp* app, const NosCmd* cmd) {
  auto req = cmd->request->New();
  auto res = cmd->reply->New();
  req->CopyFrom(*cmd->request);
  res->CopyFrom(*cmd->reply);
  auto num_fields = req->GetDescriptor()->field_count();
  if ((num_fields > 0) && !body) {
    printRequestDefinition(req);
  }
  if (body) {
    auto status = JsonStringToMessage(body, req);
    if (status.ok()) {
      std::cout << "Request:" << endl;
      req->PrintDebugString();
      std::cout << endl;
    } else {
      std::cerr << "Json parsing issue: " << status << std::endl;
      return 1;
    }
  }
  NuggetClient client(CITADEL_DEV);
  uint32_t rv;
  client.Open();
  if (!client.IsOpen()) {
    std::cerr << "Error opening client " << CITADEL_DEV << std::endl;
    return 2;
  }
  std::string sreq;
  req->SerializeToString(&sreq);
  std::vector<uint8_t> vecreq(sreq.begin(), sreq.end());
  std::vector<uint8_t> vecres;
  vecres.resize(MAX_RESPONSE_SIZE);
  rv = client.CallApp(app->id, cmd->id, vecreq, &vecres);
  std::string response_str(vecres.begin(), vecres.end());
  res->ParseFromString(response_str);
  std::cout << "Response:" << endl;
  res->PrintDebugString();
  client.Close();
  return rv;
}
int callNosCmd ( const char * body , const NosApp * app , const NosCmd * cmd ) { auto req = cmd -> request -> New ( ) ; auto res = cmd -> reply -> New ( ) ; req -> CopyFrom ( * cmd -> request ) ; res -> CopyFrom ( * cmd -> reply ) ; auto num_fields = req -> GetDescriptor ( ) -> field_count ( ) ; if ( ( num_fields > 0 ) && ! body ) { printRequestDefinition ( req ) ; } if ( body ) { auto status = JsonStringToMessage ( body , req ) ; if ( status . ok ( ) ) { std :: cout << " " << endl ; req -> PrintDebugString ( ) ; std :: cout << endl ; } else { std :: cerr << " " << status << std :: endl ; return 1 ; } } NuggetClient client ( CITADEL_DEV ) ; uint32_t rv ; client . Open ( ) ; if ( ! client . IsOpen ( ) ) { std :: cerr << " " << CITADEL_DEV << std :: endl ; return 2 ; } std :: string sreq ; req -> SerializeToString ( & sreq ) ; std :: vector < uint8_t > vecreq ( sreq . begin ( ) , sreq . end ( ) ) ; std :: vector < uint8_t > vecres ; vecres . resize ( MAX_RESPONSE_SIZE ) ; rv = client . CallApp ( app -> id , cmd -> id , vecreq , & vecres ) ; std :: string response_str ( vecres . begin ( ) , vecres . end ( ) ) ; res -> ParseFromString ( response_str ) ; std :: cout << " " << endl ; res -> PrintDebugString ( ) ; client . Close ( ) ; return rv ; }
Send a command to a Citadel application.
Send a command to a Citadel application .
// return 3; // init the client // convert request to vector<uint8_t> // call nos lib // print result // close the client