コード例 #1
0
 void LogCollector::logString( char const *data, size_t length )
 {
   std::vector<std::string> src;
   src.push_back( "DG" );
   
   Util::SimpleString json;
   {
     JSON::Encoder jg( &json );
     jg.makeString( data, length );
   }
   m_context->jsonNotify( src, "log", 3, &json );
 }
コード例 #2
0
    RC::Handle<ResourceLoadNode> ResourceLoadNode::Create( std::string const &name, RC::Handle<Context> const &context )
    {
      RC::Handle<ResourceLoadNode> resourceLoadNode = new ResourceLoadNode( name, context );
      
      Util::SimpleString json;
      {
        JSON::Encoder jg( &json );
        resourceLoadNode->jsonDesc( jg );
      }
      resourceLoadNode->jsonNotifyDelta( json );

      return resourceLoadNode;
    }
コード例 #3
0
ファイル: publicFunc.cpp プロジェクト: wangzhen625/SendMail
int parseJosnString(string jsonStr, string& strRet)
{
	json_object* message = json_tokener_parse(jsonStr.c_str());
	if(message == NULL || is_error(message) || (json_object_get_type(message) != json_type_object)){		
		return false;		
	}
	JsonObjGuard jg(message);
	json_object* obj_data = json_object_object_get(message, "data");
	if((NULL == obj_data) || (is_error(obj_data)) || (json_type_array != json_object_get_type(obj_data))){
		printf("get data is null!");
		return -1; 
	}

	const int arrLen = json_object_array_length(obj_data);
	if(0 == arrLen){
		return -1;
	}
	string ss;
	for(int i = 0; i < arrLen; i++)
	{
		string temp("日期: ");
		json_object* obj_arr_element = NULL;
		obj_arr_element = json_object_array_get_idx(obj_data, i);
		if(NULL == obj_arr_element)
			continue;

		json_object* obj_TimeDate= json_object_object_get(obj_arr_element, "TimeDate");
		if((NULL == obj_TimeDate) || (is_error(obj_TimeDate)) || (json_type_string != json_object_get_type(obj_TimeDate))){
			printf("get TimeDate error\n");
			return false;
		}
		string TimeDateSting =json_object_get_string(obj_TimeDate);
		int pos = TimeDateSting.find("T");
		TimeDateSting = TimeDateSting.substr(0,pos);
		temp.append(TimeDateSting+"  ");
		
		json_object* obj_DelegateSum= json_object_object_get(obj_arr_element, "DelegateSum");
		if((NULL == obj_DelegateSum) || (is_error(obj_DelegateSum)) || (json_type_string != json_object_get_type(obj_DelegateSum))){
			printf("get DelegateSum error\n");
			return false;
		}
		temp = temp + "委托单:" + json_object_get_string(obj_DelegateSum) +"  ";

		json_object* obj_QuerySum= json_object_object_get(obj_arr_element, "QuerySum");
		if((NULL == obj_QuerySum) || (is_error(obj_QuerySum)) || (json_type_string != json_object_get_type(obj_QuerySum))){
			printf("get QuerySum error\n");
			return false;
		}
		temp = temp + "查询单:" + json_object_get_string(obj_QuerySum) +"  ";

		json_object* obj_MaxOnline = json_object_object_get(obj_arr_element, "MaxOnline");
		if((NULL == obj_MaxOnline) || (is_error(obj_MaxOnline)) || (json_type_string != json_object_get_type(obj_MaxOnline))){
			printf("get MaxOnline error\n");
			return false;
		}
		temp = temp + "最大在线人数:" + json_object_get_string(obj_QuerySum) +"  ";

		ss = ss + temp+"\r\n";
	}
	strRet = ss;
	return 0;
}
コード例 #4
0
ファイル: feature_vector.cpp プロジェクト: CSEmbree/capstone
bool feature_vector::write( config_handler *ch, audio_recorder *ar, bool formatOutput ) {
  
  string mn = "write::";
  cout<<cn<<mn<<" Preparing to write feature vector ... "<<endl;
  bool res = true;
  
  bool format_output_flag = ch->get_output_formatted();
  if( formatOutput != true ) format_output_flag = formatOutput;


  string filepath = ch->get_data_location();
  string filename = get_time_stamp() + ".dat";
  //  if( fpath != "" ) filepath = fpath;
  //  if( fname != "" ) filename = fname;
  
  string file =  filepath + filename;



  cout<<cn<<mn<<" Going to place json file to \""<<filename<<"\""<<endl;
  json_generator jg( file );
  

  // ***FIRST - write ci_rainbow administrative info
  jg.open_object();

  //  jg.add_pair( "date", utils::get_current_date_time() );
  jg.add_pair( "date", utils::get_current_time() % 1000 ); //TMPORARY FOR TEST
  jg.add_pair( "type", ch->get_output_type_id() );
  


  // Gather any files if user wants them
  vector< string > files;
  files.clear();

  // Gather media file name for transport 
  if( ch->get_save_rec() == true ) {
    string audio_fname = ar->get_rec_file_name_core() + ar->get_rec_extention();
    files.push_back( audio_fname );  
  }

  
  // Gather feature file names for transport (unless they are being wrapped in JSON later)
  if( ch->get_analysis() == true && (ch->get_final_feature_format() == "FILES") ) {
    for( unsigned int feat_i = 0; feat_i < features.size(); feat_i++ ) {
      files.push_back( feature_fnames_base.at( feat_i ) );
    }
  }


  // If we are saving audio and/or feature files, then save wrapped audio and/or feature files
  if( !files.empty() ) {
    jg.add_pair( "files", files);
  }


  
  // **SECOND - all data is in the "data" section
  // Open data key for the ramining meta date info
  jg.add_key( "data" ); 


  // write meta data info
  jg.open_object(); // open object for 

  jg.add_pair( "sampleRate",          ch->get_samp_rate() );
  jg.add_pair( "recordingNumber",     ch->get_rec_number() );
  jg.add_pair( "recordingDuration",   ch->get_rec_duration() );
  jg.add_pair( "latitude",            ch->get_latitude() );
  jg.add_pair( "longitude",           ch->get_longitude() );
  jg.add_pair( "rpid",                ch->get_rpid() );
  jg.add_pair( "datetimeOfRecording", ar->get_time_stamp() );
  jg.add_pair( "simulation",          (ch->get_simulate()? "yes":"no") );
  jg.add_pair( "filter",              (ch->get_filter()? "yes":"no") );
  jg.add_pair( "analysis",            (ch->get_analysis()? "yes":"no") );
  jg.add_pair( "dataPath",            ch->get_data_location() );
  jg.add_pair( "configPath",          ch->get_config_file() );

  if( ch->get_save_rec() == true ) {
    string media_path = utils::pathify(ch->get_media_location()) + ar->get_rec_file_name_core() + ar->get_rec_extention();
    jg.add_pair( "mediaPath", media_path ); 
  }



  // Only save feature extraction info if user wants it
  if( ch->get_analysis() == true ) {
    
    // Save feature file names
    vector<string > feature_names;
    feature_names.clear();
    
    for( unsigned int feat_i = 0; feat_i < features.size(); feat_i++ ) {
      
      //get the name of the feature
      vector<pair<string, string> > details = features.at(feat_i).first;
      string feature_name = "<missing>";
      bool found = false;
      
      for( unsigned int det_i = 0; det_i < details.size() && found == false; det_i++ ) {
	if( details.at(det_i).first == "featurename" ) {
	  feature_name = details.at(det_i).second;
	  found = true;
	}	
      }
      
      feature_names.push_back( feature_name ); //save whole feature fname
    }



    
    // format saved feature informaton according to user's final format choice
    if( ch->get_final_feature_format() == "FILES" ) {

      // FILES format means we need to provide the names and paths of files from YAAFE we need to send


      // provide a list of the features extracted before the feature values individually
      jg.add_pair( "featureNames", feature_names );
      
      // provide file names for each feature
      jg.add_key( "featureFileNames" );
      jg.open_object();
      
      for( unsigned int feat_i = 0; feat_i < features.size(); feat_i++ ) {
	jg.add_pair( feature_names.at( feat_i ), feature_fnames_base.at( feat_i ) );
      }
      
      jg.close_object();
    
    } else if( ch->get_final_feature_format() == "WRAPPED" ) {    

      // WRAPPED format means we need to provide the values of each YAAFE feature extracted in the meta data    

  
      // provide a list of the features extracted before the feature values individually
      jg.add_pair( "featureNames", feature_names );

      jg.add_key( "features" );
      jg.open_object();
      
      // add feature names with details and data to json
      for( unsigned int feat_i = 0; feat_i < features.size(); feat_i++ ) {
	
	vector<pair<string, string> > details = features.at(feat_i).first;
	
	// open an individual feature with that name
	jg.add_key( feature_names.at(feat_i) );
	jg.open_object();
	
	// add key,vals for each detail of the feature
	for( unsigned int det_i = 0; det_i < details.size(); det_i++ ) {
	  jg.add_pair( details.at(det_i).first, details.at(det_i).second );
	}	
	
	
	
	// add a key,val for the data extracted for our individual feature
	jg.add_key( "data" );
	
	// Add each value of the data extracted to the individual feature
	jg.add_array_value( features.at(feat_i).second );
	
	
	
	//close individual feature
	jg.close_object();
      }
      
      jg.close_object(); //close features
    } // close feature analysis wrapped section
  }


  jg.close_object(); //close meta data part
  

  jg.close_object(); //close whole object


  //TEST
  cout<<cn<<mn<<" TEST: Sample JSON format:"<<endl;
  cout<<jg.get_contents_string( format_output_flag )<<endl;


  // write json file out
  string out_fpath = utils::pathify( ch->get_data_location() );
  string out_fname = get_fv_file_name();

  cout<<cn<<mn<<" writing to: \""<<out_fpath+out_fname<<"\"."<<endl;

  jg.write_to( out_fname, out_fpath, formatOutput );

  
  cout<<cn<<mn<<" JSON formatted feature vector written to: \""<<out_fpath+out_fname<<"\"."<<endl;
  
  return res;
}