Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
28
cde/programs/dtprintinfo/objects/PrintObj/Imakefile
Normal file
28
cde/programs/dtprintinfo/objects/PrintObj/Imakefile
Normal file
@@ -0,0 +1,28 @@
|
||||
XCOMM $XConsortium: Imakefile /main/4 1996/04/21 19:52:17 drk $
|
||||
#define DoNormalLib YES
|
||||
#define DoSharedLib NO
|
||||
#define DoDebugLib NO
|
||||
#define DoProfileLib NO
|
||||
#define LibName PrintObj
|
||||
#define LibHeaders NO
|
||||
#define LibInstall NO
|
||||
|
||||
#define CplusplusSource YES
|
||||
DEPEND_DEFINES = $(CXXDEPENDINCLUDES)
|
||||
|
||||
INCLUDES = -I. -I.. -I../.. -I../../util
|
||||
|
||||
#ifdef RsArchitecture
|
||||
DEFINES = -DHAS_EXCEPTIONS
|
||||
#endif
|
||||
|
||||
#ifdef AlphaArchitecture
|
||||
DEFINES = -UNO_REGCOMP
|
||||
#endif
|
||||
|
||||
SRCS = ParseJobs.C PrintJob.C PrintSubSys.C Queue.C
|
||||
OBJS = ParseJobs.o PrintJob.o PrintSubSys.o Queue.o
|
||||
|
||||
#include <Library.tmpl>
|
||||
|
||||
DependTarget()
|
||||
1444
cde/programs/dtprintinfo/objects/PrintObj/ParseJobs.C
Normal file
1444
cde/programs/dtprintinfo/objects/PrintObj/ParseJobs.C
Normal file
File diff suppressed because it is too large
Load Diff
64
cde/programs/dtprintinfo/objects/PrintObj/ParseJobs.h
Normal file
64
cde/programs/dtprintinfo/objects/PrintObj/ParseJobs.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* $XConsortium: ParseJobs.h /main/3 1995/11/06 09:46:45 rswiston $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#ifndef PARSEJOBS_H
|
||||
#define PARSEJOBS_H
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNKNOWN_OUTPUT,
|
||||
AIX_V2_OUTPUT,
|
||||
AIX_V3_OUTPUT,
|
||||
BSD_OUTPUT
|
||||
} JobOutputType;
|
||||
|
||||
extern JobOutputType DetermineOutput(char *output);
|
||||
|
||||
// returns socket to print server, or -1 if error
|
||||
// timeout is in seconds, a default of 5 is used if timeout <= 0.
|
||||
extern int ConnectToPrintServer(const char *server, int timeout);
|
||||
|
||||
// return 0 if error, otherwise return 1 if successful
|
||||
extern int SendPrintJobStatusReguest(int sockfd, const char *printer);
|
||||
|
||||
extern void LocalPrintJobs(
|
||||
char *printer,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
extern int RemotePrintJobs(
|
||||
char *server,
|
||||
char *printer,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
extern int ParseRemotePrintJobs(
|
||||
char *printer,
|
||||
char *jobs,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
extern int ParseBSDPrintJobs(
|
||||
char *printer,
|
||||
char *jobs,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
extern int ParseAIXv3PrintJobs(
|
||||
char *printer,
|
||||
char *jobs,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
extern int ParseAIXv2PrintJobs(
|
||||
char *printer,
|
||||
char *jobs,
|
||||
char **return_job_list,
|
||||
int *return_n_jobs);
|
||||
|
||||
#endif // PARSEJOBS_H
|
||||
107
cde/programs/dtprintinfo/objects/PrintObj/PrintJob.C
Normal file
107
cde/programs/dtprintinfo/objects/PrintObj/PrintJob.C
Normal file
@@ -0,0 +1,107 @@
|
||||
/* $TOG: PrintJob.C /main/6 1998/07/24 16:17:39 mgreess $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#include "PrintJob.h"
|
||||
|
||||
// Object Class Name
|
||||
const char *PRINTJOB = "PrintJob";
|
||||
|
||||
// Actions
|
||||
const char *CANCEL_PRINT_JOB = "CancelPrintJob";
|
||||
|
||||
// Attributes
|
||||
const char *PRINTJOB_NAME = "PrintJobName";
|
||||
const char *OWNER = "Owner";
|
||||
const char *JOB_NUMBER = "JobNumber";
|
||||
const char *JOB_SIZE = "JobSize";
|
||||
const char *SUBMITTED = "Submitted";
|
||||
const char *DATE_SUBMITTED = "DateSubmitted";
|
||||
const char *TIME_SUBMITTED = "TimeSubmitted";
|
||||
|
||||
PrintJob::PrintJob(BaseObj *parent,
|
||||
char *JobName,
|
||||
char *JobNumber,
|
||||
char *Owner,
|
||||
char *Date,
|
||||
char *Time,
|
||||
char *Size)
|
||||
: BaseObj(parent, JobName)
|
||||
{
|
||||
AddAction(&PrintJob::CancelJob, CANCEL_PRINT_JOB, MESSAGE(CancelChoiceL),
|
||||
MESSAGE(CancelMnemonicL), NULL, NULL, true,
|
||||
MESSAGE(CancelAcceleratorL), "<Key>osfDelete");
|
||||
|
||||
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
|
||||
Characteristics Mask = OPTIONAL;
|
||||
ValueList ValueListType = NO_LIST;
|
||||
int n = 0;
|
||||
|
||||
AddAttribute(PRINTJOB_NAME, MESSAGE(JobNameL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(JobName);
|
||||
_attributes[n]->DisplayValue = STRDUP(JobName);
|
||||
n++;
|
||||
AddAttribute(OWNER, MESSAGE(OwnerL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(Owner);
|
||||
_attributes[n]->DisplayValue = STRDUP(Owner);
|
||||
n++;
|
||||
AddAttribute(JOB_NUMBER, MESSAGE(JobNumberL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(JobNumber);
|
||||
_attributes[n]->DisplayValue = STRDUP(JobNumber);
|
||||
_jobNumber = _attributes[n]->DisplayValue;
|
||||
n++;
|
||||
AddAttribute(JOB_SIZE, MESSAGE(SizeL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(Size);
|
||||
_attributes[n]->DisplayValue = STRDUP(Size);
|
||||
n++;
|
||||
ValueListType = INFORMATION_LINE;
|
||||
AddAttribute(SUBMITTED, MESSAGE(SubmittedL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(Time);
|
||||
_attributes[n]->DisplayValue = STRDUP(Time);
|
||||
n++;
|
||||
ValueListType = NO_LIST;
|
||||
char *message = new char [strlen(MESSAGE(TimeL)) + 4];
|
||||
sprintf(message, " %s", MESSAGE(TimeL));
|
||||
AddAttribute(TIME_SUBMITTED, message,
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(Time);
|
||||
_attributes[n]->DisplayValue = STRDUP(Time);
|
||||
delete [] message;
|
||||
n++;
|
||||
message = new char [strlen(MESSAGE(DateL)) + 4];
|
||||
sprintf(message, " %s", MESSAGE(DateL));
|
||||
AddAttribute(DATE_SUBMITTED, message,
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
_attributes[n]->Value = STRDUP(Date);
|
||||
_attributes[n]->DisplayValue = STRDUP(Date);
|
||||
delete [] message;
|
||||
}
|
||||
|
||||
PrintJob::~PrintJob()
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
int PrintJob::CancelJob(BaseObj *obj, char **output, BaseObj * /*requestor*/)
|
||||
{
|
||||
static char command[256];
|
||||
PrintJob *me = (PrintJob *) obj;
|
||||
|
||||
#ifdef aix
|
||||
sprintf(command, "enq -P%s -x%s", me->Parent()->Name(), me->_jobNumber);
|
||||
#elif __osf__
|
||||
sprintf(command, "lprm -P%s %s", me->Parent()->Name(), me->_jobNumber);
|
||||
#else
|
||||
sprintf(command, "cancel %s-%s", me->Parent()->Name(), me->_jobNumber);
|
||||
#endif
|
||||
return me->RunCommand(command, NULL, output);
|
||||
}
|
||||
54
cde/programs/dtprintinfo/objects/PrintObj/PrintJob.h
Normal file
54
cde/programs/dtprintinfo/objects/PrintObj/PrintJob.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* $XConsortium: PrintJob.h /main/3 1995/11/06 09:47:08 rswiston $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#ifndef PRINTJOB_H
|
||||
#define PRINTJOB_H
|
||||
|
||||
#include "BaseObj.h"
|
||||
#include "dtprintinfomsg.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// Object Class Name
|
||||
extern const char *PRINTJOB;
|
||||
|
||||
// Actions
|
||||
extern const char *CANCEL_PRINT_JOB;
|
||||
|
||||
// Attributes
|
||||
extern const char *PRINTJOB_NAME;
|
||||
extern const char *OWNER;
|
||||
extern const char *JOB_NUMBER;
|
||||
extern const char *JOB_SIZE;
|
||||
extern const char *SUBMITTED;
|
||||
extern const char *DATE_SUBMITTED;
|
||||
extern const char *TIME_SUBMITTED;
|
||||
|
||||
class PrintJob : public BaseObj {
|
||||
|
||||
friend int CancelJob(BaseObj *, char **output, BaseObj *requestor);
|
||||
|
||||
protected:
|
||||
|
||||
char *_jobNumber;
|
||||
static int CancelJob(BaseObj *, char **output, BaseObj *requestor);
|
||||
|
||||
public:
|
||||
|
||||
PrintJob(BaseObj *parent, char *JobName, char *JobNumber, char *Owner,
|
||||
char *Date, char *Time, char *Size);
|
||||
|
||||
virtual ~PrintJob();
|
||||
|
||||
const char *JobNumber() { return _jobNumber; }
|
||||
|
||||
virtual const char *const ObjectClassName() { return PRINTJOB; }
|
||||
|
||||
};
|
||||
|
||||
#endif // PRINTJOB_H
|
||||
86
cde/programs/dtprintinfo/objects/PrintObj/PrintSubSys.C
Normal file
86
cde/programs/dtprintinfo/objects/PrintObj/PrintSubSys.C
Normal file
@@ -0,0 +1,86 @@
|
||||
/* $XConsortium: PrintSubSys.C /main/4 1996/01/17 18:02:47 lehors $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#include "PrintSubSys.h"
|
||||
#include "Queue.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef aix
|
||||
const char *LIST_QUEUES = "lsallq | grep -v '^bsh$' | sort";
|
||||
#else
|
||||
#ifdef hpux
|
||||
const char *LIST_QUEUES = "LANG=C lpstat -v | "
|
||||
"awk '"
|
||||
" $2 == \"for\" "
|
||||
" { "
|
||||
" x = match($3, /:/); "
|
||||
" print substr($3, 1, x-1)"
|
||||
" }' | sort";
|
||||
#else
|
||||
#ifdef __osf__
|
||||
const char *LIST_QUEUES = "LANG=C lpstat -v | "
|
||||
"nawk '"
|
||||
" $2 == \"for\" "
|
||||
" { print $10 }' "
|
||||
" | sort";
|
||||
#else
|
||||
#ifdef __uxp__
|
||||
const char *LIST_QUEUES = "LANG=C lpstat -v | "
|
||||
"nawk '"
|
||||
" $4 == \"for\" "
|
||||
" { "
|
||||
" x = match($5, /:/); "
|
||||
" print substr($5, 1, x-1)"
|
||||
" }' | sort";
|
||||
#else
|
||||
const char *LIST_QUEUES = "LANG=C lpstat -v | "
|
||||
"nawk '"
|
||||
" $2 == \"for\" "
|
||||
" { "
|
||||
" x = match($3, /:/); "
|
||||
" print substr($3, 1, x-1)"
|
||||
" }' | sort";
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Object Class Name
|
||||
const char *PRINTSUBSYSTEM = "PrintSubSystem";
|
||||
|
||||
PrintSubSystem::PrintSubSystem(BaseObj *parent)
|
||||
: BaseObj(parent, "PrintSubSystem")
|
||||
{
|
||||
_displayName = strdup(MESSAGE(PrinterMenuL));
|
||||
_details = strdup("Status Number Owner Date Time Size");
|
||||
}
|
||||
|
||||
PrintSubSystem::~PrintSubSystem()
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
|
||||
void PrintSubSystem::InitChildren()
|
||||
{
|
||||
char *std_out;
|
||||
if (RunCommand(LIST_QUEUES, &std_out))
|
||||
{
|
||||
Error("InitChildren method could not list queues.");
|
||||
}
|
||||
else
|
||||
{
|
||||
char *queue = strtok(std_out, " \n");
|
||||
while (queue && *queue)
|
||||
{
|
||||
new Queue(this, queue);
|
||||
queue = strtok(NULL, " \n");
|
||||
}
|
||||
}
|
||||
delete std_out;
|
||||
}
|
||||
36
cde/programs/dtprintinfo/objects/PrintObj/PrintSubSys.h
Normal file
36
cde/programs/dtprintinfo/objects/PrintObj/PrintSubSys.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* $XConsortium: PrintSubSys.h /main/3 1995/11/06 09:47:33 rswiston $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#ifndef PRINTSUBSYS_H
|
||||
#define PRINTSUBSYS_H
|
||||
|
||||
#include "BaseObj.h"
|
||||
#include "dtprintinfomsg.h"
|
||||
|
||||
// Object Class Name
|
||||
extern const char *PRINTSUBSYSTEM;
|
||||
|
||||
// List Children command;
|
||||
extern const char *LIST_QUEUES;
|
||||
|
||||
class PrintSubSystem : public BaseObj {
|
||||
|
||||
protected:
|
||||
|
||||
void InitChildren();
|
||||
|
||||
public:
|
||||
|
||||
PrintSubSystem(BaseObj *parent);
|
||||
virtual ~PrintSubSystem();
|
||||
|
||||
virtual const char *const ObjectClassName() { return PRINTSUBSYSTEM; }
|
||||
|
||||
};
|
||||
|
||||
#endif // PRINTSUBSYS_H
|
||||
440
cde/programs/dtprintinfo/objects/PrintObj/Queue.C
Normal file
440
cde/programs/dtprintinfo/objects/PrintObj/Queue.C
Normal file
@@ -0,0 +1,440 @@
|
||||
/* $TOG: Queue.C /main/4 1998/07/24 16:17:58 mgreess $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#include "Queue.h"
|
||||
#include "PrintJob.h"
|
||||
#include "ParseJobs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
extern "C" {
|
||||
#include <Dt/DtNlUtils.h>
|
||||
}
|
||||
|
||||
#ifdef aix
|
||||
const char *GET_ATTRS = "lsque -cq%s |awk -F: 'NR == 2 {print $2,$6,$9}' OFS=:";
|
||||
const char *GET_QUEUE_STATUS = "LANG=C enq -As -P%s | "
|
||||
"egrep 'READY|RUNNING' > /dev/null";
|
||||
const char *GET_DEVICE_STATUS = "LANG=C enq -As -P%s | "
|
||||
"egrep 'READY|RUNNING' > /dev/null";
|
||||
const char *START_QUEUE_CMD = "enq -U -P%s";
|
||||
const char *STOP_QUEUE_CMD = "enq -D -P%s";
|
||||
#else
|
||||
#ifdef hpux
|
||||
const char *GET_ATTRS = "LANG=C lpstat -v%s 2>&1 | awk '"
|
||||
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
|
||||
"/device for/ { device = $4 } "
|
||||
"/remote to/ { rhost = $5; rp = $3 } "
|
||||
"END { print device,rhost,rp }' OFS=:";
|
||||
const char *GET_QUEUE_STATUS = "LANG=C lpstat -i -a%s | awk '"
|
||||
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
|
||||
const char *GET_DEVICE_STATUS = "LANG=C lpstat -i -p%s | "
|
||||
"awk '/disabled/ {exit 1}'";
|
||||
const char *START_QUEUE_CMD = "/usr/lib/accept %s";
|
||||
const char *STOP_QUEUE_CMD = "/usr/lib/reject %s";
|
||||
const char *START_PRINTING_CMD = "enable %s";
|
||||
const char *STOP_PRINTING_CMD = "disable %s";
|
||||
#else
|
||||
const char *GET_ATTRS = "LANG=C lpstat -v %s 2>&1 | nawk '"
|
||||
"BEGIN { device=\"\"; rhost=\"\"; rp=\"\" } "
|
||||
"/device for/ { device = $4 } "
|
||||
"/system for/ { rhost = $4; x = match($7, /\\)/); "
|
||||
" if (x == 0) "
|
||||
" rp = substr($3, 1, match($3, /:/) - 1); "
|
||||
" else "
|
||||
" rp = substr($7, 1, x - 1) } "
|
||||
"END { print device,rhost,rp }' OFS=:";
|
||||
const char *GET_QUEUE_STATUS = "LANG=C lpstat -a%s | awk '"
|
||||
"{if ($2 == \"not\") {exit 1} else {exit 0}}'";
|
||||
const char *GET_DEVICE_STATUS = "LANG=C lpstat -p%s | "
|
||||
"awk '/disabled/ {exit 1}'";
|
||||
const char *START_QUEUE_CMD = "/usr/sbin/accept %s";
|
||||
const char *STOP_QUEUE_CMD = "/usr/sbin/reject %s";
|
||||
const char *START_PRINTING_CMD = "enable %s";
|
||||
const char *STOP_PRINTING_CMD = "disable %s";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Object Class Name
|
||||
const char *QUEUE = "Queue";
|
||||
|
||||
// Actions
|
||||
const char *START_QUEUE = "StartQueue";
|
||||
const char *STOP_QUEUE = "StopQueue";
|
||||
#ifndef aix
|
||||
const char *START_PRINTING = "StartPrinting";
|
||||
const char *STOP_PRINTING = "StopPrinting";
|
||||
#endif
|
||||
|
||||
// Attributes
|
||||
const char *ICON_NAME = "IconName";
|
||||
const char *PRINTER_QUEUE = "PrinterQueue";
|
||||
const char *QUEUE_DEVICE = "QueueDevice";
|
||||
|
||||
Queue::Queue(BaseObj *parent,
|
||||
char *_name)
|
||||
: BaseObj(parent, _name)
|
||||
{
|
||||
if (getenv("DO_ADMIN"))
|
||||
{
|
||||
AddAction(&Queue::Start, START_QUEUE, MESSAGE(StartChoiceL),
|
||||
MESSAGE(StartMnemonicL));
|
||||
AddAction(&Queue::Stop, STOP_QUEUE, MESSAGE(StopChoiceL),
|
||||
MESSAGE(StopMnemonicL));
|
||||
#ifndef aix
|
||||
AddAction(&Queue::StartPrint, START_PRINTING, MESSAGE(EnableChoiceL),
|
||||
MESSAGE(EnableMnemonicL));
|
||||
AddAction(&Queue::StopPrint, STOP_PRINTING, MESSAGE(DisableChoiceL),
|
||||
MESSAGE(DisableMnemonicL));
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef aix
|
||||
local_devices = NULL;
|
||||
n_devices = 0;
|
||||
#endif
|
||||
remote_server = NULL;
|
||||
remote_printer = NULL;
|
||||
is_remote = false;
|
||||
_loaded_attributes = false;
|
||||
|
||||
char *Help = NULL, *ContextualHelp = NULL, *Listing = NULL;
|
||||
Characteristics Mask = EDITABLE_AFTER_CREATE;
|
||||
ValueList ValueListType = NO_LIST;
|
||||
|
||||
// AddAttribute(ICON_NAME, MESSAGE(IconNameL),
|
||||
// Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
|
||||
Mask = OPTIONAL;
|
||||
AddAttribute(PRINTER_QUEUE, MESSAGE(PrintQueueL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
AddAttribute(QUEUE_DEVICE, MESSAGE(DeviceL),
|
||||
Help, ContextualHelp, Mask, ValueListType, Listing);
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
{
|
||||
#ifdef aix
|
||||
int i;
|
||||
for (i = 0; i < n_devices; i++)
|
||||
delete local_devices[i];
|
||||
delete local_devices;
|
||||
#endif
|
||||
delete remote_server;
|
||||
delete remote_printer;
|
||||
}
|
||||
|
||||
void Queue::LoadAttributes(int /*n_attrs*/, Attribute **attrs)
|
||||
{
|
||||
char *command = new char[500];
|
||||
sprintf(command, GET_ATTRS, Name());
|
||||
char *output;
|
||||
RunCommand(command, &output);
|
||||
delete [] command;
|
||||
|
||||
char *s = output, *s1;
|
||||
char *dollar[3];
|
||||
int i;
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
if (s1 = strchr(s, ':'))
|
||||
*s1++ = '\0';
|
||||
else if (s1 = strchr(s, '\n'))
|
||||
*s1++ = '\0';
|
||||
dollar[i] = s;
|
||||
s = s1;
|
||||
}
|
||||
i = 0;
|
||||
attrs[i]->Value = strdup(Name());
|
||||
attrs[i]->DisplayValue = strdup(Name());
|
||||
i++;
|
||||
if (_loaded_attributes == false)
|
||||
{
|
||||
if (*dollar[2]) // It's a remote printer
|
||||
{
|
||||
#ifdef aix
|
||||
n_devices = 1;
|
||||
local_devices = new char *[1];
|
||||
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
|
||||
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
|
||||
#endif
|
||||
is_remote = true;
|
||||
char *new_value = new char [strlen(MESSAGE(PrinterOnServerL)) +
|
||||
strlen(dollar[1]) + strlen(dollar[2])];
|
||||
remote_server = strdup(dollar[1]);
|
||||
remote_printer = strdup(dollar[2]);
|
||||
sprintf(new_value, MESSAGE(PrinterOnServerL), remote_printer,
|
||||
remote_server);
|
||||
attrs[i]->Value = strdup(new_value);
|
||||
attrs[i]->DisplayValue = strdup(new_value);
|
||||
delete [] new_value;
|
||||
}
|
||||
else // It's a local printer
|
||||
{
|
||||
#ifdef aix
|
||||
if (strchr(dollar[0], ',')) // AIX can have multiple devices per queue
|
||||
{
|
||||
DeleteAttribute(QUEUE_DEVICE);
|
||||
char *device = new char [strlen(MESSAGE(DeviceNL)) + 4];
|
||||
s = dollar[0];
|
||||
while (s && *s)
|
||||
{
|
||||
if (s1 = strchr(s, ','))
|
||||
s1++;
|
||||
s = s1;
|
||||
n_devices++;
|
||||
}
|
||||
local_devices = new char *[n_devices];
|
||||
n_devices = 0;
|
||||
s = dollar[0];
|
||||
while (s && *s)
|
||||
{
|
||||
sprintf(device, MESSAGE(DeviceNL), n_devices + 1);
|
||||
AddAttribute(QUEUE_DEVICE, device,
|
||||
NULL, NULL, OPTIONAL, NO_LIST, NULL);
|
||||
if (s1 = strchr(s, ','))
|
||||
*s1++ = '\0';
|
||||
_attributes[i]->Value = strdup(s);
|
||||
_attributes[i]->DisplayValue = strdup(s);
|
||||
local_devices[n_devices] = new char[strlen(Name()) + strlen(s)+2];
|
||||
sprintf(local_devices[n_devices], "%s:%s", Name(), s);
|
||||
i++;
|
||||
s = s1;
|
||||
n_devices++;
|
||||
}
|
||||
delete [] device;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#ifdef aix
|
||||
n_devices = 1;
|
||||
local_devices = new char *[1];
|
||||
local_devices[0] = new char[strlen(Name()) + strlen(dollar[0]) + 2];
|
||||
sprintf(local_devices[0], "%s:%s", Name(), dollar[0]);
|
||||
|
||||
#endif
|
||||
attrs[i]->Value = strdup(dollar[0]);
|
||||
attrs[i]->DisplayValue = strdup(dollar[0]);
|
||||
}
|
||||
}
|
||||
_loaded_attributes = true;
|
||||
}
|
||||
delete output;
|
||||
}
|
||||
|
||||
#ifdef aix
|
||||
char *Queue::Device(int index)
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
if (index >= 0 && index <= n_devices)
|
||||
return local_devices[index];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Queue::NumberDevices()
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
return n_devices;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int Queue::Start(BaseObj *obj, char **output, BaseObj * /*requestor*/)
|
||||
{
|
||||
Queue *queue = (Queue *)obj;
|
||||
int rc;
|
||||
char *command = new char[100];
|
||||
|
||||
#ifdef aix
|
||||
if (queue->n_devices > 1)
|
||||
{
|
||||
sprintf(command, START_QUEUE_CMD, "$d");
|
||||
int i, len;
|
||||
len = 30 + strlen(command) + queue->n_devices;
|
||||
for (i = 0; i < queue->n_devices; i++)
|
||||
len += strlen(queue->local_devices[i]);
|
||||
char *cmd = new char[len];
|
||||
strcpy(cmd, "for d in");
|
||||
for (i = 0; i < queue->n_devices; i++)
|
||||
{
|
||||
strcat(cmd, " ");
|
||||
strcat(cmd, queue->local_devices[i]);
|
||||
}
|
||||
strcat(cmd, " ; do ");
|
||||
strcat(cmd, command);
|
||||
strcat(cmd, "; done");
|
||||
rc = queue->RunCommand(cmd, NULL, output);
|
||||
delete [] cmd;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sprintf(command, START_QUEUE_CMD, queue->Name());
|
||||
rc = queue->RunCommand(command, NULL, output);
|
||||
}
|
||||
delete [] command;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int Queue::Stop(BaseObj *obj, char **output, BaseObj * /*requestor*/)
|
||||
{
|
||||
Queue *queue = (Queue *)obj;
|
||||
char *command = new char[100];
|
||||
int rc;
|
||||
|
||||
#ifdef aix
|
||||
if (queue->n_devices > 1)
|
||||
{
|
||||
sprintf(command, STOP_QUEUE_CMD, "$d");
|
||||
int i, len;
|
||||
len = 30 + strlen(command) + queue->n_devices;
|
||||
for (i = 0; i < queue->n_devices; i++)
|
||||
len += strlen(queue->local_devices[i]);
|
||||
char *cmd = new char[len];
|
||||
strcpy(cmd, "for d in");
|
||||
for (i = 0; i < queue->n_devices; i++)
|
||||
{
|
||||
strcat(cmd, " ");
|
||||
strcat(cmd, queue->local_devices[i]);
|
||||
}
|
||||
strcat(cmd, " ; do ");
|
||||
strcat(cmd, command);
|
||||
strcat(cmd, "; done");
|
||||
rc = queue->RunCommand(cmd, NULL, output);
|
||||
delete [] cmd;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
sprintf(command, STOP_QUEUE_CMD, queue->Name());
|
||||
rc = queue->RunCommand(command, NULL, output);
|
||||
}
|
||||
delete [] command;
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifndef aix
|
||||
int Queue::StartPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
|
||||
{
|
||||
Queue *queue = (Queue *)obj;
|
||||
char *command = new char[100];
|
||||
int rc;
|
||||
|
||||
sprintf(command, STOP_PRINTING_CMD, queue->Name());
|
||||
rc = queue->RunCommand(command, NULL, output);
|
||||
delete [] command;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int Queue::StopPrint(BaseObj *obj, char **output, BaseObj * /*requestor*/)
|
||||
{
|
||||
Queue *queue = (Queue *)obj;
|
||||
char *command = new char[100];
|
||||
int rc;
|
||||
|
||||
sprintf(command, STOP_PRINTING_CMD, queue->Name());
|
||||
rc = queue->RunCommand(command, NULL, output);
|
||||
delete [] command;
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Queue::InitChildren()
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
ProcessJobs();
|
||||
}
|
||||
|
||||
void Queue::ProcessJobs(char *jobs)
|
||||
{
|
||||
char *job_list;
|
||||
int n_jobs;
|
||||
|
||||
// Get remote jobs first
|
||||
if (is_remote)
|
||||
{
|
||||
int rc;
|
||||
if (jobs)
|
||||
rc = ParseRemotePrintJobs(remote_printer, jobs, &job_list, &n_jobs);
|
||||
else
|
||||
rc = RemotePrintJobs(remote_server, remote_printer, &job_list,
|
||||
&n_jobs);
|
||||
remote_up = rc ? true : false;
|
||||
|
||||
ParseOutput(job_list, n_jobs);
|
||||
#ifdef sun
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Get local jobs next
|
||||
#ifdef aix
|
||||
if (is_remote)
|
||||
LocalPrintJobs(local_devices[0], &job_list, &n_jobs);
|
||||
else
|
||||
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
|
||||
#else
|
||||
LocalPrintJobs((char*)Name(), &job_list, &n_jobs);
|
||||
#endif
|
||||
ParseOutput(job_list, n_jobs);
|
||||
}
|
||||
|
||||
void Queue::ParseOutput(char *job_list, int n_jobs)
|
||||
{
|
||||
int i;
|
||||
char *printer = DtStrtok(job_list, "|");
|
||||
for (i = 0; i < n_jobs; i++)
|
||||
{
|
||||
char *JobName = DtStrtok(NULL, "|");
|
||||
char *JobNumber = DtStrtok(NULL, "|");
|
||||
char *Owner = DtStrtok(NULL, "|");
|
||||
char *Date = DtStrtok(NULL, "|");
|
||||
char *Time = DtStrtok(NULL, "|");
|
||||
char *tmp = DtStrtok(NULL, "\n");
|
||||
char *Size = new char [strlen(tmp) + strlen(MESSAGE(BytesL)) + 2];
|
||||
sprintf(Size, "%s %s", tmp, MESSAGE(BytesL));
|
||||
|
||||
new PrintJob(this, JobName, JobNumber, Owner, Date, Time, Size);
|
||||
delete [] Size;
|
||||
printer = DtStrtok(NULL, "|");
|
||||
}
|
||||
}
|
||||
|
||||
void Queue::ParseRemoteStatus(char *output)
|
||||
{
|
||||
SetInitChildren();
|
||||
DeleteChildren();
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
ProcessJobs(output);
|
||||
}
|
||||
|
||||
boolean Queue::IsRemote()
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
return is_remote;
|
||||
}
|
||||
|
||||
const char *Queue::RemotePrinter()
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
return remote_printer;
|
||||
}
|
||||
|
||||
const char *Queue::Server()
|
||||
{
|
||||
if (_loaded_attributes == false)
|
||||
ReadAttributes();
|
||||
return remote_server;
|
||||
}
|
||||
89
cde/programs/dtprintinfo/objects/PrintObj/Queue.h
Normal file
89
cde/programs/dtprintinfo/objects/PrintObj/Queue.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* $XConsortium: Queue.h /main/3 1995/11/06 09:47:44 rswiston $ */
|
||||
/* *
|
||||
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
|
||||
* (c) Copyright 1993, 1994 International Business Machines Corp. *
|
||||
* (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
|
||||
* (c) Copyright 1993, 1994 Novell, Inc. *
|
||||
*/
|
||||
|
||||
#ifndef QUEUE_H
|
||||
#define QUEUE_H
|
||||
|
||||
#include "BaseObj.h"
|
||||
#include "dtprintinfomsg.h"
|
||||
|
||||
// Object Class Name
|
||||
extern const char *QUEUE;
|
||||
|
||||
// Actions
|
||||
extern const char *START_QUEUE;
|
||||
extern const char *STOP_QUEUE;
|
||||
#ifndef aix
|
||||
extern const char *START_PRINTING;
|
||||
extern const char *STOP_PRINTING;
|
||||
#endif
|
||||
|
||||
// Attributes
|
||||
extern const char *ICON_NAME;
|
||||
extern const char *PRINTER_QUEUE;
|
||||
extern const char *QUEUE_DEVICE;
|
||||
|
||||
// Status Commands
|
||||
extern const char *GET_QUEUE_STATUS;
|
||||
extern const char *GET_DEVICE_STATUS;
|
||||
|
||||
class Queue : public BaseObj {
|
||||
|
||||
friend int Start(BaseObj *, char **output, BaseObj *requestor);
|
||||
friend int Stop(BaseObj *, char **output, BaseObj *requestor);
|
||||
#ifndef aix
|
||||
friend int StartPrint(BaseObj *, char **output, BaseObj *requestor);
|
||||
friend int StopPrint(BaseObj *, char **output, BaseObj *requestor);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
static int Start(BaseObj *, char **output, BaseObj *requestor);
|
||||
static int Stop(BaseObj *, char **output, BaseObj *requestor);
|
||||
#ifndef aix
|
||||
static int StartPrint(BaseObj *, char **output, BaseObj *requestor);
|
||||
static int StopPrint(BaseObj *, char **output, BaseObj *requestor);
|
||||
#endif
|
||||
|
||||
boolean _loaded_attributes;
|
||||
|
||||
void InitChildren();
|
||||
void LoadAttributes(int numAttributes, Attribute **attributes);
|
||||
void ParseOutput(char *, int);
|
||||
|
||||
void ProcessJobs(char *jobs = NULL);
|
||||
|
||||
boolean is_remote;
|
||||
boolean remote_up;
|
||||
#ifdef aix
|
||||
char **local_devices;
|
||||
int n_devices;
|
||||
#endif
|
||||
char *remote_server;
|
||||
char *remote_printer;
|
||||
|
||||
public:
|
||||
|
||||
Queue(BaseObj *parent, char *name);
|
||||
virtual ~Queue();
|
||||
|
||||
const char *Server();
|
||||
const char *RemotePrinter();
|
||||
#ifdef aix
|
||||
char *Device(int index = 0);
|
||||
int NumberDevices();
|
||||
#endif
|
||||
boolean IsRemote();
|
||||
boolean RemoteUp() { return remote_up; }
|
||||
void ParseRemoteStatus(char *output);
|
||||
|
||||
virtual const char *const ObjectClassName() { return QUEUE; }
|
||||
|
||||
};
|
||||
|
||||
#endif // QUEUE_H
|
||||
Reference in New Issue
Block a user