Fixed style issues.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33558 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -4,25 +4,28 @@
|
|||||||
#include "LprTransport.h"
|
#include "LprTransport.h"
|
||||||
#include "DbgMsg.h"
|
#include "DbgMsg.h"
|
||||||
|
|
||||||
LprTransport *transport = NULL;
|
|
||||||
|
|
||||||
extern "C" _EXPORT void exit_transport()
|
static LprTransport *gTransport = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
exit_transport()
|
||||||
{
|
{
|
||||||
DBGMSG(("> exit_transport\n"));
|
DBGMSG(("> exit_transport\n"));
|
||||||
if (transport) {
|
delete gTransport;
|
||||||
delete transport;
|
gTransport = NULL;
|
||||||
transport = NULL;
|
|
||||||
}
|
|
||||||
DBGMSG(("< exit_transport\n"));
|
DBGMSG(("< exit_transport\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" _EXPORT BDataIO *init_transport(BMessage *msg)
|
|
||||||
|
extern "C" BDataIO *
|
||||||
|
init_transport(BMessage *msg)
|
||||||
{
|
{
|
||||||
DBGMSG(("> init_transport\n"));
|
DBGMSG(("> init_transport\n"));
|
||||||
|
|
||||||
transport = new LprTransport(msg);
|
gTransport = new LprTransport(msg);
|
||||||
|
|
||||||
if (transport->fail()) {
|
if (gTransport->fail()) {
|
||||||
exit_transport();
|
exit_transport();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,5 +33,5 @@ extern "C" _EXPORT BDataIO *init_transport(BMessage *msg)
|
|||||||
msg->what = 'okok';
|
msg->what = 'okok';
|
||||||
|
|
||||||
DBGMSG(("< init_transport\n"));
|
DBGMSG(("< init_transport\n"));
|
||||||
return transport;
|
return gTransport;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "LprDefs.h"
|
#include "LprDefs.h"
|
||||||
#include "DbgMsg.h"
|
#include "DbgMsg.h"
|
||||||
|
|
||||||
|
|
||||||
#define DLG_WIDTH 370
|
#define DLG_WIDTH 370
|
||||||
#define DLG_HEIGHT 100
|
#define DLG_HEIGHT 100
|
||||||
|
|
||||||
@@ -74,44 +75,51 @@ enum MSGS {
|
|||||||
|
|
||||||
class LprSetupView : public BView {
|
class LprSetupView : public BView {
|
||||||
public:
|
public:
|
||||||
LprSetupView(BRect, BDirectory *);
|
LprSetupView(BRect, BDirectory *);
|
||||||
~LprSetupView() {}
|
~LprSetupView() {}
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
bool UpdateViewData();
|
bool UpdateViewData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BTextControl *server;
|
BTextControl* fServer;
|
||||||
BTextControl *queue;
|
BTextControl* fQueue;
|
||||||
BDirectory *dir;
|
BDirectory* fDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
LprSetupView::LprSetupView(BRect frame, BDirectory *d)
|
LprSetupView::LprSetupView(BRect frame, BDirectory *d)
|
||||||
: BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), dir(d)
|
:
|
||||||
|
BView(frame, "", B_FOLLOW_ALL, B_WILL_DRAW), fDir(d)
|
||||||
{
|
{
|
||||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LprSetupView::AttachedToWindow()
|
|
||||||
|
void
|
||||||
|
LprSetupView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
float width = max(StringWidth(SERVER_TEXT), StringWidth(QUEUE_TEXT)) + 10;
|
float width = max(StringWidth(SERVER_TEXT), StringWidth(QUEUE_TEXT)) + 10;
|
||||||
|
|
||||||
/* server name box */
|
/* server name box */
|
||||||
|
|
||||||
// TODO remember previous value
|
// TODO remember previous value
|
||||||
server = new BTextControl(SERVER_RECT, "", SERVER_TEXT, "192.168.0.0", NULL);
|
fServer = new BTextControl(SERVER_RECT, "", SERVER_TEXT, "192.168.0.0",
|
||||||
AddChild(server);
|
NULL);
|
||||||
server->SetDivider(width);
|
AddChild(fServer);
|
||||||
|
fServer->SetDivider(width);
|
||||||
|
|
||||||
/* queue name box */
|
/* queue name box */
|
||||||
|
|
||||||
// TODO remember previous value
|
// TODO remember previous value
|
||||||
queue = new BTextControl(QUEUE_RECT, "", QUEUE_TEXT, "LPT1_PASSTHRU", NULL);
|
fQueue = new BTextControl(QUEUE_RECT, "", QUEUE_TEXT, "LPT1_PASSTHRU",
|
||||||
AddChild(queue);
|
NULL);
|
||||||
queue->SetDivider(width);
|
AddChild(fQueue);
|
||||||
|
fQueue->SetDivider(width);
|
||||||
|
|
||||||
/* cancel */
|
/* cancel */
|
||||||
|
|
||||||
BButton *button = new BButton(CANCEL_RECT, "", CANCEL_TEXT, new BMessage(M_CANCEL));
|
BButton *button = new BButton(CANCEL_RECT, "", CANCEL_TEXT,
|
||||||
|
new BMessage(M_CANCEL));
|
||||||
AddChild(button);
|
AddChild(button);
|
||||||
|
|
||||||
/* ok */
|
/* ok */
|
||||||
@@ -121,12 +129,14 @@ void LprSetupView::AttachedToWindow()
|
|||||||
button->MakeDefault(true);
|
button->MakeDefault(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LprSetupView::UpdateViewData()
|
|
||||||
|
bool
|
||||||
|
LprSetupView::UpdateViewData()
|
||||||
{
|
{
|
||||||
if (*server->Text() && *queue->Text()) {
|
if (*fServer->Text() && *fQueue->Text()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LpsClient lpr(server->Text());
|
LpsClient lpr(fServer->Text());
|
||||||
lpr.connect();
|
lpr.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +146,8 @@ bool LprSetupView::UpdateViewData()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, server->Text(), strlen(server->Text()) + 1);
|
fDir->WriteAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer->Text(), strlen(fServer->Text()) + 1);
|
||||||
dir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, queue->Text(), strlen(queue->Text()) + 1);
|
fDir->WriteAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, fQueue->Text(), strlen(fQueue->Text()) + 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,60 +156,68 @@ bool LprSetupView::UpdateViewData()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LprSetupDlg::LprSetupDlg(BDirectory *dir)
|
LprSetupDlg::LprSetupDlg(BDirectory *dir)
|
||||||
: BWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT),
|
:
|
||||||
|
BWindow(BRect(100, 100, 100 + DLG_WIDTH, 100 + DLG_HEIGHT),
|
||||||
"LPR Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
"LPR Setup", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
|
||||||
B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE)
|
B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE)
|
||||||
{
|
{
|
||||||
result = 0;
|
fResult = 0;
|
||||||
|
|
||||||
Lock();
|
Lock();
|
||||||
LprSetupView *view = new LprSetupView(Bounds(), dir);
|
LprSetupView *view = new LprSetupView(Bounds(), dir);
|
||||||
AddChild(view);
|
AddChild(view);
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
semaphore = create_sem(0, "lprSetupSem");
|
fExitSemaphore = create_sem(0, "lprSetupSem");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LprSetupDlg::QuitRequested()
|
|
||||||
|
bool
|
||||||
|
LprSetupDlg::QuitRequested()
|
||||||
{
|
{
|
||||||
result = B_ERROR;
|
fResult = B_ERROR;
|
||||||
release_sem(semaphore);
|
release_sem(fExitSemaphore);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LprSetupDlg::MessageReceived(BMessage *msg)
|
|
||||||
|
void
|
||||||
|
LprSetupDlg::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case M_OK:
|
case M_OK:
|
||||||
Lock();
|
Lock();
|
||||||
success = ((LprSetupView *)ChildAt(0))->UpdateViewData();
|
success = ((LprSetupView *)ChildAt(0))->UpdateViewData();
|
||||||
Unlock();
|
Unlock();
|
||||||
if (success) {
|
if (success) {
|
||||||
result = B_NO_ERROR;
|
fResult = B_NO_ERROR;
|
||||||
release_sem(semaphore);
|
release_sem(fExitSemaphore);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case M_CANCEL:
|
case M_CANCEL:
|
||||||
result = B_ERROR;
|
fResult = B_ERROR;
|
||||||
release_sem(semaphore);
|
release_sem(fExitSemaphore);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(msg);
|
BWindow::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int LprSetupDlg::Go()
|
|
||||||
|
int
|
||||||
|
LprSetupDlg::Go()
|
||||||
{
|
{
|
||||||
Show();
|
Show();
|
||||||
acquire_sem(semaphore);
|
acquire_sem(fExitSemaphore);
|
||||||
delete_sem(semaphore);
|
delete_sem(fExitSemaphore);
|
||||||
int value = result;
|
int value = fResult;
|
||||||
Lock();
|
Lock();
|
||||||
Quit();
|
Quit();
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
// Sun, 18 Jun 2000
|
// Sun, 18 Jun 2000
|
||||||
// Y.Takagi
|
// Y.Takagi
|
||||||
|
|
||||||
#ifndef __LprSetupDlg_H
|
#ifndef __LprSetupDlg_H
|
||||||
#define __LprSetupDlg_H
|
#define __LprSetupDlg_H
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
class BDirectory;
|
class BDirectory;
|
||||||
|
|
||||||
class LprSetupDlg : public BWindow {
|
class LprSetupDlg : public BWindow {
|
||||||
public:
|
public:
|
||||||
LprSetupDlg(BDirectory *);
|
LprSetupDlg(BDirectory *);
|
||||||
~LprSetupDlg() {}
|
~LprSetupDlg() {}
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage *message);
|
||||||
int Go();
|
int Go();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int result;
|
int fResult;
|
||||||
long semaphore;
|
sem_id fExitSemaphore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __LprSetupDlg_H
|
#endif // __LprSetupDlg_H
|
||||||
|
|||||||
@@ -20,27 +20,23 @@
|
|||||||
#include "LprDefs.h"
|
#include "LprDefs.h"
|
||||||
#include "DbgMsg.h"
|
#include "DbgMsg.h"
|
||||||
|
|
||||||
#if (!__MWERKS__)
|
|
||||||
using namespace std;
|
|
||||||
#else
|
|
||||||
#define std
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LprTransport::LprTransport(BMessage *msg)
|
LprTransport::LprTransport(BMessage *msg)
|
||||||
: BDataIO()
|
:
|
||||||
|
BDataIO()
|
||||||
{
|
{
|
||||||
__server[0] = '\0';
|
fServer[0] = '\0';
|
||||||
__queue[0] = '\0';
|
fQueue[0] = '\0';
|
||||||
__file[0] = '\0';
|
fFile[0] = '\0';
|
||||||
__user[0] = '\0';
|
fUser[0] = '\0';
|
||||||
__jobid = 0;
|
fJobId = 0;
|
||||||
__error = false;
|
fError = false;
|
||||||
|
|
||||||
struct passwd *pwd = getpwuid(geteuid());
|
struct passwd *pwd = getpwuid(geteuid());
|
||||||
if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0])
|
if (pwd != NULL && pwd->pw_name != NULL && pwd->pw_name[0])
|
||||||
strcpy(__user, pwd->pw_name);
|
strcpy(fUser, pwd->pw_name);
|
||||||
else
|
else
|
||||||
strcpy(__user, "baron");
|
strcpy(fUser, "baron");
|
||||||
|
|
||||||
DUMP_BMESSAGE(msg);
|
DUMP_BMESSAGE(msg);
|
||||||
|
|
||||||
@@ -49,68 +45,69 @@ LprTransport::LprTransport(BMessage *msg)
|
|||||||
BDirectory dir(spool_path);
|
BDirectory dir(spool_path);
|
||||||
DUMP_BDIRECTORY(&dir);
|
DUMP_BDIRECTORY(&dir);
|
||||||
|
|
||||||
dir.ReadAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, __server, sizeof(__server));
|
dir.ReadAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer, sizeof(fServer));
|
||||||
if (__server[0] == '\0') {
|
if (fServer[0] == '\0') {
|
||||||
LprSetupDlg *dlg = new LprSetupDlg(&dir);
|
LprSetupDlg *dlg = new LprSetupDlg(&dir);
|
||||||
if (dlg->Go() == B_ERROR) {
|
if (dlg->Go() == B_ERROR) {
|
||||||
__error = true;
|
fError = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dir.ReadAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, __server, sizeof(__server));
|
dir.ReadAttr(LPR_SERVER_NAME, B_STRING_TYPE, 0, fServer, sizeof(fServer));
|
||||||
dir.ReadAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, __queue, sizeof(__queue));
|
dir.ReadAttr(LPR_QUEUE_NAME, B_STRING_TYPE, 0, fQueue, sizeof(fQueue));
|
||||||
dir.ReadAttr(LPR_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid));
|
dir.ReadAttr(LPR_JOB_ID, B_INT32_TYPE, 0, &fJobId, sizeof(fJobId));
|
||||||
__jobid++;
|
fJobId++;
|
||||||
if (__jobid > 255) {
|
if (fJobId > 255) {
|
||||||
__jobid = 1;
|
fJobId = 1;
|
||||||
}
|
}
|
||||||
dir.WriteAttr(LPR_JOB_ID, B_INT32_TYPE, 0, &__jobid, sizeof(__jobid));
|
dir.WriteAttr(LPR_JOB_ID, B_INT32_TYPE, 0, &fJobId, sizeof(fJobId));
|
||||||
|
|
||||||
sprintf(__file, "%s/%s@ipp.%ld", spool_path, __user, __jobid);
|
sprintf(fFile, "%s/%s@ipp.%ld", spool_path, fUser, fJobId);
|
||||||
|
|
||||||
__fs.open(__file, ios::in | ios::out | ios::binary | ios::trunc);
|
fStream.open(fFile, ios::in | ios::out | ios::binary | ios::trunc);
|
||||||
if (__fs.good()) {
|
if (fStream.good()) {
|
||||||
DBGMSG(("spool_file: %s\n", __file));
|
DBGMSG(("spool_file: %s\n", fFile));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
__error = true;
|
fError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LprTransport::~LprTransport()
|
LprTransport::~LprTransport()
|
||||||
{
|
{
|
||||||
char hostname[128];
|
char hostname[128];
|
||||||
gethostname(hostname, sizeof(hostname));
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
|
||||||
ostringstream cfname;
|
ostringstream cfname;
|
||||||
cfname << "cfA" << setw(3) << setfill('0') << __jobid << hostname;
|
cfname << "cfA" << setw(3) << setfill('0') << fJobId << hostname;
|
||||||
|
|
||||||
ostringstream dfname;
|
ostringstream dfname;
|
||||||
dfname << "dfA" << setw(3) << setfill('0') << __jobid << hostname;
|
dfname << "dfA" << setw(3) << setfill('0') << fJobId << hostname;
|
||||||
|
|
||||||
ostringstream cf;
|
ostringstream cf;
|
||||||
cf << 'H' << hostname << '\n';
|
cf << 'H' << hostname << '\n';
|
||||||
cf << 'P' << __user << '\n';
|
cf << 'P' << fUser << '\n';
|
||||||
cf << 'l' << dfname.str() << '\n';
|
cf << 'l' << dfname.str() << '\n';
|
||||||
cf << 'U' << dfname.str() << '\n';
|
cf << 'U' << dfname.str() << '\n';
|
||||||
|
|
||||||
long cfsize = cf.str().length();
|
long cfsize = cf.str().length();
|
||||||
long dfsize = __fs.tellg();
|
long dfsize = fStream.tellg();
|
||||||
__fs.seekg(0, ios::beg);
|
fStream.seekg(0, ios::beg);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LpsClient lpr(__server);
|
LpsClient lpr(fServer);
|
||||||
|
|
||||||
lpr.connect();
|
lpr.connect();
|
||||||
lpr.receiveJob(__queue);
|
lpr.receiveJob(fQueue);
|
||||||
|
|
||||||
lpr.receiveControlFile(cfsize, cfname.str().c_str());
|
lpr.receiveControlFile(cfsize, cfname.str().c_str());
|
||||||
lpr.transferData(cf.str().c_str(), cfsize);
|
lpr.transferData(cf.str().c_str(), cfsize);
|
||||||
lpr.endTransfer();
|
lpr.endTransfer();
|
||||||
|
|
||||||
lpr.receiveDataFile(dfsize, dfname.str().c_str());
|
lpr.receiveDataFile(dfsize, dfname.str().c_str());
|
||||||
lpr.transferData(__fs, dfsize);
|
lpr.transferData(fStream, dfsize);
|
||||||
lpr.endTransfer();
|
lpr.endTransfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,21 +117,23 @@ LprTransport::~LprTransport()
|
|||||||
alert->Go();
|
alert->Go();
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(__file);
|
unlink(fFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LprTransport::Read(void *, size_t)
|
|
||||||
|
ssize_t
|
||||||
|
LprTransport::Read(void *, size_t)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LprTransport::Write(const void *buffer, size_t size)
|
|
||||||
|
ssize_t
|
||||||
|
LprTransport::Write(const void *buffer, size_t size)
|
||||||
{
|
{
|
||||||
// DBGMSG(("write: %d\n", size));
|
if (!fStream.write((char *)buffer, size)) {
|
||||||
if (!__fs.write((char *)buffer, size)) {
|
fError = true;
|
||||||
__error = true;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// return __fs.pcount();
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,38 +9,37 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if (!__MWERKS__)
|
|
||||||
using namespace std;
|
|
||||||
#else
|
|
||||||
#define std
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class LprTransport : public BDataIO {
|
class LprTransport : public BDataIO {
|
||||||
public:
|
public:
|
||||||
LprTransport(BMessage *msg);
|
LprTransport(BMessage *msg);
|
||||||
virtual ~LprTransport();
|
virtual ~LprTransport();
|
||||||
virtual ssize_t Read(void *buffer, size_t size);
|
virtual ssize_t Read(void *buffer, size_t size);
|
||||||
virtual ssize_t Write(const void *buffer, size_t size);
|
virtual ssize_t Write(const void *buffer, size_t size);
|
||||||
|
|
||||||
bool operator !() const;
|
bool operator!() const;
|
||||||
bool fail() const;
|
bool fail() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char __server[256];
|
char fServer[256];
|
||||||
char __queue[256];
|
char fQueue[256];
|
||||||
char __file[256];
|
char fFile[256];
|
||||||
char __user[256];
|
char fUser[256];
|
||||||
int32 __jobid;
|
int32 fJobId;
|
||||||
fstream __fs;
|
fstream fStream;
|
||||||
bool __error;
|
bool fError;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool LprTransport::fail() const
|
|
||||||
|
inline bool
|
||||||
|
LprTransport::fail() const
|
||||||
{
|
{
|
||||||
return __error;
|
return fError;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool LprTransport::operator !() const
|
|
||||||
|
inline bool
|
||||||
|
LprTransport::operator!() const
|
||||||
{
|
{
|
||||||
return fail();
|
return fail();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
// Sun, 18 Jun 2000
|
// Sun, 18 Jun 2000
|
||||||
// Y.Takagi
|
// Y.Takagi
|
||||||
|
|
||||||
#if defined(__HAIKU__) || defined(HAIKU_TARGET_PLATFORM_BONE)
|
#include <sys/socket.h>
|
||||||
# include <sys/socket.h>
|
#include <netdb.h>
|
||||||
# include <netdb.h>
|
|
||||||
#else
|
|
||||||
# include <net/socket.h>
|
|
||||||
# include <net/netdb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -16,13 +11,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "LpsClient.h"
|
#include "LpsClient.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
//#include "DbgMsg.h"
|
|
||||||
|
|
||||||
#if (!__MWERKS__)
|
|
||||||
using namespace std;
|
|
||||||
#else
|
|
||||||
#define std
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define LPS_SERVER_PORT 515
|
#define LPS_SERVER_PORT 515
|
||||||
#define LPS_CLIENT_PORT_S 721
|
#define LPS_CLIENT_PORT_S 721
|
||||||
@@ -50,110 +39,115 @@ using namespace std;
|
|||||||
|
|
||||||
|
|
||||||
LpsClient::LpsClient(const char *host)
|
LpsClient::LpsClient(const char *host)
|
||||||
: connected(false), __host(host), __sock(NULL)
|
:
|
||||||
|
fConnected(false),
|
||||||
|
fHost(host),
|
||||||
|
fSock(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LpsClient::~LpsClient()
|
LpsClient::~LpsClient()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::connect() throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("connect\n"));
|
|
||||||
|
|
||||||
for (int localPort = LPS_CLIENT_PORT_S ; localPort <= LPS_CLIENT_PORT_E ; localPort++) {
|
void
|
||||||
if (__sock) {
|
LpsClient::connect() throw(LPSException)
|
||||||
delete __sock;
|
{
|
||||||
|
for (int localPort = LPS_CLIENT_PORT_S; localPort <= LPS_CLIENT_PORT_E;
|
||||||
|
localPort++) {
|
||||||
|
|
||||||
|
if (fSock) {
|
||||||
|
delete fSock;
|
||||||
}
|
}
|
||||||
__sock = new Socket(__host.c_str(), LPS_SERVER_PORT, localPort);
|
fSock = new Socket(fHost.c_str(), LPS_SERVER_PORT, localPort);
|
||||||
if (__sock->good()) {
|
if (fSock->good()) {
|
||||||
__is = &__sock->getInputStream();
|
fInput = &fSock->getInputStream();
|
||||||
__os = &__sock->getOutputStream();
|
fOutput = &fSock->getOutputStream();
|
||||||
connected = true;
|
fConnected = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw(LPSException(__sock->getLastError()));
|
throw(LPSException(fSock->getLastError()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::close()
|
|
||||||
{
|
|
||||||
// DBGMSG(("close\n"));
|
|
||||||
|
|
||||||
connected = false;
|
void
|
||||||
if (__sock) {
|
LpsClient::close()
|
||||||
delete __sock;
|
{
|
||||||
__sock = NULL;
|
fConnected = false;
|
||||||
|
if (fSock) {
|
||||||
|
delete fSock;
|
||||||
|
fSock = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::receiveJob(const char *printer) throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("tell_receive_job\n"));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
*__os << LPS_PRINT_JOB << printer << '\n' << flush;
|
LpsClient::receiveJob(const char *printer) throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
*fOutput << LPS_PRINT_JOB << printer << '\n' << flush;
|
||||||
checkAck();
|
checkAck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::receiveControlFile(int size, const char *name) throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("tell_receive_control_file\n"));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
|
LpsClient::receiveControlFile(int size, const char *name) throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
|
||||||
char cfname[32];
|
char cfname[32];
|
||||||
strncpy(cfname, name, sizeof(cfname));
|
strncpy(cfname, name, sizeof(cfname));
|
||||||
cfname[sizeof(cfname) - 1] = '\0';
|
cfname[sizeof(cfname) - 1] = '\0';
|
||||||
|
|
||||||
*__os << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
|
*fOutput << LPS_RECEIVE_CONTROL_FILE << size << ' ' << cfname << '\n' << flush;
|
||||||
|
|
||||||
checkAck();
|
checkAck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
|
void
|
||||||
|
LpsClient::receiveDataFile(int size, const char *name) throw(LPSException)
|
||||||
{
|
{
|
||||||
// DBGMSG(("tell_receive_data_file\n"));
|
if (fConnected) {
|
||||||
|
|
||||||
if (connected) {
|
|
||||||
|
|
||||||
char dfname[32];
|
char dfname[32];
|
||||||
strncpy(dfname, name, sizeof(dfname));
|
strncpy(dfname, name, sizeof(dfname));
|
||||||
dfname[sizeof(dfname) - 1] = '\0';
|
dfname[sizeof(dfname) - 1] = '\0';
|
||||||
|
|
||||||
*__os << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
|
*fOutput << LPS_RECEIVE_DATA_FILE << size << ' ' << dfname << '\n' << flush;
|
||||||
|
|
||||||
checkAck();
|
checkAck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::transferData(const char *buffer, int size) throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("send: %d\n", size));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
|
LpsClient::transferData(const char *buffer, int size) throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
size = strlen(buffer);
|
size = strlen(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!__os->write(buffer, size)) {
|
if (!fOutput->write(buffer, size)) {
|
||||||
close();
|
close();
|
||||||
throw(LPSException("error talking to lpd server"));
|
throw(LPSException("error talking to lpd server"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::transferData(istream &is, int size) throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("send: %d\n", size));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
|
LpsClient::transferData(istream &is, int size) throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
is.seekg(0, ios::end);
|
is.seekg(0, ios::end);
|
||||||
@@ -163,7 +157,7 @@ void LpsClient::transferData(istream &is, int size) throw(LPSException)
|
|||||||
|
|
||||||
char c;
|
char c;
|
||||||
while (is.get(c)) {
|
while (is.get(c)) {
|
||||||
if (!__os->put(c)) {
|
if (!fOutput->put(c)) {
|
||||||
close();
|
close();
|
||||||
throw(LPSException("error reading file."));
|
throw(LPSException("error reading file."));
|
||||||
return;
|
return;
|
||||||
@@ -172,41 +166,41 @@ void LpsClient::transferData(istream &is, int size) throw(LPSException)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::endTransfer() throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("tell_end_transfer\n"));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
*__os << LPS_END_TRANSFER << flush;
|
LpsClient::endTransfer() throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
*fOutput << LPS_END_TRANSFER << flush;
|
||||||
checkAck();
|
checkAck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LpsClient::checkAck() throw(LPSException)
|
|
||||||
{
|
|
||||||
// DBGMSG(("check_ack\n"));
|
|
||||||
|
|
||||||
if (connected) {
|
void
|
||||||
|
LpsClient::checkAck() throw(LPSException)
|
||||||
|
{
|
||||||
|
if (fConnected) {
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (!__is->get(c)) {
|
if (!fInput->get(c)) {
|
||||||
close();
|
close();
|
||||||
throw(LPSException("server not responding."));
|
throw(LPSException("server not responding."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case LPS_OK:
|
case LPS_OK:
|
||||||
break;
|
break;
|
||||||
case LPS_ERROR:
|
case LPS_ERROR:
|
||||||
close();
|
close();
|
||||||
throw(LPSException("server error."));
|
throw(LPSException("server error."));
|
||||||
break;
|
break;
|
||||||
case LPS_NO_SPOOL_SPACE:
|
case LPS_NO_SPOOL_SPACE:
|
||||||
close();
|
close();
|
||||||
throw(LPSException("not enough spool space on server."));
|
throw(LPSException("not enough spool space on server."));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,44 +7,54 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#if (!__MWERKS__)
|
|
||||||
using namespace std;
|
|
||||||
#else
|
|
||||||
#define std
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Socket;
|
class Socket;
|
||||||
|
|
||||||
|
|
||||||
class LPSException {
|
class LPSException {
|
||||||
private:
|
|
||||||
string str;
|
|
||||||
public:
|
public:
|
||||||
LPSException(const string &what_arg) : str(what_arg) {}
|
LPSException(const string& what)
|
||||||
const char *what() const { return str.c_str(); }
|
:
|
||||||
|
fWhat(what)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char * what() const
|
||||||
|
{
|
||||||
|
return fWhat.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string fWhat;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class LpsClient {
|
class LpsClient {
|
||||||
public:
|
public:
|
||||||
LpsClient(const char *host);
|
LpsClient(const char* host);
|
||||||
~LpsClient();
|
~LpsClient();
|
||||||
void connect() throw(LPSException);
|
void connect() throw(LPSException);
|
||||||
void close();
|
void close();
|
||||||
void receiveJob(const char *queue) throw(LPSException);
|
void receiveJob(const char* queue) throw(LPSException);
|
||||||
void receiveControlFile(int cfsize, const char *cfname) throw(LPSException);
|
void receiveControlFile(int cfsize, const char* cfname)
|
||||||
void receiveDataFile(int dfsize, const char *dfname) throw(LPSException);
|
throw(LPSException);
|
||||||
void transferData(const char *buffer, int size = -1) throw(LPSException);
|
void receiveDataFile(int dfsize, const char* dfname)
|
||||||
void transferData(istream &is, int size = -1) throw(LPSException);
|
throw(LPSException);
|
||||||
void endTransfer() throw(LPSException);
|
void transferData(const char* buffer, int size = -1)
|
||||||
void checkAck() throw(LPSException);
|
throw(LPSException);
|
||||||
|
void transferData(istream& is, int size = -1)
|
||||||
protected:
|
throw(LPSException);
|
||||||
bool connected;
|
void endTransfer() throw(LPSException);
|
||||||
|
void checkAck() throw(LPSException);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string __host;
|
bool fConnected;
|
||||||
Socket *__sock;
|
string fHost;
|
||||||
istream *__is;
|
Socket* fSock;
|
||||||
ostream *__os;
|
istream* fInput;
|
||||||
|
ostream* fOutput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif /* __LPSCLIENT_H */
|
#endif /* __LPSCLIENT_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user