Skip to content
Snippets Groups Projects
Commit 6ba21fdc authored by Andrea Zoli's avatar Andrea Zoli
Browse files

Add openDevice() for Input and Output classes.

parent bb689179
Branches
Tags
No related merge requests found
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "PacketExceptionIO.h" #include "PacketExceptionIO.h"
#include "ByteStream.h" #include "ByteStream.h"
#include <vector>
#include <string>
namespace PacketLib namespace PacketLib
{ {
...@@ -35,6 +37,8 @@ public: ...@@ -35,6 +37,8 @@ public:
virtual bool open( char** parameters ) throw(PacketExceptionIO*) = 0; virtual bool open( char** parameters ) throw(PacketExceptionIO*) = 0;
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*) = 0;
virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*) = 0; virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*) = 0;
virtual char* readString() throw(PacketExceptionIO*) = 0; virtual char* readString() throw(PacketExceptionIO*) = 0;
......
...@@ -35,6 +35,9 @@ public: ...@@ -35,6 +35,9 @@ public:
virtual bool open( char** parameters ) throw(PacketExceptionIO*); virtual bool open( char** parameters ) throw(PacketExceptionIO*);
/// parameters[0] = filename
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual void close() throw(PacketExceptionIO*); virtual void close() throw(PacketExceptionIO*);
virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*);
...@@ -52,7 +55,7 @@ protected: ...@@ -52,7 +55,7 @@ protected:
File* file; File* file;
char* filename; std::string filename;
}; };
} }
......
...@@ -35,6 +35,8 @@ public: ...@@ -35,6 +35,8 @@ public:
virtual bool open( char** parameters ) throw(PacketExceptionIO*); virtual bool open( char** parameters ) throw(PacketExceptionIO*);
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual void close() throw(PacketExceptionIO*); virtual void close() throw(PacketExceptionIO*);
virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*);
...@@ -50,7 +52,7 @@ protected: ...@@ -50,7 +52,7 @@ protected:
Serial* serial; Serial* serial;
char* device; std::string device;
int flag; int flag;
}; };
......
...@@ -35,6 +35,8 @@ public: ...@@ -35,6 +35,8 @@ public:
virtual bool open( char** parameters ) throw(PacketExceptionIO*); virtual bool open( char** parameters ) throw(PacketExceptionIO*);
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual void close() throw(PacketExceptionIO*); virtual void close() throw(PacketExceptionIO*);
virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "PacketLibDefinition.h" #include "PacketLibDefinition.h"
#include "ByteStream.h" #include "ByteStream.h"
#include "PacketExceptionIO.h" #include "PacketExceptionIO.h"
#include <vector>
#include <string>
namespace PacketLib namespace PacketLib
{ {
...@@ -35,6 +37,8 @@ public: ...@@ -35,6 +37,8 @@ public:
virtual bool open(char** parameters) throw(PacketExceptionIO*) = 0; virtual bool open(char** parameters) throw(PacketExceptionIO*) = 0;
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*) = 0;
virtual bool isClosed(); virtual bool isClosed();
virtual bool isBigendian(); virtual bool isBigendian();
......
...@@ -40,6 +40,10 @@ public: ...@@ -40,6 +40,10 @@ public:
///second parameter: fopen modes: w, r, a (optional) ///second parameter: fopen modes: w, r, a (optional)
virtual bool open(char** parameters) throw(PacketExceptionIO*); virtual bool open(char** parameters) throw(PacketExceptionIO*);
/// parameters[0] = filename
/// parameters[1] = modes: w, a (default w)
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*);
virtual bool writeString(const char* str) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*);
...@@ -53,7 +57,7 @@ protected: ...@@ -53,7 +57,7 @@ protected:
File* file; File* file;
char* filename; std::string filename;
}; };
......
...@@ -38,6 +38,8 @@ public: ...@@ -38,6 +38,8 @@ public:
virtual bool open(char** parameters) throw(PacketExceptionIO*); virtual bool open(char** parameters) throw(PacketExceptionIO*);
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*);
virtual bool writeString(const char* str) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*);
...@@ -50,7 +52,7 @@ public: ...@@ -50,7 +52,7 @@ public:
protected: protected:
char* device; std::string device;
Serial* serial; Serial* serial;
int flag; int flag;
......
...@@ -37,6 +37,8 @@ public: ...@@ -37,6 +37,8 @@ public:
virtual bool open(char** parameters) throw(PacketExceptionIO*); virtual bool open(char** parameters) throw(PacketExceptionIO*);
virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*);
virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*); virtual bool writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*);
virtual bool writeString(const char* str) throw(PacketExceptionIO*); virtual bool writeString(const char* str) throw(PacketExceptionIO*);
...@@ -50,7 +52,7 @@ protected: ...@@ -50,7 +52,7 @@ protected:
SocketClient* socketclient; SocketClient* socketclient;
char* host; std::string host;
int port; int port;
}; };
......
...@@ -41,6 +41,13 @@ bool InputFile::open( char** parameters ) throw(PacketExceptionIO*) ...@@ -41,6 +41,13 @@ bool InputFile::open( char** parameters ) throw(PacketExceptionIO*)
return true; return true;
} }
void InputFile::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
file->open(parameters[0].c_str(), (char*) "r");
filename = parameters[0];
closed = false;
eof = file->isEOF();
}
void InputFile::close() throw(PacketExceptionIO*) void InputFile::close() throw(PacketExceptionIO*)
{ {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
***************************************************************************/ ***************************************************************************/
#include "InputSerial.h" #include "InputSerial.h"
#include <sstream>
using namespace PacketLib; using namespace PacketLib;
...@@ -38,14 +39,27 @@ bool InputSerial::open( char** parameters ) throw(PacketExceptionIO*) ...@@ -38,14 +39,27 @@ bool InputSerial::open( char** parameters ) throw(PacketExceptionIO*)
flag = atoi( parameters[1] ); flag = atoi( parameters[1] );
device = parameters[0]; device = parameters[0];
//cout << "SSSSS: " << O_NONBLOCK << endl; //cout << "SSSSS: " << O_NONBLOCK << endl;
serial->open( device, O_NONBLOCK); serial->open((char*)device.c_str(), O_NONBLOCK);
serial->dump(); serial->dump();
serial->close(); serial->close();
serial->open( device, flag ); serial->open((char*)device.c_str(), flag);
closed = false; closed = false;
return true; return true;
} }
void InputSerial::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
std::istringstream ss(parameters[1]);
ss >> flag;
device = parameters[0];
serial->open((char*)device.c_str(), O_NONBLOCK);
serial->dump();
serial->close();
serial->open((char*)device.c_str(), flag);
closed = false;
}
void InputSerial::close() throw(PacketExceptionIO*) void InputSerial::close() throw(PacketExceptionIO*)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
***************************************************************************/ ***************************************************************************/
#include "InputSocketServer.h" #include "InputSocketServer.h"
#include <sstream>
using namespace PacketLib; using namespace PacketLib;
...@@ -46,7 +47,17 @@ bool InputSocketServer::open( char** parameters ) throw(PacketExceptionIO*) ...@@ -46,7 +47,17 @@ bool InputSocketServer::open( char** parameters ) throw(PacketExceptionIO*)
return true; return true;
} }
void InputSocketServer::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
std::istringstream ss(parameters[0]);
ss >> port;
socketserver = new SocketServer(bigendian, port);
new_sock = new SocketServer(bigendian);
accepted = false;
closed = false;
}
void InputSocketServer::close() throw(PacketExceptionIO*) void InputSocketServer::close() throw(PacketExceptionIO*)
{ {
......
...@@ -55,6 +55,18 @@ bool OutputFile::open(char** parameters) throw(PacketExceptionIO*) ...@@ -55,6 +55,18 @@ bool OutputFile::open(char** parameters) throw(PacketExceptionIO*)
return true; return true;
} }
void OutputFile::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
std::string mode = "w";
if(parameters.size() > 1)
mode = parameters[2];
file->open(parameters[0].c_str(), mode.c_str());
filename = parameters[0];
isclosed = false;
}
bool OutputFile::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) bool OutputFile::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
***************************************************************************/ ***************************************************************************/
#include "OutputSerial.h" #include "OutputSerial.h"
#include <sstream>
using namespace PacketLib; using namespace PacketLib;
...@@ -46,12 +47,19 @@ bool OutputSerial::open(char** parameters) throw(PacketExceptionIO*) ...@@ -46,12 +47,19 @@ bool OutputSerial::open(char** parameters) throw(PacketExceptionIO*)
{ {
flag = atoi( parameters[1] ); flag = atoi( parameters[1] );
device = parameters[0]; device = parameters[0];
serial->open( device, flag ); serial->open((char*)device.c_str(), flag);
isclosed = false; isclosed = false;
return true; return true;
} }
void OutputSerial::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
device = parameters[0];
std::istringstream ss(parameters[1]);
ss >> flag;
serial->open((char*)device.c_str(), flag);
isclosed = false;
}
bool OutputSerial::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) bool OutputSerial::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
{ {
......
...@@ -16,14 +16,14 @@ ...@@ -16,14 +16,14 @@
***************************************************************************/ ***************************************************************************/
#include "OutputSocketClient.h" #include "OutputSocketClient.h"
#include <sstream>
using namespace PacketLib; using namespace PacketLib;
OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian) OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian), host("")
{ {
socketclient = 0; socketclient = 0;
host = 0;
} }
...@@ -31,7 +31,6 @@ OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian) ...@@ -31,7 +31,6 @@ OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian)
OutputSocketClient::~OutputSocketClient() OutputSocketClient::~OutputSocketClient()
{ {
delete socketclient; delete socketclient;
delete host;
} }
...@@ -50,7 +49,14 @@ bool OutputSocketClient::open(char** argv) throw(PacketExceptionIO*) ...@@ -50,7 +49,14 @@ bool OutputSocketClient::open(char** argv) throw(PacketExceptionIO*)
return true; return true;
} }
void OutputSocketClient::openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*)
{
host = parameters[0];
std::istringstream ss(parameters[1]);
ss >> port;
socketclient = new SocketClient(bigendian, host, port);
isclosed = false;
}
bool OutputSocketClient::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*) bool OutputSocketClient::writeByteStream(ByteStreamPtr b) throw(PacketExceptionIO*)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment