[gimp/bug-357818: 4/10] Bug 357818 - TWAIN plug-in - Changed logging from file to g_message.
- From: Michael Schumacher <schumaml src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/bug-357818: 4/10] Bug 357818 - TWAIN plug-in - Changed logging from file to g_message.
- Date: Wed, 8 Jun 2016 21:59:49 +0000 (UTC)
commit 78475609a60e8726c32548a1cbbe66a13dc3d62b
Author: Jens M. Plonka <jens plonka gmx de>
Date: Fri Jun 3 01:31:11 2016 +0200
Bug 357818 - TWAIN plug-in - Changed logging from file to g_message.
Adapted to 2.8 by Dieter Verfaillie <dieterv optionexplicit be>
Applying a slightly changed patch to accommodate for the code changes since the original patch had been
made.
plug-ins/twain/tw_func.c | 142 ++++++++++++++----------------------------
plug-ins/twain/tw_func.h | 1 -
plug-ins/twain/tw_platform.h | 8 +-
plug-ins/twain/tw_util.c | 92 +--------------------------
plug-ins/twain/tw_util.h | 2 +-
plug-ins/twain/tw_win.c | 6 +-
plug-ins/twain/twain.c | 9 +--
plug-ins/twain/twain.h | 4 -
8 files changed, 61 insertions(+), 203 deletions(-)
---
diff --git a/plug-ins/twain/tw_func.c b/plug-ins/twain/tw_func.c
index d8b689d..062b555 100644
--- a/plug-ins/twain/tw_func.c
+++ b/plug-ins/twain/tw_func.c
@@ -191,26 +191,22 @@ getImage (pTW_SESSION twSession)
if (!twainIsAvailable ())
{
- LogMessage("TWAIN is not available for image capture\n");
return FALSE;
}
/* One step at a time */
if (!openDSM (twSession))
{
- LogMessage("Unable to open data source manager\n");
return FALSE;
}
if (!selectDS (twSession))
{
- LogMessage("Data source not selected\n");
return FALSE;
}
if (!openDS (twSession))
{
- LogMessage("Unable to open datasource\n");
return FALSE;
}
@@ -247,7 +243,7 @@ openDSM (pTW_SESSION twSession)
return TRUE;
case TWRC_FAILURE:
- LogMessage("OpenDSM failure\n");
+ log_message ("OpenDSM failure: %s\n", currentTwainError(twSession) );
break;
}
@@ -266,7 +262,7 @@ selectDS (pTW_SESSION twSession)
/* The datasource manager must be open */
if (DSM_IS_CLOSED(twSession))
{
- LogMessage("Can't select data source with closed source manager\n");
+ log_message ("Can't select data source with closed source manager.\n");
return FALSE;
}
@@ -281,18 +277,10 @@ selectDS (pTW_SESSION twSession)
switch (twSession->twRC)
{
case TWRC_SUCCESS:
- LogMessage ("Data source %s selected\n", DS_IDENTITY(twSession)->ProductName);
return TRUE;
- break;
-
- case TWRC_CANCEL:
- LogMessage ("User cancelled TWAIN source selection\n");
- break;
case TWRC_FAILURE:
- default:
- LogMessage ("Error \"%s\" during TWAIN source selection\n",
- currentTwainError(twSession));
+ log_message ("Error selecting datasource: %s\n", currentTwainError(twSession));
break;
}
@@ -300,30 +288,6 @@ selectDS (pTW_SESSION twSession)
}
/*
- * selectDefaultDS
- *
- * Select the default datasource.
- */
-int
-selectDefaultDS(pTW_SESSION twSession)
-{
- /* The datasource manager must be open */
- if (DSM_IS_CLOSED(twSession))
- {
- LogMessage("Can't select data source with closed source manager\n");
- return FALSE;
- }
-
- /* Ask TWAIN to present the source select dialog */
- twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
- DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT,
- (TW_MEMREF) DS_IDENTITY(twSession));
-
- /* Check the return code */
- return (twSession->twRC == TWRC_SUCCESS);
-}
-
-/*
* openDS
*
* Open a data source using the TWAIN user interface.
@@ -336,15 +300,15 @@ openDS (pTW_SESSION twSession)
/* The datasource manager must be open */
if (DSM_IS_CLOSED(twSession))
{
- LogMessage("openDS: Cannot open data source... manager closed\n");
+ log_message ("The DSM needs to be opened first.\n");
return FALSE;
}
/* Is the data source already open? */
if (DS_IS_OPEN(twSession))
{
- LogMessage("openDS: Data source already open\n");
- return TRUE;
+ log_message ("A source has already been opened, please close it first.\n");
+ return FALSE;
}
/* Open the TWAIN datasource */
@@ -363,10 +327,9 @@ openDS (pTW_SESSION twSession)
twSession->twainState = 4;
twainSetupCallback (twSession);
return TRUE;
- break;
case TWRC_FAILURE:
- LogMessage("Error \"%s\" opening data source\n", currentTwainError(twSession));
+ log_message ("Error opening data source: %s\n", currentTwainError(twSession));
break;
}
@@ -392,7 +355,11 @@ setBufferedXfer (pTW_SESSION twSession)
bufXfer.Cap = ICAP_XFERMECH;
bufXfer.ConType = TWON_ONEVALUE;
bufXfer.hContainer = twainAllocHandle (sizeof(TW_ONEVALUE));
-
+ if (bufXfer.hContainer == NULL)
+ {
+ log_message ("Error allocating memory for XFer mechanism.\n");
+ return FALSE;
+ }
pvalOneValue = (pTW_ONEVALUE) twainLockHandle (bufXfer.hContainer);
pvalOneValue->ItemType = TWTY_UINT16;
pvalOneValue->Item = TWSX_MEMORY;
@@ -402,8 +369,13 @@ setBufferedXfer (pTW_SESSION twSession)
twSession->twRC = callDSM(APP_IDENTITY(twSession), DS_IDENTITY(twSession),
DG_CONTROL, DAT_CAPABILITY, MSG_SET,
(TW_MEMREF) &bufXfer);
+ if (twSession->twRC == TWRC_FAILURE)
+ {
+ log_message ("Could not set capability: %s\n", currentTwainError(twSession));
+ }
/* Free the container */
+ twainUnlockHandle (bufXfer.hContainer);
twainFreeHandle (bufXfer.hContainer);
/* Let the caller know what happened */
@@ -423,7 +395,7 @@ requestImageAcquire (pTW_SESSION twSession, gboolean showUI)
/* Make sure in the correct state */
if (DS_IS_CLOSED(twSession))
{
- LogMessage("Can't acquire image with closed datasource\n");
+ log_message ("You need to open the data source first.\n");
return FALSE;
}
@@ -448,18 +420,9 @@ requestImageAcquire (pTW_SESSION twSession, gboolean showUI)
return TRUE;
}
- else
- {
- LogMessage("Error during data source enable\n");
- return FALSE;
- }
- }
- else
- {
- LogMessage("Unable to set buffered transfer mode: %s\n",
- currentTwainError(twSession));
- return FALSE;
+ log_message ("Error enabeling data source: %s\n", currentTwainError(twSession));
}
+ return FALSE;
}
/*
@@ -473,7 +436,7 @@ disableDS(pTW_SESSION twSession)
/* Verify the datasource is enabled */
if (DS_IS_DISABLED(twSession))
{
- LogMessage("disableDS: Data source not enabled\n");
+ log_message ("You need to enable the data source first.\n");
return;
}
@@ -482,14 +445,16 @@ disableDS(pTW_SESSION twSession)
DG_CONTROL, DAT_USERINTERFACE, MSG_DISABLEDS,
(TW_MEMREF) &ui);
- if (twSession->twRC == TWRC_SUCCESS)
- {
- /* We are now at a new twain state */
- twSession->twainState = 4;
- }
- else
+ switch (twSession->twRC)
{
- LogMessage("Error during data source disable\n");
+ case TWRC_SUCCESS:
+ /* We are now at a new twain state */
+ twSession->twainState = 4;
+ break;
+
+ case TWRC_FAILURE:
+ log_message ("Can't disable data source: %s\n, currentTwainError(twSession));
+ break;
}
}
@@ -505,7 +470,7 @@ closeDS (pTW_SESSION twSession)
/* Can't close a closed data source */
if (DS_IS_CLOSED(twSession))
{
- LogMessage("closeDS: Data source already closed\n");
+ log_message ("closeDS: Data source already closed\n");
return;
}
@@ -516,17 +481,16 @@ closeDS (pTW_SESSION twSession)
/* Check the return to determine what the user decided
* to do.
- */
+ */
switch (twSession->twRC)
{
case TWRC_SUCCESS:
/* We are now in TWAIN state 3 */
twSession->twainState = 3;
- LogMessage("Data source %s closed\n", DS_IDENTITY(twSession)->ProductName);
break;
- default:
- LogMessage("Error \"%s\" closing data source\n", currentTwainError(twSession));
+ case TWRC_FAILURE:
+ log_message ("Error closing data source: %s\n", currentTwainError(twSession));
break;
}
}
@@ -541,31 +505,24 @@ closeDSM (pTW_SESSION twSession)
{
if (DSM_IS_CLOSED(twSession))
{
- LogMessage("closeDSM: Source Manager not open\n");
+ log_message ("Data Source Manager not open\n");
}
else
{
- if (DS_IS_OPEN(twSession))
- {
- LogMessage("closeDSM: Can't close source manager with open source\n");
- }
- else
- {
- twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
+ twSession->twRC = callDSM(APP_IDENTITY(twSession), NULL,
DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM,
(TW_MEMREF)&(twSession->hwnd));
- switch (twSession->twRC)
- {
- case TWRC_SUCCESS:
- /* We are now in state 2 */
- twSession->twainState = 2;
- break;
+ switch (twSession->twRC)
+ {
+ case TWRC_SUCCESS:
+ /* We are now in state 2 */
+ twSession->twainState = 2;
+ break;
- case TWRC_FAILURE:
- LogMessage("CloseDSM failure -- %s\n", currentTwainError(twSession));
- break;
- }
+ case TWRC_FAILURE:
+ log_message ("Error closing Data Source Manager: %s\n", currentTwainError(twSession));
+ break;
}
}
}
@@ -602,7 +559,7 @@ beginImageTransfer (pTW_SESSION twSession, pTW_IMAGEINFO imageInfo)
/* We should continue */
return TRUE;
case TWRC_FAILURE:
- LogMessage("Get Image Info failure - %s\n", currentTwainError(twSession));
+ log_message ("Get Image Info failure - %s\n", currentTwainError(twSession));
break;
}
return FALSE;
@@ -732,12 +689,11 @@ endImageTransfer (pTW_SESSION twSession, int *pendingCount)
{
case TWRC_XFERDONE:
case TWRC_CANCEL:
- LogMessage("Xfer done received\n");
*pendingCount = endPendingTransfer (twSession);
break;
case TWRC_FAILURE:
- LogMessage("Failure received\n");
+ log_message ("Failure received: %s\n", currentTwainError(twSession));
*pendingCount = endPendingTransfer (twSession);
break;
}
@@ -770,7 +726,7 @@ transferImages (pTW_SESSION twSession)
*/
if (!twSession->transferFunctions || !twSession->transferFunctions->txfrDataCb)
{
- LogMessage("Attempting image transfer without callback function\n");
+ log_message ("Attempting image transfer without callback function.\n");
return;
}
@@ -817,7 +773,6 @@ processTwainMessage (TW_UINT16 message, pTW_SESSION twSession)
switch (message)
{
case MSG_XFERREADY:
- LogMessage("Source says that data is ready\n");
transferImages (twSession);
break;
@@ -825,7 +780,6 @@ processTwainMessage (TW_UINT16 message, pTW_SESSION twSession)
/* Disable the datasource, Close the Data source
* and close the data source manager
*/
- LogMessage("CloseDSReq\n");
disableDS (twSession);
closeDS (twSession);
closeDSM (twSession);
diff --git a/plug-ins/twain/tw_func.h b/plug-ins/twain/tw_func.h
index d70fe35..fc8ed96 100644
--- a/plug-ins/twain/tw_func.h
+++ b/plug-ins/twain/tw_func.h
@@ -211,7 +211,6 @@ int loadTwainLibrary (pTW_SESSION twSession);
void unloadTwainLibrary (pTW_SESSION twSession);
int openDSM (pTW_SESSION twSession);
int selectDS (pTW_SESSION twSession);
-int selectDefaultDS (pTW_SESSION twSession);
int openDS (pTW_SESSION twSession);
int requestImageAcquire (pTW_SESSION twSession, gboolean showUI);
void disableDS (pTW_SESSION twSession);
diff --git a/plug-ins/twain/tw_platform.h b/plug-ins/twain/tw_platform.h
index 891553f..ef8b6cc 100644
--- a/plug-ins/twain/tw_platform.h
+++ b/plug-ins/twain/tw_platform.h
@@ -24,11 +24,11 @@
/* Coding style violation: Don't include headers in headers */
#include <windows.h>
/* Coding style violation: Don't include headers in headers */
+ #define _MSWIN_ /* Definition for TWAIN.H */
#include "twain.h"
/* The DLL to be loaded for TWAIN support */
#define TWAIN_DLL_NAME "TWAIN_32.DLL"
-#define DEBUG_LOGFILE "c:\\twain.log"
#define DUMP_FILE "C:\\TWAINCAP.BIN"
#define DUMP_NAME "DTWAIN.EXE"
#define READDUMP_NAME "RTWAIN.EXE"
@@ -36,9 +36,9 @@
/* Windows uses separate entry point */
#define TWAIN_ALTERNATE_MAIN
-/*
- * Plug-in Definitions
- */
+ /*
+ * Plug-in Definitions
+ */
#define PRODUCT_FAMILY "GNU"
#define PRODUCT_NAME "GIMP"
#define PLUG_IN_NAME "TWAIN"
diff --git a/plug-ins/twain/tw_util.c b/plug-ins/twain/tw_util.c
index 5060b1c..9b3177f 100644
--- a/plug-ins/twain/tw_util.c
+++ b/plug-ins/twain/tw_util.c
@@ -68,105 +68,21 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
-#include <time.h>
#include "tw_platform.h"
-#ifdef _DEBUG
-#include "tw_func.h"
-FILE *logFile = NULL;
-#endif
#include "tw_util.h"
-#ifdef _DEBUG
-
/*
- * LogMessage
+ * log_message
*/
void
-LogMessage (char *format, ...)
+log_message (char *format, ...)
{
va_list args;
- time_t time_of_day;
- char *ctime_string;
-
- /* Open the log file as necessary */
- if (!logFile)
- logFile = g_fopen(DEBUG_LOGFILE, "w");
-
- time_of_day = time (NULL);
- ctime_string = ctime (&time_of_day);
- ctime_string[19] = '\0';
-
- fprintf (logFile, "[%s] ", (ctime_string + 11));
va_start (args, format);
- vfprintf (logFile, format, args);
- fflush (logFile);
+ g_message (format, args);
va_end (args);
+ return;
}
-void
-logBegin(pTW_IMAGEINFO imageInfo, void *clientData)
-{
- int i;
- char buffer[256];
-
- LogMessage("\n");
- LogMessage("*************************************\n");
- LogMessage("\n");
- LogMessage("Image transfer begin:\n");
- /* LogMessage("\tClient data: %s\n", (char *) clientData); */
-
- /* Log the image information */
- LogMessage("Image information:\n");
- LogMessage("\tXResolution: %f\n", FIX32ToFloat(imageInfo->XResolution));
- LogMessage("\tYResolution: %f\n", FIX32ToFloat(imageInfo->YResolution));
- LogMessage("\tImageWidth: %d\n", imageInfo->ImageWidth);
- LogMessage("\tImageLength: %d\n", imageInfo->ImageLength);
- LogMessage("\tSamplesPerPixel: %d\n", imageInfo->SamplesPerPixel);
- sprintf(buffer, "\tBitsPerSample: {");
- for (i = 0; i < 8; i++) {
- if (imageInfo->BitsPerSample[i])
- strcat(buffer, "1");
- else
- strcat(buffer, "0");
-
- if (i != 7)
- strcat(buffer, ",");
- }
- LogMessage("%s}\n", buffer);
-
- LogMessage("\tBitsPerPixel: %d\n", imageInfo->BitsPerPixel);
- LogMessage("\tPlanar: %s\n", (imageInfo->Planar ? "TRUE" : "FALSE"));
- LogMessage("\tPixelType: %d\n", imageInfo->PixelType);
- /* Compression */
-
-}
-
-void
-logData(pTW_IMAGEINFO imageInfo,
- pTW_IMAGEMEMXFER imageMemXfer,
- void *clientData)
-{
- LogMessage("Image transfer callback called:\n");
- LogMessage("\tClient data: %s\n", (char *) clientData);
- LogMessage("Memory block transferred:\n");
- LogMessage("\tBytesPerRow = %d\n", imageMemXfer->BytesPerRow);
- LogMessage("\tColumns = %d\n", imageMemXfer->Columns);
- LogMessage("\tRows = %d\n", imageMemXfer->Rows);
- LogMessage("\tXOffset = %d\n", imageMemXfer->XOffset);
- LogMessage("\tYOffset = %d\n", imageMemXfer->YOffset);
- LogMessage("\tBytesWritten = %d\n", imageMemXfer->BytesWritten);
-}
-
-#else
-
-/*
- * LogMessage
- */
-void
-LogMessage(char *format, ...)
-{
-}
-
-#endif /* DEBUG */
diff --git a/plug-ins/twain/tw_util.h b/plug-ins/twain/tw_util.h
index e0c46ed..1fe4391 100644
--- a/plug-ins/twain/tw_util.h
+++ b/plug-ins/twain/tw_util.h
@@ -61,7 +61,7 @@
#ifndef __TW_UTIL_H
#define __TW_UTIL_H
-void LogMessage(char *, ...);
+void log_message (char *format, ...);
#ifdef _DEBUG
void logBegin(pTW_IMAGEINFO, void *);
diff --git a/plug-ins/twain/tw_win.c b/plug-ins/twain/tw_win.c
index b931189..9096217 100644
--- a/plug-ins/twain/tw_win.c
+++ b/plug-ins/twain/tw_win.c
@@ -149,7 +149,6 @@ unloadTwainLibrary (pTW_SESSION twSession)
/* We are now back at state 0 */
twSession->twainState = 0;
- LogMessage("Source Manager successfully closed\n");
}
/*
@@ -166,7 +165,7 @@ TwainProcessMessage (LPMSG lpMsg, pTW_SESSION twSession)
twSession->twRC = TWRC_NOTDSEVENT;
/* Only ask Source Manager to process event if there is a Source connected. */
- if (DSM_IS_OPEN(twSession) && DS_IS_OPEN(twSession))
+ if (DS_IS_OPEN(twSession))
{
/*
* A Source provides a modeless dialog box as its user interface.
@@ -240,7 +239,7 @@ LogLastWinError (void)
NULL
);
- LogMessage("%s\n", lpMsgBuf);
+ log_message ("%s\n", lpMsgBuf);
/* Free the buffer. */
LocalFree ( lpMsgBuf );
@@ -444,7 +443,6 @@ WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
case WM_DESTROY:
- LogMessage("Exiting application\n");
PostQuitMessage (0);
break;
diff --git a/plug-ins/twain/twain.c b/plug-ins/twain/twain.c
index 049e648..2a3a9f2 100644
--- a/plug-ins/twain/twain.c
+++ b/plug-ins/twain/twain.c
@@ -148,7 +148,7 @@ setRunMode(char *argv[])
{
char *exeName = strrchr(argv[0], '\\') + 1;
- LogMessage("Executable name: %s\n", exeName);
+ log_message ("Executable name: %s\n", exeName);
if (!_stricmp(exeName, DUMP_NAME))
twain_run_mode = RUN_DUMP;
@@ -174,7 +174,7 @@ scanImage (void)
}
/*
- * initTwainAppIdentity
+ * getAppIdentity
*
* Initialize and return our application's identity for
* the TWAIN runtime.
@@ -879,9 +879,6 @@ endTransferCallback (int completionState, int pendingCount, void *clientData)
{
pClientDataStruct theClientData = (pClientDataStruct) clientData;
- LogMessage("endTransferCallback: CompState = %d, pending = %d\n",
- completionState, pendingCount);
-
/* Clean up and detach from the drawable */
if (destBuf)
{
@@ -900,13 +897,11 @@ endTransferCallback (int completionState, int pendingCount, void *clientData)
theClientData->image_id;
/* Display the image */
- LogMessage("Displaying image %d\n", theClientData->image_id);
gimp_display_new (theClientData->image_id);
}
else
{
/* The transfer did not complete successfully */
- LogMessage("Deleting image\n");
gimp_image_delete (theClientData->image_id);
}
diff --git a/plug-ins/twain/twain.h b/plug-ins/twain/twain.h
index fd30243..46500c1 100644
--- a/plug-ins/twain/twain.h
+++ b/plug-ins/twain/twain.h
@@ -73,10 +73,6 @@
****************************************************************************/
/* Define one of the following, depending on the platform */
-/* #define _MAC_ */
-/* #define _UNIX_ */
-#define _MSWIN_
-
#ifdef _MSWIN_
typedef HANDLE TW_HANDLE;
typedef LPVOID TW_MEMREF;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]