Devices working a bit now

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7287 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2004-04-21 18:55:56 +00:00
parent bbf495f47d
commit 62b323538c
18 changed files with 1109 additions and 401 deletions
+4 -6
View File
@@ -13,18 +13,16 @@ Devices by Sikosis
#include "Devices.h"
#include "DevicesWindows.h"
#include "DevicesViews.h"
#include "DevicesConstants.h"
#define APP_SIGNATURE "application/x-vnd.OBOS.Devices" // Application Signature and Title
// ---------------------------------------------------------------------------------------------------------- //
DevicesWindow *ptrDevicesWindow;
// Devices -- constructor
Devices::Devices() : BApplication (APP_SIGNATURE)
{
BRect DevicesWindowRect(0,0,396,400);
ptrDevicesWindow = new DevicesWindow(DevicesWindowRect);
new DevicesWindow(DevicesWindowRect);
}
// ---------------------------------------------------------------------------------------------------------- //
+68
View File
@@ -0,0 +1,68 @@
resource large_icon
{
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF00370000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF003737370000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037733737370000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FAFA373737370000FFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA37FAFA373737370000FFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA0037FA3700373737370000FFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA0000FA370000FA373737370000FFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA3700FA373700FA37FAFA37373700000808FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA2137FA37FAFAFA37FA37FAFA3737081B1B08FFFFFF"
$"FFFFFFFFFFFFFFFF0037373721FA37FA37FA37FA3737FA37081B1B08FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FAFA000037FA37C437FA373721081B1B0800FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA007B7B00FA37C4C4FAFA37370808081600FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037FA00DA7B7B00FA37C43737FAFA0816161600FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037002B2CDA7B0037FAFA3737373708160B1600FFFFFFFF"
$"FFFFFFFFFFFFFFFF0037002B2F2F0037373737FAFA733708160B1600FFFFFFFF"
$"FFFFFFFFFFFFFFFF00002B2CEB2F00FA3700373737FAFA0816161600FFFFFFFF"
$"FFFFFFFFFFFFFFFFFF002B2F2F0037FAFA00003737373708160B1600FFFFFFFF"
$"FFFFFFFFFFFFFFFF002B2CEB2F0037FA373700FAFA373708160B1600FFFFFFFF"
$"FFFF000000FFFFFF002B2F2F00FA37FA373737FA37FAFA0816161600FFFFFFFF"
$"FF007B7B7B00FF002B2CEB2F000037FA37FA37FA3737370816161600FFFFFFFF"
$"007B7B7BDA00FF002B2F2F000F0F000037FA37FA37C4370816161600FFFFFFFF"
$"002B2CDA7B7B002B2CEB2F00FFFF0F0F000037FA0000370816161600FFFFFFFF"
$"FF002B2CDA7B2B2CEB2F00FFFFFFFFFF0F0F00000FFF000816161600FFFFFFFF"
$"FF002B2CDA7B2B2CEB2F00FFFFFFFFFFFFFF0F0F0FFFFF00161616000F0FFFFF"
$"FFFF002B2C2B2B2F2F00FFFFFFFFFFFFFFFFFFFFFFFFFF00161616000F0F0F0F"
$"FFFF002B2C2B2B2F2F00FFFFFFFFFFFFFFFFFFFFFFFFFF0F0016000F0F0F0FFF"
$"FFFFFF002B2CEB2F00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F000F0F0F0FFFFF"
$"FFFFFF002B2CEB2F00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0F0F0FFFFFFFFF"
$"FFFFFFFF002B2F000E0F0F0F0F0F0F0F0F0FFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFF0000000E0F0F0F0F0F0F0F0F0F0FFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
resource mini_icon
{
$"FFFFFF2929FFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFF299F2929FFFFFFFFFFFFFFFFFF"
$"FFFFFF2970379F0129FFFFFFFFFFFFFF"
$"FFFFFF29FAFA773AB72929FFFFFFFFFF"
$"FFFFFF29913E91DC779797290000FFFF"
$"FFFFFF29907F71FA6BFA7197071329FF"
$"FFFFFF29717000FACB6B3E081400FFFF"
$"FFFFFF296B007B00AAFA71051129FFFF"
$"FFFFFF294B002F007171FA061129FFFF"
$"FFFFFF29002F0071DF7770071200FFFF"
$"FF00FF00002F006B3AFAFA061229FFFF"
$"002B00002F0097F951FA97081601FFFF"
$"002B7B2CEB00290097FA06071600FFFF"
$"FF002B2F00FFFF0F2900000616000FFF"
$"FF002B2F00FFFFFFFFFF0F000D000F0F"
$"FFFF00000E0F0F0F0FFFFFFF000F0FFF"
};
resource(1, "BEOS:FILE_TYPES") message;
resource app_signature "application/x-vnd.OBOS.Devices";
resource app_version
{
short_info = "OBOS-Devices",
long_info = "OpenBeOS version of Devices"
};
resource app_flags B_SINGLE_LAUNCH;
Binary file not shown.
-16
View File
@@ -1,16 +0,0 @@
/*
Devices Constants by Sikosis
(C)2003
*/
#ifndef __DEVICESCONSTANTS_H__
#define __DEVICESCONSTANTS_H__
// Constants ------------------------------------------------------------------------------------------------- //
const char *APP_SIGNATURE = "application/x-vnd.OBOS.Devices"; // Application Signature and Title
#endif
+166
View File
@@ -0,0 +1,166 @@
#include <strings.h>
#include <GraphicsDefs.h>
#include <String.h>
#include <View.h>
#include "DevicesInfo.h"
#include <stdio.h>
const char *base_desc[] = {
"Legacy",
"Mass Storage Controller",
"Network Controller", // "NIC"
"Display Controller",
"Multimedia Device",
"Memory Controller",
"Bridge Device",
"Communication Device",
"Motherboard Device", // "Generic System Peripheral"
"Input Device",
"Docking Station",
"Processor", // "CPU"
"Serial Bus Controller"
};
struct subtype_descriptions {
uchar base, subtype;
char *name;
} subtype_desc[] = {
{ 0, 0, "non-VGA" },
{ 0, 0, "VGA" },
{ 1, 0, "SCSI Controller" },
{ 1, 1, "IDE Controller" }, // "IDE"
{ 1, 2, "Floppy Controller" }, // "Floppy"
{ 1, 3, "IPI" },
{ 1, 4, "RAID" },
{ 2, 0, "Ethernet" },
{ 2, 1, "Token Ring" },
{ 2, 2, "FDDI" },
{ 2, 3, "ATM" },
{ 3, 0, "VGA" }, // "VGA/8514"
{ 3, 1, "XGA" },
{ 4, 0, "Video" },
{ 4, 1, "Sound" }, // was "Audio"
{ 5, 0, "RAM" },
{ 5, 1, "Flash Memory" }, // "Flash"
{ 6, 0, "Host bridge" }, // "Host"
{ 6, 1, "ISA bridge" }, // "ISA"
{ 6, 2, "EISA" },
{ 6, 3, "MCA" },
{ 6, 4, "PCI-PCI bridge"}, // "PCI-PCI"
{ 6, 5, "PCMCIA" },
{ 6, 6, "NuBus" },
{ 6, 7, "CardBus bridge" }, // "CardBus"
{ 7, 0, "Serial Port" }, // "Serial"
{ 7, 1, "Parallel Port" }, // "Parallel"
{ 8, 0, "PIC" },
{ 8, 1, "DMA" },
{ 8, 2, "Timer" },
{ 8, 3, "RTC" },
{ 9, 0, "Keyboard" },
{ 9, 1, "Digitizer" },
{ 9, 2, "Mouse" },
{10, 0, "Generic" },
{11, 0, "386" },
{11, 1, "486" },
{11, 2, "Pentium" },
{11,16, "Alpha" },
{11,32, "PowerPC" },
{11,48, "Coprocessor" },
{12, 0, "FireWire" }, // was "IEEE 1394"
{12, 1, "ACCESS" },
{12, 2, "SSA" },
{12, 3, "USB" },
{12, 4, "Fibre Channel" },
{255,255, NULL }
};
DevicesInfo::DevicesInfo(struct device_info *info,
struct device_configuration *current,
struct possible_device_configurations *possible)
: fInfo(info),
fCurrent(current),
fPossible(possible)
{
struct subtype_descriptions *s = NULL;
if (info->devtype.subtype != 0x80) {
s = subtype_desc;
while (s->name) {
if ((info->devtype.base == s->base) && (info->devtype.subtype == s->subtype))
break;
s++;
}
}
fName = strdup((info->devtype.base < 13)
? ( (s && s->name) ? s->name : base_desc[info->devtype.base])
: "Unknown");
}
DevicesInfo::~DevicesInfo()
{
delete fInfo;
delete fCurrent;
delete fPossible;
}
DeviceItem::DeviceItem(DevicesInfo *info, const char* name)
: BListItem(),
fInfo(info)
{
fName = strdup(name);
}
DeviceItem::~DeviceItem()
{
delete fName;
}
/***********************************************************
* DrawItem
***********************************************************/
void
DeviceItem::DrawItem(BView *owner, BRect itemRect, bool complete)
{
rgb_color kBlack = { 0,0,0,0 };
rgb_color kHighlight = { 156,154,156,0 };
if (IsSelected() || complete) {
rgb_color color;
if (IsSelected())
color = kHighlight;
else
color = owner->ViewColor();
owner->SetHighColor(color);
owner->SetLowColor(color);
owner->FillRect(itemRect);
owner->SetHighColor(kBlack);
} else {
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(5, 10);
owner->SetHighColor(kBlack);
owner->SetFont(be_plain_font);
owner->MovePenTo(point);
owner->DrawString(fName);
point += BPoint(223, 0);
BString string = "enabled";
if (!(fInfo->GetInfo()->flags & B_DEVICE_INFO_ENABLED))
switch (fInfo->GetInfo()->config_status) {
case B_DEV_RESOURCE_CONFLICT: string = "disabled by system"; break;
case B_DEV_DISABLED_BY_USER: string = "disabled by user"; break;
default: string = "disabled for unknown reason"; break;
}
owner->MovePenTo(point);
owner->DrawString(string.String());
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef __DEVICESINFO_H__
#define __DEVICESINFO_H__
#include <drivers/config_manager.h>
#include <ListItem.h>
class DevicesInfo
{
public:
DevicesInfo(struct device_info *info,
struct device_configuration *current,
struct possible_device_configurations *possible);
~DevicesInfo();
struct device_info * GetInfo() { return fInfo;}
char * GetName() const { return fName; }
struct device_configuration * GetCurrent() { return fCurrent;}
private:
struct device_info *fInfo;
struct device_configuration *fCurrent;
struct possible_device_configurations *fPossible;
char* fName;
};
class DeviceItem : public BListItem
{
public:
DeviceItem(DevicesInfo *info, const char* name);
~DeviceItem();
DevicesInfo *GetInfo() { return fInfo; }
virtual void DrawItem(BView *, BRect, bool = false);
private:
DevicesInfo *fInfo;
char* fName;
};
#endif
-80
View File
@@ -1,80 +0,0 @@
/*
DevicesViews by Sikosis
(C)2003 OBOS
*/
// Includes -------------------------------------------------------------------------------------------------- //
#include <Alert.h>
#include <Application.h>
#include <Screen.h>
#include <stdio.h>
#include <Window.h>
#include <View.h>
#include "DevicesWindows.h"
#include "DevicesViews.h"
//#include "DevicesConstants.h"
// ------------------------------------------------------------------------------------------------------------- //
// DevicesView - Constructor
DevicesView::DevicesView (BRect frame) : BView (frame, "DevicesView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
void DevicesView::Draw(BRect updateRect)
{
BRect r;
r = Bounds();
}
// ---------------------------------------------------------------------------------------------------------- //
// ResourceUsageView - Constructor
ResourceUsageView::ResourceUsageView (BRect frame) : BView (frame, "ResourceUsageView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
// IRQView - used in Resource Usage Window
IRQView::IRQView (BRect frame) : BView (frame, "IRQView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
// DMAView - used in Resource Usage Window
DMAView::DMAView (BRect frame) : BView (frame, "DMAView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
// IORangeView - used in Resource Usage Window
IORangeView::IORangeView (BRect frame) : BView (frame, "IORangeView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
// MemoryRangeView - used in Resource Usage Window
MemoryRangeView::MemoryRangeView (BRect frame) : BView (frame, "MemoryRangeView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
// ModemView - Constructor
ModemView::ModemView (BRect frame) : BView (frame, "ModemView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ---------------------------------------------------------------------------------------------------------- //
-67
View File
@@ -1,67 +0,0 @@
/*
Devices Views Header by Sikosis
(C)2003 OBOS
*/
#ifndef __DEVICESVIEWS_H__
#define __DEVICESVIEWS_H__
#include "Devices.h"
#include "DevicesWindows.h"
class DevicesView : public BView
{
public:
DevicesView(BRect frame);
virtual void Draw(BRect updateRect);
};
class ResourceUsageView : public BView
{
public:
ResourceUsageView(BRect frame);
};
class ModemView : public BView
{
public:
ModemView(BRect frame);
};
class IRQView : public BView
{
public:
IRQView(BRect frame);
};
class DMAView : public BView
{
public:
DMAView(BRect frame);
};
class IORangeView : public BView
{
public:
IORangeView(BRect frame);
};
class MemoryRangeView : public BView
{
public:
MemoryRangeView(BRect frame);
};
#endif
+267 -80
View File
@@ -2,7 +2,7 @@
Devices - DevicesWindow by Sikosis
(C)2003-2004 OBOS
(C)2003 OBOS
*/
@@ -13,6 +13,7 @@ Devices - DevicesWindow by Sikosis
#include <Bitmap.h>
#include <Box.h>
#include <Button.h>
#include <ClassInfo.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
@@ -31,13 +32,14 @@ Devices - DevicesWindow by Sikosis
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <String.h>
#include <StringView.h>
#include <Window.h>
#include <View.h>
#include "Devices.h"
#include "DevicesViews.h"
#include "DevicesWindows.h"
#include "DevicesInfo.h"
const uint32 MENU_FILE_ABOUT_DEVICES = 'mfad';
const uint32 MENU_FILE_QUIT = 'mfqt';
@@ -47,6 +49,7 @@ const uint32 MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM = 'mdcj';
const uint32 MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM = 'mdcm';
const uint32 MENU_DEVICES_RESOURCE_USAGE = 'mdru';
const uint32 BTN_CONFIGURE = 'bcfg';
const uint32 SELECTION_CHANGED = 'slch';
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
@@ -64,7 +67,7 @@ static void CenterWindowOnScreen(BWindow* w)
// DevicesWindow - Constructor
DevicesWindow::DevicesWindow(BRect frame) : BWindow (frame, "OBOS Devices", B_TITLED_WINDOW, B_NORMAL_WINDOW_FEEL , 0)
DevicesWindow::DevicesWindow(BRect frame) : BWindow (frame, "Devices", B_TITLED_WINDOW, B_NORMAL_WINDOW_FEEL , 0)
{
InitWindow();
CenterWindowOnScreen(this);
@@ -77,6 +80,37 @@ DevicesWindow::DevicesWindow(BRect frame) : BWindow (frame, "OBOS Devices", B_TI
BMessage msg;
msg.Unflatten(&file);
LoadSettings (&msg);
status_t error;
if ((error = init_cm_wrapper()) < 0) {
printf("Error initializing configuration manager (%s)\n", strerror(error));
exit(1);
}
InitDevices(B_ISA_BUS);
InitDevices(B_PCI_BUS);
for (int32 i=fList.CountItems()-1; i>=0; i--) {
DevicesInfo *deviceInfo = (DevicesInfo *) fList.ItemAt(i);
struct device_info *info = deviceInfo->GetInfo();
BListItem *item = systemMenu;
if (info->bus == B_ISA_BUS)
item = systemMenu;
else if (info->bus == B_PCI_BUS)
item = pciMenu;
outline->AddUnder(new DeviceItem(deviceInfo, deviceInfo->GetName()), item);
}
if (outline->CountItemsUnder(jumperedMenu, true)==0)
outline->AddUnder(new BStringItem("<no devices>"), jumperedMenu);
if (outline->CountItemsUnder(pciMenu, true)==0)
outline->AddUnder(new BStringItem("<no devices>"), pciMenu);
if (outline->CountItemsUnder(isaMenu, true)==0)
outline->AddUnder(new BStringItem("<no devices>"), isaMenu);
if (outline->CountItemsUnder(systemMenu, true)==0)
outline->AddUnder(new BStringItem("<no devices>"), systemMenu);
Show();
}
@@ -86,7 +120,10 @@ DevicesWindow::DevicesWindow(BRect frame) : BWindow (frame, "OBOS Devices", B_TI
// DevicesWindow - Destructor
DevicesWindow::~DevicesWindow()
{
exit(0);
void *item;
while ((item = fList.RemoveItem((int32)0)))
delete item;
uninit_cm_wrapper();
}
// ---------------------------------------------------------------------------------------------------------- //
@@ -99,76 +136,63 @@ void DevicesWindow::InitWindow(void)
BRect r;
r = Bounds(); // the whole view
BMenu *FileMenu;
BMenu *DevicesMenu;
BMenu *JumperedDevicesMenu;
BMenuItem *mniRemoveJumperedDevice;
// Add the menu bar
menubar = new BMenuBar(r, "menu_bar");
// Add File menu to menu bar
FileMenu = new BMenu("File");
FileMenu->AddItem(new BMenuItem("About Devices" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_ABOUT_DEVICES), 0));
FileMenu->AddSeparatorItem();
FileMenu->AddItem(new BMenuItem("Quit", new BMessage(MENU_FILE_QUIT), 'Q'));
BMenu *menu = new BMenu("File");
menu->AddItem(new BMenuItem("About Devices" B_UTF8_ELLIPSIS, new BMessage(MENU_FILE_ABOUT_DEVICES), 0));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Quit", new BMessage(MENU_FILE_QUIT), 'Q'));
menubar->AddItem(menu);
DevicesMenu = new BMenu("Devices");
JumperedDevicesMenu = new BMenu("New Jumpered Device");
JumperedDevicesMenu->AddItem(new BMenuItem("Custom ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM), 0));
JumperedDevicesMenu->AddItem(new BMenuItem("Modem ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM), 0));
menu = new BMenu("Devices");
menubar->AddItem(menu);
BMenu *jumperedDevicesMenu = new BMenu("New Jumpered Device");
jumperedDevicesMenu->AddItem(new BMenuItem("Custom ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_CUSTOM), 0));
jumperedDevicesMenu->AddItem(new BMenuItem("Modem ...", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM), 0));
//DevicesMenu->AddItem(new BMenuItem("New Jumpered Device", new BMessage(MENU_DEVICES_NEW_JUMPERED_DEVICE), NULL));
DevicesMenu->AddItem(JumperedDevicesMenu);
menu->AddItem(jumperedDevicesMenu);
DevicesMenu->AddItem(mniRemoveJumperedDevice = new BMenuItem("Remove Jumpered Device", new BMessage(MENU_DEVICES_REMOVE_JUMPERED_DEVICE), 'R'));
DevicesMenu->AddSeparatorItem();
DevicesMenu->AddItem(new BMenuItem("Resource Usage", new BMessage(MENU_DEVICES_RESOURCE_USAGE), 'U'));
menu->AddItem(mniRemoveJumperedDevice = new BMenuItem("Remove Jumpered Device", new BMessage(MENU_DEVICES_REMOVE_JUMPERED_DEVICE), 'R'));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Resource Usage", new BMessage(MENU_DEVICES_RESOURCE_USAGE), 'U'));
mniRemoveJumperedDevice->SetEnabled(false);
menubar->AddItem(FileMenu);
menubar->AddItem(DevicesMenu);
// Create the StringViews
stvDeviceName = new BStringView(BRect(LeftMargin, 16, 150, 40), "DeviceName", "Device Name");
stvCurrentState = new BStringView(BRect(RightMargin, 16, r.right-10, 40), "CurrentState", "Current State");
BStringView *stvIRQ;
BStringView *stvDMA;
BStringView *stvIORanges;
BStringView *stvMemoryRanges;
float fCurrentHeight = 280;
float fCurrentGap = 16;
stvIRQ = new BStringView(BRect(r.left+20,r.top+fCurrentHeight,r.left+80,r.top+fCurrentHeight+20),"IRQ","IRQs:");
float fCurrentHeight = 279;
float fCurrentGap = 15;
stvIRQ = new BStringView(BRect(r.left+22,r.top+fCurrentHeight,r.right-13,r.top+fCurrentHeight+20),"IRQ","IRQs:", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fCurrentHeight = fCurrentHeight + fCurrentGap;
stvDMA = new BStringView(BRect(r.left+20,r.top+fCurrentHeight,r.left+80,r.top+fCurrentHeight+20),"DMA","DMAs:");
stvDMA = new BStringView(BRect(r.left+22,r.top+fCurrentHeight,r.right-13,r.top+fCurrentHeight+20),"DMA","DMAs:", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fCurrentHeight = fCurrentHeight + fCurrentGap;
stvIORanges = new BStringView(BRect(r.left+20,r.top+fCurrentHeight,r.left+80,r.top+fCurrentHeight+20),"IORanges","IO Ranges:");
stvIORanges = new BStringView(BRect(r.left+22,r.top+fCurrentHeight,r.right-13,r.top+fCurrentHeight+20),"IORanges","IO Ranges:", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fCurrentHeight = fCurrentHeight + fCurrentGap;
stvMemoryRanges = new BStringView(BRect(r.left+20,r.top+fCurrentHeight,r.left+160,r.top+fCurrentHeight+20),"MemoryRanges","Memory Ranges:");
stvMemoryRanges = new BStringView(BRect(r.left+22,r.top+fCurrentHeight,r.right-13,r.top+fCurrentHeight+20),"MemoryRanges","Memory Ranges:", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fCurrentHeight = fCurrentHeight + fCurrentGap;
// Create the OutlineView
BRect outlinerect(r.left+12,r.top+50,r.right-29,r.top+262);
BOutlineListView *outline;
BListItem *topmenu;
BListItem *submenu;
BRect outlinerect(r.left+12,r.top+45,r.right-29,r.top+262);
BScrollView *outlinesv;
outline = new BOutlineListView(outlinerect,"devices_list", B_SINGLE_SELECTION_LIST);
outline->AddItem(topmenu = new BStringItem("System Devices"));
outline->AddUnder(new BStringItem("<no devices>"), topmenu);
outline->AddUnder(new BStringItem("<no devices>"), topmenu);
outline->AddItem(topmenu = new BStringItem("ISA/Plug and Play Devices"));
outline->AddUnder(submenu = new BStringItem("<no devices>"), topmenu);
outline->AddItem(topmenu = new BStringItem("PCI Devices"));
outline->AddUnder(submenu = new BStringItem("<no devices>"), topmenu);
outline->AddItem(topmenu = new BStringItem("Jumpered Devices"));
outline->AddUnder(submenu = new BStringItem("<no devices>"), topmenu);
outline = new BOutlineListView(outlinerect,"devices_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM);
outline->AddItem(systemMenu = new BStringItem("System Devices"));
outline->AddItem(isaMenu = new BStringItem("ISA/Plug and Play Devices"));
outline->AddItem(pciMenu = new BStringItem("PCI Devices"));
outline->AddItem(jumperedMenu = new BStringItem("Jumpered Devices"));
outline->SetSelectionMessage(new BMessage(SELECTION_CHANGED));
// Add ScrollView to Devices Window
outlinesv = new BScrollView("scroll_devices", outline, B_FOLLOW_LEFT|B_FOLLOW_TOP, 0, false, true, B_FANCY_BORDER);
outlinesv = new BScrollView("scroll_devices", outline, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER);
// Setup the OutlineView
outline->AllAttached();
@@ -187,43 +211,32 @@ void DevicesWindow::InitWindow(void)
// Create BBox (or Frame)
BBox *BottomFrame;
BRect BottomFrameRect(r.left+11,r.bottom-124,r.right-12,r.bottom-12);
BottomFrame = new BBox(BottomFrameRect, "BottomFrame", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW, B_FANCY_BORDER);
BottomFrame = new BBox(BottomFrameRect, "BottomFrame", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);
// Create BButton - Configure
BButton *btnConfigure;
BRect ConfigureButtonRect(r.left+298,r.bottom-44,r.right-23,r.bottom-20);
btnConfigure = new BButton(ConfigureButtonRect,"btnConfigure","Configure", new BMessage(BTN_CONFIGURE), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
BRect ConfigureButtonRect(r.left+298,r.bottom-47,r.right-23,r.bottom-23);
btnConfigure = new BButton(ConfigureButtonRect,"btnConfigure","Configure", new BMessage(BTN_CONFIGURE), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
btnConfigure->MakeDefault(true);
btnConfigure->SetEnabled(false);
// Create a basic View
AddChild(ptrDevicesView = new DevicesView(r));
BBox *background = new BBox(Bounds(), "background", B_FOLLOW_ALL_SIDES, B_WILL_DRAW, B_PLAIN_BORDER);
AddChild(background);
// Add Child(ren)
ptrDevicesView->AddChild(menubar);
ptrDevicesView->AddChild(stvDeviceName);
ptrDevicesView->AddChild(stvCurrentState);
ptrDevicesView->AddChild(stvIRQ);
ptrDevicesView->AddChild(stvDMA);
ptrDevicesView->AddChild(stvIORanges);
ptrDevicesView->AddChild(stvMemoryRanges);
ptrDevicesView->AddChild(outlinesv);
ptrDevicesView->AddChild(btnConfigure);
ptrDevicesView->AddChild(BottomFrame);
background->AddChild(menubar);
background->AddChild(stvDeviceName);
background->AddChild(stvCurrentState);
background->AddChild(stvIRQ);
background->AddChild(stvDMA);
background->AddChild(stvIORanges);
background->AddChild(stvMemoryRanges);
background->AddChild(outlinesv);
background->AddChild(btnConfigure);
background->AddChild(BottomFrame);
// Set Window Limits
SetSizeLimits(396,396,400,400);
}
// ---------------------------------------------------------------------------------------------------------- //
// DevicesWindow::FrameResized
void DevicesWindow::FrameResized (float width, float height)
{
BRect r;
r = Bounds();
// enforce width but not height
SetSizeLimits(396,396,400,BScreen().Frame().Height());
}
// ---------------------------------------------------------------------------------------------------------- //
@@ -257,8 +270,6 @@ void DevicesWindow::SaveSettings(void)
BMessage msg;
msg.AddRect("windowframe",Frame());
//printf("%i",outline->
BPath path;
status_t result = find_directory(B_USER_SETTINGS_DIRECTORY,&path);
if (result == B_OK)
@@ -272,7 +283,8 @@ void DevicesWindow::SaveSettings(void)
// DevicesWindow::MessageReceived -- receives messages
void DevicesWindow::MessageReceived (BMessage *message)
void
DevicesWindow::MessageReceived (BMessage *message)
{
switch(message->what)
{
@@ -288,14 +300,24 @@ void DevicesWindow::MessageReceived (BMessage *message)
break;
case MENU_DEVICES_NEW_JUMPERED_DEVICE_MODEM:
{
ptrModemWindow = new ModemWindow(BRect (0,0,200,194));
ptrModemWindow = new ModemWindow(BRect(0,0,200,194), BMessenger(this));
}
break;
case MENU_DEVICES_RESOURCE_USAGE:
{
ptrResourceUsageWindow = new ResourceUsageWindow(BRect (0,0,430,350));
ptrResourceUsageWindow = new ResourceUsageWindow(BRect(0,0,430,350), fList);
}
break;
break;
case SELECTION_CHANGED:
{
UpdateDeviceInfo();
}
break;
case MODEM_ADDED:
{
}
break;
default:
BWindow::MessageReceived(message);
break;
@@ -303,3 +325,168 @@ void DevicesWindow::MessageReceived (BMessage *message)
}
// ---------------------------------------------------------------------------------------------------------- //
void
DevicesWindow::InitDevices(bus_type bus)
{
status_t size;
uint64 cookie;
struct device_info dummy, *info;
struct device_configuration *current;
struct possible_device_configurations *possible;
cookie = 0;
while (get_next_device_info(bus, &cookie, &dummy, sizeof(dummy)) == B_OK) {
info = (struct device_info *)malloc(dummy.size);
if (!info) {
printf("Out of core\n");
break;
}
if (get_device_info_for(cookie, info, dummy.size) != B_OK) {
printf("Error getting device information\n");
break;
}
size = get_size_of_current_configuration_for(cookie);
if (size < B_OK) {
printf("Error getting the size of the current configuration\n");
break;
}
current = (struct device_configuration *)malloc(size);
if (!current) {
printf("Out of core\n");
break;
}
if (get_current_configuration_for(cookie, current, size) != B_OK) {
printf("Error getting the current configuration\n");
break;
}
size = get_size_of_possible_configurations_for(cookie);
if (size < B_OK) {
printf("Error getting the size of the possible configurations\n");
break;
}
possible = (struct possible_device_configurations *)malloc(size);
if (!possible) {
printf("Out of core\n");
break;
}
if (get_possible_configurations_for(cookie, possible, size) != B_OK) {
printf("Error getting the possible configurations\n");
break;
}
fList.AddItem(new DevicesInfo(info, current, possible));
}
}
void
DevicesWindow::UpdateDeviceInfo()
{
DeviceItem *item = (DeviceItem *)outline->ItemAt(outline->CurrentSelection());
if (item && is_instance_of(item, DeviceItem) ) {
DevicesInfo *deviceInfo = item->GetInfo();
struct device_configuration *current = deviceInfo->GetCurrent();
resource_descriptor r;
{
BString text = "IRQs: ";
bool first = true;
int32 num = count_resource_descriptors_of_type(current, B_IRQ_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_IRQ_RESOURCE,
&r, sizeof(resource_descriptor));
uint32 mask = r.d.m.mask;
int i = 0;
if (!mask)
continue;
for (;mask;mask>>=1,i++)
if (mask & 1) {
char value[50];
sprintf(value, "%s%d", first ? "" : ",", i);
text += value;
first = false;
}
}
stvIRQ->SetText(text.String());
}
{
BString text = "DMAs: ";
bool first = true;
int32 num = count_resource_descriptors_of_type(current, B_DMA_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_DMA_RESOURCE,
&r, sizeof(resource_descriptor));
uint32 mask = r.d.m.mask;
int i = 0;
if (!mask)
continue;
for (;mask;mask>>=1,i++)
if (mask & 1) {
char value[50];
sprintf(value, "%s%d", first ? "" : ",", i);
text += value;
first = false;
}
}
stvDMA->SetText(text.String());
}
{
BString text = "IO Ranges: ";
bool first = true;
int32 num = count_resource_descriptors_of_type(current, B_IO_PORT_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_IO_PORT_RESOURCE,
&r, sizeof(resource_descriptor));
char value[50];
sprintf(value, "%s0x%04lx - 0x%04lx", first ? "" : ", ", r.d.r.minbase, r.d.r.minbase + r.d.r.len - 1);
text += value;
first = false;
}
if (text.Length()>70) {
text.Truncate(70);
text += "...";
}
stvIORanges->SetText(text.String());
}
{
BString text = "Memory Ranges: ";
bool first = true;
int32 num = count_resource_descriptors_of_type(current, B_MEMORY_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_MEMORY_RESOURCE,
&r, sizeof(resource_descriptor));
char value[50];
sprintf(value, "%s0x%06lx - 0x%06lx", first ? "" : ", ", r.d.r.minbase, r.d.r.minbase + r.d.r.len - 1);
text += value;
first = false;
}
if (text.Length()>70) {
text.Truncate(70);
text += "...";
}
stvMemoryRanges->SetText(text.String());
}
btnConfigure->SetEnabled(true);
} else {
stvIRQ->SetText("IRQs: ");
stvDMA->SetText("DMAs: ");
stvIORanges->SetText("IO Ranges: ");
stvMemoryRanges->SetText("Memory Ranges: ");
btnConfigure->SetEnabled(false);
}
}
+19 -18
View File
@@ -10,24 +10,19 @@ Devices Windows Header by Sikosis
#define __DEVICESWINDOWS_H__
#include "Devices.h"
#include "DevicesViews.h"
class DevicesView;
class ResourceUsageView;
class IRQView;
class ModemView;
#include "cm_wrapper.h"
#define MODEM_ADDED 'moad'
class ResourceUsageWindow : public BWindow
{
public:
ResourceUsageWindow(BRect frame);
ResourceUsageWindow(BRect frame, BList &);
~ResourceUsageWindow();
virtual void MessageReceived(BMessage *message);
private:
void InitWindow(void);
ResourceUsageView* ptrResourceUsageView;
IRQView* ptrIRQView;
void InitWindow(BList &);
BTabView *tabView;
BTab *tab;
};
@@ -36,16 +31,12 @@ class ResourceUsageWindow : public BWindow
class ModemWindow : public BWindow
{
public:
ModemWindow(BRect frame);
ModemWindow(BRect frame, BMessenger);
~ModemWindow();
virtual void MessageReceived(BMessage *message);
private:
void InitWindow(void);
ModemView* ptrModemView;
BBox *boxInternalModem;
BButton *btnAdd;
BButton *btnCancel;
BMessenger fMessenger;
};
@@ -56,11 +47,13 @@ class DevicesWindow : public BWindow
~DevicesWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void FrameResized(float width, float height);
private:
void InitWindow(void);
void InitDevices(bus_type bus);
void LoadSettings(BMessage *msg);
void SaveSettings(void);
void UpdateDeviceInfo();
ResourceUsageWindow* ptrResourceUsageWindow;
ModemWindow* ptrModemWindow;
@@ -68,7 +61,15 @@ class DevicesWindow : public BWindow
BStringView *stvCurrentState;
BMenuBar *menubar;
DevicesView* ptrDevicesView;
BList fList;
BListItem *systemMenu, *isaMenu, *pciMenu, *jumperedMenu;
BOutlineListView *outline;
BStringView *stvIRQ;
BStringView *stvDMA;
BStringView *stvIORanges;
BStringView *stvMemoryRanges;
BButton *btnConfigure;
};
#endif
+3 -2
View File
@@ -1,15 +1,16 @@
SubDir OBOS_TOP src prefs devices ;
AddResources Devices : Devices.rsrc ;
AddResources Devices : Devices.rdef ;
UsePrivateHeaders Devices ;
Preference Devices :
Devices.cpp
DevicesWindow.cpp
DevicesViews.cpp
ResourceUsageWindow.cpp
ModemWindow.cpp
cm_wrapper.c
DevicesInfo.cpp
;
LinkSharedOSLibs Devices : be ;
-29
View File
@@ -1,29 +0,0 @@
/*
ModemView
Author: Sikosis
(C)2003 OBOS - Released under the MIT License
*/
// Includes ------------------------------------------------------------------------------------------ //
#include <Alert.h>
#include <Application.h>
#include <Screen.h>
#include <stdio.h>
#include <Window.h>
#include <View.h>
#include "DevicesWindows.h"
#include "DevicesViews.h"
// -------------------------------------------------------------------------------------------------- //
// ModemView - Constructor
ModemView::ModemView (BRect frame) : BView (frame, "ModemView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ------------------------------------------------------------------------------------------------- //
+66 -23
View File
@@ -12,16 +12,19 @@ Author: Sikosis
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <MenuItem.h>
#include <MenuField.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <stdio.h>
#include <String.h>
#include <TextView.h>
#include <Window.h>
#include <View.h>
#include "Devices.h"
#include "DevicesWindows.h"
#include "DevicesViews.h"
// -------------------------------------------------------------------------------------------------- //
const uint32 BTN_ADD = 'badd';
const uint32 BTN_CANCEL = 'bcnl';
@@ -41,7 +44,9 @@ static void CenterWindowOnScreen(BWindow* w)
// ModemWindow - Constructor
ModemWindow::ModemWindow(BRect frame) : BWindow (frame, "ModemWindow", B_MODAL_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 0)
ModemWindow::ModemWindow(BRect frame, BMessenger messenger)
: BWindow (frame, "ModemWindow", B_MODAL_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE),
fMessenger(messenger)
{
InitWindow();
CenterWindowOnScreen(this);
@@ -57,40 +62,72 @@ ModemWindow::~ModemWindow()
}
// -------------------------------------------------------------------------------------------------- //
/*BBox(BRect frame, const char *name = NULL,
  
    uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
      uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | 
            B_NAVIGABLE_JUMP,
      border_style border = B_FANCY_BORDER)*/
// ModemWindow::InitWindow -- Initialization Commands here
void ModemWindow::InitWindow(void)
{
BRect r;
r = Bounds();
boxInternalModem = new BBox(BRect (r.left+10,r.top+15,r.right-10,r.bottom-50),
" Internal Modem ", B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW, B_FANCY_BORDER);
BBox *background = new BBox(r, "background", B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW, B_PLAIN_BORDER);
AddChild(background);
BRect CancelButtonRect(24,r.bottom-37,100,r.bottom-13);
btnCancel = new BButton(CancelButtonRect,"btnCancel","Cancel",
BBox *boxInternalModem = new BBox(BRect (r.left+9,r.top+9,r.right-11,r.bottom-44),
"boxInternalModem", B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW, B_FANCY_BORDER);
boxInternalModem->SetLabel("Internal Modem");
boxInternalModem->SetFont(be_plain_font);
rgb_color black = {0,0,0};
BRect rect = boxInternalModem->Bounds();
rect.left += 9;
rect.top += 58;
rect.right -= 11;
rect.bottom -= 20;
BRect textRect(rect);
textRect.OffsetTo(B_ORIGIN);
textRect.InsetBy(1,1);
BTextView *textView = new BTextView(rect, "text", textRect, be_plain_font, &black, B_FOLLOW_TOP | B_FOLLOW_LEFT, B_WILL_DRAW);
textView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
textView->SetText("This is intended for configuring\n"
"jumpered modem only. Plug and\n"
"Play modems are automatically\n"
"detected by the system.");
boxInternalModem->AddChild(textView);
BRect CancelButtonRect(29,r.bottom-34,104,r.bottom-13);
BButton *btnCancel = new BButton(CancelButtonRect,"btnCancel","Cancel",
new BMessage(BTN_CANCEL), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BRect AddButtonRect(115,r.bottom-37,r.right - 10,r.bottom-13);
btnAdd = new BButton(AddButtonRect,"btnAdd","Add",
BRect AddButtonRect(115,r.bottom-34,r.right - 10,r.bottom-13);
BButton *btnAdd = new BButton(AddButtonRect,"btnAdd","Add",
new BMessage(BTN_ADD), B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
btnAdd->MakeDefault(true);
btnAdd->MakeDefault(true);
rect = boxInternalModem->Bounds();
rect.top += 28;
rect.left += 38;
rect.right = rect.left + 105;
rect.bottom = rect.top + 5;
BPopUpMenu *serialMenu = new BPopUpMenu("pick one");
BMenuItem *item;
serialMenu->AddItem(item = new BMenuItem("serial3 ", NULL));
item->SetMarked(true);
serialMenu->AddItem(item = new BMenuItem("serial4 ", NULL));
BMenuField *serialMenuField = new BMenuField(rect, "serialMenuField",
"Port:", serialMenu);
serialMenuField->SetDivider(40.0);
serialMenuField->SetAlignment(B_ALIGN_RIGHT);
boxInternalModem->AddChild(serialMenuField);
// Create the Views
AddChild(ptrModemView = new ModemView(r));
ptrModemView->AddChild(boxInternalModem);
ptrModemView->AddChild(btnCancel);
ptrModemView->AddChild(btnAdd);
background->AddChild(boxInternalModem);
background->AddChild(btnCancel);
background->AddChild(btnAdd);
}
// -------------------------------------------------------------------------------------------------- //
@@ -105,6 +142,12 @@ void ModemWindow::MessageReceived (BMessage *message)
Quit();
}
break;
case BTN_ADD:
{
fMessenger.SendMessage(MODEM_ADDED);
Quit();
}
break;
default:
BWindow::MessageReceived(message);
break;
-29
View File
@@ -1,29 +0,0 @@
/*
ResourceUsageView
Author: Sikosis
(C)2003 OBOS - Released under the MIT License
*/
// Includes ------------------------------------------------------------------------------------------ //
#include <Alert.h>
#include <Application.h>
#include <Screen.h>
#include <stdio.h>
#include <Window.h>
#include <View.h>
#include "DevicesWindows.h"
#include "DevicesViews.h"
// -------------------------------------------------------------------------------------------------- //
// ResourceUsageView - Constructor
ResourceUsageView::ResourceUsageView (BRect frame) : BView (frame, "ResourceUsageView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW )
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
// ------------------------------------------------------------------------------------------------- //
+274 -51
View File
@@ -4,12 +4,13 @@ ResourceUsageWindow
Author: Sikosis
(C)2003-2004 OBOS - Released under the MIT License
(C)2003 OBOS - Released under the MIT License
*/
// Includes ------------------------------------------------------------------------------------------ //
#include <Application.h>
#include <Box.h>
#include <List.h>
#include <ListView.h>
#include <Path.h>
@@ -22,14 +23,161 @@ Author: Sikosis
#include <View.h>
#include "Devices.h"
#include "DevicesInfo.h"
#include "DevicesWindows.h"
#include "DevicesViews.h"
class IRQDMAItem : public BListItem
{
public:
IRQDMAItem(int32 number, const char* name);
~IRQDMAItem();
virtual void DrawItem(BView *, BRect, bool = false);
private:
char* fName;
int32 fNumber;
};
IRQDMAItem::IRQDMAItem(int32 number, const char* name)
: BListItem(),
fNumber(number)
{
fName = strdup(name);
}
IRQDMAItem::~IRQDMAItem()
{
delete fName;
}
/***********************************************************
* DrawItem
***********************************************************/
void
IRQDMAItem::DrawItem(BView *owner, BRect itemRect, bool complete)
{
rgb_color kBlack = { 0,0,0,0 };
rgb_color kHighlight = { 156,154,156,0 };
if (IsSelected() || complete) {
rgb_color color;
if (IsSelected())
color = kHighlight;
else
color = owner->ViewColor();
owner->SetHighColor(color);
owner->SetLowColor(color);
owner->FillRect(itemRect);
owner->SetHighColor(kBlack);
} else {
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(5, 10);
owner->SetHighColor(kBlack);
owner->SetFont(be_plain_font);
owner->MovePenTo(point);
if (fNumber > -1) {
char string[2];
sprintf(string, "%ld", fNumber);
owner->DrawString(string);
}
point += BPoint(28, 0);
owner->MovePenTo(point);
owner->DrawString(fName);
}
class RangeItem : public BListItem
{
public:
RangeItem(uint32 lowAddress, uint32 highAddress, const char* name);
~RangeItem();
virtual void DrawItem(BView *, BRect, bool = false);
static int Compare(const void *firstArg, const void *secondArg);
private:
char* fName;
uint32 fLowAddress, fHighAddress;
};
RangeItem::RangeItem(uint32 lowAddress, uint32 highAddress, const char* name)
: BListItem(),
fLowAddress(lowAddress),
fHighAddress(highAddress)
{
fName = strdup(name);
}
RangeItem::~RangeItem()
{
delete fName;
}
/***********************************************************
* DrawItem
***********************************************************/
void
RangeItem::DrawItem(BView *owner, BRect itemRect, bool complete)
{
rgb_color kBlack = { 0,0,0,0 };
rgb_color kHighlight = { 156,154,156,0 };
if (IsSelected() || complete) {
rgb_color color;
if (IsSelected())
color = kHighlight;
else
color = owner->ViewColor();
owner->SetHighColor(color);
owner->SetLowColor(color);
owner->FillRect(itemRect);
owner->SetHighColor(kBlack);
} else {
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(17, 10);
owner->SetFont(be_fixed_font);
owner->SetHighColor(kBlack);
owner->MovePenTo(point);
if (fLowAddress >= 0) {
char string[255];
sprintf(string, "0x%04lx - 0x%04lx", fLowAddress, fHighAddress);
owner->DrawString(string);
}
point += BPoint(174, 0);
owner->SetFont(be_plain_font);
owner->MovePenTo(point);
owner->DrawString(fName);
}
int
RangeItem::Compare(const void *firstArg, const void *secondArg)
{
const RangeItem *item1 = *static_cast<const RangeItem * const *>(firstArg);
const RangeItem *item2 = *static_cast<const RangeItem * const *>(secondArg);
if (item1->fLowAddress < item2->fLowAddress) {
return -1;
} else if (item1->fLowAddress > item2->fLowAddress) {
return 1;
} else
return 0;
}
// -------------------------------------------------------------------------------------------------- //
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
static void CenterWindowOnScreen(BWindow* w)
{
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
BRect screenFrame = (BScreen().Frame());
BPoint pt;
pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2;
pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2;
@@ -41,9 +189,10 @@ static void CenterWindowOnScreen(BWindow* w)
// ResourceUsageWindow - Constructor
ResourceUsageWindow::ResourceUsageWindow(BRect frame) : BWindow (frame, "Resource Usage", B_TITLED_WINDOW, B_MODAL_SUBSET_WINDOW_FEEL , 0)
ResourceUsageWindow::ResourceUsageWindow(BRect frame, BList &list)
: BWindow (frame, "Resource Usage", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL , B_NOT_ZOOMABLE|B_NOT_RESIZABLE)
{
InitWindow();
InitWindow(list);
CenterWindowOnScreen(this);
Show();
}
@@ -53,76 +202,151 @@ ResourceUsageWindow::ResourceUsageWindow(BRect frame) : BWindow (frame, "Resourc
// ResourceUsageWindow - Destructor
ResourceUsageWindow::~ResourceUsageWindow()
{
//exit(0);
}
// -------------------------------------------------------------------------------------------------- //
// ResourceUsageWindow::InitWindow -- Initialization Commands here
void ResourceUsageWindow::InitWindow(void)
void ResourceUsageWindow::InitWindow(BList &list)
{
BRect r;
BRect rtab;
BRect rlist;
r = Bounds();
rtab = Bounds();
rtab.top += 10;
rlist = Bounds();
BRect rtab = Bounds();
BRect rlist = Bounds();
rtab.top += 10;
rlist.top += 10;
rlist.left += 12;
rlist.right -= 15;
rlist.right -= 15 + B_V_SCROLL_BAR_WIDTH;
rlist.bottom -= 47;
ptrIRQView = new IRQView(r);
// Create the TabView and Tabs
// Create the TabView and Tabs
tabView = new BTabView(rtab,"resource_usage_tabview");
tabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rtab = tabView->Bounds();
rtab.InsetBy(5,5);
tab = new BTab();
tabView->AddTab(ptrIRQView, tab);
tab->SetLabel("IRQ");
tab = new BTab();
tabView->AddTab(new DMAView(r), tab);
tab->SetLabel("DMA");
tab = new BTab();
tabView->AddTab(new IORangeView(r), tab);
tab->SetLabel("IO Range");
tab = new BTab();
tabView->AddTab(new MemoryRangeView(r), tab);
tab->SetLabel("Memory Range");
// Create the ListViews
BListView *IRQListView;
BListView *DMAListView;
IRQListView = new BListView(rlist, "IRQListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
BListView *IRQListView = new BListView(rlist, "IRQListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
DMAListView = new BListView(rlist, "DMAListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
BListView *DMAListView = new BListView(rlist, "DMAListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *IORangeListView = new BListView(rlist, "IORangeListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *memoryListView = new BListView(rlist, "memoryListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BString tmp;
tmp.SetTo("0 Timer");
Lock();
IRQListView->AddItem(new BStringItem(tmp.String()));
Unlock();
ptrIRQView->AddChild(IRQListView);
// write function to add items to IRQ list
// write another function that just deals with getting the IRQ list
BScrollView *IRQScrollView = new BScrollView("scroll_list1", IRQListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
BScrollView *DMAScrollView = new BScrollView("scroll_list2", DMAListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
BScrollView *IORangeScrollView = new BScrollView("scroll_list3", IORangeListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
BScrollView *memoryScrollView = new BScrollView("scroll_list4", memoryListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
// Create the Views
AddChild(ptrResourceUsageView = new ResourceUsageView(r));
ptrResourceUsageView->AddChild(tabView);
tab = new BTab();
tabView->AddTab(IRQScrollView, tab);
tab->SetLabel("IRQ");
tab = new BTab();
tabView->AddTab(DMAScrollView, tab);
tab->SetLabel("DMA");
tab = new BTab();
tabView->AddTab(IORangeScrollView, tab);
tab->SetLabel("IO Range");
tab = new BTab();
tabView->AddTab(memoryScrollView, tab);
tab->SetLabel("Memory Range");
{
uint32 mask = 1;
for (int i=0;i<16;mask<<=1,i++) {
bool first = true;
for (int32 j=0; j<list.CountItems(); j++) {
DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
struct device_configuration *current = deviceInfo->GetCurrent();
resource_descriptor r;
int32 num = count_resource_descriptors_of_type(current, B_IRQ_RESOURCE);
for (int32 k=0;k<num;k++) {
get_nth_resource_descriptor_of_type(current, k, B_IRQ_RESOURCE,
&r, sizeof(resource_descriptor));
if (mask & r.d.m.mask) {
IRQListView->AddItem(new IRQDMAItem(first ? i : -1, deviceInfo->GetName()));
first = false;
}
}
}
if (first) {
IRQListView->AddItem(new IRQDMAItem(i, ""));
}
}
}
{
uint32 mask = 1;
for (int i=0;i<8;mask<<=1,i++) {
bool first = true;
for (int32 j=0; j<list.CountItems(); j++) {
DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
struct device_configuration *current = deviceInfo->GetCurrent();
resource_descriptor r;
int32 num = count_resource_descriptors_of_type(current, B_DMA_RESOURCE);
for (int32 k=0;k<num;k++) {
get_nth_resource_descriptor_of_type(current, k, B_DMA_RESOURCE,
&r, sizeof(resource_descriptor));
if (mask & r.d.m.mask) {
DMAListView->AddItem(new IRQDMAItem(first ? i : -1, deviceInfo->GetName()));
first = false;
}
}
}
if (first) {
DMAListView->AddItem(new IRQDMAItem(i, ""));
}
}
}
{
for (int32 j=0; j<list.CountItems(); j++) {
DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
struct device_configuration *current = deviceInfo->GetCurrent();
resource_descriptor r;
int32 num = count_resource_descriptors_of_type(current, B_IO_PORT_RESOURCE);
for (int32 k=0;k<num;k++) {
get_nth_resource_descriptor_of_type(current, k, B_IO_PORT_RESOURCE,
&r, sizeof(resource_descriptor));
IORangeListView->AddItem(new RangeItem(r.d.r.minbase, r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetName()));
}
}
IORangeListView->SortItems(&RangeItem::Compare);
}
BBox *background = new BBox(Bounds(), "background");
background->SetBorder(B_NO_BORDER);
AddChild(background);
background->AddChild(tabView);
}
// -------------------------------------------------------------------------------------------------- //
// ResourceUsageWindow::MessageReceived -- receives messages
void ResourceUsageWindow::MessageReceived (BMessage *message)
void
ResourceUsageWindow::MessageReceived (BMessage *message)
{
switch(message->what)
{
@@ -132,4 +356,3 @@ void ResourceUsageWindow::MessageReceived (BMessage *message)
}
}
// -------------------------------------------------------------------------------------------------- //
+141
View File
@@ -0,0 +1,141 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "cm_wrapper.h"
#include "config_driver.h"
static int fd;
status_t init_cm_wrapper(void)
{
static const char device[] = "/dev/" CM_DEVICE_NAME;
fd = open(device, 0);
if (fd < 0)
return errno;
return B_OK;
}
status_t uninit_cm_wrapper(void)
{
close(fd);
return B_OK;
}
status_t get_next_device_info(bus_type bus, uint64 *cookie,
struct device_info *info, uint32 size)
{
status_t result;
struct cm_ioctl_data params;
params.magic = CM_GET_NEXT_DEVICE_INFO;
params.bus = bus;
params.cookie = *cookie;
params.data = (void *)info;
params.data_len = size;
result = ioctl(fd, params.magic, &params, sizeof(params));
if (result == B_OK) *cookie = params.cookie;
return result;
}
status_t get_device_info_for(uint64 id, struct device_info *info,
uint32 size)
{
struct cm_ioctl_data params;
params.magic = CM_GET_DEVICE_INFO_FOR;
params.cookie = id;
params.data = (void *)info;
params.data_len = size;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t get_size_of_current_configuration_for(uint64 id)
{
struct cm_ioctl_data params;
params.magic = CM_GET_SIZE_OF_CURRENT_CONFIGURATION_FOR;
params.cookie = id;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t get_current_configuration_for(uint64 id,
struct device_configuration *current, uint32 size)
{
struct cm_ioctl_data params;
params.magic = CM_GET_CURRENT_CONFIGURATION_FOR;
params.cookie = id;
params.data = (void *)current;
params.data_len = size;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t get_size_of_possible_configurations_for(uint64 id)
{
struct cm_ioctl_data params;
params.magic = CM_GET_SIZE_OF_POSSIBLE_CONFIGURATIONS_FOR;
params.cookie = id;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t get_possible_configurations_for(uint64 id,
struct possible_device_configurations *possible, uint32 size)
{
struct cm_ioctl_data params;
params.magic = CM_GET_POSSIBLE_CONFIGURATIONS_FOR;
params.cookie = id;
params.data = (void *)possible;
params.data_len = size;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t count_resource_descriptors_of_type(
struct device_configuration *c, resource_type type)
{
struct cm_ioctl_data params;
params.magic = CM_COUNT_RESOURCE_DESCRIPTORS_OF_TYPE;
params.config = c;
params.type = type;
return ioctl(fd, params.magic, &params, sizeof(params));
}
status_t get_nth_resource_descriptor_of_type(
struct device_configuration *c, uint32 n,
resource_type type, resource_descriptor *d, uint32 size)
{
struct cm_ioctl_data params;
params.magic = CM_GET_NTH_RESOURCE_DESCRIPTOR_OF_TYPE;
params.config = c;
params.n = n;
params.type = type;
params.data = d;
params.data_len = size;
return ioctl(fd, params.magic, &params, sizeof(params));
}
uchar mask_to_value(uint32 mask)
{
uchar value;
if (!mask) return 0;
for (value=0,mask>>=1;mask;value++,mask>>=1)
;
return value;
}
+36
View File
@@ -0,0 +1,36 @@
#ifndef _CM_WRAPPER_H_
#define _CM_WRAPPER_H_
#include <drivers/config_manager.h>
#ifdef __cplusplus
extern "C" {
#endif
status_t init_cm_wrapper(void);
status_t uninit_cm_wrapper(void);
status_t get_next_device_info(bus_type bus, uint64 *cookie,
struct device_info *info, uint32 size);
status_t get_device_info_for(uint64 id, struct device_info *info,
uint32 size);
status_t get_size_of_current_configuration_for(uint64 id);
status_t get_current_configuration_for(uint64 id,
struct device_configuration *current, uint32 size);
status_t get_size_of_possible_configurations_for(uint64 id);
status_t get_possible_configurations_for(uint64 id,
struct possible_device_configurations *possible, uint32 size);
status_t count_resource_descriptors_of_type(
struct device_configuration *c, resource_type type);
status_t get_nth_resource_descriptor_of_type(
struct device_configuration *c, uint32 n, resource_type type,
resource_descriptor *d, uint32 size);
uchar mask_to_value(uint32 mask);
#ifdef __cplusplus
}
#endif
#endif
+29
View File
@@ -0,0 +1,29 @@
#ifndef _CONFIG_MANAGER_DRIVER_H_
#define _CONFIG_MANAGER_DRIVER_H_
/* the magic is the ioctl */
#define CM_GET_NEXT_DEVICE_INFO 'GNDI'
#define CM_GET_DEVICE_INFO_FOR 'GDIF'
#define CM_GET_SIZE_OF_CURRENT_CONFIGURATION_FOR 'GSCC'
#define CM_GET_CURRENT_CONFIGURATION_FOR 'GCCF'
#define CM_GET_SIZE_OF_POSSIBLE_CONFIGURATIONS_FOR 'GSPC'
#define CM_GET_POSSIBLE_CONFIGURATIONS_FOR 'GPCF'
#define CM_COUNT_RESOURCE_DESCRIPTORS_OF_TYPE 'CRDT'
#define CM_GET_NTH_RESOURCE_DESCRIPTOR_OF_TYPE 'GNRD'
struct cm_ioctl_data {
uint32 magic;
bus_type bus;
uint64 cookie;
void *config;
uint32 n;
uint32 type;
void *data;
uint32 data_len;
};
#define CM_DEVICE_NAME "misc/config"
#endif