Commit d89e4128 authored by Yoann Pigné's avatar Yoann Pigné

change preprocessor defines to C consts, plus, modified makefile to produce static lib

parent 8a4ec0ff
......@@ -7,30 +7,34 @@ CC = g++
CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O
CDBG = -g $(CWARN) -fno-inline
CFLAGS = -I$(INCDIR) -03
CFLAGS = -I$(INCDIR) -03
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1
CTAG = ctags
CTAGFILE = filelist
# src, object and bin files
MAIN := netstream-main
OUT_BINARY := netstream-main
OUT_LIBRARY := libnetstream.a
HEADERS = $(INCDIR)/global.h
OBJS = \
$(OBJDIR)/tcpip/storage.o \
$(OBJDIR)/tcpip/socket.o \
$(OBJDIR)/netstream-storage.o \
$(OBJDIR)/netstream-socket.o \
$(OBJDIR)/netstream-sender.o \
$(OBJDIR)/netstream-main.o
.SECONDARY:
#-- Rules
all : $(MAIN)
all : $(OUT_BINARY) $(OUT_LIBRARY)
$(OUT_BINARY) : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUT_BINARY)
$(OUT_LIBRARY) : $(OBJS)
libtool -o $(OUT_LIBRARY) $(OBJS)
$(MAIN) : $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(MAIN)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c $? -o $@
......@@ -46,6 +50,7 @@ clean :
-rm -f $(SRCDIR)/*.output $(LEX_C)
-rm -f */*~ *~ core
-rm -f $(BINDIR)/*
-rm -f $(MAIN)
-rm -f $(OUT_BINARY)
-rm -f $(OUT_LIBRARY)
fresh : clean all
/**
*
*
* Copyright (c) 2010-2011 University of Luxembourg
*
*
* @file client_socket.h
* @date 2011-08-21
*
* @author Yoann Pigné
*/
#ifndef CLIENT_SOCKET_H
#define CLIENT_SOCKET_H
class ClientSocket{
public:
ClientSocket();
Initialize();
void SetNonBloking();
void Open(const string & host, int port);
int Send((uint8 *) data, int size);
int Receive(int limit);
}
#endif // CLIENT_SOCKET_H
\ No newline at end of file
......@@ -13,20 +13,20 @@
#ifndef NETSTREAM_CONSTANTS_H
#define NETSTREAM_CONSTANTS_H
namespace netstream{
/**
* Followed by an 32-bit signed integer for this protocol version. Certainly useless.
*/
#define EVENT_GETVERSION 0x00
const unsigned char EVENT_GETVERSION=0x00;
/**
* Not used.
*/
#define EVENT_START 0x01
const unsigned char EVENT_START=0x01;
/**
* Not used.
*/
#define EVENT_END 0x02
const unsigned char EVENT_END=0x02;
//
......@@ -38,12 +38,12 @@
/**
* Followed by a node id (TYPE_STRING format)
*/
#define EVENT_ADD_NODE 0x10
const unsigned char EVENT_ADD_NODE=0x10;
/**
* Followed by a node id (TYPE_STRING format)
*/
#define EVENT_DEL_NODE 0x11
const unsigned char EVENT_DEL_NODE=0x11;
/**
* Followed by
......@@ -52,21 +52,21 @@
* - a target node id (TYPE_STRING format
* - a boolean indicating if directed (TYPE_BOOLEAN format)
*/
#define EVENT_ADD_EDGE 0x12
const unsigned char EVENT_ADD_EDGE=0x12;
/**
* Followed by an edge id (TYPE_STRING format)
*/
#define EVENT_DEL_EDGE 0x13
const unsigned char EVENT_DEL_EDGE=0x13;
/**
* Followed by double (TYPE_DOUBLE format)
*/
#define EVENT_STEP 0x14
const unsigned char EVENT_STEP=0x14;
/**
*
*/
#define EVENT_CLEARED 0x15
const unsigned char EVENT_CLEARED=0x15;
/**
* Followed by
......@@ -74,7 +74,7 @@
* - the attribute TYPE
* - the attribute value
*/
#define EVENT_ADD_GRAPH_ATTR 0x16
const unsigned char EVENT_ADD_GRAPH_ATTR=0x16;
/**
* Followed by
* - an attribute id (TYPE_STRING format)
......@@ -82,12 +82,12 @@
* - the attribute old value
* - the attribute new value
*/
#define EVENT_CHG_GRAPH_ATTR 0x17
const unsigned char EVENT_CHG_GRAPH_ATTR=0x17;
/**
* Followed by
* - the attribute id (TYPE_STRING format)
*/
#define EVENT_DEL_GRAPH_ATTR 0x18
const unsigned char EVENT_DEL_GRAPH_ATTR=0x18;
/**
* Followed by
......@@ -95,7 +95,7 @@
* - the attribute TYPE
* - the attribute value
*/
#define EVENT_ADD_NODE_ATTR 0x19
const unsigned char EVENT_ADD_NODE_ATTR=0x19;
/**
* Followed by
* - an attribute id (TYPE_STRING format)
......@@ -103,20 +103,20 @@
* - the attribute old value
* - the attribute new value
*/
#define EVENT_CHG_NODE_ATTR 0x1a
const unsigned char EVENT_CHG_NODE_ATTR=0x1a;
/**
* Followed by
* - the node id (TYPE_STRING format)
* - the attribute id (TYPE_STRING format)
*/
#define EVENT_DEL_NODE_ATTR 0x1b
const unsigned char EVENT_DEL_NODE_ATTR=0x1b;
/**
* Followed by
* - an attribute id (TYPE_STRING format)
* - the attribute TYPE
* - the attribute value
*/
#define EVENT_ADD_EDGE_ATTR 0x1c
const unsigned char EVENT_ADD_EDGE_ATTR=0x1c;
/**
* Followed by
* - an attribute id (TYPE_STRING format)
......@@ -124,13 +124,13 @@
* - the attribute old value
* - the attribute new value
*/
#define EVENT_CHG_EDGE_ATTR 0x1d
const unsigned char EVENT_CHG_EDGE_ATTR=0x1d;
/**
* Followed by
* - the edge id (TYPE_STRING format)
* - the attribute id (TYPE_STRING format)
*/
#define EVENT_DEL_EDGE_ATTR 0x1e
const unsigned char EVENT_DEL_EDGE_ATTR=0x1e;
......@@ -140,83 +140,85 @@
/**
* Followed by a byte who's value is 0 or 1
*/
#define TYPE_BOOLEAN 0x50
const unsigned char TYPE_BOOLEAN=0x50;
/**
* An array of booleans. Followed by first, a 16-bits integer for the number
* of booleans and then, a list of bytes who's value is 0 or 1
*/
#define TYPE_BOOLEAN_ARRAY 0x51
const unsigned char TYPE_BOOLEAN_ARRAY=0x51;
/**
* Followed by a signed byte [-127,127]
*/
#define TYPE_BYTE 0x52
const unsigned char TYPE_BYTE=0x52;
/**
* An array of bytes. Followed by first, a 16-bits integer for the number
* of integers and then, a list of signed bytes.
*/
#define TYPE_BYTE_ARRAY 0x53
const unsigned char TYPE_BYTE_ARRAY=0x53;
/**
* Followed by an 16-bit signed integer (a short)
*/
#define TYPE_SHORT 0x54
const unsigned char TYPE_SHORT=0x54;
/**
* An array of shorts. Followed by first, a 16-bits integer for the number
* of integers and then, a list of 16-bit signed shorts
*/
#define TYPE_SHORT_ARRAY 0x55
const unsigned char TYPE_SHORT_ARRAY=0x55;
/**
* Followed by an 32-bit signed integer
*/
#define TYPE_INT 0x56
const unsigned char TYPE_INT=0x56;
/**
* An array of integers. Followed by first, a 16-bits integer for the number
* of integers and then, a list of 32-bit signed integers
*/
#define TYPE_INT_ARRAY 0x57
const unsigned char TYPE_INT_ARRAY=0x57;
/**
* Followed by an 64-bit signed integer
*/
#define TYPE_LONG 0x58
const unsigned char TYPE_LONG=0x58;
/**
* An array of longs. Followed by first, a 16-bits integer for the number of
* longs and then, a list of 62-bit signed integers
*/
#define TYPE_LONG_ARRAY 0x59
const unsigned char TYPE_LONG_ARRAY=0x59;
/**
* Followed by a single precision 32-bits floating point number
*/
#define TYPE_FLOAT 0x5a
const unsigned char TYPE_FLOAT=0x5a;
/**
* Array of double. Followed by first, a 16-bits integer for the number of
* floats and then, a list of 32-bit floats
*/
#define TYPE_FLOAT_ARRAY 0x5b
const unsigned char TYPE_FLOAT_ARRAY=0x5b;
/**
* Followed by a double precision 64-bits floating point number
*/
#define TYPE_DOUBLE 0x5c
const unsigned char TYPE_DOUBLE=0x5c;
/**
* Array of double. Followed by first, a 16-bits integer for the number of
* doubles and then, a list of 64-bit doubles
*/
#define TYPE_DOUBLE_ARRAY 0x5d
const unsigned char TYPE_DOUBLE_ARRAY=0x5d;
/**
* Array of characters. Followed by first, a 16-bits integer for the size in
* bytes (not in number of characters) of the string, then by the unicode
* string
*/
#define TYPE_STRING 0x5e
const unsigned char TYPE_STRING=0x5e;
/**
* Raw data, good for serialization. Followed by first, a 16-bits integer
* indicating the length in bytes of the dataset, and then the data itself.
*/
#define TYPE_RAW 0x5f
const unsigned char TYPE_RAW=0x5f;
/**
* An type-unspecified array. Followed by first, a
* 16-bits integer indicating the number of elements, and then, the elements
* themselves. The elements themselves have to give their type.
*/
#define TYPE_ARRAY 0x60
const unsigned char TYPE_ARRAY=0x60;
}// end netstream namespace
#endif
......@@ -13,13 +13,13 @@
#include <iostream>
#include <sstream>
#include "tcpip/storage.h"
#include "tcpip/socket.h"
#include "netstream-storage.h"
#include "netstream-socket.h"
#include "netstream-constants.h"
#include "netstream-sender.h"
using namespace tcpip;
using namespace std;
using namespace netstream;
void events_test();
void types_test();
......
......@@ -13,7 +13,8 @@
#include "netstream-sender.h"
namespace netstream{
NetStreamSender::NetStreamSender(const string & host, int port):
_stream_name("default"),_host(host),_port(port),_stream(),_socket(host,port),debug(false) {
init();
......@@ -123,58 +124,58 @@ return TYPE_DOUBLE_ARRAY;}
// =================
// = data encoding =
// =================
void NetStreamSender::_encode(Storage & event, char value){
void NetStreamSender::_encode(NetStreamStorage & event, char value){
event.writeByte((int)value);
}
void NetStreamSender::_encode(Storage & event, bool value){
void NetStreamSender::_encode(NetStreamStorage & event, bool value){
event.writeByte(value?1:0);
}
void NetStreamSender::_encode(Storage & event, int value){
void NetStreamSender::_encode(NetStreamStorage & event, int value){
event.writeInt(value);
}
void NetStreamSender::_encode(Storage & event, long value){
void NetStreamSender::_encode(NetStreamStorage & event, long value){
event.writeLong(value);
}
void NetStreamSender::_encode(Storage & event, float value){
void NetStreamSender::_encode(NetStreamStorage & event, float value){
event.writeFloat(value);
}
void NetStreamSender::_encode(Storage & event, double value){
void NetStreamSender::_encode(NetStreamStorage & event, double value){
event.writeDouble(value);
}
void NetStreamSender::_encode(Storage & event,const string & value){
void NetStreamSender::_encode(NetStreamStorage & event,const string & value){
event.writeString(value);
}
void NetStreamSender::_encode(Storage & event, const vector<char> & value){
void NetStreamSender::_encode(NetStreamStorage & event, const vector<char> & value){
event.writeInt(value.size());
for(vector<char>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeByte((*i));
}
}
void NetStreamSender::_encode(Storage & event, const vector<bool> & value){
void NetStreamSender::_encode(NetStreamStorage & event, const vector<bool> & value){
event.writeInt(value.size());
for(vector<bool>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeByte((*i));
}
}
void NetStreamSender::_encode(Storage & event, const vector<int> & value){
void NetStreamSender::_encode(NetStreamStorage & event, const vector<int> & value){
event.writeInt(value.size());
for(vector<int>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeInt((*i));
}
}
void NetStreamSender::_encode(Storage & event, const vector<long> & value){
void NetStreamSender::_encode(NetStreamStorage & event, const vector<long> & value){
event.writeInt(value.size());
for(vector<long>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeLong((*i));
}
}
void NetStreamSender::_encode(Storage & event, const vector<float> & value){
void NetStreamSender::_encode(NetStreamStorage & event, const vector<float> & value){
event.writeInt(value.size());
for(vector<float>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeFloat((*i));
}
}
void NetStreamSender::_encode(Storage & event, const vector<double> & value){
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));
......@@ -182,12 +183,12 @@ void NetStreamSender::_encode(Storage & event, const vector<double> & value){
}
void NetStreamSender::_sendEvent(Storage & event){
void NetStreamSender::_sendEvent(NetStreamStorage & event){
if(debug){
cout<<event<<endl;
/*
for(Storage::StorageType::const_iterator it = event.begin(); it != event.end();){
for(NetStreamStorage::NetStreamStorageType::const_iterator it = event.begin(); it != event.end();){
cout<<(int)(*it)<<",";
it++;
}
......@@ -197,7 +198,7 @@ void NetStreamSender::_sendEvent(Storage & event){
try{
_socket.sendExact(_stream+event);
}
catch (SocketException &e)
catch (NetStreamSocketException &e)
{
cout << "Error while sending message: " << e.what();
}
......@@ -207,7 +208,7 @@ void NetStreamSender::_sendEvent(Storage & event){
// = Element events =
// ==================
void NetStreamSender::addNode(const string & source_id, long time_id, const string & node_id){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_ADD_NODE);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -215,7 +216,7 @@ void NetStreamSender::addNode(const string & source_id, long time_id, const stri
_sendEvent(event);
}
void NetStreamSender::removeNode(const string & source_id, long time_id, const string & node_id){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_DEL_NODE);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -223,7 +224,7 @@ void NetStreamSender::removeNode(const string & source_id, long time_id, const s
_sendEvent(event);
}
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();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_ADD_EDGE);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -234,7 +235,7 @@ void NetStreamSender::addEdge(const string & source_id, long time_id, const stri
_sendEvent(event);
}
void NetStreamSender::removeEdge(const string & source_id, long time_id, const string & edge_id){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_DEL_EDGE);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -242,7 +243,7 @@ void NetStreamSender::removeEdge(const string & source_id, long time_id, const s
_sendEvent(event);
}
void NetStreamSender::stepBegins(const string & source_id, long time_id, double timestamp){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_STEP);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -250,7 +251,7 @@ void NetStreamSender::stepBegins(const string & source_id, long time_id, double
_sendEvent(event);
}
void NetStreamSender::graphClear(const string & source_id, long time_id){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_CLEARED);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -262,7 +263,7 @@ void NetStreamSender::graphClear(const string & source_id, long time_id){
// =====================
void NetStreamSender::removeNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_DEL_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -271,7 +272,7 @@ void NetStreamSender::removeNodeAttribute(const string & source_id, long time_id
_sendEvent(event);
}
void NetStreamSender::removeGraphAttribute(const string & source_id, long time_id, const string & attribute){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_DEL_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -279,7 +280,7 @@ void NetStreamSender::removeGraphAttribute(const string & source_id, long time_i
_sendEvent(event);
}
void NetStreamSender::removeEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_DEL_EDGE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -287,3 +288,4 @@ void NetStreamSender::removeEdgeAttribute(const string & source_id, long time_id
event.writeString(attribute);
_sendEvent(event);
}
}
\ No newline at end of file
......@@ -18,21 +18,23 @@
#include <sys/socket.h>
#include <errno.h>
#include "tcpip/storage.h"
#include "tcpip/socket.h"
#include "netstream-storage.h"
#include "netstream-socket.h"
#include "netstream-constants.h"
using namespace std;
using namespace tcpip;
namespace netstream{
class NetStreamSender{
protected:
string _stream_name;
string _host;
int _port;
Socket _socket;
Storage _stream;
NetStreamSocket _socket;
NetStreamStorage _stream;
bool debug;
void init();
......@@ -63,30 +65,30 @@ protected:
int _getType( const vector<double> & object);
template <typename T>
void encode(Storage & event, const T & value){
void encode(NetStreamStorage & event, const T & value){
_encode(event, value);
}
template <typename T>
void encode(Storage & event, const vector<T> & value){
void encode(NetStreamStorage & event, const vector<T> & value){
_encode(event, value);
}
void _encode(Storage & event, char value);
void _encode(Storage & event, bool value);
void _encode(Storage & event, int value);
void _encode(Storage & event, long value);
void _encode(Storage & event, float value);
void _encode(Storage & event, double value);
void _encode(Storage & event, const string & value);
void _encode(NetStreamStorage & event, char value);
void _encode(NetStreamStorage & event, bool value);
void _encode(NetStreamStorage & event, int value);
void _encode(NetStreamStorage & event, long value);
void _encode(NetStreamStorage & event, float value);
void _encode(NetStreamStorage & event, double value);
void _encode(NetStreamStorage & event, const string & value);
void _encode(Storage & event, const vector<char> & value);
void _encode(Storage & event, const vector<bool> & value);
void _encode(Storage & event, const vector<int> & value);
void _encode(Storage & event, const vector <long> & value);
void _encode(Storage & event, const vector <float> & value);
void _encode(Storage & event, const vector <double> & value);
void _encode(NetStreamStorage & event, const vector<char> & value);
void _encode(NetStreamStorage & event, const vector<bool> & value);
void _encode(NetStreamStorage & event, const vector<int> & value);
void _encode(NetStreamStorage & event, const vector <long> & value);
void _encode(NetStreamStorage & event, const vector <float> & value);
void _encode(NetStreamStorage & event, const vector <double> & value);
void _sendEvent(Storage &);
void _sendEvent(NetStreamStorage &);
public:
......@@ -112,8 +114,8 @@ public:
// ====================
template <typename T>
void addGraphAttribute(const string & source_id, long time_id, const string & attribute, T value){
Storage event = Storage();
event.writeByte(EVENT_ADD_GRAPH_ATTR);
NetStreamStorage event = NetStreamStorage();
event.writeByte(netstream::EVENT_ADD_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
event.writeString(attribute);
......@@ -124,7 +126,7 @@ public:
template <typename T>
void changeGraphAttribute(const string & source_id, long time_id, const string & attribute, const T oldValue, const T newValue){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_CHG_GRAPH_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -139,7 +141,7 @@ public:
template <typename T>
void addNodeAttribute(const string & source_id, long time_id, const string & node_id, const string & attribute, const T & value){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_ADD_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -152,7 +154,7 @@ public:
template <typename T>
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();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_CHG_NODE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);
......@@ -168,7 +170,7 @@ public:
template <typename T>
void addEdgeAttribute(const string & source_id, long time_id, const string & edge_id, const string & attribute, const T & value){
Storage event = Storage();
NetStreamStorage event = NetStreamStorage();
event.writeByte(EVENT_ADD_EDGE_ATTR);
event.writeString(source_id);
event.writeLong(time_id);