diff --git a/include/Input.h b/include/Input.h index 031d7990a29083b3ff38eaf616fa7d0775bbe11b..a33f8f48d4f2728fb9d00d977d1856bdf5b9cf64 100644 --- a/include/Input.h +++ b/include/Input.h @@ -20,6 +20,8 @@ #include "PacketExceptionIO.h" #include "ByteStream.h" +#include <vector> +#include <string> namespace PacketLib { @@ -35,6 +37,8 @@ public: 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 char* readString() throw(PacketExceptionIO*) = 0; diff --git a/include/InputFile.h b/include/InputFile.h index 8b048475964913708ec015f866b0e738e383da33..596e1a51fcfbe5422e407908ecc9e736b97240ab 100644 --- a/include/InputFile.h +++ b/include/InputFile.h @@ -35,6 +35,9 @@ public: 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 ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); @@ -52,7 +55,7 @@ protected: File* file; - char* filename; + std::string filename; }; } diff --git a/include/InputSerial.h b/include/InputSerial.h index e00b52588813fc9f3e393a2d77c889e4b60df688..40836f414867f7abbaf19eaf7021c5fd3650a9af 100644 --- a/include/InputSerial.h +++ b/include/InputSerial.h @@ -35,6 +35,8 @@ public: virtual bool open( char** parameters ) throw(PacketExceptionIO*); + virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*); + virtual void close() throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); @@ -50,7 +52,7 @@ protected: Serial* serial; - char* device; + std::string device; int flag; }; diff --git a/include/InputSocketServer.h b/include/InputSocketServer.h index 30ac6327c3ccc6a07f84a26df65daee7a9f2ae7f..715ea171d61cb3d2309edd425764b0e8165685f1 100644 --- a/include/InputSocketServer.h +++ b/include/InputSocketServer.h @@ -35,6 +35,8 @@ public: virtual bool open( char** parameters ) throw(PacketExceptionIO*); + virtual void openDevice(const std::vector<std::string>& parameters) throw(PacketExceptionIO*); + virtual void close() throw(PacketExceptionIO*); virtual ByteStreamPtr readByteStream(dword n_byte) throw(PacketExceptionIO*); diff --git a/include/Output.h b/include/Output.h index 980dbf561b833b1d9734e6856aa6872051fe7889..a82f4ec249972d0a8a9b83abf52f7e5734df2187 100644 --- a/include/Output.h +++ b/include/Output.h @@ -21,6 +21,8 @@ #include "PacketLibDefinition.h" #include "ByteStream.h" #include "PacketExceptionIO.h" +#include <vector> +#include <string> namespace PacketLib { @@ -35,6 +37,8 @@ public: 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 isBigendian(); diff --git a/include/OutputFile.h b/include/OutputFile.h index d53d4259eaf23a689936fd0ca801e911e00f16c2..5b18637158854d80d56668c7986e32d6a8e97cbb 100644 --- a/include/OutputFile.h +++ b/include/OutputFile.h @@ -40,6 +40,10 @@ public: ///second parameter: fopen modes: w, r, a (optional) 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 writeString(const char* str) throw(PacketExceptionIO*); @@ -53,7 +57,7 @@ protected: File* file; - char* filename; + std::string filename; }; diff --git a/include/OutputSerial.h b/include/OutputSerial.h index 0a316a0ad521b6ed8c497d4e01108346360e255b..f2cdcfe1dfa2dd85266cea18c55119dd12d80ad1 100644 --- a/include/OutputSerial.h +++ b/include/OutputSerial.h @@ -38,6 +38,8 @@ public: 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 writeString(const char* str) throw(PacketExceptionIO*); @@ -50,7 +52,7 @@ public: protected: - char* device; + std::string device; Serial* serial; int flag; diff --git a/include/OutputSocketClient.h b/include/OutputSocketClient.h index 1ad78388e5b9309357db614e268c1694525e76ef..c57400925f1cc92a7b1256e09a1236e8ceecd7f2 100644 --- a/include/OutputSocketClient.h +++ b/include/OutputSocketClient.h @@ -37,6 +37,8 @@ public: 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 writeString(const char* str) throw(PacketExceptionIO*); @@ -50,7 +52,7 @@ protected: SocketClient* socketclient; - char* host; + std::string host; int port; }; diff --git a/src/InputFile.cpp b/src/InputFile.cpp index bb577671311c5f16f1a92f4cf3e0d04d25ee9bf4..31ff2d8ec7709f5abff796495af2b9fe159b4330 100644 --- a/src/InputFile.cpp +++ b/src/InputFile.cpp @@ -41,6 +41,13 @@ bool InputFile::open( char** parameters ) throw(PacketExceptionIO*) 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*) { diff --git a/src/InputSerial.cpp b/src/InputSerial.cpp index b2b3d269019560e4cf867500f8157684ad0ea11c..416a0b2b9215346b6d86420b3a758d6cccc11934 100644 --- a/src/InputSerial.cpp +++ b/src/InputSerial.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "InputSerial.h" +#include <sstream> using namespace PacketLib; @@ -38,14 +39,27 @@ bool InputSerial::open( char** parameters ) throw(PacketExceptionIO*) flag = atoi( parameters[1] ); device = parameters[0]; //cout << "SSSSS: " << O_NONBLOCK << endl; - serial->open( device, O_NONBLOCK); + serial->open((char*)device.c_str(), O_NONBLOCK); serial->dump(); serial->close(); - serial->open( device, flag ); + serial->open((char*)device.c_str(), flag); closed = false; 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*) diff --git a/src/InputSocketServer.cpp b/src/InputSocketServer.cpp index 7cb5853a6f64da8d6074298d9bf532778bd39549..41d09c410fbbfacf29b94467e4be6f64478bf02e 100644 --- a/src/InputSocketServer.cpp +++ b/src/InputSocketServer.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "InputSocketServer.h" +#include <sstream> using namespace PacketLib; @@ -46,7 +47,17 @@ bool InputSocketServer::open( char** parameters ) throw(PacketExceptionIO*) 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*) { diff --git a/src/OutputFile.cpp b/src/OutputFile.cpp index 8725e483f718cacbdc63daf58d58d661c5002e80..9343b1366f8c27867dd3d48cfb409404122be82a 100644 --- a/src/OutputFile.cpp +++ b/src/OutputFile.cpp @@ -55,6 +55,18 @@ bool OutputFile::open(char** parameters) throw(PacketExceptionIO*) 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*) diff --git a/src/OutputSerial.cpp b/src/OutputSerial.cpp index c594ff26c4f91f2f6f7daeb01607178b360ef72f..8ae2157d41ce63ea578e127946bd37825e33f6a7 100644 --- a/src/OutputSerial.cpp +++ b/src/OutputSerial.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "OutputSerial.h" +#include <sstream> using namespace PacketLib; @@ -46,12 +47,19 @@ bool OutputSerial::open(char** parameters) throw(PacketExceptionIO*) { flag = atoi( parameters[1] ); device = parameters[0]; - serial->open( device, flag ); + serial->open((char*)device.c_str(), flag); isclosed = false; 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*) { diff --git a/src/OutputSocketClient.cpp b/src/OutputSocketClient.cpp index 1a0f707bad3caa2017cf7f8ec2219d4729828ded..319510480cab5916b8d592e8f72dcb92c662d249 100644 --- a/src/OutputSocketClient.cpp +++ b/src/OutputSocketClient.cpp @@ -16,14 +16,14 @@ ***************************************************************************/ #include "OutputSocketClient.h" +#include <sstream> using namespace PacketLib; -OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian) +OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian), host("") { socketclient = 0; - host = 0; } @@ -31,7 +31,6 @@ OutputSocketClient::OutputSocketClient(bool bigendian) : Output(bigendian) OutputSocketClient::~OutputSocketClient() { delete socketclient; - delete host; } @@ -50,7 +49,14 @@ bool OutputSocketClient::open(char** argv) throw(PacketExceptionIO*) 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*) {