Modified to use libtransportaddon.a.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3741 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
37b3e403fe
commit
8843cf3906
@ -1,8 +1,14 @@
|
|||||||
SubDir OBOS_TOP src add-ons print transports parallel_port ;
|
SubDir OBOS_TOP src add-ons print transports parallel_port ;
|
||||||
|
|
||||||
Addon Parallel\ Port : print transport :
|
SubDirHdrs [ FDirName $(OBOS_TOP) src add-ons print transports shared ] ;
|
||||||
print_transport.cpp
|
|
||||||
|
UsePrivateHeaders interface print ;
|
||||||
|
|
||||||
|
Addon Parallel\ Port
|
||||||
|
: print transport
|
||||||
|
: print_transport.cpp
|
||||||
;
|
;
|
||||||
|
|
||||||
LinkSharedOSLibs Parallel\ Port : be ;
|
LinkSharedOSLibs Parallel\ Port : be libtransportaddon.a
|
||||||
|
;
|
||||||
|
|
||||||
|
@ -29,77 +29,44 @@
|
|||||||
// DEALINGS IN THE SOFTWARE.
|
// DEALINGS IN THE SOFTWARE.
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
#include <SupportKit.h>
|
#include <SupportKit.h>
|
||||||
|
|
||||||
|
#include "TransportAddOn.h"
|
||||||
|
|
||||||
class ParallelPort : public BDataIO {
|
class ParallelPort : public BDataIO {
|
||||||
int fFile;
|
int fFile;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ParallelPort(BMessage* msg);
|
ParallelPort(BDirectory* printer, BMessage* msg);
|
||||||
~ParallelPort();
|
~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 Read(void* buffer, size_t size);
|
||||||
ssize_t Write(const 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
|
// Impelmentation of ParallelPort
|
||||||
ParallelPort::ParallelPort(BMessage* msg)
|
ParallelPort::ParallelPort(BDirectory* printer, BMessage* msg)
|
||||||
: fFile(-1)
|
: fFile(-1)
|
||||||
{
|
{
|
||||||
const char* printer_name = msg->FindString("printer_file");
|
|
||||||
char address[80];
|
char address[80];
|
||||||
char device[B_PATH_NAME_LENGTH];
|
char device[B_PATH_NAME_LENGTH];
|
||||||
|
|
||||||
if (printer_name && *printer_name != '\0') {
|
int size = printer->ReadAttr("transport_address", B_STRING_TYPE, 0, address, sizeof(address));
|
||||||
BDirectory printer(printer_name);
|
if (size <= 0 || size >= sizeof(address)) return;
|
||||||
if (printer.InitCheck() != B_OK) return;
|
address[size] = 0; // make sure string is 0-terminated
|
||||||
|
|
||||||
int size = printer.ReadAttr("transport_address", B_STRING_TYPE, 0, address, sizeof(address));
|
strcat(strcpy(device, "/dev/parallel/"), address);
|
||||||
if (size <= 0 || size >= sizeof(address)) return;
|
fFile = open(device, O_RDWR | O_EXCL | O_BINARY, 0);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParallelPort::~ParallelPort() {
|
ParallelPort::~ParallelPort() {
|
||||||
if (IsOk()) {
|
if (InitCheck() == B_OK) {
|
||||||
close(fFile); fFile = -1;
|
close(fFile); fFile = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,3 +79,11 @@ ssize_t ParallelPort::Write(const void* buffer, size_t size) {
|
|||||||
return write(fFile, buffer, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user