Commit 6220c3f1 authored by Yoann Pigné's avatar Yoann Pigné

Added support for GS synchronization

parent 51d3e1ff
......@@ -24,6 +24,7 @@ using namespace std;
void events_test();
void types_test();
void example();
void e();
int main (int argc, char const *argv[])
{
//events_test();
......@@ -33,18 +34,33 @@ int main (int argc, char const *argv[])
}
void e(){
string source_id="C++_netstream_test";
long time_id=0L;
NetStreamSender stream("default","10.91.100.76",2001,false);
string n1("node");
while(1) {
//stream.changeNodeAttribute(n1,att,old,n);
stream.addNode(source_id, time_id++, n1);
}
}
void example(){
string source_id("C++_netstream_test");
long time_id=0L;
NetStreamSender stream("default","localhost",2001,false);
string style("node{fill-mode:plain;fill-color:#567;size:6px;}");
stream.addGraphAttribute("stylesheet", style);
stream.addGraphAttribute("ui.antialias", true);
stream.addGraphAttribute("layout.stabilization-limit", 0);
stream.addGraphAttribute(source_id, time_id++, "stylesheet", style);
stream.addGraphAttribute(source_id, time_id++, "ui.antialias", true);
stream.addGraphAttribute(source_id, time_id++, "layout.stabilization-limit", 0);
for (int i = 0; i < 500; i++) {
stringstream n1;
n1<<i;
stream.addNode(n1.str());
stream.addNode(source_id, time_id++, n1.str());
if (i > 0) {
......@@ -59,115 +75,70 @@ void example(){
stringstream e2;
e2<<n1.str()<<"-"<<n3.str();
//cout<<"edge :"<<e1.str()<<endl;
stream.addEdge(e1.str(), n1.str(), n2.str(), false);
stream.addEdge(e2.str(), n1.str(), n3.str(), false);
stream.addEdge(source_id, time_id++, e1.str(), n1.str(), n2.str(), false);
stream.addEdge(source_id, time_id++, e2.str(), n1.str(), n3.str(), false);
}
}
}
void types_test(){
string source_id="C++_netstream_test";
long time_id=0L;
NetStreamSender stream("default","localhost",2001,true);
stream.addGraphAttribute("int", 1);
stream.addGraphAttribute("float", (float)1);
stream.addGraphAttribute("double", 1.0);
stream.addGraphAttribute("long", 1L);
stream.addGraphAttribute("byte", (char) 0);
stream.addGraphAttribute("boolean", true);
stream.addGraphAttribute(source_id, time_id++, "int", 1);
stream.addGraphAttribute(source_id, time_id++, "float", (float)1);
stream.addGraphAttribute(source_id, time_id++, "double", 1.0);
stream.addGraphAttribute(source_id, time_id++, "long", 1L);
stream.addGraphAttribute(source_id, time_id++, "byte", (char) 0);
stream.addGraphAttribute(source_id, time_id++, "boolean", true);
int v[] = {1776,7,4};
vector<int> value(v,v+3);
stream.addGraphAttribute("intArray", value);
stream.addGraphAttribute(source_id, time_id++, "intArray", value);
float v2[] = {(float)1776.3,(float)7.3};
vector<float> value2(v2,v2+2);
stream.addGraphAttribute("floatArray", value2);
stream.addGraphAttribute(source_id, time_id++, "floatArray", value2);
double v3[] = {776.3,.3};
vector<double> value3(v3,v3+2);
stream.addGraphAttribute("doubleArray", value3);
stream.addGraphAttribute(source_id, time_id++, "doubleArray", value3);
long int v4[] = {1776,7,4};
vector<long int> value4(v4,v4+3);
stream.addGraphAttribute("longArray", value4);
stream.addGraphAttribute(source_id, time_id++, "longArray", value4);
char v5[] = {'0',(char)0,'z'};
vector<char> value5(v5,v5+3);
stream.addGraphAttribute("byteArray",value5 );
stream.addGraphAttribute(source_id, time_id++, "byteArray",value5 );
bool v6[] = {true,false};
vector<bool> value6(v6,v6+2);
stream.addGraphAttribute("booleanArray", value6);
stream.addGraphAttribute(source_id, time_id++, "booleanArray", value6);
stream.addGraphAttribute("string", string("true"));
stream.addGraphAttribute(source_id, time_id++, "string", string("true"));
}
void events_test(){
string source_id="C++_netstream_test";
long time_id=0L;
NetStreamSender stream("localhost", 2001);
stream.addNode("node0");
stream.addEdge("edge", "node0", "node1", true);
stream.addNodeAttribute("node0","nodeAttribute", 0);
stream.changeNodeAttribute("node0","nodeAttribute",0, 1);
stream.removeNodeAttribute("node0","nodeAttribute");
stream.addEdgeAttribute("edge","edgeAttribute", 0);
stream.changeEdgeAttribute("edge","edgeAttribute", 0,1);
stream.removeEdgeAttribute("edge","edgeAttribute");
stream.addGraphAttribute("graphAttribute", 0);
stream.changeGraphAttribute("graphAttribute", 0, 1);
stream.removeGraphAttribute("graphAttribute");
stream.stepBegins(1.1);
stream.removeEdge("edge");
stream.removeNode("node0");
stream.graphClear();
stream.addNode(source_id, time_id++, "node0");
stream.addEdge(source_id, time_id++, "edge", "node0", "node1", true);
stream.addNodeAttribute(source_id, time_id++, "node0","nodeAttribute", 0);
stream.changeNodeAttribute(source_id, time_id++, "node0","nodeAttribute",0, 1);
stream.removeNodeAttribute(source_id, time_id++, "node0","nodeAttribute");
stream.addEdgeAttribute(source_id, time_id++, "edge","edgeAttribute", 0);
stream.changeEdgeAttribute(source_id, time_id++, "edge","edgeAttribute", 0,1);
stream.removeEdgeAttribute(source_id, time_id++, "edge","edgeAttribute");
stream.addGraphAttribute(source_id, time_id++, "graphAttribute", 0);
stream.changeGraphAttribute(source_id, time_id++, "graphAttribute", 0, 1);
stream.removeGraphAttribute(source_id, time_id++, "graphAttribute");
stream.stepBegins(source_id, time_id++, 1.1);
stream.removeEdge(source_id, time_id++, "edge");
stream.removeNode(source_id, time_id++, "node0");
stream.graphClear(source_id, time_id++);
}
void crapy_test(){
//NetStreamSender stream = NetStreamSender("default","localhost",2001);
//stream.nodeAdded("node");
string stream = "default";
Socket socket = Socket("localhost",2001);
Storage _stream = Storage();
_stream.writeString(stream);
try
{
socket.connect();
}
catch (tcpip::SocketException &e)
{
cout << "#Error while connecting: " << e.what();
return ;
}
Storage event = Storage();
event.writeByte(EVENT_ADD_NODE);
event.writeString("node0");
//Storage all = Storage();
//all.writeStorage(_stream);
//all.writeStorage(event);
//cout.setf ( ios::hex, ios::basefield ); // set hex as the basefield
//cout.setf ( ios::showbase ); // activate showbase
for(Storage::StorageType::const_iterator it = event.begin(); it != event.end();){
cout<<(int)(*it)<<",";
it++;
}
cout<<endl;
try
{
socket.sendExact(_stream+event);
}
catch (SocketException &e)
{
cout << "Error while sending command: " << e.what();
return ;
}
socket.close();
}
\ No newline at end of file
......@@ -206,42 +206,54 @@ void NetStreamSender::_sendEvent(Storage & event){
// ==================
// = Element events =
// ==================
void NetStreamSender::addNode(const string & node_id){
void NetStreamSender::addNode(const string & source_id, long time_id, const string & node_id){
Storage event = Storage();
event.writeByte(EVENT_ADD_NODE);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(node_id);
_sendEvent(event);
}
void NetStreamSender::removeNode(const string & node_id){
void NetStreamSender::removeNode(const string & source_id, long time_id, const string & node_id){
Storage event = Storage();
event.writeByte(EVENT_DEL_NODE);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(node_id);
_sendEvent(event);
}
void NetStreamSender::addEdge(const string & edge_id, const string & from_node, const string & to_node, bool directed){
void NetStreamSender::addEdge(const string & source_id, long time_id, const string & edge_id, const string & from_node, const string & to_node, bool directed){
Storage event = Storage();
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::removeEdge(const string & edge_id){
void NetStreamSender::removeEdge(const string & source_id, long time_id, const string & edge_id){
Storage event = Storage();
event.writeByte(EVENT_DEL_EDGE);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(edge_id);
_sendEvent(event);
}
void NetStreamSender::stepBegins(double timestamp){
void NetStreamSender::stepBegins(const string & source_id, long time_id, double timestamp){
Storage event = Storage();
event.writeByte(EVENT_STEP);
event.writeString(source_id);
event.writeLong(time_id);
event.writeDouble(timestamp);
_sendEvent(event);
}
void NetStreamSender::graphClear(){
void NetStreamSender::graphClear(const string & source_id, long time_id){
Storage event = Storage();
event.writeByte(EVENT_CLEARED);
event.writeString(source_id);
event.writeLong(time_id);
_sendEvent(event);
}
......@@ -249,22 +261,28 @@ void NetStreamSender::graphClear(){
// = Attributes events =
// =====================
void NetStreamSender::removeNodeAttribute(const string & node_id, const string & attribute){
void NetStreamSender::removeNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute){
Storage event = Storage();
event.writeByte(EVENT_DEL_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(node_id);
event.writeString(attribute);
_sendEvent(event);
}
void NetStreamSender::removeGraphAttribute(const string & attribute){
void NetStreamSender::removeGraphAttribute(const string & source_id, long time_id, const string & attribute){
Storage event = Storage();
event.writeByte(EVENT_DEL_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(attribute);
_sendEvent(event);
}
void NetStreamSender::removeEdgeAttribute(const string & edge_id, const string & attribute){
void NetStreamSender::removeEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute){
Storage event = Storage();
event.writeByte(EVENT_DEL_EDGE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(edge_id);
event.writeString(attribute);
_sendEvent(event);
......
......@@ -100,20 +100,22 @@ public:
// ==================
// = Element events =
// ==================
void addNode(const string & node_id);
void removeNode(const string & node_id);
void addEdge(const string & edge_id, const string & from_node, const string & to_node, bool directed);
void removeEdge(const string & edge_id);
void stepBegins(double timestamp);
void graphClear();
void addNode(const string & source_id, long time_id, const string & node_id);
void removeNode(const string & source_id, long time_id, const string & node_id);
void addEdge(const string & source_id, long time_id, const string & edge_id, const string & from_node, const string & to_node, bool directed);
void removeEdge(const string & source_id, long time_id, const string & edge_id);
void stepBegins(const string & source_id, long time_id, double timestamp);
void graphClear(const string & source_id, long time_id);
// ====================
// = Attribute events =
// ====================
template <typename T>
void addGraphAttribute(const string & attribute, T value){
void addGraphAttribute(const string & source_id, long time_id, const string & attribute, T value){
Storage event = Storage();
event.writeByte(EVENT_ADD_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(attribute);
event.writeByte(getType(value));
encode(event, value);
......@@ -121,9 +123,11 @@ public:
}
template <typename T>
void changeGraphAttribute(const string & attribute, const T oldValue, const T newValue){
void changeGraphAttribute(const string & source_id, long time_id, const string & attribute, const T oldValue, const T newValue){
Storage event = Storage();
event.writeByte(EVENT_CHG_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(attribute);
event.writeByte(getType(newValue));
encode(event, oldValue);
......@@ -131,12 +135,14 @@ public:
_sendEvent(event);
}
void removeGraphAttribute(const string & attribute);
void removeGraphAttribute(const string & source_id, long time_id, const string & attribute);
template <typename T>
void addNodeAttribute(const string & node_id, const string & attribute, const T & value){
void addNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute, const T & value){
Storage event = Storage();
event.writeByte(EVENT_ADD_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(node_id);
event.writeString(attribute);
event.writeByte(getType(value));
......@@ -145,9 +151,11 @@ public:
}
template <typename T>
void changeNodeAttribute(const string & node_id, const string & attribute, const T & oldValue, const T & newValue){
void changeNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute, const T & oldValue, const T & newValue){
Storage event = Storage();
event.writeByte(EVENT_CHG_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(node_id);
event.writeString(attribute);
event.writeByte(getType(newValue));
......@@ -156,12 +164,14 @@ public:
_sendEvent(event);
}
void removeNodeAttribute(const string & node_id, const string & attribute);
void removeNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute);
template <typename T>
void addEdgeAttribute(const string & edge_id, const string & attribute, const T & value){
void addEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute, const T & value){
Storage event = Storage();
event.writeByte(EVENT_ADD_EDGE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(edge_id);
event.writeString(attribute);
event.writeByte(getType(value));
......@@ -171,9 +181,11 @@ public:
}
template <typename T>
void changeEdgeAttribute(const string & edge_id, const string & attribute, const T & oldValue, const T & newValue){
void changeEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute, const T & oldValue, const T & newValue){
Storage event = Storage();
event.writeByte(EVENT_CHG_EDGE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(edge_id);
event.writeString(attribute);
event.writeByte(getType(newValue));
......@@ -182,7 +194,7 @@ public:
_sendEvent(event);
}
void removeEdgeAttribute(const string & edge_id, const string & attribute);
void removeEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute);
};
#endif
\ No newline at end of file
......@@ -15,56 +15,50 @@ import unittest
class AttributeSink(object):
def graphAttributeAdded(self, attribute, value):
def graphAttributeAdded(self, source_id, time_id, attribute, value):
raise NotImplementedError
def graphAttributeChanged(self, attribute, old_value, new_value):
def graphAttributeChanged(self, source_id, time_id, attribute, old_value, new_value):
raise NotImplementedError
def graphAttributeRemoved(self, attribute):
def graphAttributeRemoved(self, source_id, time_id, attribute):
raise NotImplementedError
def nodeAttributeAdded(self, node_id, attribute, value):
def nodeAttributeAdded(self, source_id, time_id, node_id, attribute, value):
raise NotImplementedError
def nodeAttributeChanged(self, node_id, attribute, old_value, new_value):
def nodeAttributeChanged(self, source_id, time_id, node_id, attribute, old_value, new_value):
raise NotImplementedError
def nodeAttributeRemoved(self, node_id, attribute):
def nodeAttributeRemoved(self, source_id, time_id, node_id, attribute):
raise NotImplementedError
def edgeAttributeAdded(self, edge_id, attribute, value):
def edgeAttributeAdded(self, source_id, time_id, edge_id, attribute, value):
raise NotImplementedError
def edgeAttributeChanged(self, edge_id, attribute, old_value, new_value):
def edgeAttributeChanged(self, source_id, time_id, edge_id, attribute, old_value, new_value):
raise NotImplementedError
def edgeAttributeRemoved(self, edge_id, attribute):
def edgeAttributeRemoved(self, source_id, time_id, edge_id, attribute):
raise NotImplementedError
class ElementSink(object):
def nodeAdded(self, node_id):
def nodeAdded(self, source_id, time_id, node_id):
raise NotImplementedError
def nodeRemoved(self, node_id):
def nodeRemoved(self, source_id, time_id, node_id):
raise NotImplementedError
def edgeAdded(self, edge_id, from_node, to_node, directed):
def edgeAdded(self, source_id, time_id, edge_id, from_node, to_node, directed):
raise NotImplementedError
def edgeRemoved(self, edge_id):
def edgeRemoved(self, source_id, time_id, edge_id):
raise NotImplementedError
def graphCleared(self):
raise NotImplementedError
def stepBegins(self, timestamp):
def stepBegins(self, source_id, time_id, timestamp):
raise NotImplementedError
class untitledTests(unittest.TestCase):
def setUp(self):
pass
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment