2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2001 Red Hat Inc., Durham, North Carolina.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation on the rights to use, copy, modify, merge,
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Authors:
|
|
|
|
* Rickard E. (Rik) Faith <faith@redhat.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* This file encapsulated all of the logging functions that are used by
|
|
|
|
* DMX for informational, warning, and error messages. */
|
|
|
|
|
|
|
|
#ifdef HAVE_DMX_CONFIG_H
|
|
|
|
#include <dmx-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "dmx.h"
|
|
|
|
#include "dmxlog.h"
|
|
|
|
#include "dmxinput.h"
|
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XIproto.h>
|
|
|
|
|
|
|
|
static dmxLogLevel dmxCurrentLogLevel = dmxDebug;
|
|
|
|
|
|
|
|
/** Set the default level for logging to #dmxLogLevel. Returns the
|
|
|
|
* previous log level. */
|
2012-06-10 07:21:05 -06:00
|
|
|
dmxLogLevel
|
|
|
|
dmxSetLogLevel(dmxLogLevel newLevel)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
dmxLogLevel oldLevel = dmxCurrentLogLevel;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
if (newLevel > dmxFatal)
|
|
|
|
newLevel = dmxFatal;
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxCurrentLogLevel = newLevel;
|
|
|
|
return oldLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the log level set by #dmxLogLevel. */
|
2012-06-10 07:21:05 -06:00
|
|
|
dmxLogLevel
|
|
|
|
dmxGetLogLevel(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
return dmxCurrentLogLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DMX_LOG_STANDALONE
|
|
|
|
/* When using this file as part of a stand-alone (i.e., non-X-Server
|
|
|
|
* program, then the ultimate output routines have to be defined. */
|
|
|
|
|
|
|
|
/** Provide an ErrorF function when used stand-alone. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
ErrorF(const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
2012-06-10 07:21:05 -06:00
|
|
|
vfprintf(stderr, format, args); /* RATS: We assume the format string
|
|
|
|
* is trusted, since it is always
|
|
|
|
* from a log message in our code. */
|
2006-11-26 11:13:41 -07:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Provide an VFatalError function when used stand-alone. */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
VFatalError(const char *format, va_list args) _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN;
|
|
|
|
static void
|
|
|
|
VFatalError(const char *format, va_list args)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
vfprintf(stderr, format, args); /* RATS: We assume the format string
|
|
|
|
* is trusted, since it is always
|
|
|
|
* from a log message in our code. */
|
2006-11-26 11:13:41 -07:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Provide an VErrorF function when used stand-alone. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
VErrorF(const char *format, va_list args)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
vfprintf(stderr, format, args); /* RATS: We assume the format string
|
|
|
|
* is trusted, since it is always
|
|
|
|
* from a log message in our code. */
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
/** This function was removed between XFree86 4.3.0 and XFree86 4.4.0. */
|
2012-06-10 07:21:05 -06:00
|
|
|
extern void AbortServer(void) _X_NORETURN;
|
|
|
|
static void
|
|
|
|
VFatalError(const char *format, va_list args) _X_ATTRIBUTE_PRINTF(1, 0) _X_NORETURN;
|
|
|
|
static void
|
|
|
|
VFatalError(const char *format, va_list args)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
VErrorF(format, args);
|
|
|
|
ErrorF("\n");
|
|
|
|
AbortServer();
|
2012-06-10 07:21:05 -06:00
|
|
|
/*NOTREACHED*/}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Prints a consistent header for each line. */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxHeader(dmxLogLevel logLevel, DMXInputInfo * dmxInput,
|
|
|
|
DMXScreenInfo * dmxScreen)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
const char *type = "??";
|
|
|
|
|
|
|
|
switch (logLevel) {
|
2012-06-10 07:21:05 -06:00
|
|
|
case dmxDebug:
|
|
|
|
type = "..";
|
|
|
|
break;
|
|
|
|
case dmxInfo:
|
|
|
|
type = "II";
|
|
|
|
break;
|
|
|
|
case dmxWarning:
|
|
|
|
type = "**";
|
|
|
|
break;
|
|
|
|
case dmxError:
|
|
|
|
type = "!!";
|
|
|
|
break;
|
|
|
|
case dmxFatal:
|
|
|
|
type = "Fatal Error";
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dmxInput && dmxScreen) {
|
|
|
|
ErrorF("(%s) dmx[i%d/%s;o%d/%s]: ", type,
|
|
|
|
dmxInput->inputIdx, dmxInput->name,
|
|
|
|
dmxScreen->index, dmxScreen->name);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else if (dmxScreen) {
|
|
|
|
ErrorF("(%s) dmx[o%d/%s]: ", type, dmxScreen->index, dmxScreen->name);
|
|
|
|
}
|
|
|
|
else if (dmxInput) {
|
2006-11-26 11:13:41 -07:00
|
|
|
const char *pt = strchr(dmxInput->name, ',');
|
2012-06-10 07:21:05 -06:00
|
|
|
int len = (pt ? (size_t) (pt - dmxInput->name)
|
|
|
|
: strlen(dmxInput->name));
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
ErrorF("(%s) dmx[i%d/%*.*s]: ", type,
|
|
|
|
dmxInput->inputIdx, len, len, dmxInput->name);
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
ErrorF("(%s) dmx: ", type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prints the error message with the appropriate low-level X output
|
|
|
|
* routine. */
|
2012-06-10 07:21:05 -06:00
|
|
|
static void
|
|
|
|
dmxMessage(dmxLogLevel logLevel, const char *format, va_list args) _X_ATTRIBUTE_PRINTF(2, 0);
|
|
|
|
static void
|
|
|
|
dmxMessage(dmxLogLevel logLevel, const char *format, va_list args)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
if (logLevel == dmxFatal || logLevel >= dmxCurrentLogLevel) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (logLevel == dmxFatal)
|
|
|
|
VFatalError(format, args);
|
|
|
|
else
|
|
|
|
VErrorF(format, args);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Log the specified message at the specified \a logLevel. \a format
|
|
|
|
* can be a printf-like format expression. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLog(dmxLogLevel logLevel, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxHeader(logLevel, NULL, NULL);
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(logLevel, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Continue a log message without printing the message prefix. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogCont(dmxLogLevel logLevel, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(logLevel, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DMX_LOG_STANDALONE
|
|
|
|
/** Log an informational message (at level #dmxInfo) related to ouput.
|
|
|
|
* The message prefix will contain backend information from \a
|
|
|
|
* dmxScreen. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogOutput(DMXScreenInfo * dmxScreen, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
dmxHeader(dmxInfo, NULL, dmxScreen);
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(dmxInfo, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Continue a message related to output without printing the message
|
|
|
|
* prefix. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogOutputCont(DMXScreenInfo * dmxScreen, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(dmxInfo, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Log a warning message (at level #dmxWarning) related to output.
|
|
|
|
* The message prefix will contain backend information from \a
|
|
|
|
* dmxScreen. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogOutputWarning(DMXScreenInfo * dmxScreen, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
dmxHeader(dmxWarning, NULL, dmxScreen);
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(dmxWarning, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Log an informational message (at level #dmxInfo) related to input.
|
|
|
|
* The message prefix will contain information from \a dmxInput. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogInput(DMXInputInfo * dmxInput, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
dmxHeader(dmxInfo, dmxInput, NULL);
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(dmxInfo, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Continue a message related to input without printing the message
|
|
|
|
* prefix. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogInputCont(DMXInputInfo * dmxInput, const char *format, ...)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
dmxMessage(dmxInfo, format, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Print \a argc messages, each describing an element in \a argv. This
|
|
|
|
* is maingly for debugging purposes. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogArgs(dmxLogLevel logLevel, int argc, char **argv)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
int i;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
dmxLog(logLevel, " Arg[%d] = \"%s\"\n", i, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Print messages at level #dmxInfo describing the visuals in \a vi. */
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
dmxLogVisual(DMXScreenInfo * dmxScreen, XVisualInfo * vi, int defaultVisual)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *class = "Unknown";
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
switch (vi->class) {
|
2012-06-10 07:21:05 -06:00
|
|
|
case StaticGray:
|
|
|
|
class = "StaticGray ";
|
|
|
|
break;
|
|
|
|
case GrayScale:
|
|
|
|
class = "GrayScale ";
|
|
|
|
break;
|
|
|
|
case StaticColor:
|
|
|
|
class = "StaticColor";
|
|
|
|
break;
|
|
|
|
case PseudoColor:
|
|
|
|
class = "PseudoColor";
|
|
|
|
break;
|
|
|
|
case TrueColor:
|
|
|
|
class = "TrueColor ";
|
|
|
|
break;
|
|
|
|
case DirectColor:
|
|
|
|
class = "DirectColor";
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
#define VisualLogFormat "0x%02lx %s %2db %db/rgb %3d 0x%04lx 0x%04lx 0x%04lx%s\n"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (dmxScreen) {
|
|
|
|
dmxLogOutput(dmxScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
VisualLogFormat,
|
2006-11-26 11:13:41 -07:00
|
|
|
vi->visualid, class, vi->depth, vi->bits_per_rgb,
|
|
|
|
vi->colormap_size,
|
|
|
|
vi->red_mask, vi->green_mask, vi->blue_mask,
|
|
|
|
defaultVisual ? " *" : "");
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
dmxLog(dmxInfo,
|
2012-06-10 07:21:05 -06:00
|
|
|
" " VisualLogFormat,
|
2006-11-26 11:13:41 -07:00
|
|
|
vi->visualid, class, vi->depth, vi->bits_per_rgb,
|
|
|
|
vi->colormap_size,
|
|
|
|
vi->red_mask, vi->green_mask, vi->blue_mask,
|
|
|
|
defaultVisual ? " *" : "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Translate a (normalized) XInput event \a type into a human-readable
|
|
|
|
* string. */
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *
|
|
|
|
dmxXInputEventName(int type)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
switch (type) {
|
2012-06-10 07:21:05 -06:00
|
|
|
case XI_DeviceValuator:
|
|
|
|
return "XI_DeviceValuator";
|
|
|
|
case XI_DeviceKeyPress:
|
|
|
|
return "XI_DeviceKeyPress";
|
|
|
|
case XI_DeviceKeyRelease:
|
|
|
|
return "XI_DeviceKeyRelease";
|
|
|
|
case XI_DeviceButtonPress:
|
|
|
|
return "XI_DeviceButtonPress";
|
|
|
|
case XI_DeviceButtonRelease:
|
|
|
|
return "XI_DeviceButtonRelease";
|
|
|
|
case XI_DeviceMotionNotify:
|
|
|
|
return "XI_DeviceMotionNotify";
|
|
|
|
case XI_DeviceFocusIn:
|
|
|
|
return "XI_DeviceFocusIn";
|
|
|
|
case XI_DeviceFocusOut:
|
|
|
|
return "XI_DeviceFocusOut";
|
|
|
|
case XI_ProximityIn:
|
|
|
|
return "XI_ProximityIn";
|
|
|
|
case XI_ProximityOut:
|
|
|
|
return "XI_ProximityOut";
|
|
|
|
case XI_DeviceStateNotify:
|
|
|
|
return "XI_DeviceStateNotify";
|
|
|
|
case XI_DeviceMappingNotify:
|
|
|
|
return "XI_DeviceMappingNotify";
|
|
|
|
case XI_ChangeDeviceNotify:
|
|
|
|
return "XI_ChangeDeviceNotify";
|
|
|
|
case XI_DeviceKeystateNotify:
|
|
|
|
return "XI_DeviceKeystateNotify";
|
|
|
|
case XI_DeviceButtonstateNotify:
|
|
|
|
return "XI_DeviceButtonstateNotify";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Translate an event \a type into a human-readable string. */
|
2012-06-10 07:21:05 -06:00
|
|
|
const char *
|
|
|
|
dmxEventName(int type)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
switch (type) {
|
2012-06-10 07:21:05 -06:00
|
|
|
case KeyPress:
|
|
|
|
return "KeyPress";
|
|
|
|
case KeyRelease:
|
|
|
|
return "KeyRelease";
|
|
|
|
case ButtonPress:
|
|
|
|
return "ButtonPress";
|
|
|
|
case ButtonRelease:
|
|
|
|
return "ButtonRelease";
|
|
|
|
case MotionNotify:
|
|
|
|
return "MotionNotify";
|
|
|
|
case EnterNotify:
|
|
|
|
return "EnterNotify";
|
|
|
|
case LeaveNotify:
|
|
|
|
return "LeaveNotify";
|
|
|
|
case FocusIn:
|
|
|
|
return "FocusIn";
|
|
|
|
case FocusOut:
|
|
|
|
return "FocusOut";
|
|
|
|
case KeymapNotify:
|
|
|
|
return "KeymapNotify";
|
|
|
|
case Expose:
|
|
|
|
return "Expose";
|
|
|
|
case GraphicsExpose:
|
|
|
|
return "GraphicsExpose";
|
|
|
|
case NoExpose:
|
|
|
|
return "NoExpose";
|
|
|
|
case VisibilityNotify:
|
|
|
|
return "VisibilityNotify";
|
|
|
|
case CreateNotify:
|
|
|
|
return "CreateNotify";
|
|
|
|
case DestroyNotify:
|
|
|
|
return "DestroyNotify";
|
|
|
|
case UnmapNotify:
|
|
|
|
return "UnmapNotify";
|
|
|
|
case MapNotify:
|
|
|
|
return "MapNotify";
|
|
|
|
case MapRequest:
|
|
|
|
return "MapRequest";
|
|
|
|
case ReparentNotify:
|
|
|
|
return "ReparentNotify";
|
|
|
|
case ConfigureNotify:
|
|
|
|
return "ConfigureNotify";
|
|
|
|
case ConfigureRequest:
|
|
|
|
return "ConfigureRequest";
|
|
|
|
case GravityNotify:
|
|
|
|
return "GravityNotify";
|
|
|
|
case ResizeRequest:
|
|
|
|
return "ResizeRequest";
|
|
|
|
case CirculateNotify:
|
|
|
|
return "CirculateNotify";
|
|
|
|
case CirculateRequest:
|
|
|
|
return "CirculateRequest";
|
|
|
|
case PropertyNotify:
|
|
|
|
return "PropertyNotify";
|
|
|
|
case SelectionClear:
|
|
|
|
return "SelectionClear";
|
|
|
|
case SelectionRequest:
|
|
|
|
return "SelectionRequest";
|
|
|
|
case SelectionNotify:
|
|
|
|
return "SelectionNotify";
|
|
|
|
case ColormapNotify:
|
|
|
|
return "ColormapNotify";
|
|
|
|
case ClientMessage:
|
|
|
|
return "ClientMessage";
|
|
|
|
case MappingNotify:
|
|
|
|
return "MappingNotify";
|
|
|
|
default:
|
|
|
|
return "<unknown>";
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|