Datum return_bson(const mongo::BSONObj& b)
{
    std::size_t bson_size = b.objsize() + VARHDRSZ;
    bytea* new_bytea = (bytea *) palloc(bson_size);
    SET_VARSIZE(new_bytea, bson_size);
    std::memcpy(VARDATA(new_bytea), b.objdata(), b.objsize());
    PG_RETURN_BYTEA_P(new_bytea);
}
Пример #2
0
void Processer::DoHost(const std::string& grid,const std::string& cluster,mongo::BSONObj& host)
{
	std::string host_id;
	std::cout << host << std::endl;
	if(host.hasField("host_ID") && host.hasField("heartbeat"))
	{
        //deal the record with host level
        //do not need to cut it off
        DBModules::iterator iter = db_modules_.begin();
        for(;iter!=db_modules_.end();++iter)
        {
            iter->handler(host.objdata(),host.objsize(),NULL);
        }

	//	host_id = host.getStringField("host_ID");
	//	std::vector<mongo::BSONElement> ele;
	//	host.elems(ele);
	//	for(int i=0;i<ele.size();i++)
	//	{
	//		if((!strcmp(ele[i].fieldName(),"host_ID")) || 
	//				(!strcmp(ele[i].fieldName(),"heartbeat")))
	//		{
	//			continue;
	//		}
	//		else
	//		{
	//			std::string ds_name = ele[i].fieldName();
	//			std::string path;
	//			if(grid!="")
	//				path = grid + '/' + cluster + '/' + host_id;
	//			else
	//				path = cluster + '/' + host_id;
	//			mongo::BSONObj obj = ele[i].wrap();
	//			std::cout << obj << std::endl;

	//			std::list<void(*)(const char*,int,const char*)>::iterator iter;
	//			iter = callback_[ds_name].begin();
	//			for(;iter!=callback_[ds_name].end();++iter)
	//			{
	//				(*iter)(obj.objdata(),obj.objsize(),path.c_str());
	//			}
	//		}
	//	}
	}
	else
	{
		std::stringstream oss;
		oss << "This data is illegal! Drop!!";
		LOG4CXX_WARN(log_,oss.str());
	}
}
Пример #3
0
 virtual msgPtr fillmessage() {
     return boost::shared_ptr<zmq::message_t>(new zmq::message_t(const_cast<char*>(_obj.objdata()), _obj.objsize(), msg_free));
 }