Used exceptions to handle errors on InitData(). I hope I didn't made
stupid errors, since I don't use exceptions usually. Feel free to beat me on this. Moved uninitialization to _DisposeData(). Corrected some styling issues pointed out by axel. Used fprintf instead of printf. Turned off debugging. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21450 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -78,6 +78,8 @@ class BWindowScreen : public BWindow {
|
|||||||
BWindowScreen &operator=(BWindowScreen& other);
|
BWindowScreen &operator=(BWindowScreen& other);
|
||||||
|
|
||||||
status_t _InitData(uint32 space, uint32 attributes);
|
status_t _InitData(uint32 space, uint32 attributes);
|
||||||
|
void _DisposeData();
|
||||||
|
|
||||||
status_t _SetActiveState(int32 state);
|
status_t _SetActiveState(int32 state);
|
||||||
status_t _SetupAccelerantHooks(bool enable);
|
status_t _SetupAccelerantHooks(bool enable);
|
||||||
status_t _GetCardInfo();
|
status_t _GetCardInfo();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2006, Haiku. All Rights Reserved.
|
* Copyright 2002-2007, Haiku. All Rights Reserved.
|
||||||
* Copyright 2002-2005,
|
* Copyright 2002-2005,
|
||||||
* Marcus Overhagen,
|
* Marcus Overhagen,
|
||||||
* Stefano Ceccherini ([email protected]),
|
* Stefano Ceccherini ([email protected]),
|
||||||
* Carwyn Jones ([email protected])
|
* Carwyn Jones ([email protected])
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
#include <input_globals.h>
|
#include <input_globals.h>
|
||||||
#include <InputServerTypes.h> // For IS_SET_MOUSE_POSITION
|
#include <InputServerTypes.h> // For IS_SET_MOUSE_POSITION
|
||||||
#include <WindowPrivate.h>
|
#include <WindowPrivate.h>
|
||||||
@@ -29,7 +31,7 @@
|
|||||||
using BPrivate::AppServerLink;
|
using BPrivate::AppServerLink;
|
||||||
|
|
||||||
|
|
||||||
#define TRACE_WINDOWSCREEN 1
|
#define TRACE_WINDOWSCREEN 0
|
||||||
#if TRACE_WINDOWSCREEN
|
#if TRACE_WINDOWSCREEN
|
||||||
#define CALLED() printf("%s\n", __PRETTY_FUNCTION__);
|
#define CALLED() printf("%s\n", __PRETTY_FUNCTION__);
|
||||||
#else
|
#else
|
||||||
@@ -312,19 +314,7 @@ BWindowScreen::BWindowScreen(const char *title, uint32 space,
|
|||||||
BWindowScreen::~BWindowScreen()
|
BWindowScreen::~BWindowScreen()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
Disconnect();
|
_DisposeData();
|
||||||
if (fAddonImage >= 0)
|
|
||||||
unload_add_on(fAddonImage);
|
|
||||||
|
|
||||||
delete_sem(fActivateSem);
|
|
||||||
delete_sem(fDebugSem);
|
|
||||||
|
|
||||||
if (fDebugState)
|
|
||||||
activate_workspace(fDebugWorkspace);
|
|
||||||
|
|
||||||
free(fDisplayMode);
|
|
||||||
free(fOriginalDisplayMode);
|
|
||||||
free(fModeList);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -679,51 +669,96 @@ BWindowScreen::_InitData(uint32 space, uint32 attributes)
|
|||||||
fAttributes = attributes;
|
fAttributes = attributes;
|
||||||
// TODO: not really used right now, but should probably be known by the app_server
|
// TODO: not really used right now, but should probably be known by the app_server
|
||||||
|
|
||||||
fWorkspaceIndex = fDebugWorkspace = current_workspace();
|
fWorkspaceIndex = current_workspace();
|
||||||
|
fDebugWorkspace = fWorkspaceIndex > 0 ? fWorkspaceIndex - 1 : 1;
|
||||||
fLockState = 0;
|
fLockState = 0;
|
||||||
fAddonImage = -1;
|
fAddonImage = -1;
|
||||||
fWindowState = 0;
|
fWindowState = 0;
|
||||||
|
fOriginalDisplayMode = NULL;
|
||||||
|
fDisplayMode = NULL;
|
||||||
|
fModeList = NULL;
|
||||||
|
fModeCount = 0;
|
||||||
|
fActivateSem = -1;
|
||||||
|
fDebugSem = -1;
|
||||||
|
fActivateState = 0;
|
||||||
|
fWorkState = 0;
|
||||||
|
|
||||||
// TODO: free resources upon failure!
|
status_t status = B_ERROR;
|
||||||
|
try {
|
||||||
|
fOriginalDisplayMode = new display_mode;
|
||||||
|
fDisplayMode = new display_mode;
|
||||||
|
|
||||||
BScreen screen(this);
|
BScreen screen(this);
|
||||||
status_t status = screen.GetModeList(&fModeList, &fModeCount);
|
status = screen.GetMode(fOriginalDisplayMode);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
throw status;
|
||||||
|
|
||||||
fDisplayMode = (display_mode *)malloc(sizeof(display_mode));
|
status = screen.GetModeList(&fModeList, &fModeCount);
|
||||||
if (fDisplayMode == NULL)
|
if (status < B_OK)
|
||||||
return B_NO_MEMORY;
|
throw status;
|
||||||
|
|
||||||
status = _GetModeFromSpace(space, fDisplayMode);
|
status = _GetModeFromSpace(space, fDisplayMode);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
throw status;
|
||||||
|
|
||||||
memcpy(fPalette, screen.ColorMap()->color_list, 256);
|
|
||||||
|
|
||||||
status = _GetCardInfo();
|
status = _GetCardInfo();
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
throw status;
|
||||||
|
|
||||||
fActivateSem = create_sem(0, "WindowScreen start lock");
|
fActivateSem = create_sem(0, "WindowScreen start lock");
|
||||||
if (fActivateSem < B_OK)
|
if (fActivateSem < B_OK)
|
||||||
return fActivateSem;
|
throw fActivateSem;
|
||||||
|
|
||||||
fActivateState = 0;
|
|
||||||
|
|
||||||
fDebugSem = create_sem(1, "WindowScreen debug sem");
|
fDebugSem = create_sem(1, "WindowScreen debug sem");
|
||||||
if (fDebugSem < B_OK)
|
if (fDebugSem < B_OK)
|
||||||
return fDebugSem;
|
throw fDebugSem;
|
||||||
|
|
||||||
|
memcpy(fPalette, screen.ColorMap()->color_list, 256);
|
||||||
|
fActivateState = 0;
|
||||||
fWorkState = 1;
|
fWorkState = 1;
|
||||||
|
|
||||||
fOriginalDisplayMode = (display_mode *)malloc(sizeof(display_mode));
|
} catch (std::bad_alloc) {
|
||||||
if (fOriginalDisplayMode == NULL)
|
status = B_NO_MEMORY;
|
||||||
return B_NO_MEMORY;
|
} catch (int error) {
|
||||||
|
status = error;
|
||||||
|
} catch (...) {
|
||||||
|
status = B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
screen.GetMode(fOriginalDisplayMode);
|
if (status != B_OK)
|
||||||
|
_DisposeData();
|
||||||
|
|
||||||
return B_OK;
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BWindowScreen::_DisposeData()
|
||||||
|
{
|
||||||
|
CALLED();
|
||||||
|
Disconnect();
|
||||||
|
if (fAddonImage >= 0) {
|
||||||
|
unload_add_on(fAddonImage);
|
||||||
|
fAddonImage = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_sem(fActivateSem);
|
||||||
|
fActivateSem = -1;
|
||||||
|
delete_sem(fDebugSem);
|
||||||
|
fDebugSem = -1;
|
||||||
|
|
||||||
|
if (fDebugState)
|
||||||
|
activate_workspace(fDebugWorkspace);
|
||||||
|
|
||||||
|
delete fDisplayMode;
|
||||||
|
fDisplayMode = NULL;
|
||||||
|
delete fOriginalDisplayMode;
|
||||||
|
fOriginalDisplayMode = NULL;
|
||||||
|
delete fModeList;
|
||||||
|
fModeList = NULL;
|
||||||
|
fModeCount = 0;
|
||||||
|
|
||||||
|
fLockState = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -733,7 +768,6 @@ BWindowScreen::_SetActiveState(int32 state)
|
|||||||
CALLED();
|
CALLED();
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
if (state == 1) {
|
if (state == 1) {
|
||||||
//be_app->HideCursor();
|
|
||||||
status = _AssertDisplayMode(fDisplayMode);
|
status = _AssertDisplayMode(fDisplayMode);
|
||||||
if (status == B_OK && (status = _SetupAccelerantHooks(true)) == B_OK) {
|
if (status == B_OK && (status = _SetupAccelerantHooks(true)) == B_OK) {
|
||||||
if (!fActivateState) {
|
if (!fActivateState) {
|
||||||
@@ -993,35 +1027,35 @@ BWindowScreen::_InitClone()
|
|||||||
link.ReadString(accelerantPath);
|
link.ReadString(accelerantPath);
|
||||||
fAddonImage = load_add_on(accelerantPath.String());
|
fAddonImage = load_add_on(accelerantPath.String());
|
||||||
if (fAddonImage < B_OK) {
|
if (fAddonImage < B_OK) {
|
||||||
printf("InitClone: cannot load accelerant image\n");
|
fprintf(stderr, "InitClone: cannot load accelerant image\n");
|
||||||
return fAddonImage;
|
return fAddonImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = get_image_symbol(fAddonImage, B_ACCELERANT_ENTRY_POINT,
|
status = get_image_symbol(fAddonImage, B_ACCELERANT_ENTRY_POINT,
|
||||||
B_SYMBOL_TYPE_TEXT, (void **)&fGetAccelerantHook);
|
B_SYMBOL_TYPE_TEXT, (void **)&fGetAccelerantHook);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
printf("InitClone: cannot get accelerant entry point\n");
|
fprintf(stderr, "InitClone: cannot get accelerant entry point\n");
|
||||||
unload_add_on(fAddonImage);
|
unload_add_on(fAddonImage);
|
||||||
fAddonImage = -1;
|
fAddonImage = -1;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
accelerant_clone_info_size clone_info_size;
|
accelerant_clone_info_size cloneInfoSizeHook;
|
||||||
get_accelerant_clone_info clone_info;
|
get_accelerant_clone_info cloneInfoHook;
|
||||||
clone_accelerant clone;
|
clone_accelerant cloneHook;
|
||||||
clone_info_size = (accelerant_clone_info_size)fGetAccelerantHook(B_ACCELERANT_CLONE_INFO_SIZE, NULL);
|
cloneInfoSizeHook = (accelerant_clone_info_size)fGetAccelerantHook(B_ACCELERANT_CLONE_INFO_SIZE, NULL);
|
||||||
clone_info = (get_accelerant_clone_info)fGetAccelerantHook(B_GET_ACCELERANT_CLONE_INFO, NULL);
|
cloneInfoHook = (get_accelerant_clone_info)fGetAccelerantHook(B_GET_ACCELERANT_CLONE_INFO, NULL);
|
||||||
clone = (clone_accelerant)fGetAccelerantHook(B_CLONE_ACCELERANT, NULL);
|
cloneHook = (clone_accelerant)fGetAccelerantHook(B_CLONE_ACCELERANT, NULL);
|
||||||
|
|
||||||
status = B_ERROR;
|
status = B_ERROR;
|
||||||
if (!clone_info_size || !clone_info || !clone) {
|
if (!cloneInfoSizeHook || !cloneInfoHook || !cloneHook) {
|
||||||
printf("InitClone: cannot get clone hook\n");
|
fprintf(stderr, "InitClone: cannot get clone hook\n");
|
||||||
unload_add_on(fAddonImage);
|
unload_add_on(fAddonImage);
|
||||||
fAddonImage = -1;
|
fAddonImage = -1;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t cloneInfoSize = clone_info_size();
|
ssize_t cloneInfoSize = cloneInfoSizeHook();
|
||||||
void *cloneInfo = malloc(cloneInfoSize);
|
void *cloneInfo = malloc(cloneInfoSize);
|
||||||
if (!cloneInfo) {
|
if (!cloneInfo) {
|
||||||
unload_add_on(fAddonImage);
|
unload_add_on(fAddonImage);
|
||||||
@@ -1029,15 +1063,15 @@ BWindowScreen::_InitClone()
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone_info(cloneInfo);
|
cloneInfoHook(cloneInfo);
|
||||||
// no way to see if this call fails
|
// no way to see if this call fails
|
||||||
|
|
||||||
status = clone(cloneInfo);
|
status = cloneHook(cloneInfo);
|
||||||
|
|
||||||
free(cloneInfo);
|
free(cloneInfo);
|
||||||
|
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
printf("InitClone: cannot clone accelerant\n");
|
fprintf(stderr, "InitClone: cannot clone accelerant\n");
|
||||||
unload_add_on(fAddonImage);
|
unload_add_on(fAddonImage);
|
||||||
fAddonImage = -1;
|
fAddonImage = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user