Example #1
0
JSONNode Rig::toJSON() {
  JSONNode root;

  stringstream ss;
  ss << LumiverseCore_VERSION_MAJOR << "." << LumiverseCore_VERSION_MINOR;

  root.push_back(JSONNode("version", ss.str()));
  root.push_back(JSONNode("refreshRate", m_refreshRate));

  JSONNode devices;
  devices.set_name("devices");
  for (auto d : m_devices) {
    devices.push_back(d->toJSON());
  }
  root.push_back(devices);

  JSONNode patches;
  patches.set_name("patches");
  for (auto& p : m_patches) {
    JSONNode patch = p.second->toJSON();
    patch.set_name(p.first);
    patches.push_back(patch);
  }
  root.push_back(patches);

  return root;
}
Example #2
0
JSONNode Programmer::toJSON() {
  JSONNode root;
  root.set_name("programmer");

  JSONNode devices;
  devices.set_name("devices");

  for (const auto& kvp : m_devices) {
    devices.push_back(kvp.second->toJSON());
  }

  root.push_back(devices);

  root.push_back(captured.toJSON("captured"));

  return root;
}
Example #3
0
JSONNode Event::toJSON() {
  // this is equivalent to saying "something happened here but I have no idea what it is"
  JSONNode e;
  e.set_name(_id);
  e.push_back(JSONNode("type", getType()));

  return e;
}
int main(){
JSONNode n = read_formatted("input.json");
JSONNode n1 = read_formatted("input1.json");
test *tst = new test();
int status;
//n.set_name(abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status ));
n.push_back(JSONNode("FF::Node_Subclass", abi::__cxa_demangle(typeid(*tst).name(), 0,0,&status )));
if(n1.type()==JSON_NULL){
   std::cout<<"null"<<std::endl; 
}
JSONNode n2 (JSON_NODE);
n2.set_name("Child1");
n2.push_back(JSONNode("id",1));
n.set_name("Parrent");
n.push_back(n2);
JSONNode::iterator it =n.find_nocase("String Node");
if(it->as_string()=="-1"){std::cout<<it->as_int()<<std::endl;}
it->as_int()!=-1 ? (std::cout<< "it is"<<std::endl) : (std::cout<<"Mapper Warning: processor id is -1"<<std::endl);
if (n.at("String Node")==""){
std::cout<<"ha ha ha"<<std::endl;
}
std::cout<< "This is the name: "<<n.name()<<std::endl;
n.at("String Node")="";
bool x =true;
n.push_back(JSONNode("MyBOOLNODE", x));
n["String Node"]=x;
//n.erase(n.find_nocase("String Node"));
write_formatted(n1, "out1.json");
write_formatted(n, "out.json");
JSONNode::const_iterator i =n.find_nocase("ArrayOfNumbers");
std::string strLowerCase= "ARRAYOfNUMbers"; 
std::string myTest= "ff::ff_farm<adaptive_loadbalancer, ff::ff_gatherer>";
std::transform(myTest.begin(), myTest.end(), myTest.begin(), ::tolower);
std::size_t found = myTest.find("adaptive_loadbalancer");
if (found!=std::string::npos)
  std::cout << "first 'needle' found at: " << found << '\n';

std::cout<< "here it is: " << myTest<< std::endl;
JSONNode n_ar = n.at("ArrayOfNumbers");
std::cout<<"here :"<<n_ar[0].as_int()<< std::endl;
// if (0 == strcasecmp("hello", "HELLO"))

if(strcasecmp((i->name()).c_str(), strLowerCase.c_str()) == 0)
//if(!(n2.empty()))
  std::cout<<"haha"<<i->size()<<std::endl;
std::cout<<i->name()<<std::endl;
std::cout<<((i->as_array()).begin()+1)->as_int()<<std::endl;
std::cout<<((i->as_array()).at(1)).as_int()<<std::endl;
std::cout<<((i->as_array())[1]).as_int()<<std::endl;
//std::cout<<i->as_string()<<std::endl;
//JSONNode c(JSON_ARRAY);
//c=i->as_array();
//JSONNode nk= c.at(0);
//JSONNode::const_iterator it = c.begin();
//std::cout <<nk.as_int()<<std::endl;
return 0;
}
Example #5
0
 JSONNode JSONNode::stringType(const json_string & str){
     JSONNode res;
     res.set_name(json_global(EMPTY_JSON_STRING));
     #ifdef JSON_LESS_MEMORY
         res = JSONWorker::FixString(str, res.internal, false);
     #else
         res = JSONWorker::FixString(str, res.internal -> _string_encoded);
     #endif
     return res;
 }
Example #6
0
MEVENT CSkypeProto::AppendDBEvent(MCONTACT hContact, MEVENT hEvent, const char *szContent, const char *szUid, time_t edit_time)
{
	mir_cslock lck(m_AppendMessageLock);
	DBEVENTINFO dbei = { sizeof(dbei) };
	dbei.cbBlob = db_event_getBlobSize(hEvent);
	dbei.pBlob = mir_ptr<BYTE>((PBYTE)mir_alloc(dbei.cbBlob));
	db_event_get(hEvent, &dbei);

	JSONNode jMsg = JSONNode::parse((char*)dbei.pBlob);
	if (jMsg)
	{
		JSONNode &jEdits = jMsg["edits"];
		if (jEdits)
		{
			for (auto it = jEdits.begin(); it != jEdits.end(); ++it)
			{
				const JSONNode &jEdit = *it;

				if (jEdit["time"].as_int() == edit_time)
					return hEvent;
			}
			JSONNode jEdit;
			jEdit 
				<< JSONNode("time", (long)edit_time)
				<< JSONNode("text", szContent);

			jEdits << jEdit;
		}
	}
	else
	{
		jMsg = JSONNode();
		JSONNode jOriginalMsg; jOriginalMsg.set_name("original_message");
		JSONNode jEdits(JSON_ARRAY); jEdits.set_name("edits");
		JSONNode jEdit;

		jOriginalMsg
			<< JSONNode("time", (long)dbei.timestamp)
			<< JSONNode("text", (char*)dbei.pBlob);

		jMsg << jOriginalMsg;

		jEdit 
			<< JSONNode("time", (long)edit_time)
			<< JSONNode("text", szContent);

		jEdits << jEdit;	
		jMsg   << jEdits;


	}
	db_event_delete(hContact, hEvent);	
	return AddDbEvent(SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE, hContact, dbei.timestamp, DBEF_UTF, jMsg.write().c_str(), szUid);
}
Example #7
0
JSONNode LumiverseFloat::toJSON(string name) {
  JSONNode node;
  node.set_name(name);

  node.push_back(JSONNode("type", getTypeName()));
  node.push_back(JSONNode("val", m_val));
  node.push_back(JSONNode("default", m_default));
  node.push_back(JSONNode("max", m_max));
  node.push_back(JSONNode("min", m_min));

  return node;
}
Example #8
0
void StreamingDevice::onClientAttach(ClientConn* client){
	Device::onClientAttach(client);
	
	JSONNode n(JSON_NODE);
	n.push_back(JSONNode("_action", "deviceConfig"));

	JSONNode jstate = stateToJSON();
	jstate.set_name("device");
	n.push_back(jstate);
	
	client->sendJSON(n);
}
Example #9
0
static int json__newindex(lua_State *L)
{
	JSONNode &node = *((JSON*)luaL_checkudata(L, 1, MT_JSON))->node;
	const char *key = lua_tostring(L, 2);

	JSONNode child = node[key];
	if (child.isnull())
	{
		child.set_name(key);
		node << child;
	}
	lua2json(L, child);
	node[key] = child;

	return 0;
}
Example #10
0
JSONNode *Database::CreateTable(const string &name, const vector<string> &columnNames)
{
	if (this->FindTable(name))
		return NULL;
	JSONNode table;
	table.set_name(name);
	JSONNode columns(JSON_ARRAY);
	columns.set_name("columns");
	for (auto i = columnNames.begin(); i != columnNames.end(); i++)
		columns.push_back(JSONNode("", *i));
	table.push_back(columns);
	JSONNode rows(JSON_ARRAY);
	rows.set_name("rows");
	table.push_back(rows);
	auto tables = data.find("tables");
	tables->push_back(table);
	//cout << tables->write_formatted() << endl;
	//cout << data.write_formatted() << endl;
	auto t = tables->find(name);
	return t == tables->end() ? NULL : &*t;
}
Example #11
0
void lua2json(lua_State *L, JSONNode &node)
{
	const char *name = lua_tostring(L, -2);

	switch (lua_type(L, -1))
	{
	case LUA_TNIL:
		node.nullify();
		break;
	case LUA_TSTRING:
		node = lua_tostring(L, -1);
		break;
	case LUA_TBOOLEAN:
		node = lua_toboolean(L, -1) != 0;
		break;
	case LUA_TNUMBER:
		node = lua_tonumber(L, -1);
		break;
	case LUA_TTABLE:
	{
		node.cast(JSON_NODE);
		if (name)
			node.set_name(name);

		lua_pushnil(L);
		while (lua_next(L, -2) != 0)
		{
			JSONNode child;
			lua2json(L, child);
			node << child;

			lua_pop(L, 1);
		}
	}
	}
}
void JSONResult::setData(JSONNode & data){
  data.set_name("data");
  this->push_back(data);
}
      PresetReaderJson::PresetReaderJson(std::string data) {
        LOGDEBUG("Preset Data:" << data);
        JSONNode node = libjson::parse(data);
        if(node.contains("profile-uuid")){
          db::HiveDb db=DatabaseService::getDatabase();//"sqlite3", org::esb::config::Config::get("db.url"));
          litesql::DataSource<db::Preset>s = litesql::select<db::Preset > (db, db::Preset::Uuid == node["profile-uuid"].as_string());
          if(s.count()==1){
            data=s.one().data;
          }else{
            throw org::esb::lang::Exception(__FILE__,__LINE__,"profile defined by profile-uuid not found");
          }
          node = libjson::parse(data);
        }
        if (node.contains("format") && node["format"].contains("id")) {
          _preset["id"] = node["format"]["id"].as_string();
          if(node.contains("name")){
            _preset["name"]=node["name"].as_string();
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no format attribute found");
        }
        std::string type;
        type = "video";
        if (node.contains(type)) {
          int c = node[type].size();
          for (int a = 0; a < c; a++) {
            JSONNode n = node[type].at(a);
            std::string name = n.name();
            std::string value = n.as_string();
            /*filter out some unwanted attributes*/
            if (name == "frame_size"){
              int width;
              int height;
              int result=sscanf(value.c_str(),"%dx%d", &width, &height);
              LOGDEBUG("width="<<width);
              LOGDEBUG("width="<<height);
              _codecs[type]["width"]=StringUtil::toString(width);
              _codecs[type]["height"]=StringUtil::toString(height);
              continue;
            }
            //LOGDEBUG("json type : "<<n.type());
            if (name == "id") {
              name = "codec_id";
            }
            if (name == "b" || name == "maxrate" || name == "bt" || name == "bufsize" || name == "minrate")
              value += "000";
            LOGDEBUG("Name=" << name << " val=" << value);

            _codecs[type][name] = value; //.insert(std::pair<std::string, std::string>(name,value));
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no video attribute found");
        }
        type = "audio";
        if (node.contains(type)) {
          int c = node[type].size();
          for (int a = 0; a < c; a++) {
            JSONNode n = node[type].at(a);
            LOGDEBUG("Name=" << n.name() << " val=" << n.as_string());
            if (n.name() == "id") {
              n.set_name("codec_id");
              //AVCodec * codec=avcodec_find_encoder_by_name(n.as_string().c_str());
              //n=JSONNode("codec_id",codec->id);
            }
            _codecs[type][n.name()] = n.as_string(); //.insert(std::pair<std::string, std::string>(n.name(),n.as_string()));
          }
        }else{
          throw org::esb::lang::Exception(__FILE__,__LINE__,"no audio attribute found");
        }
      }