Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/Header Files/AsynchHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef __INTERCHANGE_ASYNCH_HANDLER_H
#define __INTERCHANGE_ASYNCH_HANDLER_H

#include "Handler.h"

#include <vector>
#include <string>
#include <map>
#include "Protocol.h"
#include "Daemon.h"
#include "IPAddr.h"

#include <auto>
#include <pthread.h>

/*
* @author Marcus Plutowski
*/

class AsynchHandler : public Handler{
friend class Daemon;
friend class Protocol;
public:
Handler(IPAddr targetAddress, Timer* timer);

void addDaemon(Daemon *newDaemon);
void removeDaemon(std::string name);

void addProtocol(Protocol *newProtocol);
void removeProtocol(std::string name);

Daemon* getDaemon(std::string name);
Protocol* getProtocol(std::string name);

private:
void stageData(Datum data);
void retData(Datum data);

map<std::string, *Protocol> Protocols;
map<std::string, *Daemon> Daemons;

IPAddr target;

map<std::string, vector<std::string>> recieveBuffer;
map<std::string, vector<Timer::Datum>> sendBuffer;

Timer* ticker;
pthread_t clock;

void regulateHandler();
void tickDaemons();
void tickProtocols();
};

#endif //__INTERCHANGE_ASYNCH_HANDLER_H
28 changes: 28 additions & 0 deletions src/Header Files/Buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef __INTERCHANGE_BUFFER_H
#define __INTERCHANGE_BUFFER_H

#include <queue>
#include <string>

template<class T>
class Buffer{
public:
Buffer(std::string identifier, unsigned short initSize);

std::string getIdentifier();
void setIdentifier(std::string identifier);

void push(T newData);
T pop();
T get();

void resize(unsigned short newSize);
unsigned short getSize();

private:
std::string identifier;
std::queue<T> data;
unsigned short size;
};

#endif //__INTERCHANGE_BUFFER_H
File renamed without changes.
2 changes: 2 additions & 0 deletions src/Datum.h → src/Header Files/Datum.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Timer.h"
#include <vector>


class Datum {
public:
Datum();
Expand All @@ -15,6 +16,7 @@ class Datum {

void setData(std::string newData);
std::string getData();
std::string getSendable();

std::string getTarget();

Expand Down
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/Header Files/Protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _INTERCHANGE_PROTOCOL_H
#define _INTERCHANGE_PROTOCOL_H

#include "Handler.h"
#include <boost/asio.hpp>
#include <string>

/*
* @author Marcus Plutowski, Arushi Rai
*/

class Protocol{

public:
Protocol(int port);
std::string getName();
protected:
boost::asio::io_service io_service;
std::string name;
int targetPort;

virtual send(std::string data) = 0;
virtual receive() = 0;
};

#endif
File renamed without changes.
44 changes: 44 additions & 0 deletions src/Header Files/UDP/UDP_Client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef __INTERCHANGE_UDP_CLIENT_H
#define __INTERCHANGE_UDP_CLIENT_H

#include <string>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h> //used for fprintf
#include <netdb.h>

#include "..\Buffer.h"
#include "..\Datum.h"

#define BUFFER_SIZE 64; //needs to be changed

using namespace std;

/*
* @author Arushi Rai
*/

class UDP_Client {
private:
char recipientAddr[32];
Buffer<Datum> buffer;

int udp_socket;
int PORT;
struct sockaddr_in servaddr;
struct sockaddr_in myaddr;

void setup();
void bindSocket();
void timestamp(Datum* data, bool add);
bool validate(string data); //validates the buffer
Datum empty(); //empties buffer

public:
UDP_Client(string address, int port);
void send(); //sends the next item in the buffer, empties it as well
void addToSendBuffer(string message);
};

#endif
42 changes: 42 additions & 0 deletions src/Header Files/UDP/UDP_Server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef __INTERCHANGE_UDP_SERVER_H
#define __INTERCHANGE_UDP_SERVER_H

#include <string>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h> //used for fprintf
#include <netdb.h>

#include "..\Buffer.h"
#include "..\Datum.h"

#define BUFFER_SIZE 64;

using namespace std;

/*
* @author Arushi Rai
*/

class UDP_Server {
private:
char recipientAddr[32];
Buffer <Datum> buffer;

int server_socket;
int PORT;

void start();
void timestamp(Datum* data, bool add);
bool validate(string data); //validates the buffer
struct sockaddr_in remaddr; // remote address
socklen_t addrlen; //length of addresses

public:
UDP_Server(string address, int port);
void receive();
string empty(); //empties buffer //use a more intuitive name
};

#endif
29 changes: 29 additions & 0 deletions src/Header Files/UDP_Protocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __INTERCHANGE_UDP_PROTOCOL_H
#define __INTERCHANGE_UDP_PROTOCOL_H

#include "UDP\UDP_Client.h"
#include "UDP\UDP_Server.h"
#include "Protocol.h"
#include "IPAddr.h"

#include <string>
#include <Boost/asio.hpp>

/*
* @author Arushi Rai
*/

class UDP_Protocol :: public Protocol {
private:
UDP_Server server; //make static?
UDP_Client client; //make static?
IPAddr address;
public:
UDP_Protocol(int port);
std::string getName();
void start(); //will start thread to run client and server simultaniously
std::string receive();
void send(string message); //might not need this function
};

#endif
29 changes: 0 additions & 29 deletions src/Protocol.h

This file was deleted.

44 changes: 44 additions & 0 deletions src/Source Files/Buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "..\\Header Files\Buffer.h"

Buffer<T>::Buffer(std::int identifer, unsigned short initSize){
this->identifier = identifier;
size = initSize;

}

std::string Buffer<T>::getIdentifier(){
return identifier;
}
void Buffer<T>::setIdentifier(std::string identifier){
this->identifier = identifier;
}

void Buffer<T>::push(T newData){
if(size == 0){return;}

while(data.getSize() == size){
this->pop();
}
data.push(newData);
}
T Buffer<T>::pop(){
if(!data.empty()){
T buff;
buff = data.front()
data.pop();
return buff;
}
}
T Buffer<T>::get(){
if(!data.empty()){
return data.front();
}
}

void Buffer<T>::resize(unsigned short newSize){
data.resize(newSize);
}

unsigned short Buffer<T>::getSize(){
return size;
}
2 changes: 2 additions & 0 deletions src/Daemon.cpp → src/Source Files/Daemon.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "..\\Header Files\Daemon.h"

#include "Daemon.h"
#include "Datum.h"
#include "Handler.h"
Expand Down
33 changes: 22 additions & 11 deletions src/Datum.cpp → src/Source Files/Datum.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "Datum.h"
#include "..\\Header Files\Datum.h"

/*
* @author Marcus Plutowski, Arushi Rai
*/
Datum::Datum()
{
// Use null protocol rather than this or check for empty protocol
Expand All @@ -8,23 +11,31 @@ Datum::Datum()
protocolTransited = "";
}

Datum::Datum(std::string initData, std::string target, std::string protocol)
{
data = initData;
targetName = target;
protocolTransited = protocol;
}
Datum::Datum(std::string initData, std::string target, std::string protocol){
data = initData;
targetName = target;
protocolTransited = protocol;

std::string Datum::getTarget() { return targetName; }

void Datum::timeStamp(Timer* timer) { timestamps.push_back(timer->getTime()); }
Timer::milliseconds Datum::getTimeStamp(int num) { return timestamps[num]; }

std::string Datum::getSendable(){
std::string sendable;
sendable = protocolTransited;
sendable += "; "; //seperation characters
sendable += data;

if (protocolTransited[0] == 'T') {
//enter TCP data string format
}

return sendable;
}

void Datum::setData(std::string newData) { data = newData; }
std::string Datum::getData() { return data; }

void Datum::setProtocol(std::string newProtocol)
{
protocolTransited = newProtocol;
}
void Datum::setProtocol(std::string newProtocol) { protocolTransited = newProtocol; }
std::string Datum::getProtocol() { return protocolTransited; }
2 changes: 1 addition & 1 deletion src/IPAddr.cpp → src/Source Files/IPAddr.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IPAddr.h"
#include "..\\Header Files\IPAddr.h"
#include <sstream>
#include <algorithm>
#include <string>
Expand Down
Loading