Esempio n. 1
0
void NetStreamSender::graphClear(const string & source_id, long time_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_CLEARED);
  event.writeString(source_id);
  event.writeLong(time_id);
  _sendEvent(event);  
}
void NetStreamSender::graphClear(const GS_STRING & source_id, GS_LONG time_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_CLEARED);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  _sendEvent(event);  
}
 // -----------------------------------------------------------------------
 NetStreamStorage NetStreamStorage::operator+(const NetStreamStorage &storage)
 {
   NetStreamStorage msg;
   msg.store.insert(msg.store.end(), store.begin(), store.end());
   msg.store.insert(msg.store.end(), storage.begin(), storage.end());
   return msg;
 }
void NetStreamSender::removeGraphAttribute(const GS_STRING & source_id, GS_LONG time_id, const GS_STRING & attribute){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_DEL_GRAPH_ATTR);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  event.writeString(attribute);
  _sendEvent(event);
}
void NetStreamSender::stepBegins(const GS_STRING & source_id, GS_LONG time_id, GS_DOUBLE timestamp){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_STEP);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  event.writeDouble(timestamp);
  _sendEvent(event);
}
void NetStreamSender::removeEdge(const GS_STRING & source_id, GS_LONG time_id, const GS_STRING & edge_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_DEL_EDGE);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  event.writeString(edge_id);
  _sendEvent(event);
}
// ==================
// = Element events =
// ================== 
void NetStreamSender::addNode(const GS_STRING & source_id, GS_LONG time_id, const GS_STRING & node_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_ADD_NODE);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  event.writeString(node_id);
  _sendEvent(event);
}
Esempio n. 8
0
void NetStreamSender::stepBegins(const string & source_id, long time_id, double timestamp){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_STEP);
  event.writeString(source_id);
  event.writeLong(time_id);
  event.writeDouble(timestamp);
  _sendEvent(event);
}
Esempio n. 9
0
void NetStreamSender::removeGraphAttribute(const string & source_id, long time_id, const string & attribute){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_DEL_GRAPH_ATTR);
  event.writeString(source_id);
  event.writeLong(time_id);
  event.writeString(attribute);
  _sendEvent(event);
}
Esempio n. 10
0
// ==================
// = Element events =
// ================== 
void NetStreamSender::addNode(const string & source_id, long time_id, const string & node_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_ADD_NODE);
  event.writeString(source_id);
  event.writeLong(time_id);
  event.writeString(node_id);
  _sendEvent(event);
}
Esempio n. 11
0
void NetStreamSender::removeEdge(const string & source_id, long time_id, const string & edge_id){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_DEL_EDGE);
  event.writeString(source_id);
  event.writeLong(time_id);
  event.writeString(edge_id);
  _sendEvent(event);
}
	void
		NetStreamSocket::
		sendExact( const NetStreamStorage &b)
		throw( NetStreamSocketException )
	{
		int length = static_cast<int>(b.size());
		NetStreamStorage length_storage;
		length_storage.writeInt(length);
		vector<unsigned char> msg;
		msg.insert(msg.end(), length_storage.begin(), length_storage.end());
		msg.insert(msg.end(), b.begin(), b.end());
		send(msg);
	}
Esempio n. 13
0
void NetStreamSender::addEdge(const string & source_id, long time_id, const string & edge_id, const string & from_node, const string & to_node, bool directed){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_ADD_EDGE);
  event.writeString(source_id);
  event.writeLong(time_id);
  event.writeString(edge_id);
  event.writeString(from_node);
  event.writeString(to_node);
  event.writeByte(directed?1:0);
  _sendEvent(event);
}
void NetStreamSender::addEdge(const GS_STRING & source_id, GS_LONG time_id, const GS_STRING & edge_id, const GS_STRING & from_node, const GS_STRING & to_node, GS_BOOL directed){
  NetStreamStorage event = NetStreamStorage();
  event.writeByte(EVENT_ADD_EDGE);
  event.writeString(source_id);
  event.writeUnsignedVarInt(time_id);
  event.writeString(edge_id);
  event.writeString(from_node);
  event.writeString(to_node);
  event.writeByte(directed?1:0);
  _sendEvent(event);
}
Esempio n. 15
0
void NetStreamSender::_encode(NetStreamStorage & event, bool value){
  event.writeByte(value?1:0);
}
Esempio n. 16
0
void NetStreamSender::_encode(NetStreamStorage & event, const vector<double> &  value){
  event.writeInt(value.size());
  for(vector<double>::const_iterator i = value.begin(); i != value.end(); i++){
    event.writeDouble((*i));
  }
}
Esempio n. 17
0
void NetStreamSender::_encode(NetStreamStorage & event,const  string & value){
  event.writeString(value);
}
Esempio n. 18
0
void NetStreamSender::_encode(NetStreamStorage & event, double value){
  event.writeDouble(value);
}
Esempio n. 19
0
void NetStreamSender::_encode(NetStreamStorage & event, float value){
  event.writeFloat(value);
}
void NetStreamSender::_encode(NetStreamStorage & event, const vector<GS_BOOL> & value){
  event.writeInt(value.size());
  for(vector<bool>::const_iterator i = value.begin(); i != value.end(); i++){
    event.writeByte((*i));
  }
}
Esempio n. 21
0
// =================
// = data encoding =
// =================
void NetStreamSender::_encode(NetStreamStorage & event, char value){
  event.writeByte((int)value);
}
Esempio n. 22
0
void NetStreamSender::_encode(NetStreamStorage & event, int value){
  event.writeInt(value);
}
Esempio n. 23
0
void NetStreamSender::_encode(NetStreamStorage & event, long value){
  event.writeLong(value);
}
	bool
		NetStreamSocket::
		receiveExact( NetStreamStorage &msg )
		throw( NetStreamSocketException )
	{
		/* receive length of vector */
		unsigned char * const bufLength = new unsigned char[4];
		int bytesRead = 0;
		int readThisTime = 0;
		
		while (bytesRead<4)
		{
			readThisTime = recv( socket_, (char*)(bufLength + bytesRead), 4-bytesRead, 0 );

			if( readThisTime <= 0 )
			{
				// BailOnNetStreamSocketError definitely throws an exception so clear up heap
				delete[] bufLength;
				BailOnNetStreamSocketError( "NetStreamSocket::receive() @ recv" );
			}

			bytesRead += readThisTime;
		}
		NetStreamStorage length_storage(bufLength,4);
		int NN = length_storage.readInt() - 4;

		/* receive vector */
		unsigned char * const buf = new unsigned char[NN];
		bytesRead = 0;
		readThisTime = 0;
		
		while (bytesRead<NN)
		{
			readThisTime = recv( socket_, (char*)(buf + bytesRead), NN-bytesRead, 0 );

			if( readThisTime <= 0 )
			{
				// BailOnNetStreamSocketError definitely throws an exception so clear up heap
				delete[] bufLength;
				delete[] buf;
				BailOnNetStreamSocketError( "netstream::NetStreamSocket::receive() @ recv" );
			}

			bytesRead += readThisTime;
		}
		msg.reset();
		msg.writePacket(buf, NN);
		
		if (verbose_)
		{
			cerr << "Rcvd Storage with "  << 4 + NN <<  " bytes via netstream::NetStreamSocket: [";
			for (int i=0; i < 4; ++i)
			{
				cerr << " " << (int)bufLength[i] << " ";
			}
			for (int i=0; i < NN; ++i)
			{
				cerr << " " << (int)buf[i] << " ";
			}
			cerr << "]" << endl;
		}

		delete[] buf;
		delete[] bufLength;
		return true;
	}
// =================
// = data encoding =
// =================
void NetStreamSender::_encode(NetStreamStorage & event, GS_CHAR value){
  event.writeByte((GS_INT)value);
}