Commit 692ed37e by jackalone

添加日志的输出。

parent 83cc2f68
#include "fmp_printer_p.h"
#include "fmp_logger_i.h"
FMPPrinter::FMPPrinter(ctkPluginContext *context)
: FMPPrinterInterface(context),
_inited(false),
d_ptr(new FMPPrinterPrivate(this))
{
}
void FMPPrinter::UninitService()
{
if (_inited) {
d_func()->Uninit();
}
}
void FMPPrinter::InitService()
{
d_func()->Init();
}
bool FMPPrinter::DoPrint(QString data)
{
Q_D(FMPPrinter);
return d->_DoPrint(data);
}
QString FMPPrinter::GetPrintName()
{
Q_D(FMPPrinter);
return d->_GetPrintName();
}
#ifndef FMPPRINTER_H
#define FMPPRINTER_H
#include <QObject>
#include "fmp_printer_i.h"
class FMPPrinterPrivate;
class FMPPrinter : public QObject ,public FMPPrinterInterface
{
Q_OBJECT
Q_INTERFACES(FMPBaseInterface)
Q_INTERFACES(FMPPrinterInterface)
Q_DECLARE_PRIVATE(FMPPrinter)
public:
FMPPrinter(ctkPluginContext *context);
void InitService();
void UninitService();
bool DoPrint(QString data);
QString GetPrintName();
private:
bool _inited;
FMPPrinterPrivate *d_ptr;
signals:
public slots:
};
#endif // FMPPRINTER_H
TEMPLATE = lib
QT += core gui network sql multimedia printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
DESTDIR = ./bin
MOC_DIR = ./tmp
OBJECTS_DIR = ./tmp
UI_HEADERS_DIR = ./tmp
RCC_DIR = ./tmp
SOURCES +=fmp_printer.cpp \
fmp_printer_p.cpp \
fmp_printer_plugin.cpp \
fmp_te_handlers.cpp
HEADERS +=fmp_printer_i.h \
fmp_printer.h \
fmp_printer_p.h \
fmp_printer_plugin_p.h \
fmp_te_handlers.h
unix {
target.path = /usr/lib
INSTALLS += target
}
#Target name
VER = $$system($$PWD/../fmprc.bat $$TARGET)
ORIGIN_TARGET = $$TARGET
TARGET = $${TARGET}_$${VER}
#Header path
INCLUDEPATH += $$PWD/../include/ctk \
+= $$PWD/../include/interface \
#Library path
LIBS += -L$$PWD/../lib
CONFIG(debug, debug|release) {
#Linking library
LIBS += -lCTKCored -lCTKPluginFrameworkd
#Destination path
DESTDIR = $$PWD/../debug/plugins
} else {
LIBS += -lCTKCore -lCTKPluginFramework
DESTDIR = $$PWD/../release/plugins
}
#
RESOURCES += \
res/$${ORIGIN_TARGET}.qrc
win32 {
RC_FILE += res/$${ORIGIN_TARGET}.rc
system($$PWD/../fmprc.bat $$PWD/version.h $$ORIGIN_TARGET)
LIBS += -lWinspool
}
else {
system($$PWD/../fmprc.sh $$PWD/version.h $$ORIGIN_TARGET)
}
DISTFILES +=
#ifndef FMPPRINTERINTERFACE_H
#define FMPPRINTERINTERFACE_H
#include <fmp_plugin_i.h>
/**
* 业务插件接口,必须继承自 FMPluginInterface
* @brief The FMPPrinterInterface class
*/
class FMPPrinterInterface : public FMPBaseInterface
{
public:
explicit FMPPrinterInterface(ctkPluginContext *ctx) : FMPBaseInterface(), _ctx(ctx) {}
virtual bool DoPrint(QString data)=0;
virtual QString GetPrintName()=0;
int PostEvent(const QString &topic, const FMPProps &pps) { return FMP_NOIMPL; }
public:
ctkPluginContext *_ctx;
};
Q_DECLARE_INTERFACE(FMPPrinterInterface, "com.fmp.printer")
#endif // FMPPRINTERINTERFACE_H
#include "fmp_printer_p.h"
#include <fmp_settings_i.h>
#include <QDateTime>
#include <ctkPluginContext.h>
#include <ctkServiceReference.h>
#include <QDir>
#include "fmp_te_handlers.h"
#include <QDebug>
#include "fmp_home_i.h"
#include "fmp_logger_i.h"
#include <windows.h>
#include <winspool.h>
FMPPrinterPrivate::FMPPrinterPrivate(FMPPrinter *q)
: q_ptr(q),printname("")
{
FMPLoggerInterface::InitContext(q->_ctx);
}
int FMPPrinterPrivate::Init()
{
Q_Q(FMPPrinter);
q->_inited = true;
return FMP_SUCCESS;
}
FMPPrinterPrivate::~FMPPrinterPrivate()
{
Uninit();
}
int FMPPrinterPrivate::Uninit()
{
Q_Q(FMPPrinter);
if(_settings !=nullptr)
delete _settings;
_settings = 0;
q->_inited = false;
return FMP_SUCCESS;
}
bool FMPPrinterPrivate::_DoPrint(QString data)
{
FMP_INFO() << "receive data is"<<data;
if(GetInfo(printname,data))
{
FMP_INFO() << "print is ok";
return 1;
}
else
{
FMP_INFO() << "print is false";
return 0;
}
}
QString FMPPrinterPrivate::_GetPrintName()
{
Q_Q(FMPPrinter);
_settings = q->GetService<FMPSettingsInterface>(q->_ctx);
printname = _settings->GetString(FMP_INIKEY_PRINTER);
return printname;
}
bool FMPPrinterPrivate::GetInfo(QString &printername,QString data)
{
FMP_INFO() << "printname is ok"<<printername;
LPTSTR szPrinterName = (LPTSTR)printername.toStdWString().c_str();
LPBYTE lpData=(LPBYTE)data.toLocal8Bit().data();
DWORD dwCount = strlen((char*)lpData);
BOOL bStatus = FALSE;
HANDLE hPrinter = NULL;
DOC_INFO_1 DocInfo;
DWORD dwJob = 0L;
DWORD dwBytesWritten = 0L;
// Open a handle to the printer.
bStatus = OpenPrinter( szPrinterName, &hPrinter, NULL );
if (bStatus) {
// Fill in the structure with info about this "document."
DocInfo.pDocName = (LPTSTR)QString("takeoutDoc").toStdWString().c_str();
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = (LPTSTR)QString("RAW").toStdWString().c_str();
// Inform the spooler the document is beginning.
dwJob = StartDocPrinter( hPrinter, 1, (LPBYTE)&DocInfo );
if (dwJob > 0) {
// Start a page.
bStatus = StartPagePrinter( hPrinter );
if (bStatus) {
// Send the data to the printer.
bStatus = WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten);
EndPagePrinter (hPrinter);
}
// Inform the spooler that the document is ending.
EndDocPrinter( hPrinter );
}
// Close the printer handle.
ClosePrinter( hPrinter );
}
// Check to see if correct number of bytes were written.
if (!bStatus || (dwBytesWritten != dwCount)) {
bStatus = FALSE;
FMP_INFO() << "printname is open is false";
} else {
FMP_INFO() << "printname is open is ok";
bStatus = TRUE;
}
return bStatus;
}
#ifndef FMP_PRINTER_P_H
#define FMP_PRINTER_P_H
#include "fmp_printer.h"
class FMPSettingsInterface;
class FMPHomeInterface;
class FMPPrinterPrivate:public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(FMPPrinter)
public:
explicit FMPPrinterPrivate(FMPPrinter *q);
~FMPPrinterPrivate();
int Init();
int Uninit();
private:
bool _DoPrint(QString data);
QString _GetPrintName();
bool GetInfo(QString &printername,QString data);
public:
FMPPrinter *q_ptr;
QString printname;
private:
FMPSettingsInterface *_settings;
};
#endif // FMP_PRINTER_P_H
/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
#include "fmp_printer_plugin_p.h"
#include "fmp_printer.h"
#include <QtPlugin>
#include <QStringList>
#include <QDebug>
FMPPrinterPlugin::FMPPrinterPlugin()
: _printer_service(0)
{
}
void FMPPrinterPlugin::start(ctkPluginContext* context)
{
_printer_service = new FMPPrinter(context);
context->registerService<FMPPrinterInterface>( _printer_service);
}
void FMPPrinterPlugin::stop(ctkPluginContext* context)
{
Q_UNUSED(context)
if (_printer_service)
{
delete _printer_service;
_printer_service = 0;
}
}
#if (QT_VERSION < QT_VERSION_CHECK(5,0,0))
Q_EXPORT_PLUGIN2(fmp_printer, FMPPrinterPlugin)
#endif
#ifndef FMP_PRINTER_PLUGIN_P_H
#define FMP_PRINTER_PLUGIN_P_H
#include <ctkPluginActivator.h>
class FMPPrinter;
class FMPPrinterPlugin : public QObject, public ctkPluginActivator
{
Q_OBJECT
Q_INTERFACES(ctkPluginActivator)
#if (QT_VERSION > QT_VERSION_CHECK(5,0,0))
Q_PLUGIN_METADATA(IID "com_fmp_printer")
#endif
public:
explicit FMPPrinterPlugin();
void start(ctkPluginContext* context);
void stop(ctkPluginContext* context);
private:
FMPPrinter* _printer_service;
}; // FMPPrinterPlugin
#endif // FMP_PRINTER_PLUGIN_P_H
#include "fmp_te_handlers.h"
#include "fmp_printer.h"
FMPStartEventHandler::FMPStartEventHandler(ctkPluginContext *ctx, FMPPrinter *_printer)
: FMPPrinterEventHandler(FMP_TOPICS_SERVICES FMPE_SERVICE_REQ_START "/"+ QString::number(ctx->getPlugin()->getPluginId()),
_printer),
_ctx(ctx)
{
FMPProps props;
props[ctkEventConstants::EVENT_TOPIC] = _topic;
_ctx->registerService<ctkEventHandler>(this, props);
}
void FMPStartEventHandler::handleEvent(const ctkEvent &event)
{
if (_printer) {
if (event.getProperty(FMP_PROPKEY_AGREED).toBool()) {
// _epay->UpgradeOldPlugins(event.getProperty(FMP_PROPKEY_PID_LIST).toList());
// _Takeout->ShowForm();
}
else {
// FMP_WARN_CTX(_ctx) << "Refused start request" << event.getTopic();
}
}
else {
// FMP_DEBUG_CTX(_ctx) << "No handler instance for event" << event.getTopic();
}
}
#ifndef FMPPRINTEREVENTHANDLER_H
#define FMPPRINTEREVENTHANDLER_H
#include <QObject>
#include <service/event/ctkEventConstants.h>
#include <service/event/ctkEventHandler.h>
class FMPPrinter;
class FMPPrinterEventHandler : public ctkEventHandler
{
public:
explicit FMPPrinterEventHandler(const QString &topic, FMPPrinter *printer) : _printer(printer), _topic(topic) {}
protected:
FMPPrinter* _printer;
const QString _topic;
};
class FMPStartEventHandler : public QObject, public FMPPrinterEventHandler
{
Q_OBJECT
Q_INTERFACES(ctkEventHandler)
public:
explicit FMPStartEventHandler(ctkPluginContext *ctx, FMPPrinter *Takeout);
void handleEvent(const ctkEvent &event);
private:
ctkPluginContext* _ctx;
};
#endif // FMPPRINTEREVENTHANDLER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment