1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
#include "printoutput.h"
PrintOutput::PrintOutput(ConfigFile *inif,char *section) : ConfigDB(Template), PrinterQueues()
{
cerr << "In PrintOutput constructor..." << endl;
new ConfigDBHandler(inif,section,this);
char *queue=FindString("Queue");
if(strlen(queue)==0 && GetPrinterCount()>0)
{
queue=GetPrinterName(0);
// char *cmd=GetPrintCommand(queue);
// SetString("Command",cmd);
// free(cmd);
if(queue)
{
SetString("Queue",queue);
char *driver=GetPrinterDriver(queue);
SetString("Driver",driver);
free(driver);
free(queue);
}
else
SetString("Driver",DEFAULT_PRINTER_DRIVER);
}
cerr << "Done..." << endl;
}
class Consumer_Queue : public Consumer
{
public:
Consumer_Queue(struct pqinfo *pq,const char *queuename) : pq(pq)
{
pq->SetPrinterQueue(pq,queuename);
pq->InitialiseJob(pq);
pq->InitialisePage(pq);
}
virtual ~Consumer_Queue()
{
pq->EndPage(pq);
pq->EndJob(pq);
}
virtual bool Write(const char *buffer, int length)
{
return(pq->WriteData(pq,buffer,length));
}
virtual void Cancel()
{
pq->CancelJob(pq);
}
protected:
struct pqinfo *pq;
};
Consumer *PrintOutput::GetConsumer()
{
char *str;
if(strlen(str=FindString("Queue")))
{
Consumer *result=new Consumer_Queue(queues,str);
return(result);
}
else if(strlen(str=FindString("File")))
{
str2=(char *)malloc(strlen(str)+12);
snprintf(str2,strlen(str)+12,str,FindInt("Serial"));
SetInt("Serial",FindInt("Serial")+1);
Consumer *result=new Consumer_File(str2);
free(str2);
str2=NULL;
return(result);
}
else if(strlen(str=FindString("Command")))
{
return(new Consumer_Pipe(str));
}
else
return(NULL);
}
ConfigTemplate PrintOutput::Template[]=
{
ConfigTemplate("Driver",""),
ConfigTemplate("File",""),
ConfigTemplate("Queue",""),
ConfigTemplate("Command",""),
ConfigTemplate("Serial",int(1)),
ConfigTemplate()
};
|