From 8843cf39068f3cb84eca724c0cd93e4cdcb5a2b5 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Sun, 29 Jun 2003 18:45:47 +0000 Subject: [PATCH] Modified to use libtransportaddon.a. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3741 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../print/transports/parallel_port/Jamfile | 12 +++- .../parallel_port/print_transport.cpp | 65 ++++++------------- 2 files changed, 29 insertions(+), 48 deletions(-) diff --git a/src/add-ons/print/transports/parallel_port/Jamfile b/src/add-ons/print/transports/parallel_port/Jamfile index 800f5d8405..6be30eb67f 100644 --- a/src/add-ons/print/transports/parallel_port/Jamfile +++ b/src/add-ons/print/transports/parallel_port/Jamfile @@ -1,8 +1,14 @@ SubDir OBOS_TOP src add-ons print transports parallel_port ; -Addon Parallel\ Port : print transport : - print_transport.cpp +SubDirHdrs [ FDirName $(OBOS_TOP) src add-ons print transports shared ] ; + +UsePrivateHeaders interface print ; + +Addon Parallel\ Port + : print transport + : print_transport.cpp ; -LinkSharedOSLibs Parallel\ Port : be ; +LinkSharedOSLibs Parallel\ Port : be libtransportaddon.a + ; diff --git a/src/add-ons/print/transports/parallel_port/print_transport.cpp b/src/add-ons/print/transports/parallel_port/print_transport.cpp index fff4bca1cd..834fa2f13f 100644 --- a/src/add-ons/print/transports/parallel_port/print_transport.cpp +++ b/src/add-ons/print/transports/parallel_port/print_transport.cpp @@ -29,77 +29,44 @@ // DEALINGS IN THE SOFTWARE. /*****************************************************************************/ -#include #include +#include #include #include +#include "TransportAddOn.h" + class ParallelPort : public BDataIO { int fFile; public: - ParallelPort(BMessage* msg); + ParallelPort(BDirectory* printer, BMessage* msg); ~ParallelPort(); - bool IsOk() { return fFile > -1; } + status_t InitCheck() { return fFile > -1 ? B_OK : B_ERROR; } ssize_t Read(void* buffer, size_t size); ssize_t Write(const void* buffer, size_t size); }; -// Only one connection per add-on permitted! -static ParallelPort* gPort = NULL; - -// Implementation of transport add-on interface - -extern "C" _EXPORT BDataIO * init_transport - ( - BMessage * msg - ) -{ - if (msg != NULL && gPort == NULL) { - ParallelPort* port = new ParallelPort(msg); - if (port->IsOk()) { - gPort = port; - return port; - } - delete port; - } - return NULL; -} - -extern "C" _EXPORT void exit_transport() -{ - if (gPort != NULL) { - delete gPort; - } -} - - // Impelmentation of ParallelPort -ParallelPort::ParallelPort(BMessage* msg) +ParallelPort::ParallelPort(BDirectory* printer, BMessage* msg) : fFile(-1) { - const char* printer_name = msg->FindString("printer_file"); char address[80]; char device[B_PATH_NAME_LENGTH]; - if (printer_name && *printer_name != '\0') { - BDirectory printer(printer_name); - if (printer.InitCheck() != B_OK) return; + int size = printer->ReadAttr("transport_address", B_STRING_TYPE, 0, address, sizeof(address)); + if (size <= 0 || size >= sizeof(address)) return; + address[size] = 0; // make sure string is 0-terminated - int size = printer.ReadAttr("transport_address", B_STRING_TYPE, 0, address, sizeof(address)); - if (size <= 0 || size >= sizeof(address)) return; - address[size] = 0; // make sure string is 0-terminated - - strcat(strcpy(device, "/dev/parallel/"), address); - fFile = open(device, O_RDWR | O_EXCL | O_BINARY, 0); - } + strcat(strcpy(device, "/dev/parallel/"), address); + fFile = open(device, O_RDWR | O_EXCL | O_BINARY, 0); } ParallelPort::~ParallelPort() { - if (IsOk()) { + if (InitCheck() == B_OK) { close(fFile); fFile = -1; } } @@ -112,3 +79,11 @@ ssize_t ParallelPort::Write(const void* buffer, size_t size) { return write(fFile, buffer, size); } +BDataIO* instanciate_transport(BDirectory* printer, BMessage* msg) { + ParallelPort* transport = new ParallelPort(printer, msg); + if (transport->InitCheck() == B_OK) { + return transport; + } else { + delete transport; return NULL; + } +}