Rewrote Input.h, adjusted Input.cpp accordingly, added nothrow on
allocations. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23905 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,12 +1,8 @@
|
|||||||
/******************************************************************************
|
/*
|
||||||
/
|
* Copyright (c) 2008, Haiku, Inc.
|
||||||
/ File: Input.h
|
* Distributed under the terms of the MIT license.
|
||||||
/
|
*
|
||||||
/ Description: Functions and class to manage input devices.
|
*/
|
||||||
/
|
|
||||||
/ Copyright 1998, Be Incorporated, All Rights Reserved.
|
|
||||||
/
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
#ifndef _INPUT_H
|
#ifndef _INPUT_H
|
||||||
#define _INPUT_H
|
#define _INPUT_H
|
||||||
@@ -15,13 +11,11 @@
|
|||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
class BList;
|
|
||||||
|
|
||||||
|
|
||||||
enum input_method_op {
|
enum input_method_op {
|
||||||
B_INPUT_METHOD_STARTED = 0,
|
B_INPUT_METHOD_STARTED = 0,
|
||||||
B_INPUT_METHOD_STOPPED = 1,
|
B_INPUT_METHOD_STOPPED = 1,
|
||||||
B_INPUT_METHOD_CHANGED = 2,
|
B_INPUT_METHOD_CHANGED = 2,
|
||||||
B_INPUT_METHOD_LOCATION_REQUEST = 3
|
B_INPUT_METHOD_LOCATION_REQUEST = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -32,14 +26,9 @@ enum input_device_type {
|
|||||||
B_UNDEFINED_DEVICE = 2
|
B_UNDEFINED_DEVICE = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
what == B_INPUT_DEVICES_CHANGED
|
|
||||||
FindString("name", name_of_device);
|
|
||||||
FindInt32("opcode", input_device_notification);
|
|
||||||
*/
|
|
||||||
|
|
||||||
enum input_device_notification {
|
enum input_device_notification {
|
||||||
B_INPUT_DEVICE_ADDED = 0x0001,
|
B_INPUT_DEVICE_ADDED = 0x0001,
|
||||||
B_INPUT_DEVICE_STARTED = 0x0002,
|
B_INPUT_DEVICE_STARTED = 0x0002,
|
||||||
B_INPUT_DEVICE_STOPPED = 0x0004,
|
B_INPUT_DEVICE_STOPPED = 0x0004,
|
||||||
B_INPUT_DEVICE_REMOVED = 0x0008
|
B_INPUT_DEVICE_REMOVED = 0x0008
|
||||||
@@ -47,10 +36,10 @@ enum input_device_notification {
|
|||||||
|
|
||||||
|
|
||||||
class BInputDevice;
|
class BInputDevice;
|
||||||
|
class BList;
|
||||||
|
|
||||||
|
BInputDevice* find_input_device(const char* name);
|
||||||
BInputDevice* find_input_device(const char *name);
|
status_t get_input_devices(BList* list);
|
||||||
status_t get_input_devices(BList *list);
|
|
||||||
status_t watch_input_devices(BMessenger target, bool start);
|
status_t watch_input_devices(BMessenger target, bool start);
|
||||||
|
|
||||||
|
|
||||||
@@ -64,27 +53,25 @@ public:
|
|||||||
|
|
||||||
status_t Start();
|
status_t Start();
|
||||||
status_t Stop();
|
status_t Stop();
|
||||||
status_t Control(uint32 code,
|
status_t Control(uint32 code, BMessage* message);
|
||||||
BMessage *message);
|
|
||||||
|
|
||||||
static status_t Start(input_device_type type);
|
static status_t Start(input_device_type type);
|
||||||
static status_t Stop(input_device_type type);
|
static status_t Stop(input_device_type type);
|
||||||
static status_t Control(input_device_type type,
|
static status_t Control(input_device_type type,
|
||||||
uint32 code,
|
uint32 code,
|
||||||
BMessage *message);
|
BMessage* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend BInputDevice* find_input_device(const char *name);
|
friend BInputDevice* find_input_device(const char* name);
|
||||||
friend status_t get_input_devices(BList *list);
|
friend status_t get_input_devices(BList* list);
|
||||||
|
|
||||||
BInputDevice();
|
BInputDevice();
|
||||||
void set_name_and_type(const char *name,
|
void _SetNameAndType(const char* name,
|
||||||
input_device_type type);
|
input_device_type type);
|
||||||
|
|
||||||
char* fName;
|
char* fName;
|
||||||
input_device_type fType;
|
input_device_type fType;
|
||||||
uint32 _reserved[4];
|
uint32 _reserved[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,30 +1,14 @@
|
|||||||
//------------------------------------------------------------------------------
|
/*
|
||||||
// Copyright (c) 2001-2002, OpenBeOS
|
* Copyright (c) 2001-2008, Haiku, Inc.
|
||||||
//
|
* Distributed under the terms of the MIT license.
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
*
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
* Author: Marc Flerackers ([email protected])
|
||||||
// to deal in the Software without restriction, including without limitation
|
* Description: Functions and class to manage input devices.
|
||||||
// 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS 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.
|
|
||||||
//
|
|
||||||
// File Name: Input.cpp
|
|
||||||
// Author: Marc Flerackers ([email protected])
|
|
||||||
// Description: Functions and class to manage input devices.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include <Input.h>
|
#include <Input.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
@@ -50,15 +34,17 @@ find_input_device(const char *name)
|
|||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
BInputDevice *dev = new BInputDevice;
|
BInputDevice *dev = new (std::nothrow) BInputDevice;
|
||||||
|
if (dev == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
const char *device;
|
const char *device;
|
||||||
int32 type;
|
int32 type;
|
||||||
|
|
||||||
reply.FindString("device", &device);
|
reply.FindString("device", &device);
|
||||||
reply.FindInt32("type", &type);
|
reply.FindInt32("type", &type);
|
||||||
|
|
||||||
dev->set_name_and_type(device, (input_device_type)type);
|
dev->_SetNameAndType(device, (input_device_type)type);
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
@@ -84,11 +70,11 @@ get_input_devices(BList *list)
|
|||||||
while (reply.FindString("device", i, &name) == B_OK) {
|
while (reply.FindString("device", i, &name) == B_OK) {
|
||||||
reply.FindInt32("type", i++, &type);
|
reply.FindInt32("type", i++, &type);
|
||||||
|
|
||||||
BInputDevice *dev = new BInputDevice;
|
BInputDevice *dev = new (std::nothrow) BInputDevice;
|
||||||
|
if (dev != NULL) {
|
||||||
dev->set_name_and_type(name, (input_device_type)type);
|
dev->_SetNameAndType(name, (input_device_type)type);
|
||||||
|
list->AddItem(dev);
|
||||||
list->AddItem(dev);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@@ -244,17 +230,18 @@ BInputDevice::Control(input_device_type type, uint32 code,
|
|||||||
|
|
||||||
|
|
||||||
BInputDevice::BInputDevice()
|
BInputDevice::BInputDevice()
|
||||||
|
:
|
||||||
|
fName(NULL),
|
||||||
|
fType(B_UNDEFINED_DEVICE)
|
||||||
{
|
{
|
||||||
fName = NULL;
|
|
||||||
fType = B_UNDEFINED_DEVICE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BInputDevice::set_name_and_type(const char *name, input_device_type type)
|
BInputDevice::_SetNameAndType(const char *name, input_device_type type)
|
||||||
{
|
{
|
||||||
if (fName) {
|
if (fName) {
|
||||||
free (fName);
|
free(fName);
|
||||||
fName = NULL;
|
fName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,9 +255,12 @@ BInputDevice::set_name_and_type(const char *name, input_device_type type)
|
|||||||
status_t
|
status_t
|
||||||
_control_input_server_(BMessage *command, BMessage *reply)
|
_control_input_server_(BMessage *command, BMessage *reply)
|
||||||
{
|
{
|
||||||
if (!sInputServer)
|
if (!sInputServer) {
|
||||||
sInputServer = new BMessenger;
|
sInputServer = new (std::nothrow) BMessenger;
|
||||||
|
if (!sInputServer)
|
||||||
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sInputServer->IsValid())
|
if (!sInputServer->IsValid())
|
||||||
*sInputServer = BMessenger("application/x-vnd.Be-input_server", -1, NULL);
|
*sInputServer = BMessenger("application/x-vnd.Be-input_server", -1, NULL);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user