* Don't define DEBUG in public headers!!! Doing it this way will break the

build for others, namely those that also include <Debug.h>
* This fixes the remaining problems of building Pe under Haiku.
* Those files need a giant style cleanup... Fredrik, time to have a look at
  our style guide :-)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26931 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-11 16:45:26 +00:00
parent 45d431a676
commit 8f38768e65
4 changed files with 81 additions and 77 deletions
+2 -4
View File
@@ -16,8 +16,6 @@
#include <SupportDefs.h> #include <SupportDefs.h>
#include <OS.h> #include <OS.h>
#define DEBUG
class BList; class BList;
class BString; class BString;
struct entry_ref; struct entry_ref;
@@ -57,7 +55,7 @@ virtual ~BJoystick();
bool button2; bool button2;
int32 CountDevices(); int32 CountDevices();
status_t GetDeviceName(int32 n, char * name, status_t GetDeviceName(int32 n, char * name,
size_t bufSize = B_OS_NAME_LENGTH); size_t bufSize = B_OS_NAME_LENGTH);
/* if you care about more than just the first two axes/buttons, here's where you go */ /* if you care about more than just the first two axes/buttons, here's where you go */
@@ -130,7 +128,7 @@ virtual status_t _Reserved_Joystick_6(void *, ...);
uint32 _reserved_Joystick_[10]; uint32 _reserved_Joystick_[10];
#endif #endif
#ifdef DEBUG #if DEBUG
public: public:
static FILE *sLogFile; static FILE *sLogFile;
#endif #endif
+6 -9
View File
@@ -1,14 +1,13 @@
/* /*
* Copyright 2008, Haiku. * Copyright 2008, Haiku, Inc.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Fredrik Modeen * Fredrik Modeen
*
*/ */
#include "joystick_driver.h" #include "joystick_driver.h"
#include <List.h> #include <List.h>
#include <Entry.h> #include <Entry.h>
#include <Path.h> #include <Path.h>
@@ -22,8 +21,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#define DEBUG
#define DEVICEPATH "/dev/joystick/" #define DEVICEPATH "/dev/joystick/"
#define JOYSTICKPATH "/boot/home/config/settings/joysticks/" #define JOYSTICKPATH "/boot/home/config/settings/joysticks/"
@@ -47,8 +44,8 @@ private:
status_t save_config(const entry_ref * ref = NULL); status_t save_config(const entry_ref * ref = NULL);
status_t get_info(); status_t get_info();
BJoystick* fJoystick; BJoystick* fJoystick;
#ifdef DEBUG #if DEBUG
public: public:
static FILE *sLogFile; static FILE *sLogFile;
#endif #endif
}; };
+54 -45
View File
@@ -3,11 +3,11 @@
* All rights reserved. * All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
/* /*
joystick preference app joystick preference app
JoyCalib::JoyCalib(BRect, BJoystick &, BWindow *): JoyCalib::JoyCalib(BRect, BJoystick &, BWindow *):
__8JoyCalibG5BRectR9BJoystickP7BWindow: __8JoyCalibG5BRectR9BJoystickP7BWindow:
*/ */
#include <List.h> #include <List.h>
@@ -25,14 +25,22 @@ __8JoyCalibG5BRectR9BJoystickP7BWindow:
#include "Joystick.h" #include "Joystick.h"
#ifdef DEBUG #if DEBUG
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \ inline void
fputs(buf, BJoystick::sLogFile); fflush(BJoystick::sLogFile); } LOG(const char *fmt, ...)
#define LOG_ERR(text...) LOG(text) {
char buf[1024];
va_list ap;
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
fputs(buf, BJoystick::sLogFile); fflush(BJoystick::sLogFile);
}
# define LOG_ERR(text...) LOG(text)
FILE *BJoystick::sLogFile = NULL; FILE *BJoystick::sLogFile = NULL;
#else #else
#define LOG(text...) # define LOG(text...)
#define LOG_ERR(text...) fprintf(stderr, text) # define LOG_ERR(text...) fprintf(stderr, text)
#endif #endif
#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__) #define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
@@ -40,28 +48,29 @@ FILE *BJoystick::sLogFile = NULL;
#include "JoystickTweaker.h" #include "JoystickTweaker.h"
BJoystick::BJoystick() BJoystick::BJoystick()
: _mBeBoxMode(false) :
, _fDevices(new BList) _mBeBoxMode(false),
, m_info(new _joystick_info()) _fDevices(new BList),
{ m_info(new _joystick_info())
#ifdef DEBUG {
#if DEBUG
sLogFile = fopen("/var/log/libdevice.log", "a"); sLogFile = fopen("/var/log/libdevice.log", "a");
#endif #endif
//ScanDevices(); //ScanDevices();
} }
BJoystick::~BJoystick() BJoystick::~BJoystick()
{ {
if (ffd >= 0) if (ffd >= 0)
close(ffd); close(ffd);
for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) { for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) {
free(_fDevices->RemoveItem(count)); free(_fDevices->RemoveItem(count));
} }
delete _fDevices; delete _fDevices;
delete m_info; delete m_info;
} }
@@ -78,49 +87,49 @@ BJoystick::Open(const char *portName, bool enter_enhanced)
{ {
CALLED(); CALLED();
char buf[64]; char buf[64];
if(!enter_enhanced) if(!enter_enhanced)
_mBeBoxMode = !enter_enhanced; _mBeBoxMode = !enter_enhanced;
if (portName == NULL) if (portName == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
if (portName[0] != '/') if (portName[0] != '/')
snprintf(buf, 64, DEVICEPATH"/%s", portName); snprintf(buf, 64, DEVICEPATH"/%s", portName);
else else
snprintf(buf, 64, "%s", portName); snprintf(buf, 64, "%s", portName);
if (ffd >= 0) if (ffd >= 0)
close(ffd); close(ffd);
// TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I // TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I
// added this flag having read some comments by Marco Nelissen on the // added this flag having read some comments by Marco Nelissen on the
// annotated BeBook. I think BeOS uses O_RDWR|O_NONBLOCK here. // annotated BeBook. I think BeOS uses O_RDWR|O_NONBLOCK here.
ffd = open(buf, O_RDWR | O_NONBLOCK | O_EXCL); ffd = open(buf, O_RDWR | O_NONBLOCK | O_EXCL);
if (ffd >= 0) { if (ffd >= 0) {
// we used open() with O_NONBLOCK flag to let it return immediately, // we used open() with O_NONBLOCK flag to let it return immediately,
// but we want read/write operations to block if needed, so we clear // but we want read/write operations to block if needed, so we clear
// that bit here. // that bit here.
int flags = fcntl(ffd, F_GETFL); int flags = fcntl(ffd, F_GETFL);
fcntl(ffd, F_SETFL, flags & ~O_NONBLOCK); fcntl(ffd, F_SETFL, flags & ~O_NONBLOCK);
//DriverControl(); //DriverControl();
} }
// TODO: I wonder why the return type is a status_t, // TODO: I wonder why the return type is a status_t,
// since we (as BeOS does) return the descriptor number for the device... // since we (as BeOS does) return the descriptor number for the device...
//Read the Joystick Description file for this port/joystick //Read the Joystick Description file for this port/joystick
_BJoystickTweaker jt(*this); _BJoystickTweaker jt(*this);
jt.get_info(m_info, portName); jt.get_info(m_info, portName);
LOG("ioctl - %d\n", m_info->num_buttons); LOG("ioctl - %d\n", m_info->num_buttons);
ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, m_info); ioctl(ffd, B_JOYSTICK_SET_DEVICE_MODULE, m_info);
ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, m_info); ioctl(ffd, B_JOYSTICK_GET_DEVICE_MODULE, m_info);
LOG("ioctl - %d\n", m_info->num_buttons); LOG("ioctl - %d\n", m_info->num_buttons);
if (ffd >= 0) { if (ffd >= 0) {
return ffd; return ffd;
} else } else
return errno; return errno;
} }
@@ -151,13 +160,13 @@ BJoystick::CountDevices()
{ {
CALLED(); CALLED();
int32 count = 0; int32 count = 0;
// Refresh devices list // Refresh devices list
ScanDevices(true); ScanDevices(true);
if (_fDevices != NULL) if (_fDevices != NULL)
count = _fDevices->CountItems(); count = _fDevices->CountItems();
LOG("Count = %d\n", count); LOG("Count = %d\n", count);
return count; return count;
} }
@@ -196,8 +205,8 @@ BJoystick::EnterEnhancedMode(const entry_ref *ref)
int32 int32
BJoystick::CountSticks() BJoystick::CountSticks()
{ {
CALLED(); CALLED();
return m_info->num_sticks; return m_info->num_sticks;
} }
@@ -222,7 +231,7 @@ int32
BJoystick::CountButtons() BJoystick::CountButtons()
{ {
CALLED(); CALLED();
return m_info->num_buttons; return m_info->num_buttons;
} }
status_t status_t
@@ -232,7 +241,7 @@ BJoystick::GetControllerModule(BString *out_name)
if (m_info != NULL && ffd >= 0) { if (m_info != NULL && ffd >= 0) {
out_name->SetTo(m_info->module_name); out_name->SetTo(m_info->module_name);
return B_OK; return B_OK;
} else } else
return B_ERROR; return B_ERROR;
} }
@@ -245,7 +254,7 @@ BJoystick::GetControllerName(BString *out_name)
if (m_info != NULL && ffd >= 0) { if (m_info != NULL && ffd >= 0) {
out_name->SetTo(m_info->controller_name); out_name->SetTo(m_info->controller_name);
return B_OK; return B_OK;
} else } else
return B_ERROR; return B_ERROR;
} }
@@ -254,7 +263,7 @@ bool
BJoystick::IsCalibrationEnabled() BJoystick::IsCalibrationEnabled()
{ {
CALLED(); CALLED();
return m_info->calibration_enable; return m_info->calibration_enable;
} }
@@ -363,7 +372,7 @@ BJoystick::save_config(const entry_ref *ref)
} }
/* These functions are here to maintain Binary Compatibility */ /* These functions are here to maintain Binary Compatibility */
void BJoystick::_ReservedJoystick1() {CALLED();} void BJoystick::_ReservedJoystick1() {CALLED();}
void BJoystick::_ReservedJoystick2() {CALLED();} void BJoystick::_ReservedJoystick2() {CALLED();}
void BJoystick::_ReservedJoystick3() {CALLED();} void BJoystick::_ReservedJoystick3() {CALLED();}
+19 -19
View File
@@ -3,7 +3,7 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Fredrik Modeen * Fredrik Modeen
* *
*/ */
#include "JoystickTweaker.h" #include "JoystickTweaker.h"
@@ -18,13 +18,13 @@
#include <UTF8.h> #include <UTF8.h>
#ifdef DEBUG #if DEBUG
inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \ inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
fputs(buf, _BJoystickTweaker::sLogFile); fflush(_BJoystickTweaker::sLogFile); } fputs(buf, _BJoystickTweaker::sLogFile); fflush(_BJoystickTweaker::sLogFile); }
#define LOG_ERR(text...) LOG(text) #define LOG_ERR(text...) LOG(text)
FILE *_BJoystickTweaker::sLogFile = NULL; FILE *_BJoystickTweaker::sLogFile = NULL;
#else #else
#define LOG(text...) #define LOG(text...)
#define LOG_ERR(text...) fprintf(stderr, text) #define LOG_ERR(text...) fprintf(stderr, text)
#endif #endif
@@ -33,19 +33,19 @@ FILE *_BJoystickTweaker::sLogFile = NULL;
_BJoystickTweaker::_BJoystickTweaker() _BJoystickTweaker::_BJoystickTweaker()
{ {
CALLED(); CALLED();
#ifdef DEBUG #if DEBUG
sLogFile = fopen("/var/log/libdevice.log", "a"); sLogFile = fopen("/var/log/libdevice.log", "a");
#endif #endif
} }
_BJoystickTweaker::_BJoystickTweaker(BJoystick &stick) _BJoystickTweaker::_BJoystickTweaker(BJoystick &stick)
{ {
CALLED(); CALLED();
#ifdef DEBUG #if DEBUG
sLogFile = fopen("/var/log/libdevice.log", "a"); sLogFile = fopen("/var/log/libdevice.log", "a");
#endif #endif
fJoystick = &stick; fJoystick = &stick;
} }
@@ -65,7 +65,7 @@ _BJoystickTweaker::save_config(const entry_ref *ref)
status_t status_t
_BJoystickTweaker::scan_including_disabled(const char* rootPath, BList *list, _BJoystickTweaker::scan_including_disabled(const char* rootPath, BList *list,
BEntry *rootEntry) BEntry *rootEntry)
{ {
BDirectory root; BDirectory root;
@@ -75,9 +75,9 @@ _BJoystickTweaker::scan_including_disabled(const char* rootPath, BList *list,
root.SetTo(rootPath); root.SetTo(rootPath);
else else
return B_ERROR; return B_ERROR;
BEntry entry; BEntry entry;
ASSERT(list != NULL); ASSERT(list != NULL);
while ((root.GetNextEntry(&entry)) > B_ERROR ) { while ((root.GetNextEntry(&entry)) > B_ERROR ) {
if (entry.IsDirectory()) { if (entry.IsDirectory()) {
@@ -85,7 +85,7 @@ _BJoystickTweaker::scan_including_disabled(const char* rootPath, BList *list,
} else { } else {
BPath path; BPath path;
entry.GetPath(&path); entry.GetPath(&path);
BString *str = new BString(path.Path()); BString *str = new BString(path.Path());
str->RemoveFirst(rootPath); str->RemoveFirst(rootPath);
list->AddItem(str); list->AddItem(str);
@@ -95,7 +95,7 @@ _BJoystickTweaker::scan_including_disabled(const char* rootPath, BList *list,
} }
void void
_BJoystickTweaker::scan_including_disabled() _BJoystickTweaker::scan_including_disabled()
{ {
CALLED(); CALLED();
@@ -116,14 +116,14 @@ _BJoystickTweaker::get_info()
status_t status_t
_BJoystickTweaker::get_info(_joystick_info* info, _BJoystickTweaker::get_info(_joystick_info* info,
const char * ref) const char * ref)
{ {
CALLED(); CALLED();
status_t err = B_ERROR; status_t err = B_ERROR;
BString str(JOYSTICKPATH); BString str(JOYSTICKPATH);
str.Append(ref); str.Append(ref);
FILE *file = fopen(str.String(), "r"); FILE *file = fopen(str.String(), "r");
if (file != NULL) { if (file != NULL) {
char line [STRINGLENGTHCPY]; char line [STRINGLENGTHCPY];
@@ -135,20 +135,20 @@ _BJoystickTweaker::get_info(_joystick_info* info,
} }
fclose(file); fclose(file);
} }
err = B_OK; err = B_OK;
return err; return err;
} }
void void
_BJoystickTweaker::BuildFromJoystickDesc(char *string, _joystick_info* info) _BJoystickTweaker::BuildFromJoystickDesc(char *string, _joystick_info* info)
{ {
BString str(string); BString str(string);
str.RemoveAll("\""); str.RemoveAll("\"");
if (str.IFindFirst("module") != -1) { if (str.IFindFirst("module") != -1) {
str.RemoveFirst("module = "); str.RemoveFirst("module = ");
strncpy(info->module_name, str.String(), STRINGLENGTHCPY); strncpy(info->module_name, str.String(), STRINGLENGTHCPY);
} else if (str.IFindFirst("gadget") != -1) { } else if (str.IFindFirst("gadget") != -1) {
str.RemoveFirst("gadget = "); str.RemoveFirst("gadget = ");