//TODO: avoid void functions
void Worker::getState(Jzon::Object &workerNode)
{
    Jzon::Array pList;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    {
        std::lock_guard<std::mutex> guard(mtx);

        while (!processors.empty()){
            current = processors.top();
            processors.pop();
            runnables[current->getId()] = current;
        }

        for (auto it : runnables){
            processors.push(it.second);
        }

    }

    for (auto it : runnables) {
        pList.Add(it.first);
    }

    workerNode.Add("type", utils::getWorkerTypeAsString(type));
    workerNode.Add("processors", pList);
}
Exemple #2
0
void push(Jzon::Object& json,const std::string& key,T i)
{
    std::string value = i->value().toString();

    switch ( i->typeId() ) {
        case Exiv2::xmpText:
        case Exiv2::asciiString : 
        case Exiv2::string:
        case Exiv2::comment:
             json.Add(key,value);
        break;

        case Exiv2::unsignedByte:
        case Exiv2::unsignedShort:
        case Exiv2::unsignedLong:
        case Exiv2::signedByte:
        case Exiv2::signedShort:
        case Exiv2::signedLong:
             json.Add(key,(int)i->value().toLong());
        break;
        
        case Exiv2::tiffFloat:
        case Exiv2::tiffDouble:
             json.Add(key,i->value().toFloat());
        break;

        case Exiv2::unsignedRational:
        case Exiv2::signedRational: {
             Jzon::Array arr;
             Rational rat = i->value().toRational();
             arr.Add (rat.first );
             arr.Add (rat.second);
             json.Add(key,arr);
        } break;

        case Exiv2::date:
        case Exiv2::time:
             json.Add(key,i->value().toString());
        break;

        default:
        case Exiv2::undefined:
        case Exiv2::tiffIfd:
        case Exiv2::directory:
        case Exiv2::xmpAlt:
        case Exiv2::xmpBag:
        case Exiv2::xmpSeq:
        case Exiv2::langAlt:
             // http://dev.exiv2.org/boards/3/topics/1367#message-1373
             if ( key == "UserComment" ) {
                size_t pos  = value.find('\0') ;
             	if (   pos != string::npos )
             	    value = value.substr(0,pos);
             }

             if ( key != "MakerNote") json.Add(key,value);
        break;
    }
}
void
trackingCallback(const opt_msgs::TrackArray::ConstPtr& tracking_msg)
{
  /// Create JSON-formatted message:
  Jzon::Object root, header, stamp;

  /// Add header (84 characters):
  header.Add("seq", int(tracking_msg->header.seq));
  stamp.Add("sec", int(tracking_msg->header.stamp.sec));
  stamp.Add("nsec", int(tracking_msg->header.stamp.nsec));
  header.Add("stamp", stamp);
  header.Add("frame_id", tracking_msg->header.frame_id);
  root.Add("header", header);

  /// Add tracks array:
  // >50 characters for every track
  Jzon::Array tracks;
  for (unsigned int i = 0; i < tracking_msg->tracks.size(); i++)
  {
    Jzon::Object current_track;
    current_track.Add("id", tracking_msg->tracks[i].id);
    current_track.Add("x", tracking_msg->tracks[i].x);
    current_track.Add("y", tracking_msg->tracks[i].y);
    current_track.Add("height", tracking_msg->tracks[i].height);
    current_track.Add("age", tracking_msg->tracks[i].age);
    current_track.Add("confidence", tracking_msg->tracks[i].confidence);

    tracks.Add(current_track);
  }
  root.Add("tracks", tracks);

  /// Convert JSON object to string:
  Jzon::Format message_format = Jzon::StandardFormat;
  message_format.indentSize = json_indent_size;
  message_format.newline = json_newline;
  message_format.spacing = json_spacing;
  message_format.useTabs = json_use_tabs;
  Jzon::Writer writer(root, message_format);
  writer.Write();
  std::string json_string = writer.GetResult();
//  std::cout << "String sent: " << json_string << std::endl;

  /// Copy string to message buffer:
  udp_data.si_num_byte_ = json_string.length()+1;
  char buf[udp_data.si_num_byte_];
  for (unsigned int i = 0; i < udp_data.si_num_byte_; i++)
  {
    buf[i] = 0;
  }
  sprintf(buf, "%s", json_string.c_str());
  udp_data.pc_pck_ = buf;         // buffer where the message is written

  /// Send message:
  udp_messaging.sendFromSocketUDP(&udp_data);
}
Exemple #4
0
std::vector<CCL_MocapJoint> loadMotionCaptureFromJson(const ci::fs::path &file)
{
  vector<CCL_MocapJoint> mJoints;

  Jzon::Object rootNode;
  Jzon::FileReader::ReadFile(file.string(), rootNode);

  const Jzon::Array &joints = rootNode.Get("joints").AsArray();
  for( Jzon::Array::const_iterator it = joints.begin() ; it != joints.end();++it){
      Jzon::Object joint = (*it).AsObject();
      // name
      string name = joint.Get("name").ToString();

      // xPos
      Jzon::Array xPosList = joint.Get("xPos").AsArray();
      vector<float> xPosVec;
      for( Jzon::Array::iterator itt = xPosList.begin() ; itt != xPosList.end();++itt){
          float pos = stof((*itt).ToString());
          xPosVec.push_back(pos);
      }
      // yPos
      Jzon::Array yPosList = joint.Get("yPos").AsArray();
      vector<float>yPosVec;
      for( Jzon::Array::iterator itt = yPosList.begin() ; itt != yPosList.end();++itt){
          float pos = stof((*itt).ToString());
          yPosVec.push_back(pos);
      }
      // zPos
      Jzon::Array zPosList = joint.Get("zPos").AsArray();
      vector<float> zPosVec;
      for( Jzon::Array::iterator itt = zPosList.begin() ; itt != zPosList.end();++itt){
          float pos = stof((*itt).ToString());
          zPosVec.push_back(pos);
      }


    //  cout << "JOINT NAME:"<<name<<endl;
      CCL_MocapJoint cclJoint = CCL_MocapJoint(name,10);

      cclJoint.xPositions = xPosVec;
      cclJoint.yPositions = yPosVec;
      cclJoint.zPositions = zPosVec;
      cclJoint.loadPositions();


      mJoints.push_back(cclJoint);

  }
/*
  for( int i  = 0 ; i < 10 ; i++) {
      CCL_MocapJoint jointt = mJoints[i];
      for( int j = 0 ; j < 3 ; j++){
          cout << "[" << jointt.jointName << "] (" << jointt.jointPositions[j].x << "," <<jointt.jointPositions[j].y << ","<< jointt.jointPositions[j].z <<")"<< endl;
      }
  }*/

  return mJoints;
};
Exemple #5
0
std::vector<CCL_MocapJoint> loadMotionCaptureFromSite( int skip)
{
  vector<CCL_MocapJoint> mJoints;
  try{
      //LOAD JSON FILE CONTAINING UUIDs of each stream under specified channel
      const JsonTree json( loadUrl(URL_STREAM_JSON) );

      //LOOP THROUGH STREAMS
      for( auto &stream : json.getChildren() ){
          const string &uuid = stream["uuid"].getValue();
          string title = stream["title"].getValue();
          if( stream.hasChild("group")){
              string group = stream["group"].getValue();
              //      std::cout << "group:"<< group << " title:" << title << " uuid[" << i << "] = " << uuid << std::endl;
              addUUIDtoJoint(group, title, uuid, skip, mJoints);
          }
      }

      // create json file
      Jzon::Object root;
      root.Add("URL", URL_STREAM_JSON);
      Jzon::Array joints;

      for( int i = 0 ; i < mJoints.size() ; i++){
          CCL_MocapJoint theJoint = mJoints[i];
          Jzon::Object joint;
          joint.Add("name", theJoint.jointName );
          Jzon::Array xPoslist;
          Jzon::Array yPoslist;
          Jzon::Array zPoslist;

          for( int j = 0 ; j < theJoint.jointPositions.size(); j++){
              xPoslist.Add(theJoint.jointPositions[j].x);
              yPoslist.Add(theJoint.jointPositions[j].y);
              zPoslist.Add(theJoint.jointPositions[j].z);
          }

          joint.Add("xPos", xPoslist);
          joint.Add("yPos", yPoslist);
          joint.Add("zPos", zPoslist);

          joints.Add(joint);
      }
      root.Add("joints", joints);
      cout << "Start writing file as CCL_JOINT.json" <<endl;
      Jzon::FileWriter::WriteFile("CCL_JOINT.json", root, Jzon::StandardFormat);
      cout << "Ended writing file" <<endl;


  }
  catch( ci::Exception &exc ) {
      std::cout << "Failed to parse json, what: " << exc.what() << std::endl;
  }

  return mJoints;
};
void VideoMixer::doGetState(Jzon::Object &filterNode)
{
    Jzon::Array jsonChannelConfigs;

    filterNode.Add("width", outputWidth);
    filterNode.Add("height", outputHeight);
    filterNode.Add("maxChannels", maxChannels);

    for (auto it : channelsConfig) {
        Jzon::Object chConfig;
        chConfig.Add("id", it.first);
        chConfig.Add("width", it.second->getWidth());
        chConfig.Add("height", it.second->getHeight());
        chConfig.Add("x", it.second->getX());
        chConfig.Add("y", it.second->getY());
        chConfig.Add("layer", it.second->getLayer());
        chConfig.Add("enabled", it.second->isEnabled());
        chConfig.Add("opacity", it.second->getOpacity());
        jsonChannelConfigs.Add(chConfig);
    }

    filterNode.Add("channels", jsonChannelConfigs);
}
void PipelineManager::getStateEvent(Jzon::Node* params, Jzon::Object &outputNode)
{
    Jzon::Array filterList;
    Jzon::Array pathList;
    Jzon::Array workersList;

    for (auto it : filters) {
        Jzon::Object filter;
        filter.Add("id", it.first);
        it.second->getState(filter);
        filterList.Add(filter);
    }

    outputNode.Add("filters", filterList);

    for (auto it : paths) {
        Jzon::Object path;
        Jzon::Array pathFilters;
        std::vector<int> pFilters = it.second->getFilters();

        path.Add("id", it.first);
        path.Add("originFilter", it.second->getOriginFilterID());
        path.Add("destinationFilter", it.second->getDestinationFilterID());
        path.Add("originWriter", it.second->getOrgWriterID());
        path.Add("destinationReader", it.second->getDstReaderID());

        for (auto it : pFilters) {
            pathFilters.Add(it);
        }

        path.Add("filters", pathFilters);
        pathList.Add(path);
    }

    outputNode.Add("paths", pathList);

    for (auto it : workers) {
        Jzon::Object worker;
        worker.Add("id", it.first);
        it.second->getState(worker);
        workersList.Add(worker);
    }

    outputNode.Add("workers", workersList);

}