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++ ...@@ -7,30 +7,34 @@ CC = g++
CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O CWARN = -W -Wall -Wshadow -Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses -Wpointer-arith -Wuninitialized -O
CDBG = -g $(CWARN) -fno-inline CDBG = -g $(CWARN) -fno-inline
CFLAGS = -I$(INCDIR) -03 CFLAGS = -I$(INCDIR) -03
DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1 DFLAGS = -I$(INCDIR) -g $(CWARN) -fno-inline -DDEBUG=1
CTAG = ctags CTAG = ctags
CTAGFILE = filelist CTAGFILE = filelist
# src, object and bin files # src, object and bin files
MAIN := netstream-main OUT_BINARY := netstream-main
OUT_LIBRARY := libnetstream.a
HEADERS = $(INCDIR)/global.h HEADERS = $(INCDIR)/global.h
OBJS = \ OBJS = \
$(OBJDIR)/tcpip/storage.o \ $(OBJDIR)/netstream-storage.o \
$(OBJDIR)/tcpip/socket.o \ $(OBJDIR)/netstream-socket.o \
$(OBJDIR)/netstream-sender.o \ $(OBJDIR)/netstream-sender.o \
$(OBJDIR)/netstream-main.o $(OBJDIR)/netstream-main.o
.SECONDARY: .SECONDARY:
#-- Rules #-- 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 $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CC) $(CFLAGS) -c $? -o $@ $(CC) $(CFLAGS) -c $? -o $@
...@@ -46,6 +50,7 @@ clean : ...@@ -46,6 +50,7 @@ clean :
-rm -f $(SRCDIR)/*.output $(LEX_C) -rm -f $(SRCDIR)/*.output $(LEX_C)
-rm -f */*~ *~ core -rm -f */*~ *~ core
-rm -f $(BINDIR)/* -rm -f $(BINDIR)/*
-rm -f $(MAIN) -rm -f $(OUT_BINARY)
-rm -f $(OUT_LIBRARY)
fresh : clean all 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 @@ ...@@ -13,20 +13,20 @@
#ifndef NETSTREAM_CONSTANTS_H #ifndef NETSTREAM_CONSTANTS_H
#define NETSTREAM_CONSTANTS_H #define NETSTREAM_CONSTANTS_H
namespace netstream{
/** /**
* Followed by an 32-bit signed integer for this protocol version. Certainly useless. * 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. * Not used.
*/ */
#define EVENT_START 0x01 const unsigned char EVENT_START=0x01;
/** /**
* Not used. * Not used.
*/ */
#define EVENT_END 0x02 const unsigned char EVENT_END=0x02;
// //
...@@ -38,12 +38,12 @@ ...@@ -38,12 +38,12 @@
/** /**
* Followed by a node id (TYPE_STRING format) * 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) * Followed by a node id (TYPE_STRING format)
*/ */
#define EVENT_DEL_NODE 0x11 const unsigned char EVENT_DEL_NODE=0x11;
/** /**
* Followed by * Followed by
...@@ -52,21 +52,21 @@ ...@@ -52,21 +52,21 @@
* - a target node id (TYPE_STRING format * - a target node id (TYPE_STRING format
* - a boolean indicating if directed (TYPE_BOOLEAN 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) * 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) * 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 * Followed by
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
* - the attribute TYPE * - the attribute TYPE
* - the attribute value * - the attribute value
*/ */
#define EVENT_ADD_GRAPH_ATTR 0x16 const unsigned char EVENT_ADD_GRAPH_ATTR=0x16;
/** /**
* Followed by * Followed by
* - an attribute id (TYPE_STRING format) * - an attribute id (TYPE_STRING format)
...@@ -82,12 +82,12 @@ ...@@ -82,12 +82,12 @@
* - the attribute old value * - the attribute old value
* - the attribute new value * - the attribute new value
*/ */
#define EVENT_CHG_GRAPH_ATTR 0x17 const unsigned char EVENT_CHG_GRAPH_ATTR=0x17;
/** /**
* Followed by * Followed by
* - the attribute id (TYPE_STRING format) * - the attribute id (TYPE_STRING format)
*/ */
#define EVENT_DEL_GRAPH_ATTR 0x18 const unsigned char EVENT_DEL_GRAPH_ATTR=0x18;
/** /**
* Followed by * Followed by
...@@ -95,7 +95,7 @@ ...@@ -95,7 +95,7 @@
* - the attribute TYPE * - the attribute TYPE
* - the attribute value * - the attribute value
*/ */
#define EVENT_ADD_NODE_ATTR 0x19 const unsigned char EVENT_ADD_NODE_ATTR=0x19;
/** /**
* Followed by * Followed by
* - an attribute id (TYPE_STRING format) * - an attribute id (TYPE_STRING format)
...@@ -103,20 +103,20 @@ ...@@ -103,20 +103,20 @@
* - the attribute old value * - the attribute old value
* - the attribute new value * - the attribute new value
*/ */
#define EVENT_CHG_NODE_ATTR 0x1a const unsigned char EVENT_CHG_NODE_ATTR=0x1a;
/** /**
* Followed by * Followed by
* - the node id (TYPE_STRING format) * - the node id (TYPE_STRING format)
* - the attribute 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 * Followed by
* - an attribute id (TYPE_STRING format) * - an attribute id (TYPE_STRING format)
* - the attribute TYPE * - the attribute TYPE
* - the attribute value * - the attribute value
*/ */
#define EVENT_ADD_EDGE_ATTR 0x1c const unsigned char EVENT_ADD_EDGE_ATTR=0x1c;
/** /**
* Followed by * Followed by
* - an attribute id (TYPE_STRING format) * - an attribute id (TYPE_STRING format)
...@@ -124,13 +124,13 @@ ...@@ -124,13 +124,13 @@
* - the attribute old value * - the attribute old value
* - the attribute new value * - the attribute new value
*/ */
#define EVENT_CHG_EDGE_ATTR 0x1d const unsigned char EVENT_CHG_EDGE_ATTR=0x1d;
/** /**
* Followed by * Followed by
* - the edge id (TYPE_STRING format) * - the edge id (TYPE_STRING format)
* - the attribute 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 @@ ...@@ -140,83 +140,85 @@
/** /**
* Followed by a byte who's value is 0 or 1 * 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 * 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 * 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] * 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 * An array of bytes. Followed by first, a 16-bits integer for the number
* of integers and then, a list of signed bytes. * 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) * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * Array of double. Followed by first, a 16-bits integer for the number of
* floats and then, a list of 32-bit floats * 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 * 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 * Array of double. Followed by first, a 16-bits integer for the number of
* doubles and then, a list of 64-bit doubles * 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 * 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 * bytes (not in number of characters) of the string, then by the unicode
* string * string
*/ */
#define TYPE_STRING 0x5e const unsigned char TYPE_STRING=0x5e;
/** /**
* Raw data, good for serialization. Followed by first, a 16-bits integer * 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. * 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 * An type-unspecified array. Followed by first, a
* 16-bits integer indicating the number of elements, and then, the elements * 16-bits integer indicating the number of elements, and then, the elements
* themselves. The elements themselves have to give their type. * themselves. The elements themselves have to give their type.
*/ */
#define TYPE_ARRAY 0x60 const unsigned char TYPE_ARRAY=0x60;
}// end netstream namespace
#endif #endif
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include "tcpip/storage.h" #include "netstream-storage.h"
#include "tcpip/socket.h" #include "netstream-socket.h"
#include "netstream-constants.h" #include "netstream-constants.h"
#include "netstream-sender.h" #include "netstream-sender.h"
using namespace tcpip;
using namespace std; using namespace std;
using namespace netstream;
void events_test(); void events_test();
void types_test(); void types_test();
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "netstream-sender.h" #include "netstream-sender.h"
namespace netstream{
NetStreamSender::NetStreamSender(const string & host, int port): NetStreamSender::NetStreamSender(const string & host, int port):
_stream_name("default"),_host(host),_port(port),_stream(),_socket(host,port),debug(false) { _stream_name("default"),_host(host),_port(port),_stream(),_socket(host,port),debug(false) {
init(); init();
...@@ -123,58 +124,58 @@ return TYPE_DOUBLE_ARRAY;} ...@@ -123,58 +124,58 @@ return TYPE_DOUBLE_ARRAY;}
// ================= // =================
// = data encoding = // = data encoding =
// ================= // =================
void NetStreamSender::_encode(Storage & event, char value){ void NetStreamSender::_encode(NetStreamStorage & event, char value){
event.writeByte((int)value); event.writeByte((int)value);
} }
void NetStreamSender::_encode(Storage & event, bool value){ void NetStreamSender::_encode(NetStreamStorage & event, bool value){
event.writeByte(value?1:0); event.writeByte(value?1:0);
} }
void NetStreamSender::_encode(Storage & event, int value){ void NetStreamSender::_encode(NetStreamStorage & event, int value){
event.writeInt(value); event.writeInt(value);
} }
void NetStreamSender::_encode(Storage & event, long value){ void NetStreamSender::_encode(NetStreamStorage & event, long value){
event.writeLong(value); event.writeLong(value);
} }
void NetStreamSender::_encode(Storage & event, float value){ void NetStreamSender::_encode(NetStreamStorage & event, float value){
event.writeFloat(value); event.writeFloat(value);
} }
void NetStreamSender::_encode(Storage & event, double value){ void NetStreamSender::_encode(NetStreamStorage & event, double value){
event.writeDouble(value); event.writeDouble(value);
} }
void NetStreamSender::_encode(Storage & event,const string & value){ void NetStreamSender::_encode(NetStreamStorage & event,const string & value){
event.writeString(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()); event.writeInt(value.size());
for(vector<char>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<char>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeByte((*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()); event.writeInt(value.size());
for(vector<bool>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<bool>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeByte((*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()); event.writeInt(value.size());
for(vector<int>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<int>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeInt((*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()); event.writeInt(value.size());
for(vector<long>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<long>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeLong((*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()); event.writeInt(value.size());
for(vector<float>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<float>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeFloat((*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()); event.writeInt(value.size());
for(vector<double>::const_iterator i = value.begin(); i != value.end(); i++){ for(vector<double>::const_iterator i = value.begin(); i != value.end(); i++){
event.writeDouble((*i)); event.writeDouble((*i));
...@@ -182,12 +183,12 @@ void NetStreamSender::_encode(Storage & event, const vector<double> & value){ ...@@ -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){ if(debug){
cout<<event<<endl; 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)<<","; cout<<(int)(*it)<<",";
it++; it++;
} }
...@@ -197,7 +198,7 @@ void NetStreamSender::_sendEvent(Storage & event){ ...@@ -197,7 +198,7 @@ void NetStreamSender::_sendEvent(Storage & event){
try{ try{
_socket.sendExact(_stream+event); _socket.sendExact(_stream+event);
} }
catch (SocketException &e) catch (NetStreamSocketException &e)
{ {
cout << "Error while sending message: " << e.what(); cout << "Error while sending message: " << e.what();
} }
...@@ -207,7 +208,7 @@ void NetStreamSender::_sendEvent(Storage & event){ ...@@ -207,7 +208,7 @@ void NetStreamSender::_sendEvent(Storage & event){
// = Element events = // = Element events =
// ================== // ==================
void NetStreamSender::addNode(const string & source_id, long time_id, const string & node_id){ void NetStreamSender::addNode(const string & source_id, long time_id, const string & node_id){
Storage event = Storage(); NetStreamStorage event = NetStreamStorage();