From oruizdorantes at mail.berlios.de Tue Jul 1 00:16:27 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 00:16:27 +0200 Subject: [Haiku-commits] r26183 - haiku/trunk/src/kits/bluetooth/UI Message-ID: <200806302216.m5UMGRBp027666@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 00:16:23 +0200 (Tue, 01 Jul 2008) New Revision: 26183 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26183&view=rev Modified: haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp Log: Make the BWindows die in a proper way as suggested by mmu & stippi Modified: haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp 2008-06-30 21:43:21 UTC (rev 26182) +++ haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp 2008-06-30 22:16:23 UTC (rev 26183) @@ -46,7 +46,7 @@ { static int a = 0; if (a++ == B_PULSES_BY_SECOND(5)) - Window()->QuitRequested(); + Window()->PostMessage(B_QUIT_REQUESTED); } @@ -85,7 +85,7 @@ //--------------------------------------------------------------- bool ConnectionIncoming::QuitRequested() { - Quit(); + return BWindow::QuitRequested(); } Modified: haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp 2008-06-30 21:43:21 UTC (rev 26182) +++ haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp 2008-06-30 22:16:23 UTC (rev 26183) @@ -149,7 +149,7 @@ // TODO: something failed here } - QuitRequested(); + PostMessage(B_QUIT_REQUESTED); } break; @@ -179,7 +179,7 @@ // TODO: something failed here } - QuitRequested(); + PostMessage(B_QUIT_REQUESTED); } break; @@ -193,9 +193,7 @@ bool PincodeWindow::QuitRequested() { - Lock(); - Quit(); - return (true); + return BWindow::QuitRequested(); }; } From phoudoin at mail.berlios.de Tue Jul 1 00:25:22 2008 From: phoudoin at mail.berlios.de (phoudoin at mail.berlios.de) Date: Tue, 1 Jul 2008 00:25:22 +0200 Subject: [Haiku-commits] r26184 - in haiku/trunk/src/system/boot: loader platform/bios_ia32 Message-ID: <200806302225.m5UMPM9C028445@sheep.berlios.de> Author: phoudoin Date: 2008-07-01 00:25:19 +0200 (Tue, 01 Jul 2008) New Revision: 26184 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26184&view=rev Modified: haiku/trunk/src/system/boot/loader/menu.cpp haiku/trunk/src/system/boot/platform/bios_ia32/menu.cpp haiku/trunk/src/system/boot/platform/bios_ia32/smp.cpp Log: Applied patch by David Powell: fix missing and existing bootloader options menu items help texts. Modified: haiku/trunk/src/system/boot/loader/menu.cpp =================================================================== --- haiku/trunk/src/system/boot/loader/menu.cpp 2008-06-30 22:16:23 UTC (rev 26183) +++ haiku/trunk/src/system/boot/loader/menu.cpp 2008-06-30 22:25:19 UTC (rev 26184) @@ -438,24 +438,28 @@ safeMenu->AddItem(item = new(nothrow) MenuItem("Safe mode")); item->SetData(B_SAFEMODE_SAFE_MODE); item->SetType(MENU_ITEM_MARKABLE); - item->SetHelpText("Puts the system into safe mode. This can be enabled independently " - "from the other options."); + item->SetHelpText("Puts the system into safe mode. This can be enabled " + "independently from the other options."); safeMenu->AddItem(item = new(nothrow) MenuItem("Disable user add-ons")); item->SetData(B_SAFEMODE_DISABLE_USER_ADD_ONS); item->SetType(MENU_ITEM_MARKABLE); - item->SetHelpText("Prevent all user installed add-ons to be loaded. Only the add-ons " - "in the system directory will be used."); + item->SetHelpText("Prevents all user installed add-ons from being loaded. " + "Only the add-ons in the system directory will be used."); safeMenu->AddItem(item = new(nothrow) MenuItem("Disable IDE DMA")); item->SetData(B_SAFEMODE_DISABLE_IDE_DMA); item->SetType(MENU_ITEM_MARKABLE); + item->SetHelpText("Disables IDE DMA, increasing IDE compatibilty " + "at the expense of performance."); platform_add_menus(safeMenu); safeMenu->AddItem(item = new(nothrow) MenuItem("Enable on screen debug output")); item->SetData("debug_screen"); item->SetType(MENU_ITEM_MARKABLE); + item->SetHelpText("Displays debug output on screen while the system " + "is booting, instead of the normal boot logo."); safeMenu->AddSeparatorItem(); safeMenu->AddItem(item = new(nothrow) MenuItem("Return to main menu")); Modified: haiku/trunk/src/system/boot/platform/bios_ia32/menu.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/menu.cpp 2008-06-30 22:16:23 UTC (rev 26183) +++ haiku/trunk/src/system/boot/platform/bios_ia32/menu.cpp 2008-06-30 22:25:19 UTC (rev 26184) @@ -26,22 +26,27 @@ menu->AddItem(item = new(nothrow) MenuItem("Use fail-safe video mode")); item->SetType(MENU_ITEM_MARKABLE); item->SetData(B_SAFEMODE_FAIL_SAFE_VIDEO_MODE); - item->SetHelpText("The system will use VESA mode and won't try to open any video graphics driver"); + item->SetHelpText("The system will use VESA mode " + "and won't try to use any video graphics drivers."); smp_add_safemode_menus(menu); menu->AddItem(item = new(nothrow) MenuItem("Don't call the BIOS")); + item->SetHelpText("Stops the system from calling BIOS functions."); item->SetType(MENU_ITEM_MARKABLE); menu->AddItem(item = new(nothrow) MenuItem("Disable APM")); item->SetType(MENU_ITEM_MARKABLE); item->SetData(B_SAFEMODE_DISABLE_APM); - item->SetHelpText("This overrides the APM setting in the kernel settings file"); + item->SetHelpText("Disables Advanced Power Management hardware support, " + "overriding the APM setting in the kernel settings file."); menu->AddItem(item = new(nothrow) MenuItem("Disable ACPI")); item->SetType(MENU_ITEM_MARKABLE); item->SetData(B_SAFEMODE_DISABLE_ACPI); - item->SetHelpText("This overrides the ACPI setting in the kernel settings file"); + item->SetHelpText("Disables Advanced Configuration and Power " + "Interface hardware support, overriding the ACPI setting " + "in the kernel settings file."); break; default: break; Modified: haiku/trunk/src/system/boot/platform/bios_ia32/smp.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/smp.cpp 2008-06-30 22:16:23 UTC (rev 26183) +++ haiku/trunk/src/system/boot/platform/bios_ia32/smp.cpp 2008-06-30 22:25:19 UTC (rev 26184) @@ -589,6 +589,7 @@ menu->AddItem(item); item->SetData(B_SAFEMODE_DISABLE_SMP); item->SetType(MENU_ITEM_MARKABLE); + item->SetHelpText("Disables all but one CPU core."); } From phoudoin at mail.berlios.de Tue Jul 1 00:35:07 2008 From: phoudoin at mail.berlios.de (phoudoin at mail.berlios.de) Date: Tue, 1 Jul 2008 00:35:07 +0200 Subject: [Haiku-commits] r26185 - haiku/trunk/src/preferences/media Message-ID: <200806302235.m5UMZ73q003170@sheep.berlios.de> Author: phoudoin Date: 2008-07-01 00:35:01 +0200 (Tue, 01 Jul 2008) New Revision: 26185 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26185&view=rev Modified: haiku/trunk/src/preferences/media/MediaViews.cpp Log: Removed mention of Haiku, a generic "system" sounds both better and distro name independent. Modified: haiku/trunk/src/preferences/media/MediaViews.cpp =================================================================== --- haiku/trunk/src/preferences/media/MediaViews.cpp 2008-06-30 22:25:19 UTC (rev 26184) +++ haiku/trunk/src/preferences/media/MediaViews.cpp 2008-06-30 22:35:01 UTC (rev 26185) @@ -144,9 +144,9 @@ rect2.bottom = rect.Height() - 5; BRect textRect(3, 3, rect2.Width() - 3, rect2.Height() - 3); BTextView *textView = new BTextView(rect2, "stringView", textRect, B_FOLLOW_ALL, B_WILL_DRAW); - textView->Insert(fIsVideo ? "Enabling Real-Time Video allows Haiku to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." + textView->Insert(fIsVideo ? "Enabling Real-Time Video allows system to perform video operations as fast and smoothly as possible. It achieves optimum performance by using more RAM." "\n\nOnly enable this feature if you need the lowest latency possible." - : "Enabling Real-time Audio allows Haiku to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM." + : "Enabling Real-time Audio allows system to record and play audio as fast as possible. It achieves this performance by using more CPU and RAM." "\n\nOnly enable this feature if you need the lowest latency possible."); textView->MakeEditable(false); textView->MakeSelectable(false); From korli at mail.berlios.de Tue Jul 1 01:06:43 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 1 Jul 2008 01:06:43 +0200 Subject: [Haiku-commits] r26186 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200806302306.m5UN6hEi009839@sheep.berlios.de> Author: korli Date: 2008-07-01 01:06:41 +0200 (Tue, 01 Jul 2008) New Revision: 26186 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26186&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: read() expects B_IS_A_DIRECTORY on directories that can't be read. This fixes grep misbehavior with directories. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-06-30 22:35:01 UTC (rev 26185) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-06-30 23:06:41 UTC (rev 26186) @@ -1179,6 +1179,8 @@ if (!inode->HasUserAccessableStream()) { *_length = 0; + if (inode->IsDirectory()) + RETURN_ERROR(B_IS_A_DIRECTORY); RETURN_ERROR(B_BAD_VALUE); } From korli at users.berlios.de Tue Jul 1 01:08:28 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Tue, 1 Jul 2008 01:08:28 +0200 Subject: [Haiku-commits] r26156 - haiku/trunk/src/bin/grep In-Reply-To: <20080629150518.524.3@knochen-vm.1214741638.fake> References: <200806281830.m5SIUQRe030780@sheep.berlios.de> <20080629150518.524.3@knochen-vm.1214741638.fake> Message-ID: 2008/6/29 Ingo Weinhold : > Just in case you're interested, there's still the annoyance that grep reports > errors for directories (e.g. when running "grep foo *" in a directory with > subdirectories). In Linux directories are silently ignored. Should be fixed as of r26186. Bye, J?r?me From ingo_weinhold at gmx.de Tue Jul 1 04:19:58 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 01 Jul 2008 04:19:58 +0200 Subject: [Haiku-commits] r26156 - haiku/trunk/src/bin/grep In-Reply-To: References: <200806281830.m5SIUQRe030780@sheep.berlios.de> <20080629150518.524.3@knochen-vm.1214741638.fake> Message-ID: <20080701041958.910.2@knochen-vm.1214873310.fake> On 2008-07-01 at 01:08:28 [+0200], J?r?me Duval wrote: > 2008/6/29 Ingo Weinhold : > > Just in case you're interested, there's still the annoyance that grep > > reports > > errors for directories (e.g. when running "grep foo *" in a directory with > > subdirectories). In Linux directories are silently ignored. > > Should be fixed as of r26186. Nice, thanks! CU, Ingo From korli at users.berlios.de Tue Jul 1 11:29:55 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Tue, 1 Jul 2008 11:29:55 +0200 Subject: [Haiku-commits] r26186 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: <200806302306.m5UN6hEi009839@sheep.berlios.de> References: <200806302306.m5UN6hEi009839@sheep.berlios.de> Message-ID: 2008/7/1 korli at BerliOS : > Modified: > haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp > Log: > read() expects B_IS_A_DIRECTORY on directories that can't be read. As I think of it, this change should also be applied for write() but can't do it ATM. Bye, J?r?me From axeld at mail.berlios.de Tue Jul 1 12:12:20 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 1 Jul 2008 12:12:20 +0200 Subject: [Haiku-commits] r26187 - in haiku/trunk/src/add-ons/kernel/file_systems: . ext2 Message-ID: <200807011012.m61ACKEU005427@sheep.berlios.de> Author: axeld Date: 2008-07-01 12:12:19 +0200 (Tue, 01 Jul 2008) New Revision: 26187 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26187&view=rev Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Modified: haiku/trunk/src/add-ons/kernel/file_systems/Jamfile Log: * Implemented a read-only ext2 file system. * It's not yet complete, doesn't support some ext2 stuff (like files over 4 GB), and might have some other bugs (I only tested it with a single 20 MB ext2 image). * To have a read/write ext2 file system, it would probably make more sense to port GNU sources (like ext2fs lib), and use that. But a small read-only ext2 file sytem doesn't hurt, I think, and I don't know if ext2fs lib would be feasible for kernel use (porting the file system from Linux directly would also be an alternative, but probably more work). Modified: haiku/trunk/src/add-ons/kernel/file_systems/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/Jamfile 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/Jamfile 2008-07-01 10:12:19 UTC (rev 26187) @@ -2,6 +2,7 @@ SubInclude HAIKU_TOP src add-ons kernel file_systems bfs ; SubInclude HAIKU_TOP src add-ons kernel file_systems cdda ; +SubInclude HAIKU_TOP src add-ons kernel file_systems ext2 ; SubInclude HAIKU_TOP src add-ons kernel file_systems fat ; SubInclude HAIKU_TOP src add-ons kernel file_systems googlefs ; SubInclude HAIKU_TOP src add-ons kernel file_systems iso9660 ; Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/CachedBlock.h 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,97 @@ +/* + * Copyright 2001-2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef CACHED_BLOCK_H +#define CACHED_BLOCK_H + +//! interface for the block cache + +#include + +#include "Volume.h" + + +class CachedBlock { +public: + CachedBlock(Volume* volume); + CachedBlock(Volume* volume, uint32 block); + ~CachedBlock(); + + void Keep(); + void Unset(); + + const uint8* SetTo(uint32 block); + + const uint8* Block() const { return fBlock; } + off_t BlockNumber() const { return fBlockNumber; } + +private: + CachedBlock(const CachedBlock &); + CachedBlock &operator=(const CachedBlock &); + // no implementation + +protected: + Volume* fVolume; + uint32 fBlockNumber; + uint8* fBlock; +}; + + +// inlines + + +inline +CachedBlock::CachedBlock(Volume* volume) + : + fVolume(volume), + fBlockNumber(0), + fBlock(NULL) +{ +} + + +inline +CachedBlock::CachedBlock(Volume* volume, uint32 block) + : + fVolume(volume), + fBlockNumber(0), + fBlock(NULL) +{ + SetTo(block); +} + + +inline +CachedBlock::~CachedBlock() +{ + Unset(); +} + + +inline void +CachedBlock::Keep() +{ + fBlock = NULL; +} + + +inline void +CachedBlock::Unset() +{ + if (fBlock != NULL) { + block_cache_put(fVolume->BlockCache(), fBlockNumber); + fBlock = NULL; + } +} + + +inline const uint8 * +CachedBlock::SetTo(uint32 block) +{ + Unset(); + fBlockNumber = block; + return fBlock = (uint8 *)block_cache_get(fVolume->BlockCache(), block); +} + +#endif // CACHED_BLOCK_H Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,77 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ + + +#include "DirectoryIterator.h" + +#include + +#include "Inode.h" + + +DirectoryIterator::DirectoryIterator(Inode* inode) + : + fInode(inode), + fOffset(0) +{ +} + + +DirectoryIterator::~DirectoryIterator() +{ +} + + +status_t +DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id) +{ + if (fOffset + sizeof(ext2_dir_entry) >= fInode->Size()) + return B_ENTRY_NOT_FOUND; + + ext2_dir_entry entry; + + while (true) { + size_t length = ext2_dir_entry::MinimumSize(); + status_t status = fInode->ReadAt(fOffset, (uint8*)&entry, &length); + if (status != B_OK) + return status; + if (length < ext2_dir_entry::MinimumSize() || entry.Length() == 0) + return B_ENTRY_NOT_FOUND; + if (!entry.IsValid()) + return B_BAD_DATA; + + if (entry.NameLength() != 0) + break; + + fOffset += entry.Length(); + } + + // read name + + size_t length = entry.NameLength(); + status_t status = fInode->ReadAt(fOffset + ext2_dir_entry::MinimumSize(), + (uint8*)entry.name, &length); + if (status == B_OK) { + if (*_nameLength < length) + length = *_nameLength - 1; + memcpy(name, entry.name, length); + name[length] = '\0'; + + *_id = entry.InodeID(); + *_nameLength = length; + + fOffset += entry.Length(); + } + + return status; +} + + +status_t +DirectoryIterator::Rewind() +{ + fOffset = 0; + return B_OK; +} Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,33 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef DIRECTORY_ITERATOR_H +#define DIRECTORY_ITERATOR_H + + +#include + + +class Inode; + +class DirectoryIterator { +public: + DirectoryIterator(Inode* inode); + ~DirectoryIterator(); + + status_t GetNext(char* name, size_t* _nameLength, ino_t* id); + + status_t Rewind(); + +private: + DirectoryIterator(const DirectoryIterator&); + DirectoryIterator &operator=(const DirectoryIterator&); + // no implementation + +private: + Inode* fInode; + off_t fOffset; +}; + +#endif // DIRECTORY_ITERATOR_H Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,172 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ + + +#include "Inode.h" + +#include + +#include "CachedBlock.h" + + +Inode::Inode(Volume* volume, ino_t id) + : + fVolume(volume), + fID(id), + fCache(NULL), + fMap(NULL), + fNode(NULL) +{ + rw_lock_init(&fLock, "ext2 inode"); + + uint32 block; + if (volume->GetInodeBlock(id, block) == B_OK) { + ext2_inode* inodes = (ext2_inode*)block_cache_get(volume->BlockCache(), + block); + if (inodes != NULL) + fNode = inodes + volume->InodeBlockIndex(id); + } + + if (fNode != NULL) { + fCache = file_cache_create(fVolume->ID(), ID(), Size()); + fMap = file_map_create(fVolume->ID(), ID(), Size()); + } +} + + +Inode::~Inode() +{ + file_cache_delete(FileCache()); + file_map_delete(Map()); + + if (fNode != NULL) { + uint32 block; + if (fVolume->GetInodeBlock(ID(), block) == B_OK) + block_cache_put(fVolume->BlockCache(), block); + } +} + + +status_t +Inode::InitCheck() +{ + return fNode != NULL ? B_OK : B_ERROR; +} + + +status_t +Inode::CheckPermissions(int accessMode) const +{ + uid_t user = geteuid(); + gid_t group = getegid(); + + // you never have write access to a read-only volume + if (accessMode & W_OK && fVolume->IsReadOnly()) + return B_READ_ONLY_DEVICE; + + // root users always have full access (but they can't execute files without + // any execute permissions set) + if (user == 0) { + if (!((accessMode & X_OK) != 0 && (Mode() & S_IXUSR) == 0) + || S_ISDIR(Mode())) + return B_OK; + } + + // shift mode bits, to check directly against accessMode + mode_t mode = Mode(); + if (user == (uid_t)fNode->UserID()) + mode >>= 6; + else if (group == (gid_t)fNode->GroupID()) + mode >>= 3; + + if (accessMode & ~(mode & S_IRWXO)) + return B_NOT_ALLOWED; + + return B_OK; +} + + +status_t +Inode::FindBlock(off_t offset, uint32& block) +{ + uint32 perBlock = fVolume->BlockSize() / 4; + uint32 perIndirectBlock = perBlock * perBlock; + uint32 index = offset >> fVolume->BlockShift(); + + if (offset >= Size()) + return B_ENTRY_NOT_FOUND; + + if (index < EXT2_DIRECT_BLOCKS) { + // direct blocks + block = B_LENDIAN_TO_HOST_INT32(Node().stream.direct[index]); + } else if ((index -= EXT2_DIRECT_BLOCKS) < perBlock) { + // indirect blocks + CachedBlock cached(fVolume); + uint32* indirectBlocks = (uint32*)cached.SetTo(Node().stream.indirect); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index]); + } else if ((index -= perBlock) < perIndirectBlock) { + // double indirect blocks + CachedBlock cached(fVolume); + uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + Node().stream.double_indirect)); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + indirectBlocks[index / perBlock])); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index & (perBlock - 1)]); + } else if ((index -= perIndirectBlock) / perBlock < perIndirectBlock) { + // triple indirect blocks + CachedBlock cached(fVolume); + uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + Node().stream.triple_indirect)); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + indirectBlocks[index / perIndirectBlock])); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + indirectBlocks[(index / perBlock) & (perBlock - 1)])); + if (indirectBlocks != NULL) + return B_IO_ERROR; + + block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index & (perBlock - 1)]); + } else { + // outside of the possible data stream + dprintf("ext2: block outside datastream!\n"); + return B_ERROR; + } + + //dprintf("FindBlock(offset %Ld): %lu\n", offset, block); + return B_OK; +} + + +status_t +Inode::ReadAt(off_t pos, uint8* buffer, size_t* _length) +{ + size_t length = *_length; + + // set/check boundaries for pos/length + if (pos < 0) + return B_BAD_VALUE; + + if (pos >= Size() || length == 0) { + *_length = 0; + return B_NO_ERROR; + } + + return file_cache_read(FileCache(), NULL, pos, buffer, _length); +} + Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.h 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.h 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,71 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef INODE_H +#define INODE_H + + +#include + +#include "ext2.h" +#include "Volume.h" + + +class Inode { +public: + Inode(Volume* volume, ino_t id); + ~Inode(); + + status_t InitCheck(); + + ino_t ID() const { return fID; } + + rw_lock* Lock() { return &fLock; } + + bool IsDirectory() const + { return S_ISDIR(Mode()); } + bool IsFile() const + { return S_ISREG(Mode()); } + bool IsSymLink() const + { return S_ISLNK(Mode()); } + + status_t CheckPermissions(int accessMode) const; + + mode_t Mode() const { return fNode->Mode(); } + int32 Flags() const { return fNode->Flags(); } + + off_t Size() const { return fNode->Size(); } + time_t ModificationTime() const + { return fNode->ModificationTime(); } + time_t CreationTime() const + { return fNode->CreationTime(); } + time_t AccessTime() const + { return fNode->AccessTime(); } + + //::Volume* _Volume() const { return fVolume; } + Volume* GetVolume() const { return fVolume; } + + status_t FindBlock(off_t offset, uint32& block); + status_t ReadAt(off_t pos, uint8 *buffer, size_t *length); + + ext2_inode& Node() { return *fNode; } + + void* FileCache() const { return fCache; } + void* Map() const { return fMap; } + +private: + Inode(const Inode&); + Inode &operator=(const Inode&); + // no implementation + +private: + rw_lock fLock; + ::Volume* fVolume; + ino_t fID; + void* fCache; + void* fMap; + ext2_inode* fNode; +}; + +#endif // INODE_H Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Jamfile 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Jamfile 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,19 @@ +SubDir HAIKU_TOP src add-ons kernel file_systems ext2 ; + +# set some additional defines +{ + SubDirCcFlags -Wall -Wno-multichar ; + SubDirC++Flags -Wall -Wno-multichar ; +} + +#UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; +UsePrivateHeaders shared storage ; +UsePrivateKernelHeaders ; + +KernelAddon ext2 : + Volume.cpp + Inode.cpp + DirectoryIterator.cpp + + kernel_interface.cpp +; Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,405 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ + +//! super block, mounting, etc. + + +#include "Volume.h" + +#include +#include +#include + +#include +#include + +#include + +#include "Inode.h" + + +class DeviceOpener { + public: + DeviceOpener(int fd, int mode); + DeviceOpener(const char *device, int mode); + ~DeviceOpener(); + + int Open(const char *device, int mode); + int Open(int fd, int mode); + void *InitCache(off_t numBlocks, uint32 blockSize); + void RemoveCache(bool allowWrites); + + void Keep(); + + int Device() const { return fDevice; } + int Mode() const { return fMode; } + bool IsReadOnly() const { return _IsReadOnly(fMode); } + + status_t GetSize(off_t *_size, uint32 *_blockSize = NULL); + + private: + static bool _IsReadOnly(int mode) + { return (mode & O_RWMASK) == O_RDONLY;} + static bool _IsReadWrite(int mode) + { return (mode & O_RWMASK) == O_RDWR;} + + int fDevice; + int fMode; + void *fBlockCache; +}; + + +DeviceOpener::DeviceOpener(const char *device, int mode) + : + fBlockCache(NULL) +{ + Open(device, mode); +} + + +DeviceOpener::DeviceOpener(int fd, int mode) + : + fBlockCache(NULL) +{ + Open(fd, mode); +} + + +DeviceOpener::~DeviceOpener() +{ + if (fDevice >= 0) { + RemoveCache(false); + close(fDevice); + } +} + + +int +DeviceOpener::Open(const char *device, int mode) +{ + fDevice = open(device, mode | O_NOCACHE); + if (fDevice < 0) + fDevice = errno; + + if (fDevice < 0 && _IsReadWrite(mode)) { + // try again to open read-only (don't rely on a specific error code) + return Open(device, O_RDONLY | O_NOCACHE); + } + + if (fDevice >= 0) { + // opening succeeded + fMode = mode; + if (_IsReadWrite(mode)) { + // check out if the device really allows for read/write access + device_geometry geometry; + if (!ioctl(fDevice, B_GET_GEOMETRY, &geometry)) { + if (geometry.read_only) { + // reopen device read-only + close(fDevice); + return Open(device, O_RDONLY | O_NOCACHE); + } + } + } + } + + return fDevice; +} + + +int +DeviceOpener::Open(int fd, int mode) +{ + fDevice = dup(fd); + if (fDevice < 0) + return errno; + + fMode = mode; + + return fDevice; +} + + +void * +DeviceOpener::InitCache(off_t numBlocks, uint32 blockSize) +{ + return fBlockCache = block_cache_create(fDevice, numBlocks, blockSize, + IsReadOnly()); +} + + +void +DeviceOpener::RemoveCache(bool allowWrites) +{ + if (fBlockCache == NULL) + return; + + block_cache_delete(fBlockCache, allowWrites); + fBlockCache = NULL; +} + + +void +DeviceOpener::Keep() +{ + fDevice = -1; +} + + +/*! Returns the size of the device in bytes. It uses B_GET_GEOMETRY + to compute the size, or fstat() if that failed. +*/ +status_t +DeviceOpener::GetSize(off_t *_size, uint32 *_blockSize) +{ + device_geometry geometry; + if (ioctl(fDevice, B_GET_GEOMETRY, &geometry) < 0) { + // maybe it's just a file + struct stat stat; + if (fstat(fDevice, &stat) < 0) + return B_ERROR; + + if (_size) + *_size = stat.st_size; + if (_blockSize) // that shouldn't cause us any problems + *_blockSize = 512; + + return B_OK; + } + + if (_size) { + *_size = 1LL * geometry.head_count * geometry.cylinder_count + * geometry.sectors_per_track * geometry.bytes_per_sector; + } + if (_blockSize) + *_blockSize = geometry.bytes_per_sector; + + return B_OK; +} + + +// #pragma mark - + + +bool +ext2_super_block::IsValid() +{ + // TODO: check some more values! + if (Magic() != (uint32)EXT2_SUPER_BLOCK_MAGIC) + return false; + + return true; +} + + +// #pragma mark - + + +Volume::Volume(fs_volume* volume) + : + fFSVolume(volume), + fFlags(0), + fGroupBlocks(NULL), + fRootNode(NULL) +{ + mutex_init(&fLock, "ext2 volume"); +} + + +Volume::~Volume() +{ + if (fGroupBlocks != NULL) { + uint32 blockCount = (fNumGroups + fGroupsPerBlock - 1) + / fGroupsPerBlock; + for (uint32 i = 0; i < blockCount; i++) { + free(fGroupBlocks[i]); + } + + free(fGroupBlocks); + } +} + + +bool +Volume::IsValidSuperBlock() +{ + return fSuperBlock.IsValid(); +} + + +const char* +Volume::Name() const +{ + if (fSuperBlock.name[0]) + return fSuperBlock.name; + + return "Unnamed Ext2 Volume"; +} + + +status_t +Volume::Mount(const char* deviceName, uint32 flags) +{ + flags |= B_MOUNT_READ_ONLY; + // we only support read-only for now + + DeviceOpener opener(deviceName, (flags & B_MOUNT_READ_ONLY) != 0 + ? O_RDONLY : O_RDWR); + fDevice = opener.Device(); + if (fDevice < B_OK) + return fDevice; + + if (opener.IsReadOnly()) + fFlags |= VOLUME_READ_ONLY; + + // read the super block + if (Identify(fDevice, &fSuperBlock) != B_OK) { + //FATAL(("invalid super block!\n")); + return B_BAD_VALUE; + } + + if ((fSuperBlock.IncompatibleFeatures() + & EXT2_INCOMPATIBLE_FEATURE_COMPRESSION) != 0) { + dprintf("ext2: compression not supported.\n"); + return B_NOT_SUPPORTED; + } + + // initialize short hands to the super block (to save byte swapping) + fBlockShift = fSuperBlock.BlockShift(); + fBlockSize = 1UL << fSuperBlock.BlockShift(); + + fNumGroups = (fSuperBlock.NumBlocks() - fSuperBlock.FirstDataBlock() - 1) + / fSuperBlock.BlocksPerGroup() + 1; + fGroupsPerBlock = fBlockSize / sizeof(ext2_block_group); + + uint32 blockCount = (fNumGroups + fGroupsPerBlock - 1) / fGroupsPerBlock; + + fGroupBlocks = (ext2_block_group**)malloc(blockCount * sizeof(void*)); + if (fGroupBlocks == NULL) + return B_NO_MEMORY; + + memset(fGroupBlocks, 0, blockCount * sizeof(void*)); + fInodesPerBlock = fBlockSize / sizeof(ext2_inode); + + // check if the device size is large enough to hold the file system + off_t diskSize; + status_t status = opener.GetSize(&diskSize); + if (status != B_OK) + return status; + if (diskSize < (NumBlocks() << BlockShift())) + return B_BAD_VALUE; + + if ((fBlockCache = opener.InitCache(NumBlocks(), fBlockSize)) == NULL) + return B_ERROR; + + status = get_vnode(fFSVolume, EXT2_ROOT_NODE, (void**)&fRootNode); + if (status == B_OK) { + // all went fine + opener.Keep(); + return B_OK; + } else + dprintf("ext2: could not create root node: get_vnode() failed!\n"); + + return status; +} + + +status_t +Volume::Unmount() +{ + //put_vnode(fVolume, ToVnode(Root())); + //block_cache_delete(fBlockCache, !IsReadOnly()); + close(fDevice); + + return B_OK; +} + + +status_t +Volume::GetInodeBlock(ino_t id, uint32& block) +{ + ext2_block_group* group; + status_t status = GetBlockGroup((id - 1) / fSuperBlock.InodesPerGroup(), + &group); + if (status != B_OK) + return status; + + block = group->InodeTable() + + ((id - 1) % fSuperBlock.InodesPerGroup()) / fInodesPerBlock; + return B_OK; +} + + +uint32 +Volume::InodeBlockIndex(ino_t id) const +{ + return ((id - 1) % fSuperBlock.InodesPerGroup()) % fInodesPerBlock; +} + + +off_t +Volume::_GroupBlockOffset(uint32 blockIndex) +{ + if ((fSuperBlock.IncompatibleFeatures() + & EXT2_INCOMPATIBLE_FEATURE_META_GROUP) == 0 + || blockIndex < fSuperBlock.FirstMetaBlockGroup()) + return EXT2_SUPER_BLOCK_OFFSET + fBlockSize * (1 + blockIndex); + + panic("meta block"); + return 0; +} + + +/*! Makes the requested block group available. + The block groups are loaded on demand, but are kept in memory until the + volume is unmounted; therefore we don't use the block cache. +*/ +status_t +Volume::GetBlockGroup(int32 index, ext2_block_group** _group) +{ + if (index < 0 || (uint32)index > fNumGroups) + return B_BAD_VALUE; + + int32 blockIndex = index / fGroupsPerBlock; + + MutexLocker _(fLock); + + if (fGroupBlocks[blockIndex] == NULL) { + ext2_block_group* groupBlock = (ext2_block_group*)malloc(fBlockSize); + if (groupBlock == NULL) + return B_NO_MEMORY; + + ssize_t bytesRead = read_pos(fDevice, _GroupBlockOffset(blockIndex), + groupBlock, fBlockSize); + if (bytesRead >= B_OK && (uint32)bytesRead != fBlockSize) + bytesRead = B_IO_ERROR; + if (bytesRead < B_OK) { + free(groupBlock); + return bytesRead; + } + + fGroupBlocks[blockIndex] = groupBlock; + } + + *_group = fGroupBlocks[blockIndex] + index % fGroupsPerBlock; + return B_OK; +} + + +// #pragma mark - Disk scanning and initialization + + +/*static*/ status_t +Volume::Identify(int fd, ext2_super_block* superBlock) +{ + if (read_pos(fd, EXT2_SUPER_BLOCK_OFFSET, superBlock, + sizeof(ext2_super_block)) != sizeof(ext2_super_block)) + return B_IO_ERROR; + + if (!superBlock->IsValid()) + return B_BAD_VALUE; + + return B_OK; +} + Added: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-06-30 23:06:41 UTC (rev 26186) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-07-01 10:12:19 UTC (rev 26187) @@ -0,0 +1,74 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * This file may be used under the terms of the MIT License. + */ +#ifndef VOLUME_H +#define VOLUME_H + + +#include + +#include "ext2.h" + +class Inode; + +enum volume_flags { + VOLUME_READ_ONLY = 0x0001 +}; + +class Volume { +public: + Volume(fs_volume* volume); + ~Volume(); + + status_t Mount(const char* device, uint32 flags); + status_t Unmount(); + + bool IsValidSuperBlock(); + bool IsReadOnly() const { return fFlags & VOLUME_READ_ONLY; } + + Inode* RootNode() const { return fRootNode; } + int Device() const { return fDevice; } + + dev_t ID() const { return fFSVolume ? fFSVolume->id : -1; } + fs_volume* FSVolume() const { return fFSVolume; } + const char* Name() const; + + off_t NumBlocks() const { return fSuperBlock.NumBlocks(); } + off_t FreeBlocks() const { return fSuperBlock.FreeBlocks(); } + + uint32 BlockSize() const { return fBlockSize; } + uint32 BlockShift() const { return fBlockShift; } + uint32 InodeSize() const { return fSuperBlock.InodeSize(); } + ext2_super_block& SuperBlock() { return fSuperBlock; } + + status_t GetInodeBlock(ino_t id, uint32& block); + uint32 InodeBlockIndex(ino_t id) const; + status_t GetBlockGroup(int32 index, ext2_block_group** _group); + + // cache access + void* BlockCache() { return fBlockCache; } + + static status_t Identify(int fd, ext2_super_block* superBlock); + +private: + off_t _GroupBlockOffset(uint32 blockIndex); + +private: + mutex fLock; + fs_volume* fFSVolume; + int fDevice; + ext2_super_block fSuperBlock; + uint32 fFlags; + uint32 fBlockSize; + uint32 fBlockShift; + uint32 fNumGroups; + uint32 fGroupsPerBlock; [... truncated: 850 lines follow ...] From axeld at mail.berlios.de Tue Jul 1 12:39:40 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 1 Jul 2008 12:39:40 +0200 Subject: [Haiku-commits] r26188 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807011039.m61AdeAX019881@sheep.berlios.de> Author: axeld Date: 2008-07-01 12:39:39 +0200 (Tue, 01 Jul 2008) New Revision: 26188 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26188&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Log: * Added support for files larger than 4GB - not yet tested, though. * The stat::st_nlink value is now correctly reported. Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 10:12:19 UTC (rev 26187) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 10:39:39 UTC (rev 26188) @@ -30,6 +30,7 @@ } if (fNode != NULL) { + // TODO: we don't need a cache for short symlinks fCache = file_cache_create(fVolume->ID(), ID(), Size()); fMap = file_map_create(fVolume->ID(), ID(), Size()); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-01 10:12:19 UTC (rev 26187) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-01 10:39:39 UTC (rev 26188) @@ -6,6 +6,8 @@ #define EXT2_H +#include + #include #include @@ -160,7 +162,11 @@ }; uint32 generation; uint32 file_access_control; - uint32 directory_access_control; + union { + // for directories vs. files + uint32 directory_access_control; + uint32 size_high; + }; uint32 fragment; uint8 fragment_number; uint8 fragment_size; @@ -170,14 +176,24 @@ uint32 _reserved2; uint16 Mode() const { return B_LENDIAN_TO_HOST_INT16(mode); } - uint32 Size() const { return B_LENDIAN_TO_HOST_INT32(size); } uint32 Flags() const { return B_LENDIAN_TO_HOST_INT32(flags); } + uint16 NumLinks() const { return B_LENDIAN_TO_HOST_INT16(num_links); } time_t AccessTime() const { return B_LENDIAN_TO_HOST_INT32(access_time); } time_t CreationTime() const { return B_LENDIAN_TO_HOST_INT32(creation_time); } time_t ModificationTime() const { return B_LENDIAN_TO_HOST_INT32(modification_time); } time_t DeletionTime() const { return B_LENDIAN_TO_HOST_INT32(deletion_time); } + off_t Size() const + { + if (S_ISREG(Mode())) { + return B_LENDIAN_TO_HOST_INT32(size) + | ((off_t)B_LENDIAN_TO_HOST_INT32(size_high) << 32); + } + + return B_LENDIAN_TO_HOST_INT32(size); + } + uint16 UserID() const { return B_LENDIAN_TO_HOST_INT16(uid) Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-01 10:12:19 UTC (rev 26187) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-01 10:39:39 UTC (rev 26188) @@ -327,7 +327,7 @@ stat->st_dev = inode->GetVolume()->ID(); stat->st_ino = inode->ID(); - stat->st_nlink = 1; + stat->st_nlink = node.NumLinks(); stat->st_blksize = EXT2_IO_SIZE; stat->st_uid = node.UserID(); From axeld at mail.berlios.de Tue Jul 1 13:24:48 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 1 Jul 2008 13:24:48 +0200 Subject: [Haiku-commits] r26189 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807011124.m61BOm1m008299@sheep.berlios.de> Author: axeld Date: 2008-07-01 13:24:48 +0200 (Tue, 01 Jul 2008) New Revision: 26189 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26189&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp Log: * Fixed a pretty dumb copy&paste error that prevented (/double/triple) indirect blocks from working. Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 10:39:39 UTC (rev 26188) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 11:24:48 UTC (rev 26189) @@ -105,8 +105,9 @@ } else if ((index -= EXT2_DIRECT_BLOCKS) < perBlock) { // indirect blocks CachedBlock cached(fVolume); - uint32* indirectBlocks = (uint32*)cached.SetTo(Node().stream.indirect); - if (indirectBlocks != NULL) + uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( + Node().stream.indirect)); + if (indirectBlocks == NULL) return B_IO_ERROR; block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index]); @@ -115,12 +116,12 @@ CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( Node().stream.double_indirect)); - if (indirectBlocks != NULL) + if (indirectBlocks == NULL) return B_IO_ERROR; indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( indirectBlocks[index / perBlock])); - if (indirectBlocks != NULL) + if (indirectBlocks == NULL) return B_IO_ERROR; block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index & (perBlock - 1)]); @@ -129,17 +130,17 @@ CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( Node().stream.triple_indirect)); - if (indirectBlocks != NULL) + if (indirectBlocks == NULL) return B_IO_ERROR; indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( indirectBlocks[index / perIndirectBlock])); - if (indirectBlocks != NULL) + if (indirectBlocks == NULL) return B_IO_ERROR; indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( indirectBlocks[(index / perBlock) & (perBlock - 1)])); - if (indirectBlocks != NULL) + if (indirectBlocks == NULL) return B_IO_ERROR; block = B_LENDIAN_TO_HOST_INT32(indirectBlocks[index & (perBlock - 1)]); From axeld at mail.berlios.de Tue Jul 1 13:28:58 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 1 Jul 2008 13:28:58 +0200 Subject: [Haiku-commits] r26190 - haiku/trunk/build/jam Message-ID: <200807011128.m61BSwb8017770@sheep.berlios.de> Author: axeld Date: 2008-07-01 13:28:48 +0200 (Tue, 01 Jul 2008) New Revision: 26190 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26190&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: * Added ext2 file system to the image. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-07-01 11:24:48 UTC (rev 26189) +++ haiku/trunk/build/jam/HaikuImage 2008-07-01 11:28:48 UTC (rev 26190) @@ -135,7 +135,7 @@ BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager agp_gart usb #firewire ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 ; #googlefs nfs $(GPL_ONLY)ntfs ; From fekdahl at gmail.com Tue Jul 1 13:36:12 2008 From: fekdahl at gmail.com (Fredrik Ekdahl) Date: Tue, 1 Jul 2008 13:36:12 +0200 Subject: [Haiku-commits] r26187 - in haiku/trunk/src/add-ons/kernel/file_systems: . ext2 In-Reply-To: <200807011012.m61ACKEU005427@sheep.berlios.de> References: <200807011012.m61ACKEU005427@sheep.berlios.de> Message-ID: 2008/7/1 axeld at BerliOS : > Author: axeld > Date: 2008-07-01 12:12:19 +0200 (Tue, 01 Jul 2008) > New Revision: 26187 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26187&view=rev > > Added: > haiku/trunk/src/add-ons/kernel/file_systems/ext2/ > Log: > * Implemented a read-only ext2 file system. Wow, great addition! This is really useful. Thanks! /Fredrik Ekdahl From axeld at mail.berlios.de Tue Jul 1 13:42:51 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 1 Jul 2008 13:42:51 +0200 Subject: [Haiku-commits] r26191 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200807011142.m61BgpGc002448@sheep.berlios.de> Author: axeld Date: 2008-07-01 13:42:51 +0200 (Tue, 01 Jul 2008) New Revision: 26191 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26191&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Fixed the bfs_write() error code for directories as suggested by Jerome. * Removed a few superfluous checks. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-01 11:28:48 UTC (rev 26190) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-01 11:42:51 UTC (rev 26191) @@ -1179,9 +1179,7 @@ if (!inode->HasUserAccessableStream()) { *_length = 0; - if (inode->IsDirectory()) - RETURN_ERROR(B_IS_A_DIRECTORY); - RETURN_ERROR(B_BAD_VALUE); + return inode->IsDirectory() ? B_IS_A_DIRECTORY : B_BAD_VALUE; } return inode->ReadAt(pos, (uint8 *)buffer, _length); @@ -1201,7 +1199,7 @@ if (!inode->HasUserAccessableStream()) { *_length = 0; - RETURN_ERROR(B_BAD_VALUE); + return inode->IsDirectory() ? B_IS_A_DIRECTORY : B_BAD_VALUE; } file_cookie *cookie = (file_cookie *)_cookie; @@ -1475,8 +1473,6 @@ FUNCTION(); TreeIterator *iterator = (TreeIterator *)_cookie; - if (iterator == NULL) - RETURN_ERROR(B_BAD_VALUE); uint16 length; ino_t id; @@ -1507,9 +1503,6 @@ FUNCTION(); TreeIterator *iterator = (TreeIterator *)_cookie; - if (iterator == NULL) - RETURN_ERROR(B_BAD_VALUE); - return iterator->Rewind(); } @@ -1525,12 +1518,7 @@ static status_t bfs_free_dir_cookie(fs_volume *_volume, fs_vnode *node, void *_cookie) { - TreeIterator *iterator = (TreeIterator *)_cookie; - - if (iterator == NULL) - RETURN_ERROR(B_BAD_VALUE); - - delete iterator; + delete (TreeIterator *)_cookie; return B_OK; } From axeld at pinc-software.de Tue Jul 1 13:42:29 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 01 Jul 2008 13:42:29 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26186_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/bfs?= In-Reply-To: Message-ID: <16904823399-BeMail@zon> "J?r?me Duval" wrote: > 2008/7/1 korli at BerliOS : > > Modified: > > haiku/trunk/src/add-ons/kernel/file_systems/bfs/ > > kernel_interface.cpp > > Log: > > read() expects B_IS_A_DIRECTORY on directories that can't be read. > As I think of it, this change should also be applied for write() but > can't do it ATM. You're right, thanks for the hint! I did so in r26191. Bye, Axel. From stippi at mail.berlios.de Tue Jul 1 17:48:01 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 1 Jul 2008 17:48:01 +0200 Subject: [Haiku-commits] r26192 - haiku/trunk/src/servers/app Message-ID: <200807011548.m61Fm1Os004276@sheep.berlios.de> Author: stippi Date: 2008-07-01 17:47:56 +0200 (Tue, 01 Jul 2008) New Revision: 26192 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26192&view=rev Modified: haiku/trunk/src/servers/app/ServerApp.cpp haiku/trunk/src/servers/app/ServerApp.h haiku/trunk/src/servers/app/ServerWindow.cpp haiku/trunk/src/servers/app/ServerWindow.h Log: stippi + bonefish: Fixed race conditions when a ServerApp or ServerWindow is created. The reply to the client that the object has been created successfully was sent in the thread creating it. Preempted at the wrong time (right after writing the message to the port) could lead to the object's thread using the link at the same time, which would screw up all subsequent communication via that link. This fixes the problem that mimeset would sometimes fail when building Haiku in Haiku (can't find the ticket). It probably also fixes #2331, and the bug that sometimes when a window is opened (Terminal, crash alert, shutdown window, etc.) it would come up with huge width/height and tiny other dimension (can't find the ticket). Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2008-07-01 11:42:51 UTC (rev 26191) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2008-07-01 15:47:56 UTC (rev 26192) @@ -206,26 +206,6 @@ /*! - \brief Starts the ServerApp monitoring for messages - \return false if the application couldn't start, true if everything went OK. -*/ -bool -ServerApp::Run() -{ - if (!MessageLooper::Run()) - return false; - - // Let's tell the client how to talk with us - fLink.StartMessage(B_OK); - fLink.Attach(fMessagePort); - fLink.Attach(fDesktop->SharedReadOnlyArea()); - fLink.Flush(); - - return true; -} - - -/*! \brief This quits the application and deletes it. You're not supposed to call its destructor directly. @@ -340,6 +320,12 @@ { // Message-dispatching loop for the ServerApp + // First let's tell the client how to talk with us. + fLink.StartMessage(B_OK); + fLink.Attach(fMessagePort); + fLink.Attach(fDesktop->SharedReadOnlyArea()); + fLink.Flush(); + BPrivate::LinkReceiver &receiver = fLink.Receiver(); int32 code; Modified: haiku/trunk/src/servers/app/ServerApp.h =================================================================== --- haiku/trunk/src/servers/app/ServerApp.h 2008-07-01 11:42:51 UTC (rev 26191) +++ haiku/trunk/src/servers/app/ServerApp.h 2008-07-01 15:47:56 UTC (rev 26192) @@ -50,7 +50,6 @@ status_t InitCheck(); void Quit(sem_id shutdownSemaphore = -1); - virtual bool Run(); virtual port_id MessagePort() const { return fMessagePort; } /*! Modified: haiku/trunk/src/servers/app/ServerWindow.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.cpp 2008-07-01 11:42:51 UTC (rev 26191) +++ haiku/trunk/src/servers/app/ServerWindow.cpp 2008-07-01 15:47:56 UTC (rev 26192) @@ -297,32 +297,6 @@ } -bool -ServerWindow::Run() -{ - if (!MessageLooper::Run()) - return false; - - // Send a reply to our window - it is expecting fMessagePort - // port and some other info - - fLink.StartMessage(B_OK); - fLink.Attach(fMessagePort); - - int32 minWidth, maxWidth, minHeight, maxHeight; - fWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); - - fLink.Attach(fWindow->Frame()); - fLink.Attach((float)minWidth); - fLink.Attach((float)maxWidth); - fLink.Attach((float)minHeight); - fLink.Attach((float)maxHeight); - fLink.Flush(); - - return true; -} - - void ServerWindow::_PrepareQuit() { @@ -2844,6 +2818,22 @@ void ServerWindow::_MessageLooper() { + // Send a reply to our window - it is expecting fMessagePort + // port and some other info. + + fLink.StartMessage(B_OK); + fLink.Attach(fMessagePort); + + int32 minWidth, maxWidth, minHeight, maxHeight; + fWindow->GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); + + fLink.Attach(fWindow->Frame()); + fLink.Attach((float)minWidth); + fLink.Attach((float)maxWidth); + fLink.Attach((float)minHeight); + fLink.Attach((float)maxHeight); + fLink.Flush(); + BPrivate::LinkReceiver& receiver = fLink.Receiver(); bool quitLoop = false; Modified: haiku/trunk/src/servers/app/ServerWindow.h =================================================================== --- haiku/trunk/src/servers/app/ServerWindow.h 2008-07-01 11:42:51 UTC (rev 26191) +++ haiku/trunk/src/servers/app/ServerWindow.h 2008-07-01 15:47:56 UTC (rev 26192) @@ -57,7 +57,6 @@ status_t Init(BRect frame, window_look look, window_feel feel, uint32 flags, uint32 workspace); - virtual bool Run(); virtual port_id MessagePort() const { return fMessagePort; } ::EventTarget& EventTarget() { return fEventTarget; } From anevilyak at gmail.com Tue Jul 1 17:50:30 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 1 Jul 2008 10:50:30 -0500 Subject: [Haiku-commits] r26192 - haiku/trunk/src/servers/app In-Reply-To: <200807011548.m61Fm1Os004276@sheep.berlios.de> References: <200807011548.m61Fm1Os004276@sheep.berlios.de> Message-ID: On Tue, Jul 1, 2008 at 10:48 AM, wrote: > Author: stippi > Date: 2008-07-01 17:47:56 +0200 (Tue, 01 Jul 2008) > New Revision: 26192 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26192&view=rev > > Modified: > haiku/trunk/src/servers/app/ServerApp.cpp > haiku/trunk/src/servers/app/ServerApp.h > haiku/trunk/src/servers/app/ServerWindow.cpp > haiku/trunk/src/servers/app/ServerWindow.h > Log: > stippi + bonefish: > Fixed race conditions when a ServerApp or ServerWindow is created. The > reply to the client that the object has been created successfully was > sent in the thread creating it. Preempted at the wrong time (right after > writing the message to the port) could lead to the object's thread using > the link at the same time, which would screw up all subsequent > communication via that link. > This fixes the problem that mimeset would sometimes fail when building > Haiku in Haiku (can't find the ticket). It probably also fixes #2331, > and the bug that sometimes when a window is opened (Terminal, crash > alert, shutdown window, etc.) it would come up with huge width/height > and tiny other dimension (can't find the ticket). > > Nice! The inf height bug is ticket 1997 by the way, should I close? Regards, Rene From mmlr at mlotz.ch Tue Jul 1 17:57:18 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Tue, 1 Jul 2008 17:57:18 +0200 Subject: [Haiku-commits] r26192 - haiku/trunk/src/servers/app In-Reply-To: References: <200807011548.m61Fm1Os004276@sheep.berlios.de> Message-ID: <20080701155645.M76205@mlotz.ch> On Tue, 1 Jul 2008 10:50:30 -0500, Rene Gollent wrote >> Fixed race conditions when a ServerApp or ServerWindow is created. The >> reply to the client that the object has been created successfully was >> sent in the thread creating it. Preempted at the wrong time (right after >> writing the message to the port) could lead to the object's thread using >> the link at the same time, which would screw up all subsequent >> communication via that link. > > Nice! The inf height bug is ticket 1997 by the way, should I close? Extremely nice catch indeed. I had tracked it down to the same issue, but didn't get around to find the cause of the corruption of the link. I'm glad it's fixed now. Bug #256 should be fixed with that. Regards Michael From anevilyak at mail.berlios.de Tue Jul 1 19:27:31 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Tue, 1 Jul 2008 19:27:31 +0200 Subject: [Haiku-commits] r26193 - haiku/trunk/src/kits/bluetooth Message-ID: <200807011727.m61HRVB9015750@sheep.berlios.de> Author: anevilyak Date: 2008-07-01 19:27:24 +0200 (Tue, 01 Jul 2008) New Revision: 26193 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26193&view=rev Modified: haiku/trunk/src/kits/bluetooth/CommandManager.cpp haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp haiku/trunk/src/kits/bluetooth/KitSupport.cpp haiku/trunk/src/kits/bluetooth/LocalDevice.cpp haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp Log: Set svn:eol property to native to deal with CR/LF problems. Property changes on: haiku/trunk/src/kits/bluetooth/CommandManager.cpp ___________________________________________________________________ Name: svn:eol + native Property changes on: haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp ___________________________________________________________________ Name: svn:eol + native Property changes on: haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp ___________________________________________________________________ Name: svn:eol + native Property changes on: haiku/trunk/src/kits/bluetooth/KitSupport.cpp ___________________________________________________________________ Name: svn:eol + native Property changes on: haiku/trunk/src/kits/bluetooth/LocalDevice.cpp ___________________________________________________________________ Name: svn:eol + native Property changes on: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp ___________________________________________________________________ Name: svn:eol + native From anevilyak at mail.berlios.de Tue Jul 1 19:31:14 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Tue, 1 Jul 2008 19:31:14 +0200 Subject: [Haiku-commits] r26194 - haiku/trunk/src/kits/bluetooth Message-ID: <200807011731.m61HVEdg030559@sheep.berlios.de> Author: anevilyak Date: 2008-07-01 19:31:11 +0200 (Tue, 01 Jul 2008) New Revision: 26194 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26194&view=rev Modified: haiku/trunk/src/kits/bluetooth/CommandManager.cpp haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp haiku/trunk/src/kits/bluetooth/Jamfile haiku/trunk/src/kits/bluetooth/KitSupport.cpp haiku/trunk/src/kits/bluetooth/KitSupport.h haiku/trunk/src/kits/bluetooth/LocalDevice.cpp haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp Log: That should've been eol-style :/ Property changes on: haiku/trunk/src/kits/bluetooth/CommandManager.cpp ___________________________________________________________________ Name: svn:eol - native Name: svn:eol-style + native Modified: haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-01 17:27:24 UTC (rev 26193) +++ haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-01 17:31:11 UTC (rev 26194) @@ -1,138 +1,138 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -#include "KitSupport.h" - -namespace Bluetooth { - - -RemoteDevicesList -DiscoveryAgent::RetrieveDevices(int option) -{ - /* No inquiry process initiated */ - if (fLastUsedListener == NULL) - return NULL; // xxx: Fix me - - return fLastUsedListener->GetRemoteDevicesList(); -} - - -status_t -DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) -{ - return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); -} - - -status_t -DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) -{ - BMessenger* btsm = NULL; - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - if (secs < 1 || secs > 61 ) - return B_TIMED_OUT; - - void* startInquiryCommand = NULL; - - // keep the listener whats the current listener for our inquiry state - fLastUsedListener = listener; - - // Inform the listener who is gonna be its owner LocalDevice - // and its discovered devices - listener->SetLocalDeviceOwner(fLocalDevice); - - /* Issue inquiry command */ - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - request.AddInt32("hci_id", fLocalDevice->GetID()); - - startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); - - // For stating the inquiry - request.AddData("raw command", B_ANY_TYPE, startInquiryCommand, size); - request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); - - // For getting each discovered message - request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_RESULT); - - // For finishing each discovered message - request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); - - - if (btsm->SendMessage(&request, listener) == B_OK) - { - return B_OK; - } - - return B_ERROR; - -} - - -status_t -DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) -{ - BMessenger* btsm = NULL; //TODO: this should be a member field - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - void* cancelInquiryCommand = NULL; - int8 bt_status = BT_ERROR; - - /* Issue inquiry command */ - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - request.AddInt32("hci_id", fLocalDevice->GetID()); - - cancelInquiryCommand = buildInquiryCancel(&size); - request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); - request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); - - if (btsm->SendMessage(&request, &reply) == B_OK) { - if (reply.FindInt8("status", &bt_status ) == B_OK ) { - return bt_status; - } - } - - return B_ERROR; -} - -void -DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) -{ - fLocalDevice = ld; -} - -DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) -{ - fLocalDevice = ld; -} - - -} +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +#include "KitSupport.h" + +namespace Bluetooth { + + +RemoteDevicesList +DiscoveryAgent::RetrieveDevices(int option) +{ + /* No inquiry process initiated */ + if (fLastUsedListener == NULL) + return NULL; // xxx: Fix me + + return fLastUsedListener->GetRemoteDevicesList(); +} + + +status_t +DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) +{ + return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); +} + + +status_t +DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) +{ + BMessenger* btsm = NULL; + size_t size; + + if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + return B_ERROR; + + if (secs < 1 || secs > 61 ) + return B_TIMED_OUT; + + void* startInquiryCommand = NULL; + + // keep the listener whats the current listener for our inquiry state + fLastUsedListener = listener; + + // Inform the listener who is gonna be its owner LocalDevice + // and its discovered devices + listener->SetLocalDeviceOwner(fLocalDevice); + + /* Issue inquiry command */ + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fLocalDevice->GetID()); + + startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); + + // For stating the inquiry + request.AddData("raw command", B_ANY_TYPE, startInquiryCommand, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); + + // For getting each discovered message + request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_RESULT); + + // For finishing each discovered message + request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); + + + if (btsm->SendMessage(&request, listener) == B_OK) + { + return B_OK; + } + + return B_ERROR; + +} + + +status_t +DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) +{ + BMessenger* btsm = NULL; //TODO: this should be a member field + size_t size; + + if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + return B_ERROR; + + void* cancelInquiryCommand = NULL; + int8 bt_status = BT_ERROR; + + /* Issue inquiry command */ + BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); + BMessage reply; + + request.AddInt32("hci_id", fLocalDevice->GetID()); + + cancelInquiryCommand = buildInquiryCancel(&size); + request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); + + if (btsm->SendMessage(&request, &reply) == B_OK) { + if (reply.FindInt8("status", &bt_status ) == B_OK ) { + return bt_status; + } + } + + return B_ERROR; +} + +void +DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) +{ + fLocalDevice = ld; +} + +DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) +{ + fLocalDevice = ld; +} + + +} Property changes on: haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp ___________________________________________________________________ Name: svn:eol - native Name: svn:eol-style + native Modified: haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp 2008-07-01 17:27:24 UTC (rev 26193) +++ haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp 2008-07-01 17:31:11 UTC (rev 26194) @@ -1,161 +1,161 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#include -#include -#include -#include -#include - -#include - -#include - -#include - -namespace Bluetooth { - - -/* hooks */ -void -DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) -{ - -} - - -void -DiscoveryListener::InquiryStarted(status_t status) -{ - -} - - -void -DiscoveryListener::InquiryCompleted(int discType) -{ - -} - - -/* private */ - -/* A LocalDevice is always referenced in any request to the - Bluetooth server therefore is going to be needed in any */ -void -DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) -{ - fLocalDevice = ld; -} - - -RemoteDevicesList -DiscoveryListener::GetRemoteDevicesList(void) -{ - return fRemoteDevicesList; -} - - -void -DiscoveryListener::MessageReceived(BMessage* message) -{ - int8 status; - - switch (message->what) - { - case BT_MSG_INQUIRY_DEVICE: - { - const struct inquiry_info* inquiryInfo; - ssize_t size; - RemoteDevice* rd = NULL; - bool duplicatedFound = false; - - if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) - { - - // Skip duplicated replies - for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { - - bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); - - if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) { - - // update these values - fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; - fRemoteDevicesList.ItemAt(index)->fScanPeriodMode = inquiryInfo->pscan_period_mode; - fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; - fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; - - duplicatedFound = true; - break; - } - - } - - if (!duplicatedFound) { - - // TODO: DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) - rd = new RemoteDevice(inquiryInfo->bdaddr); - fRemoteDevicesList.AddItem(rd); - // keep all inquiry reported data - rd->SetLocalDeviceOwner(fLocalDevice); - rd->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; - rd->fScanPeriodMode = inquiryInfo->pscan_period_mode; - rd->fScanMode = inquiryInfo->pscan_mode; - rd->fClockOffset = inquiryInfo->clock_offset; - - DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | - inquiryInfo->dev_class[1]<<8 | - inquiryInfo->dev_class[2]<<16 )); - } - } - } - break; - - case BT_MSG_INQUIRY_STARTED: - if (message->FindInt8("status", &status) == B_OK){ - fRemoteDevicesList.MakeEmpty(); - InquiryStarted(status); - } - - break; - - case BT_MSG_INQUIRY_COMPLETED: - - InquiryCompleted(BT_INQUIRY_COMPLETED); - - break; - case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ - - InquiryCompleted(BT_INQUIRY_TERMINATED); - - break; - case BT_MSG_INQUIRY_ERROR: - - InquiryCompleted(BT_INQUIRY_ERROR); - - break; - - default: - - BLooper::MessageReceived(message); - - break; - - } - -} - - -DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) -{ - // TODO: Make a better handling of the running not running state - Run(); -} - - -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +namespace Bluetooth { + + +/* hooks */ +void +DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) +{ + +} + + +void +DiscoveryListener::InquiryStarted(status_t status) +{ + +} + + +void +DiscoveryListener::InquiryCompleted(int discType) +{ + +} + + +/* private */ + +/* A LocalDevice is always referenced in any request to the + Bluetooth server therefore is going to be needed in any */ +void +DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) +{ + fLocalDevice = ld; +} + + +RemoteDevicesList +DiscoveryListener::GetRemoteDevicesList(void) +{ + return fRemoteDevicesList; +} + + +void +DiscoveryListener::MessageReceived(BMessage* message) +{ + int8 status; + + switch (message->what) + { + case BT_MSG_INQUIRY_DEVICE: + { + const struct inquiry_info* inquiryInfo; + ssize_t size; + RemoteDevice* rd = NULL; + bool duplicatedFound = false; + + if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) + { + + // Skip duplicated replies + for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { + + bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); + + if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) { + + // update these values + fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; + fRemoteDevicesList.ItemAt(index)->fScanPeriodMode = inquiryInfo->pscan_period_mode; + fRemoteDevicesList.ItemAt(index)->fScanMode = inquiryInfo->pscan_mode; + fRemoteDevicesList.ItemAt(index)->fClockOffset = inquiryInfo->clock_offset; + + duplicatedFound = true; + break; + } + + } + + if (!duplicatedFound) { + + // TODO: DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) + rd = new RemoteDevice(inquiryInfo->bdaddr); + fRemoteDevicesList.AddItem(rd); + // keep all inquiry reported data + rd->SetLocalDeviceOwner(fLocalDevice); + rd->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; + rd->fScanPeriodMode = inquiryInfo->pscan_period_mode; + rd->fScanMode = inquiryInfo->pscan_mode; + rd->fClockOffset = inquiryInfo->clock_offset; + + DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | + inquiryInfo->dev_class[1]<<8 | + inquiryInfo->dev_class[2]<<16 )); + } + } + } + break; + + case BT_MSG_INQUIRY_STARTED: + if (message->FindInt8("status", &status) == B_OK){ + fRemoteDevicesList.MakeEmpty(); + InquiryStarted(status); + } + + break; + + case BT_MSG_INQUIRY_COMPLETED: + + InquiryCompleted(BT_INQUIRY_COMPLETED); + + break; + case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ + + InquiryCompleted(BT_INQUIRY_TERMINATED); + + break; + case BT_MSG_INQUIRY_ERROR: + + InquiryCompleted(BT_INQUIRY_ERROR); + + break; + + default: + + BLooper::MessageReceived(message); + + break; + + } + +} + + +DiscoveryListener::DiscoveryListener() : BLooper() , fRemoteDevicesList(BT_MAX_RESPONSES) +{ + // TODO: Make a better handling of the running not running state + Run(); +} + + +} Property changes on: haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp ___________________________________________________________________ Name: svn:eol - native Name: svn:eol-style + native Property changes on: haiku/trunk/src/kits/bluetooth/Jamfile ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/kits/bluetooth/KitSupport.cpp ___________________________________________________________________ Name: svn:eol - native Name: svn:eol-style + native Property changes on: haiku/trunk/src/kits/bluetooth/KitSupport.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/src/kits/bluetooth/LocalDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2008-07-01 17:27:24 UTC (rev 26193) +++ haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2008-07-01 17:31:11 UTC (rev 26194) @@ -1,265 +1,265 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include "KitSupport.h" - -/* TODO: remove me */ -#include - -namespace Bluetooth { - -BMessenger* LocalDevice::sfMessenger = NULL; - - -LocalDevice* -LocalDevice::RequestLocalDeviceID(BMessage* request) -{ - BMessage reply; - hci_id hid; - - if (sfMessenger->SendMessage(request, &reply) == B_OK && - reply.FindInt32("hci_id", &hid) == B_OK ){ - - if (hid >= 0) { - return new LocalDevice(hid); - } - } - - return NULL; -} - - -#if 0 -#pragma - -#endif - - -LocalDevice* -LocalDevice::GetLocalDevice() -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - - return RequestLocalDeviceID(&request); -} - - -LocalDevice* -LocalDevice::GetLocalDevice(hci_id hid) -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - request.AddInt32("hci_id", hid); - - return RequestLocalDeviceID(&request); - -} - - -LocalDevice* -LocalDevice::GetLocalDevice(bdaddr_t bdaddr) -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t)); - - - return RequestLocalDeviceID(&request); -} - - -uint32 -LocalDevice::GetLocalDeviceCount() -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return 0; - - BMessage request(BT_MSG_COUNT_LOCAL_DEVICES); - BMessage reply; - - if (sfMessenger->SendMessage(&request, &reply) == B_OK) - return reply.FindInt32("count"); - else - return 0; - -} - - -DiscoveryAgent* -LocalDevice::GetDiscoveryAgent() -{ - /* TODO: Study a singleton here */ - return new DiscoveryAgent(this); -} - - -BString -LocalDevice::GetProperty(const char* property) -{ - - return NULL; - -} - - -void -LocalDevice::GetProperty(const char* property, uint32* value) -{ - - *value = 0; -} - - -int -LocalDevice::GetDiscoverable() -{ - - return 0; -} - - -status_t -LocalDevice::SetDiscoverable(int mode) -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return B_ERROR; - - BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); - BMessage reply; - - size_t size; - int8 bt_status = BT_ERROR; - - - request.AddInt32("hci_id", hid); - - - void* command = buildWriteScan(mode, &size); - - if (command == NULL) { - return B_NO_MEMORY; - } - - request.AddData("raw command", B_ANY_TYPE, command, size); - request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); - request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE)); - - if (fMessenger->SendMessage(&request, &reply) == B_OK) { - if (reply.FindInt8("status", &bt_status ) == B_OK ) { - return bt_status; - - } - - } - - return B_ERROR; -} - - -bdaddr_t -LocalDevice::GetBluetoothAddress() -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return bdaddrUtils::NullAddress(); - - const bdaddr_t* bdaddr; - BMessage request(BT_MSG_GET_ADDRESS); - BMessage reply; - ssize_t size; - - /* ADD ID */ - request.AddInt32("hci_id", hid); - - if (fMessenger->SendMessage(&request, &reply) == B_OK) { - - if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &size) == B_OK ){ - - return *bdaddr; - - } else { - return bdaddrUtils::NullAddress(); - } - - } - - return bdaddrUtils::NullAddress(); -} - - -BString -LocalDevice::GetFriendlyName() -{ - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BString friendlyname; - BMessage request(BT_MSG_GET_FRIENDLY_NAME); - BMessage reply; - - /* ADD ID */ - request.AddInt32("hci_id", hid); - - if (fMessenger->SendMessage(&request, &reply) == B_OK && - reply.FindString("friendlyname", &friendlyname) == B_OK ){ - - return friendlyname; - } - - return BString("Unknown"); -} - - -DeviceClass -LocalDevice::GetDeviceClass() -{ - - return DeviceClass(0); - -} - - -/* -ServiceRecord -LocalDevice::getRecord(Connection notifier) { - -} - -void -LocalDevice::updateRecord(ServiceRecord srvRecord) { - -} -*/ - - -LocalDevice::LocalDevice(hci_id hid) : hid(hid) -{ - -} - - -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "KitSupport.h" + +/* TODO: remove me */ +#include + +namespace Bluetooth { + +BMessenger* LocalDevice::sfMessenger = NULL; + + +LocalDevice* +LocalDevice::RequestLocalDeviceID(BMessage* request) +{ + BMessage reply; + hci_id hid; + + if (sfMessenger->SendMessage(request, &reply) == B_OK && + reply.FindInt32("hci_id", &hid) == B_OK ){ + + if (hid >= 0) { + return new LocalDevice(hid); + } + } + + return NULL; +} + + +#if 0 +#pragma - +#endif + + +LocalDevice* +LocalDevice::GetLocalDevice() +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + + return RequestLocalDeviceID(&request); +} + + +LocalDevice* +LocalDevice::GetLocalDevice(hci_id hid) +{ + if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) + return NULL; + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + request.AddInt32("hci_id", hid); + [... truncated: 586 lines follow ...] From oruizdorantes at mail.berlios.de Tue Jul 1 21:00:43 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 21:00:43 +0200 Subject: [Haiku-commits] r26195 - haiku/trunk/src/add-ons/kernel/network/protocols/l2cap Message-ID: <200807011900.m61J0hIW011805@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 21:00:39 +0200 (Tue, 01 Jul 2008) New Revision: 26195 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26195&view=rev Modified: haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp Log: Fix mail in header Modified: haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp 2008-07-01 17:31:11 UTC (rev 26194) +++ haiku/trunk/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp 2008-07-01 19:00:39 UTC (rev 26195) @@ -3,7 +3,7 @@ * Distributed under the terms of the MIT License. * * Authors: - * Oliver Ruiz Dorantes, oliver-ruiz.dorantes_at_gmail.com + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com */ From oruizdorantes at mail.berlios.de Tue Jul 1 21:15:19 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 21:15:19 +0200 Subject: [Haiku-commits] r26196 - in haiku/trunk/src: kits/bluetooth servers/bluetooth Message-ID: <200807011915.m61JFJXI012997@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 21:15:15 +0200 (Tue, 01 Jul 2008) New Revision: 26196 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26196&view=rev Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp Log: Handle the command status sent before the arrival of a remote name request. Avoid unhandled event in the bluetooth_server by Mika Lindqvist Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-01 19:00:39 UTC (rev 26195) +++ haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-01 19:15:15 UTC (rev 26196) @@ -64,15 +64,18 @@ remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size); + + request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); + request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); - request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); - //request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); + request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); + if (btsm->SendMessage(&request, &reply) == B_OK) { BString name; int8 status; - + if (reply.FindInt8("status", &status) == B_OK && reply.FindString("friendlyname", &name) == B_OK ) { return name; Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:00:39 UTC (rev 26195) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:15:15 UTC (rev 26196) @@ -368,6 +368,11 @@ } break; + case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST): + { + ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST)); + } + break; default: Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); break; From mmlr at mail.berlios.de Tue Jul 1 21:22:01 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Tue, 1 Jul 2008 21:22:01 +0200 Subject: [Haiku-commits] r26197 - haiku/trunk/src/add-ons/kernel/drivers/disk/usb/usb_disk Message-ID: <200807011922.m61JM1SQ013634@sheep.berlios.de> Author: mmlr Date: 2008-07-01 21:21:59 +0200 (Tue, 01 Jul 2008) New Revision: 26197 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26197&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp Log: While the comment was correct with regards to collecting the semaphore after the cancel, it wasn't actually done. This could bring a device out of sync in the case timeouts actually happened (which shouldn't be a commen case). Fixed that and increased the timeout to 2 seconds in favor of slower devices. Might need some fine tuning later still. Modified: haiku/trunk/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp 2008-07-01 19:15:15 UTC (rev 26196) +++ haiku/trunk/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp 2008-07-01 19:21:59 UTC (rev 26197) @@ -142,7 +142,7 @@ } do { - result = acquire_sem_etc(device->notify, 1, B_RELATIVE_TIMEOUT, 1000000); + result = acquire_sem_etc(device->notify, 1, B_RELATIVE_TIMEOUT, 2000000); if (result == B_TIMED_OUT) { // Cancel the transfer and collect the sem that should now be // released through the callback on cancel. Handling of device @@ -150,7 +150,7 @@ // the transfer failed. gUSBModule->cancel_queued_transfers(directionIn ? device->bulk_in : device->bulk_out); - continue; + acquire_sem_etc(device->notify, 1, B_RELATIVE_TIMEOUT, 0); } } while (result == B_INTERRUPTED); From oruizdorantes at mail.berlios.de Tue Jul 1 21:35:18 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 21:35:18 +0200 Subject: [Haiku-commits] r26198 - haiku/trunk/src/servers/bluetooth Message-ID: <200807011935.m61JZIuC014794@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 21:35:10 +0200 (Tue, 01 Jul 2008) New Revision: 26198 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26198&view=rev Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h Log: Fix a serious TODO, Report the index where the event opcode pair has been found. Currently server was expecting them to be the first entry of the request Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 19:21:59 UTC (rev 26197) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 19:35:10 UTC (rev 26198) @@ -82,39 +82,39 @@ int16 eventFound; int16 opcodeFound; int32 eventIndex = 0; - + // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - printf("@ Event expected found @%ld\n", eventIndex); + printf("@ Event expected found @%ld\n", eventIndex); if (eventFound == event) { - printf("@ Event matches %ld\n", eventIndex); + printf("@ Event matches %ld\n", eventIndex); // there is an opcode specified if (opcode != 0) { - + // The opcode matches if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && ((uint16)opcodeFound == opcode) ) { - + // this should remove only the entry printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); (void)msg->RemoveData("eventExpected", eventIndex); - (void)msg->RemoveData("opcodeExpected", eventIndex); + (void)msg->RemoveData("opcodeExpected", eventIndex); goto bail; - } - } else { + } + } else { // Event matches so far printf("@ Removed event %d from message %p\n", event, msg); (void)msg->RemoveData("eventExpected", eventIndex); goto bail; } - + } eventIndex++; } - + bail: fEventsWanted.Unlock(); @@ -123,45 +123,48 @@ BMessage* -LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode) +LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) { int16 eventFound; int16 opcodeFound; int32 eventIndex; - - fEventsWanted.Lock(); + + fEventsWanted.Lock(); // for each Petition for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { BMessage* msg = fEventsWanted.FindMessage(index); printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg); msg->PrintToStream(); - eventIndex = 0; - // for each Event + eventIndex = 0; + + // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { if (eventFound == event) { - printf("Event found %ld\n", eventIndex); + printf("Event found %ld\n", eventIndex); // there is an opcode specified.. if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { - + // ensure the opcode if ((uint16)opcodeFound != opcode) { - printf("opcode does not match %d\n", opcode); + printf("opcode does not match %d\n", opcode); break; } - printf("Opcdodes match %d %d \n", opcode , opcodeFound); + printf("Opcdodes match %d %d \n", opcode , opcodeFound); } - + fEventsWanted.Unlock(); + if (indexFound != NULL) + *indexFound = eventIndex; return msg; - + } eventIndex++; } } - + fEventsWanted.Unlock(); return NULL; } Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h 2008-07-01 19:21:59 UTC (rev 26197) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h 2008-07-01 19:35:10 UTC (rev 26198) @@ -40,7 +40,7 @@ void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0); void ClearWantedEvent(BMessage* msg); - BMessage* FindPetition(uint16 event, uint16 opcode = 0); + BMessage* FindPetition(uint16 event, uint16 opcode = 0, int32* indexFound = NULL); private: Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:21:59 UTC (rev 26197) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:35:10 UTC (rev 26198) @@ -98,17 +98,18 @@ BMessage* request = NULL; + int32 eventIndexLocation; // Check if its a requested one if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) { (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode ); + request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode, &eventIndexLocation ); } else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { (Output::Instance()->Post("Incoming Command Status\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode ); + request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode, &eventIndexLocation ); } else { @@ -160,11 +161,11 @@ break; case HCI_EVENT_CMD_COMPLETE: - CommandComplete((struct hci_ev_cmd_complete*)(event+1), request); + CommandComplete((struct hci_ev_cmd_complete*)(event+1), request, eventIndexLocation); break; - + case HCI_EVENT_CMD_STATUS: - CommandStatus((struct hci_ev_cmd_status*)(event+1), request); + CommandStatus((struct hci_ev_cmd_status*)(event+1), request, eventIndexLocation); break; case HCI_EVENT_FLUSH_OCCUR: @@ -230,7 +231,7 @@ void -LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request) { +LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index) { int16 opcodeExpected; BMessage reply; @@ -241,11 +242,11 @@ // Handle command complete information // FIX ME! the expected code might me in another // index as is relative to the event not the request - request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected); + request->FindInt16("opcodeExpected", index, &opcodeExpected); if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); + Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); switch (opcodeExpected) { @@ -332,7 +333,7 @@ void -LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request) { +LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index) { int16 opcodeExpected; BMessage reply; @@ -341,31 +342,30 @@ Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID()); // Handle command complete information - request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected); + request->FindInt16("opcodeExpected", index, &opcodeExpected); if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); - - + Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); + switch (opcodeExpected) { - + case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY): - { + { reply.what = BT_MSG_INQUIRY_STARTED; reply.AddInt8("status", event->status); - - if (event->status == BT_OK) { + + if (event->status == BT_OK) { Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT); } else { - Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT); + Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT); } - printf("Sending reply ... %ld\n", request->SendReply(&reply)); + printf("Sending reply ... %ld\n", request->SendReply(&reply)); reply.PrintToStream(); - + ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); - } + } break; case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST): @@ -374,7 +374,7 @@ } break; default: - Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); + Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); break; } @@ -415,21 +415,21 @@ LocalDeviceImpl::RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request) { BMessage reply; - - reply.AddInt8("status", remotename->status); - + + reply.AddInt8("status", remotename->status); + if (remotename->status == BT_OK) { - - reply.AddString("friendlyname", (const char*)remotename->remote_name ); + + reply.AddString("friendlyname", (const char*)remotename->remote_name ); Output::Instance()->Post("Positive reply for remote friendly name\n", BLACKBOARD_KIT); } else { - Output::Instance()->Post("Negative reply for remote friendly name\n", BLACKBOARD_KIT); + Output::Instance()->Post("Negative reply for remote friendly name\n", BLACKBOARD_KIT); } - printf("Sending reply ... %ld\n", request->SendReply(&reply)); + printf("Sending reply ... %ld\n", request->SendReply(&reply)); reply.PrintToStream(); // This request is not genna be used anymore Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h 2008-07-01 19:21:59 UTC (rev 26197) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h 2008-07-01 19:35:10 UTC (rev 26198) @@ -37,8 +37,8 @@ status_t ProcessSimpleRequest(BMessage* request); /* Events handling */ - void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request); - void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request); + void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index); + void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index); // Inquiry void InquiryResult(uint8* numberOfResponses, BMessage* request); From oruizdorantes at mail.berlios.de Tue Jul 1 21:43:46 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 21:43:46 +0200 Subject: [Haiku-commits] r26199 - haiku/trunk/src/servers/bluetooth Message-ID: <200807011943.m61Jhk08015514@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 21:43:37 +0200 (Tue, 01 Jul 2008) New Revision: 26199 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26199&view=rev Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h haiku/trunk/src/servers/bluetooth/HCIDelegate.h haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp Log: Fix EOL Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,26 +1,26 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include "HCIControllerAccessor.h" - -HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path) -{ - - -} - -status_t -HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size) -{ - - if (GetID() < 0) - return B_ERROR; - - - return B_ERROR; -} +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include "HCIControllerAccessor.h" + +HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path) +{ + + +} + +status_t +HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size) +{ + + if (GetID() < 0) + return B_ERROR; + + + return B_ERROR; +} Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,23 +1,23 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - - -#ifndef _HCICONTROLLER_ACCESSOR_H_ -#define _HCICONTROLLER_ACCESSOR_H_ - -#include "HCIDelegate.h" - - -class HCIControllerAccessor : public HCIDelegate { - - public: - HCIControllerAccessor(BPath* path); - status_t IssueCommand(raw_command* rc, size_t size); -}; - -#endif +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + + +#ifndef _HCICONTROLLER_ACCESSOR_H_ +#define _HCICONTROLLER_ACCESSOR_H_ + +#include "HCIDelegate.h" + + +class HCIControllerAccessor : public HCIDelegate { + + public: + HCIControllerAccessor(BPath* path); + status_t IssueCommand(raw_command* rc, size_t size); +}; + +#endif Modified: haiku/trunk/src/servers/bluetooth/HCIDelegate.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIDelegate.h 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/HCIDelegate.h 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,65 +1,65 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _HCIDELEGATE_H_ -#define _HCIDELEGATE_H_ - -#include -#include -#include -#include - -#include - - -typedef void* raw_command; - - -class HCIDelegate { - - public: - HCIDelegate(BPath* path) - { - status_t status; - - fFD = open (path->Path(), O_RDWR); - if (fFD > 0) { - // find out which ID was assigned - status = ioctl(fFD, GET_HCI_ID, &fHID, 0); - printf("%s: hid retrieved %ld status=%ld\n", __FUNCTION__, fHID, status); - } - else { - printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID); - fHID = B_ERROR; - } - - - - } - - hci_id GetID(void) - { - return fHID; - } - - virtual status_t IssueCommand(raw_command rc, size_t size) - { - return B_ERROR; - } - - protected: - - - hci_id fHID; - int fFD; - - private: - - -}; - -#endif +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _HCIDELEGATE_H_ +#define _HCIDELEGATE_H_ + +#include +#include +#include +#include + +#include + + +typedef void* raw_command; + + +class HCIDelegate { + + public: + HCIDelegate(BPath* path) + { + status_t status; + + fFD = open (path->Path(), O_RDWR); + if (fFD > 0) { + // find out which ID was assigned + status = ioctl(fFD, GET_HCI_ID, &fHID, 0); + printf("%s: hid retrieved %ld status=%ld\n", __FUNCTION__, fHID, status); + } + else { + printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID); + fHID = B_ERROR; + } + + + + } + + hci_id GetID(void) + { + return fHID; + } + + virtual status_t IssueCommand(raw_command rc, size_t size) + { + return B_ERROR; + } + + protected: + + + hci_id fHID; + int fFD; + + private: + + +}; + +#endif Modified: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,22 +1,22 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#ifndef _HCITRANSPORT_ACCESSOR_H_ -#define _HCITRANSPORT_ACCESSOR_H_ - -#include "HCIDelegate.h" - - -class HCITransportAccessor : public HCIDelegate { - - public: - HCITransportAccessor(BPath* path); - status_t IssueCommand(raw_command rc, size_t size); -}; - -#endif +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#ifndef _HCITRANSPORT_ACCESSOR_H_ +#define _HCITRANSPORT_ACCESSOR_H_ + +#include "HCIDelegate.h" + + +class HCITransportAccessor : public HCIDelegate { + + public: + HCITransportAccessor(BPath* path); + status_t IssueCommand(raw_command rc, size_t size); +}; + +#endif Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,170 +1,170 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include "LocalDeviceHandler.h" - - - -LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd) -{ - fHCIDelegate = hd; - fProperties = new BMessage(); - -} - -LocalDeviceHandler::~LocalDeviceHandler() -{ - -} - - -hci_id -LocalDeviceHandler::GetID() -{ - return fHCIDelegate->GetID(); -} - - -bool -LocalDeviceHandler::Available() { - - return true; -} - - -void -LocalDeviceHandler::Acquire(void) { - -} - - -bool -LocalDeviceHandler::IsPropertyAvailable(const BString& property) { - - type_code typeFound; - int32 countFound; - - return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK ); - -} - - -void -LocalDeviceHandler::AddWantedEvent(BMessage* msg) -{ - fEventsWanted.Lock(); - // TODO: review why it is neede to replicate the msg - fEventsWanted.AddMessage(msg); - fEventsWanted.Unlock(); -} - -void -LocalDeviceHandler::ClearWantedEvent(BMessage* msg) -{ - fEventsWanted.Lock(); - fEventsWanted.RemoveMessage(msg); - fEventsWanted.Unlock(); - -} - - -void -LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode) -{ - // Remove the whole petition from queue - fEventsWanted.Lock(); - - int16 eventFound; - int16 opcodeFound; - int32 eventIndex = 0; - - // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - - printf("@ Event expected found @%ld\n", eventIndex); - - if (eventFound == event) { - - printf("@ Event matches %ld\n", eventIndex); - // there is an opcode specified - if (opcode != 0) { - - // The opcode matches - if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && - ((uint16)opcodeFound == opcode) ) { - - // this should remove only the entry - printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); - (void)msg->RemoveData("eventExpected", eventIndex); - (void)msg->RemoveData("opcodeExpected", eventIndex); - goto bail; - } - } else { - // Event matches so far - printf("@ Removed event %d from message %p\n", event, msg); - (void)msg->RemoveData("eventExpected", eventIndex); - goto bail; - } - - } - eventIndex++; - } - -bail: - - fEventsWanted.Unlock(); - -} - - -BMessage* -LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) -{ - int16 eventFound; - int16 opcodeFound; - int32 eventIndex; - - fEventsWanted.Lock(); - // for each Petition - for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { - BMessage* msg = fEventsWanted.FindMessage(index); - - printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg); - msg->PrintToStream(); - eventIndex = 0; - - // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - if (eventFound == event) { - - printf("Event found %ld\n", eventIndex); - // there is an opcode specified.. - if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { - - // ensure the opcode - if ((uint16)opcodeFound != opcode) { - printf("opcode does not match %d\n", opcode); - break; - } - printf("Opcdodes match %d %d \n", opcode , opcodeFound); - } - - fEventsWanted.Unlock(); - if (indexFound != NULL) - *indexFound = eventIndex; - return msg; - - - } - eventIndex++; - } - } - - fEventsWanted.Unlock(); - return NULL; -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include "LocalDeviceHandler.h" + + + +LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd) +{ + fHCIDelegate = hd; + fProperties = new BMessage(); + +} + +LocalDeviceHandler::~LocalDeviceHandler() +{ + +} + + +hci_id +LocalDeviceHandler::GetID() +{ + return fHCIDelegate->GetID(); +} + + +bool +LocalDeviceHandler::Available() { + + return true; +} + + +void +LocalDeviceHandler::Acquire(void) { + +} + + +bool +LocalDeviceHandler::IsPropertyAvailable(const BString& property) { + + type_code typeFound; + int32 countFound; + + return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK ); + +} + + +void +LocalDeviceHandler::AddWantedEvent(BMessage* msg) +{ + fEventsWanted.Lock(); + // TODO: review why it is neede to replicate the msg + fEventsWanted.AddMessage(msg); + fEventsWanted.Unlock(); +} + +void +LocalDeviceHandler::ClearWantedEvent(BMessage* msg) +{ + fEventsWanted.Lock(); + fEventsWanted.RemoveMessage(msg); + fEventsWanted.Unlock(); + +} + + +void +LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode) +{ + // Remove the whole petition from queue + fEventsWanted.Lock(); + + int16 eventFound; + int16 opcodeFound; + int32 eventIndex = 0; + + // for each Event + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { + + printf("@ Event expected found @%ld\n", eventIndex); + + if (eventFound == event) { + + printf("@ Event matches %ld\n", eventIndex); + // there is an opcode specified + if (opcode != 0) { + + // The opcode matches + if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && + ((uint16)opcodeFound == opcode) ) { + + // this should remove only the entry + printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); + (void)msg->RemoveData("eventExpected", eventIndex); + (void)msg->RemoveData("opcodeExpected", eventIndex); + goto bail; + } + } else { + // Event matches so far + printf("@ Removed event %d from message %p\n", event, msg); + (void)msg->RemoveData("eventExpected", eventIndex); + goto bail; + } + + } + eventIndex++; + } + +bail: + + fEventsWanted.Unlock(); + +} + + +BMessage* +LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) +{ + int16 eventFound; + int16 opcodeFound; + int32 eventIndex; + + fEventsWanted.Lock(); + // for each Petition + for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { + BMessage* msg = fEventsWanted.FindMessage(index); + + printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg); + msg->PrintToStream(); + eventIndex = 0; + + // for each Event + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { + if (eventFound == event) { + + printf("Event found %ld\n", eventIndex); + // there is an opcode specified.. + if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { + + // ensure the opcode + if ((uint16)opcodeFound != opcode) { + printf("opcode does not match %d\n", opcode); + break; + } + printf("Opcdodes match %d %d \n", opcode , opcodeFound); + } + + fEventsWanted.Unlock(); + if (indexFound != NULL) + *indexFound = eventIndex; + return msg; + + + } + eventIndex++; + } + } + + fEventsWanted.Unlock(); + return NULL; +} Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:35:10 UTC (rev 26198) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp 2008-07-01 19:43:37 UTC (rev 26199) @@ -1,551 +1,551 @@ -/* - * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include "BluetoothServer.h" - -#include "LocalDeviceImpl.h" -#include "CommandManager.h" -#include "Output.h" - -#include -#include - -#include -#include -#include - -#include - - -#if 0 -#pragma mark - Class methods - -#endif - - -// Factory methods -LocalDeviceImpl* -LocalDeviceImpl::CreateControllerAccessor(BPath* path) -{ - HCIDelegate* hd = new HCIControllerAccessor(path); - - if ( hd != NULL) - return new LocalDeviceImpl(hd); - else - return NULL; -} - - -LocalDeviceImpl* -LocalDeviceImpl::CreateTransportAccessor(BPath* path) -{ - HCIDelegate* hd = new HCITransportAccessor(path); - - if ( hd != NULL) - return new LocalDeviceImpl(hd); - else - return NULL; -} - - -LocalDeviceImpl::LocalDeviceImpl(HCIDelegate* hd) : LocalDeviceHandler(hd) -{ - -} - -#if 0 -#pragma mark - Event handling methods - -#endif - -void -LocalDeviceImpl::HandleEvent(struct hci_event_header* event) -{ - -printf("### Event comming: len = %d\n", event->elen); -for (int16 index = 0 ; index < event->elen + 2; index++ ) { - printf("%x:",((uint8*)event)[index]); -} -printf("### \n"); - - // Events here might have not been initated by us - switch (event->ecode) { - case HCI_EVENT_HARDWARE_ERROR: - //HardwareError(event); - return; - case HCI_EVENT_CONN_REQUEST: - - break; - - case HCI_EVENT_CONN_COMPLETE: - ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL); // should belong to a request? - - break; - - case HCI_EVENT_PIN_CODE_REQ: - PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL); - break; - - - default: - // lets go on - break; - } - - - - BMessage* request = NULL; - int32 eventIndexLocation; - - // Check if its a requested one - if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) { - - (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode, &eventIndexLocation ); - - } else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { - - (Output::Instance()->Post("Incoming Command Status\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode, &eventIndexLocation ); - - } else - { - request = FindPetition(event->ecode); - } - - if ( request == NULL) { - (Output::Instance()->Post("Event could not be understood or delivered\n", BLACKBOARD_EVENTS)); - return; - } - - // we are waiting for a reply - switch (event->ecode) { - case HCI_EVENT_INQUIRY_COMPLETE: - InquiryComplete((uint8*)(event+1), request); - break; - - case HCI_EVENT_INQUIRY_RESULT: - InquiryResult((uint8*)(event+1), request); - break; - - case HCI_EVENT_DISCONNECTION_COMPLETE: - - break; - - case HCI_EVENT_AUTH_COMPLETE: - break; - - case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE: - RemoteNameRequestComplete((struct hci_remote_name_request_complete_reply*)(event+1), request); - break; - - case HCI_EVENT_ENCRYPT_CHANGE: - break; - - case HCI_EVENT_CHANGE_CONN_LINK_KEY_COMPLETE: - break; - - case HCI_EVENT_MASTER_LINK_KEY_COMPL: - break; - - case HCI_EVENT_RMT_FEATURES: - break; - - case HCI_EVENT_RMT_VERSION: - break; - - case HCI_EVENT_QOS_SETUP_COMPLETE: - break; - - case HCI_EVENT_CMD_COMPLETE: - CommandComplete((struct hci_ev_cmd_complete*)(event+1), request, eventIndexLocation); - break; - - case HCI_EVENT_CMD_STATUS: - CommandStatus((struct hci_ev_cmd_status*)(event+1), request, eventIndexLocation); - break; - - case HCI_EVENT_FLUSH_OCCUR: - break; - - case HCI_EVENT_ROLE_CHANGE: - break; - - case HCI_EVENT_NUM_COMP_PKTS: - break; - - case HCI_EVENT_MODE_CHANGE: - break; - - case HCI_EVENT_RETURN_LINK_KEYS: - break; - - case HCI_EVENT_LINK_KEY_REQ: - break; - - case HCI_EVENT_LINK_KEY_NOTIFY: - break; - - case HCI_EVENT_LOOPBACK_COMMAND: - break; - - case HCI_EVENT_DATA_BUFFER_OVERFLOW: - break; - - case HCI_EVENT_MAX_SLOT_CHANGE: - break; - - case HCI_EVENT_READ_CLOCK_OFFSET_COMPL: - break; - - case HCI_EVENT_CON_PKT_TYPE_CHANGED: - break; - - case HCI_EVENT_QOS_VIOLATION: - break; - - case HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE: - break; - - case HCI_EVENT_FLOW_SPECIFICATION: - break; - - case HCI_EVENT_INQUIRY_RESULT_WITH_RSSI: - break; - - case HCI_EVENT_REMOTE_EXTENDED_FEATURES: - break; - - case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETED: - break; - - case HCI_EVENT_SYNCHRONOUS_CONNECTION_CHANGED: - - break; - } - -} - - -void -LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index) { - - int16 opcodeExpected; - BMessage reply; - - Output::Instance()->Post(__FUNCTION__, BLACKBOARD_LD_OFFSET + GetID()); - Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID()); - - // Handle command complete information - // FIX ME! the expected code might me in another - // index as is relative to the event not the request - request->FindInt16("opcodeExpected", index, &opcodeExpected); - - - if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); - - switch (opcodeExpected) { - - case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): - { - struct hci_rp_read_bd_addr* readbdaddr = (struct hci_rp_read_bd_addr*)(event+1); - - if (readbdaddr->status == BT_OK) { - - reply.AddData("bdaddr", B_ANY_TYPE, &readbdaddr->bdaddr, sizeof(bdaddr_t)); - reply.AddInt32("status", readbdaddr->status); - - printf("Sending reply ... %ld\n",request->SendReply(&reply)); - reply.PrintToStream(); - - Output::Instance()->Post("Positive reply for getAdress\n", BLACKBOARD_KIT); - - } else { - reply.AddInt8("status", readbdaddr->status); - request->SendReply(&reply); - Output::Instance()->Post("Negative reply for getAdress\n", BLACKBOARD_KIT); - } - - // This request is not genna be used anymore - ClearWantedEvent(request); - } - break; - - case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME): - { - struct hci_rp_read_local_name* readLocalName = (struct hci_rp_read_local_name*)(event+1); - - reply.AddInt8("status", readLocalName->status); - - if (readLocalName->status == BT_OK) { - - reply.AddString("friendlyname", (const char*)readLocalName->local_name ); - Output::Instance()->Post("Positive reply for friendly name\n", BLACKBOARD_KIT); - - } else { - - Output::Instance()->Post("Negative reply for friendly name\n", BLACKBOARD_KIT); - - } - - printf("Sending reply ... %ld\n",request->SendReply(&reply)); - reply.PrintToStream(); - - // This request is not genna be used anymore - ClearWantedEvent(request); - } - break; - - case PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE): - { - uint8* statusReply = (uint8*)(event+1); - - reply.AddInt8("status", *statusReply); - - if (*statusReply == BT_OK) { - - Output::Instance()->Post("Positive reply for scanmode\n", BLACKBOARD_KIT); - - } else { - - Output::Instance()->Post("Negative reply for scanmode\n", BLACKBOARD_KIT); - - } - - printf("Sending reply ... %ld\n",request->SendReply(&reply)); - reply.PrintToStream(); - - // This request is not genna be used anymore - ClearWantedEvent(request); - } - break; - - default: - Output::Instance()->Post("Command Complete not handled\n", BLACKBOARD_KIT); - break; - - } -} - - -void -LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index) { - - int16 opcodeExpected; - BMessage reply; - - Output::Instance()->Post(__FUNCTION__, BLACKBOARD_LD_OFFSET + GetID()); - Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID()); - - // Handle command complete information - request->FindInt16("opcodeExpected", index, &opcodeExpected); - - - if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); - - switch (opcodeExpected) { - - case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY): [... truncated: 750 lines follow ...] From korli at users.berlios.de Tue Jul 1 22:08:34 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Tue, 1 Jul 2008 22:08:34 +0200 Subject: [Haiku-commits] r26187 - in haiku/trunk/src/add-ons/kernel/file_systems: . ext2 In-Reply-To: <200807011012.m61ACKEU005427@sheep.berlios.de> References: <200807011012.m61ACKEU005427@sheep.berlios.de> Message-ID: 2008/7/1 axeld at BerliOS : > haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h I have this with gcc4. src/add-ons/kernel/file_systems/ext2/ext2.h:155: error: 'struct ext2_inode::::data_stream' invalid; an anonymous union can only have non-static data members /home/korli/svnhaiku/haiku/generated/cross-tools/bin/i586-pc-haiku-gcc -c "src/add-ons/kernel/file_systems/ext2/Volume.cpp" -O -Wall -Wno-trigraphs -pipe -fno-strict-aliasing -fno-tree-vrp -nostdinc -Wno-multichar -Wno-deprecated -Wall -Wno-multichar -D_ZETA_USING_DEPRECATED_API_=1 -D_ZETA_TS_FIND_DIR_=1 -pipe -fno-strict-aliasing -fno-tree-vrp -finline -fno-builtin -fno-exceptions -Wno-multichar -DBOCHS_DEBUG_HACK=0 -fno-use-cxa-atexit -D_KERNEL_MODE -D__HAIKU__ -DHAIKU_DISTRO_COMPATIBILITY_DEFAULT -D__INTEL__ -DARCH_x86 -DHAIKU_TARGET_PLATFORM_HAIKU -iquote build/user_config_headers -iquote build/config_headers -iquote src/add-ons/kernel/file_systems/ext2 -iquote /home/korli/svnhaiku/haiku/generated/objects/common/add-ons/kernel/file_systems/ext2 -iquote /home/korli/svnhaiku/haiku/generated/objects/linux/x86/common/add-ons/kernel/file_systems/ext2 -iquote /home/korli/svnhaiku/haiku/generated/objects/haiku/x86/common/add-ons/kernel/file_systems/ext2 -I headers/private/shared -I headers/private/storage -I headers/private/. -I headers/private/kernel -I headers/private/libroot -I headers/private/kernel/boot/platform/bios_ia32 -I headers/private/kernel/arch/x86 -I headers/private/. -I headers/private/system -I headers/private/system/arch/x86 -I /home/korli/svnhaiku/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/include -I headers -I headers/posix -I headers/gnu -I headers/glibc -I headers/os -I headers/os/add-ons -I headers/os/add-ons/file_system -I headers/os/add-ons/graphics -I headers/os/add-ons/input_server -I headers/os/add-ons/registrar -I headers/os/add-ons/screen_saver -I headers/os/add-ons/tracker -I headers/os/app -I headers/os/device -I headers/os/drivers -I headers/os/game -I headers/os/interface -I headers/os/kernel -I headers/os/media -I headers/os/mail -I headers/os/midi -I headers/os/midi2 -I headers/os/net -I headers/os/opengl -I headers/os/storage -I headers/os/support -I headers/os/translation -I headers/private/. -I /home/korli/svnhaiku/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2 -I /home/korli/svnhaiku/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/i586-pc-haiku -I /home/korli/svnhaiku/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/backward -I /home/korli/svnhaiku/haiku/generated/cross-tools/lib/gcc/i586-pc-haiku/4.1.2/../../../../include/c++/4.1.2/ext -o "/home/korli/svnhaiku/haiku/generated/objects/haiku/x86/release/add-ons/kernel/file_systems/ext2/Volume.o" ; From mmlr at mail.berlios.de Tue Jul 1 22:18:04 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Tue, 1 Jul 2008 22:18:04 +0200 Subject: [Haiku-commits] r26200 - haiku/trunk/src/system/kernel Message-ID: <200807012018.m61KI4ic018065@sheep.berlios.de> Author: mmlr Date: 2008-07-01 22:18:02 +0200 (Tue, 01 Jul 2008) New Revision: 26200 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26200&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Take a shortcut when freeing in heap_realloc(), we already know the address belongs to our heap. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 19:43:37 UTC (rev 26199) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 20:18:02 UTC (rev 26200) @@ -1158,7 +1158,7 @@ // copy the old data and free the old allocation memcpy(*newAddress, address, min_c(maxSize, newSize)); - free(address); + heap_free(heap, address); return B_OK; } From oruizdorantes at mail.berlios.de Tue Jul 1 22:25:14 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 22:25:14 +0200 Subject: [Haiku-commits] r26201 - in haiku/trunk/src/add-ons/kernel/network/devices: . bluetooth Message-ID: <200807012025.m61KPEO7018624@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 22:25:08 +0200 (Tue, 01 Jul 2008) New Revision: 26201 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26201&view=rev Added: haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/ haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/Jamfile haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp Log: Add entity to handle the available LocalDevices from KL Added: haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/Jamfile 2008-07-01 20:18:02 UTC (rev 26200) +++ haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/Jamfile 2008-07-01 20:25:08 UTC (rev 26201) @@ -0,0 +1,26 @@ +SubDir HAIKU_TOP src add-ons kernel network devices bluetooth ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +if $(TARGET_PLATFORM) != haiku { + UseHeaders [ FStandardOSHeaders ] : true ; + # Needed for and maybe other stuff. + UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ; + # We need the public network headers also when not compiling for Haiku. + # Unfortunately we get more than we want, namely all POSIX headers. +} + +UsePrivateKernelHeaders ; +UsePrivateHeaders net bluetooth ; + +KernelAddon bluetooth : + bluetooth.cpp +; + +# Installation +#HaikuInstall install-networking : /boot/home/config/add-ons/kernel/haiku_network/devices +# : bluetooth ; + +#Package haiku-networkingkit-cvs : +# haiku : +# boot home config add-ons kernel haiku_network protocols ; Added: haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp 2008-07-01 20:18:02 UTC (rev 26200) +++ haiku/trunk/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp 2008-07-01 20:25:08 UTC (rev 26201) @@ -0,0 +1,311 @@ +/* + * Copyright 2008, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + */ + + +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#define BT_DEBUG_THIS_MODULE +#include + + +struct bluetooth_device : net_device, DoublyLinkedListLinkImpl { + int fd; + uint16 frame_size; +}; + +/* Modules references */ +net_buffer_module_info *gBufferModule = NULL; +static net_stack_module_info *sStackModule = NULL; + +static mutex sListLock; +static DoublyLinkedList sDeviceList; +static sem_id sLinkChangeSemaphore; + +// #pragma mark - + +status_t +bluetooth_init(const char *name, net_device **_device) +{ + debugf("Inidializing bluetooth device %s\n",name); + + // make sure this is a device in /dev/bluetooth + if (strncmp(name, "/dev/bluetooth/", 15)) + return B_BAD_VALUE; + + if (gBufferModule == NULL) { // lazy allocation + status_t status = get_module(NET_BUFFER_MODULE_NAME, (module_info **)&gBufferModule); + if (status < B_OK) + return status; + } + + bluetooth_device *device = new (std::nothrow) bluetooth_device; + if (device == NULL) { + put_module(NET_BUFFER_MODULE_NAME); + return B_NO_MEMORY; + } + + memset(device, 0, sizeof(bluetooth_device)); + + // Fill + strcpy(device->name, name); + + MutexLocker _(&sListLock); + + device->index = (sDeviceList.Tail())->index + 1; // TODO: index will be assigned by netstack + + // TODO: add to list whould be done in up hook + sDeviceList.Add(device); + + *_device = device; + return B_OK; +} + + +status_t +bluetooth_uninit(net_device *_device) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + // if the device is still part of the list, remove it + if (device->GetDoublyLinkedListLink()->next != NULL + || device->GetDoublyLinkedListLink()->previous != NULL + || device == sDeviceList.Head()) + sDeviceList.Remove(device); + + put_module(NET_BUFFER_MODULE_NAME); + delete device; + + return B_OK; +} + + +status_t +bluetooth_up(net_device *_device) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + device->fd = open(device->name, O_RDWR); + if (device->fd < 0) + goto err; + + return B_OK; + +err: + close(device->fd); + device->fd = -1; + return errno; +} + + +void +bluetooth_down(net_device *_device) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + close(device->fd); + device->fd = -1; +} + + +status_t +bluetooth_control(net_device *_device, int32 op, void *argument, + size_t length) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + // Forward the call to the driver + return ioctl(device->fd, op, argument, length); +} + + +status_t +bluetooth_send_data(net_device *_device, net_buffer *buffer) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld try to send bt packet of %lu bytes (flags %ld):\n",device->index, buffer->size, buffer->flags); + + /* TODO: + + */ + +// MTU and size possiblities to be checked in l2cap.... +// if (buffer->size > device->frame_size) +// return B_BAD_VALUE; + + return B_OK; +} + + +status_t +bluetooth_receive_data(net_device *_device, net_buffer **_buffer) +{ + bluetooth_device *device = (bluetooth_device *)_device; + status_t status = B_OK; + + debugf("index %ld try to send bt packet of %lu bytes (flags %ld):\n", device->index, (*_buffer)->size, (*_buffer)->flags); + + if (device->fd == -1) + return B_FILE_ERROR; + + /* TODO: + + */ + + return status; +} + + +status_t +bluetooth_set_mtu(net_device *_device, size_t mtu) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld mtu %ld\n",device->index, mtu); + + device->mtu = mtu; + + return B_OK; +} + + +status_t +bluetooth_set_promiscuous(net_device *_device, bool promiscuous) +{ + bluetooth_device *device = (bluetooth_device *)_device; + + debugf("index %ld promiscuous %d\n",device->index, promiscuous); + + return EOPNOTSUPP; +} + + +status_t +bluetooth_set_media(net_device *device, uint32 media) +{ + debugf("index %ld media %ld\n",device->index, media); + + return EOPNOTSUPP; +} + + +status_t +bluetooth_add_multicast(struct net_device *_device, const sockaddr *_address) +{ + bluetooth_device* device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + return EOPNOTSUPP; +} + +status_t +bluetooth_remove_multicast(struct net_device *_device, const sockaddr *_address) +{ + bluetooth_device* device = (bluetooth_device *)_device; + + debugf("index %ld\n",device->index); + + return EOPNOTSUPP; +} + + +static status_t +bluetooth_std_ops(int32 op, ...) +{ + + flowf("\n"); + + switch (op) { + case B_MODULE_INIT: + { + status_t status = get_module(NET_STACK_MODULE_NAME, + (module_info **)&sStackModule); + if (status < B_OK) + return status; + + new (&sDeviceList) DoublyLinkedList; + // static C++ objects are not initialized in the module startup + + sLinkChangeSemaphore = create_sem(0, "bt sem"); + if (sLinkChangeSemaphore < B_OK) { + put_module(NET_STACK_MODULE_NAME); + return sLinkChangeSemaphore; + } + + mutex_init(&sListLock, "bluetooth devices"); + + return B_OK; + } + + case B_MODULE_UNINIT: + { + delete_sem(sLinkChangeSemaphore); + + mutex_destroy(&sListLock); + put_module(NET_STACK_MODULE_NAME); + return B_OK; + } + + default: + return B_ERROR; + } +} + + +net_device_module_info sBluetoothModule = { + { + "network/devices/bluetooth/v1", + 0, + bluetooth_std_ops + }, + bluetooth_init, + bluetooth_uninit, + bluetooth_up, + bluetooth_down, + bluetooth_control, + bluetooth_send_data, + bluetooth_receive_data, + bluetooth_set_mtu, + bluetooth_set_promiscuous, + bluetooth_set_media, + bluetooth_add_multicast, + bluetooth_remove_multicast, +}; + +module_info *modules[] = { + (module_info *)&sBluetoothModule, + + NULL +}; From oruizdorantes at mail.berlios.de Tue Jul 1 22:28:15 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 1 Jul 2008 22:28:15 +0200 Subject: [Haiku-commits] r26202 - haiku/trunk/src/servers/bluetooth Message-ID: <200807012028.m61KSFim018870@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-01 22:28:12 +0200 (Tue, 01 Jul 2008) New Revision: 26202 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26202&view=rev Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp Log: Fix typos reported by Mika, and remove whitespaces Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 20:25:08 UTC (rev 26201) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-01 20:28:12 UTC (rev 26202) @@ -84,40 +84,40 @@ int32 eventIndex = 0; // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - printf("@ Event expected found @%ld\n", eventIndex); + printf("@ Event expected found @%ld\n", eventIndex); - if (eventFound == event) { + if (eventFound == event) { - printf("@ Event matches %ld\n", eventIndex); - // there is an opcode specified - if (opcode != 0) { + printf("@ Event matches %ld\n", eventIndex); + // there is an opcode specified + if (opcode != 0) { - // The opcode matches - if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && - ((uint16)opcodeFound == opcode) ) { + // The opcode matches + if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && + ((uint16)opcodeFound == opcode) ) { - // this should remove only the entry - printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); - (void)msg->RemoveData("eventExpected", eventIndex); - (void)msg->RemoveData("opcodeExpected", eventIndex); - goto bail; - } - } else { - // Event matches so far - printf("@ Removed event %d from message %p\n", event, msg); - (void)msg->RemoveData("eventExpected", eventIndex); - goto bail; - } + // this should remove only the entry + printf("@ Removed event %d and opcode %d from message %p\n", event, opcode, msg); + (void)msg->RemoveData("eventExpected", eventIndex); + (void)msg->RemoveData("opcodeExpected", eventIndex); + goto bail; + } + } else { + // Event matches so far + printf("@ Removed event %d from message %p\n", event, msg); + (void)msg->RemoveData("eventExpected", eventIndex); + goto bail; + } - } - eventIndex++; - } + } + eventIndex++; + } bail: - fEventsWanted.Unlock(); + fEventsWanted.Unlock(); } @@ -151,7 +151,7 @@ printf("opcode does not match %d\n", opcode); break; } - printf("Opcdodes match %d %d \n", opcode , opcodeFound); + printf("Opcodes match %d %d \n", opcode , opcodeFound); } fEventsWanted.Unlock(); From mmlr at mail.berlios.de Tue Jul 1 22:44:45 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Tue, 1 Jul 2008 22:44:45 +0200 Subject: [Haiku-commits] r26203 - haiku/trunk/src/system/kernel Message-ID: <200807012044.m61KijLp020188@sheep.berlios.de> Author: mmlr Date: 2008-07-01 22:44:43 +0200 (Tue, 01 Jul 2008) New Revision: 26203 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26203&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Remove the B_PAGE_SIZE page size and replace it by a heap->page_size. This allows for dynamic (heap)page sizes. It's currently just set to B_PAGE_SIZE but I'm expermienting with the creation of differently sized heaps that could use dynamic page sizes with that. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 20:28:12 UTC (rev 26202) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 20:44:43 UTC (rev 26203) @@ -87,6 +87,7 @@ uint32 bin_count; uint32 page_count; + uint32 page_size; uint32 free_page_count; heap_page * free_pages; @@ -321,7 +322,7 @@ if (!page->in_use) continue; - addr_t base = heap->base + i * B_PAGE_SIZE; + addr_t base = heap->base + i * heap->page_size; if (page->bin_index < heap->bin_count) { // page is used by a small allocation bin uint32 elementCount = page->empty_index; @@ -366,8 +367,8 @@ && heap->page_table[i + pageCount].allocation_id == page->allocation_id) pageCount++; - info = (heap_leak_check_info *)(base + pageCount * B_PAGE_SIZE - - sizeof(heap_leak_check_info)); + info = (heap_leak_check_info *)(base + pageCount + * heap->page_size - sizeof(heap_leak_check_info)); if ((team == -1 || info->team == team) && (thread == -1 || info->thread == thread) @@ -461,7 +462,7 @@ if (!page->in_use) continue; - addr_t base = heap->base + i * B_PAGE_SIZE; + addr_t base = heap->base + i * heap->page_size; if (page->bin_index < heap->bin_count) { // page is used by a small allocation bin uint32 elementCount = page->empty_index; @@ -501,8 +502,8 @@ && heap->page_table[i + pageCount].allocation_id == page->allocation_id) pageCount++; - info = (heap_leak_check_info *)(base + pageCount * B_PAGE_SIZE - - sizeof(heap_leak_check_info)); + info = (heap_leak_check_info *)(base + pageCount + * heap->page_size - sizeof(heap_leak_check_info)); caller_info* callerInfo = get_caller_info(info->caller); if (callerInfo == NULL) { @@ -636,10 +637,10 @@ // validate the free list uint32 freeSlotsCount = 0; addr_t *element = page->free_list; - addr_t pageBase = heap->base + page->index * B_PAGE_SIZE; + addr_t pageBase = heap->base + page->index * heap->page_size; while (element) { if ((addr_t)element < pageBase - || (addr_t)element >= pageBase + B_PAGE_SIZE) + || (addr_t)element >= pageBase + heap->page_size) panic("free list entry out of page range\n"); if (((addr_t)element - pageBase) % bin->element_size != 0) @@ -681,6 +682,7 @@ size_t binSizes[] = { 8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 1024, 2048, B_PAGE_SIZE }; uint32 binCount = sizeof(binSizes) / sizeof(binSizes[0]); + heap->page_size = B_PAGE_SIZE; heap->bin_count = binCount; heap->bins = (heap_bin *)base; base += binCount * sizeof(heap_bin); @@ -689,11 +691,11 @@ for (uint32 i = 0; i < binCount; i++) { heap_bin *bin = &heap->bins[i]; bin->element_size = binSizes[i]; - bin->max_free_count = B_PAGE_SIZE / binSizes[i]; + bin->max_free_count = heap->page_size / binSizes[i]; bin->page_list = NULL; } - uint32 pageCount = size / B_PAGE_SIZE; + uint32 pageCount = size / heap->page_size; size_t pageTableSize = pageCount * sizeof(heap_page); heap->page_table = (heap_page *)base; base += pageTableSize; @@ -704,7 +706,7 @@ heap->size = (size_t)(size / B_PAGE_SIZE) * B_PAGE_SIZE; // now we know the real page count - pageCount = heap->size / B_PAGE_SIZE; + pageCount = heap->size / heap->page_size; heap->page_count = pageCount; // zero out the heap alloc table at the base of the heap @@ -773,7 +775,7 @@ page->free_list = (addr_t *)*page->free_list; } else { // the page hasn't been fully allocated so use the next empty_index - address = (void *)(heap->base + page->index * B_PAGE_SIZE + address = (void *)(heap->base + page->index * heap->page_size + page->empty_index * bin->element_size); page->empty_index++; } @@ -827,7 +829,7 @@ #if KERNEL_HEAP_LEAK_CHECK heap_leak_check_info *info = (heap_leak_check_info *)(heap->base - + page->index * B_PAGE_SIZE + bin->element_size + + page->index * heap->page_size + bin->element_size - sizeof(heap_leak_check_info)); info->size = size - sizeof(heap_leak_check_info); info->thread = (kernel_startup ? 0 : thread_get_current_thread_id()); @@ -836,7 +838,7 @@ #endif // we return the first slot in this page - return (void *)(heap->base + page->index * B_PAGE_SIZE); + return (void *)(heap->base + page->index * heap->page_size); } // large allocation, we must search for contiguous slots @@ -849,7 +851,7 @@ } if (first > 0) { - if ((1 + i - first) * B_PAGE_SIZE >= size) { + if ((1 + i - first) * heap->page_size >= size) { found = true; break; } @@ -862,7 +864,7 @@ return NULL; } - uint32 pageCount = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE; + uint32 pageCount = (size + heap->page_size - 1) / heap->page_size; for (uint32 i = first; i < first + pageCount; i++) { heap_page *page = &heap->page_table[i]; page->in_use = 1; @@ -878,13 +880,13 @@ #if KERNEL_HEAP_LEAK_CHECK heap_leak_check_info *info = (heap_leak_check_info *)(heap->base - + (first + pageCount) * B_PAGE_SIZE - sizeof(heap_leak_check_info)); + + (first + pageCount) * heap->page_size - sizeof(heap_leak_check_info)); info->size = size - sizeof(heap_leak_check_info); info->thread = (kernel_startup ? 0 : thread_get_current_thread_id()); info->team = (kernel_startup ? 0 : team_get_current_team_id()); info->caller = get_caller(); #endif - return (void *)(heap->base + first * B_PAGE_SIZE); + return (void *)(heap->base + first * heap->page_size); } @@ -976,7 +978,8 @@ TRACE(("free(): asked to free at ptr = %p\n", address)); - heap_page *page = &heap->page_table[((addr_t)address - heap->base) / B_PAGE_SIZE]; + heap_page *page = &heap->page_table[((addr_t)address - heap->base) + / heap->page_size]; TRACE(("free(): page %p: bin_index %d, free_count %d\n", page, page->bin_index, page->free_count)); @@ -989,7 +992,8 @@ if (page->bin_index < heap->bin_count) { // small allocation heap_bin *bin = &heap->bins[page->bin_index]; - if (((addr_t)address - heap->base - page->index * B_PAGE_SIZE) % bin->element_size != 0) { + if (((addr_t)address - heap->base - page->index + * heap->page_size) % bin->element_size != 0) { panic("free(): passed invalid pointer %p supposed to be in bin for element size %ld\n", address, bin->element_size); mutex_unlock(&heap->lock); return B_ERROR; @@ -1091,7 +1095,8 @@ mutex_lock(&heap->lock); TRACE(("realloc(address = %p, newSize = %lu)\n", address, newSize)); - heap_page *page = &heap->page_table[((addr_t)address - heap->base) / B_PAGE_SIZE]; + heap_page *page = &heap->page_table[((addr_t)address - heap->base) + / heap->page_size]; if (page->bin_index > heap->bin_count) { panic("realloc(): page %p: invalid bin_index %d\n", page, page->bin_index); mutex_unlock(&heap->lock); @@ -1111,14 +1116,14 @@ // this was a large allocation uint32 allocationID = page->allocation_id; uint32 maxPages = heap->page_count - page->index; - maxSize = B_PAGE_SIZE; + maxSize = heap->page_size; for (uint32 i = 1; i < maxPages; i++) { if (!page[i].in_use || page[i].bin_index != heap->bin_count || page[i].allocation_id != allocationID) break; - minSize += B_PAGE_SIZE; - maxSize += B_PAGE_SIZE; + minSize += heap->page_size; + maxSize += heap->page_size; } } From korli at mail.berlios.de Tue Jul 1 22:56:24 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 1 Jul 2008 22:56:24 +0200 Subject: [Haiku-commits] r26204 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807012056.m61KuOlF021405@sheep.berlios.de> Author: korli Date: 2008-07-01 22:56:23 +0200 (Tue, 01 Jul 2008) New Revision: 26204 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26204&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Log: gcc4 build fix Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 20:44:43 UTC (rev 26203) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-01 20:56:23 UTC (rev 26204) @@ -101,12 +101,12 @@ if (index < EXT2_DIRECT_BLOCKS) { // direct blocks - block = B_LENDIAN_TO_HOST_INT32(Node().stream.direct[index]); + block = B_LENDIAN_TO_HOST_INT32(Node().u.stream.direct[index]); } else if ((index -= EXT2_DIRECT_BLOCKS) < perBlock) { // indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().stream.indirect)); + Node().u.stream.indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; @@ -115,7 +115,7 @@ // double indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().stream.double_indirect)); + Node().u.stream.double_indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; @@ -129,7 +129,7 @@ // triple indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().stream.triple_indirect)); + Node().u.stream.triple_indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-01 20:44:43 UTC (rev 26203) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-01 20:56:23 UTC (rev 26204) @@ -159,7 +159,7 @@ uint32 triple_indirect; } stream; char symlink[EXT2_SHORT_SYMLINK_LENGTH]; - }; + } u; uint32 generation; uint32 file_access_control; union { Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-01 20:44:43 UTC (rev 26203) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-01 20:56:23 UTC (rev 26204) @@ -5,7 +5,7 @@ #include -#include +#include #include #include @@ -414,7 +414,7 @@ if (inode->Size() > EXT2_SHORT_SYMLINK_LENGTH) return inode->ReadAt(0, (uint8 *)buffer, _bufferSize); - memcpy(buffer, inode->Node().symlink, *_bufferSize); + memcpy(buffer, inode->Node().u.symlink, *_bufferSize); return B_OK; } From marcusoverhagen at mail.berlios.de Wed Jul 2 00:04:34 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 2 Jul 2008 00:04:34 +0200 Subject: [Haiku-commits] r26205 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200807012204.m61M4YM0029863@sheep.berlios.de> Author: marcusoverhagen Date: 2008-07-02 00:04:33 +0200 (Wed, 02 Jul 2008) New Revision: 26205 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26205&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.h Log: Set transfer length when doing ATAPI transfers. Dump ATAPI command packet on error. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2008-07-01 20:56:23 UTC (rev 26204) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2008-07-01 22:04:33 UTC (rev 26205) @@ -790,7 +790,7 @@ // TRACE("AHCIPort::ScsiExecuteRequest ATAPI: port %d, opcode 0x%02x, length %u\n", fIndex, request->cdb[0], request->cdb_length); sata_request *sreq = new(std::nothrow) sata_request(request); - sreq->set_atapi_cmd(); + sreq->set_atapi_cmd(request->data_length); // uint8 *data = (uint8*) sreq->ccb()->cdb; // for (int i = 0; i < 16; i += 8) { // TRACE(" %02x %02x %02x %02x %02x %02x %02x %02x\n", data[i], data[i+1], data[i+2], data[i+3], data[i+4], data[i+5], data[i+6], data[i+7]); Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-01 20:56:23 UTC (rev 26204) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-01 22:04:33 UTC (rev 26205) @@ -84,47 +84,63 @@ void -sata_request::set_atapi_cmd() +sata_request::set_atapi_cmd(size_t transferLength) { fIsATAPI = true; set_ata_cmd(0xa0); - fFis[5] = 0xfe; - fFis[6] = 0xff; + if (1 /* isPIO */) { + if (transferLength == 0) + transferLength = 2; + else if (transferLength > 0xfffe) + transferLength = 0xfffe; + fFis[5] = transferLength & 0xff; + fFis[6] = (transferLength >> 8) & 0xff; + } } void sata_request::finish(int tfd, size_t bytesTransfered) { - if (tfd & ATA_ERR) - dprintf("ahci: sata_request::finish ATA_ERR set for command 0x%02x\n", fFis[2]); + if (tfd & (ATA_ERR | ATA_DF)) { + uint8 status = tfd & 0xff; + uint8 error = (tfd >> 8) & 0xff; + dprintf("ahci: sata_request::finish ATA command 0x%02x failed\n", fFis[2]); + dprintf("ahci: sata_request::finish status 0x%02x, error 0x%02x\n", status, error); + } + if (fCcb) { fCcb->data_resid = fCcb->data_length - bytesTransfered; fCcb->subsys_status = SCSI_REQ_CMP; if (tfd & (ATA_ERR | ATA_DF)) { - uint8 error = (tfd >> 8) & 0xff; - dprintf("ahci: sata_request::finish status 0x%02x, error 0x%02x\n", tfd & 0xff, error); + fCcb->subsys_status = SCSI_REQ_CMP_ERR; if (fIsATAPI) { - fCcb->subsys_status = SCSI_REQ_CMP_ERR; + dprintf("ahci: sata_request::finish ATAPI packet %02x %02x %02x %02x " + "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x (len %d)\n", + fCcb->cdb[0], fCcb->cdb[1], fCcb->cdb[2], fCcb->cdb[3], + fCcb->cdb[4], fCcb->cdb[5], fCcb->cdb[6], fCcb->cdb[7], + fCcb->cdb[8], fCcb->cdb[9], fCcb->cdb[10], fCcb->cdb[11], + fCcb->cdb[12], fCcb->cdb[13], fCcb->cdb[14], fCcb->cdb[15], + fCcb->cdb_length); fCcb->device_status = SCSI_STATUS_CHECK_CONDITION; } else { - fCcb->subsys_status = SCSI_REQ_CMP_ERR; - // TODO error handling goes here - } + // TODO ATA error handling goes here /* - if (error & 0x04) { // ABRT - fCcb->subsys_status = SCSI_REQ_ABORTED; - } else { - fCcb->device_status = SCSI_STATUS_CHECK_CONDITION; - fCcb->subsys_status |= SCSI_AUTOSNS_VALID; - fCcb->sense_resid = 0; //FIXME - scsi_sense *sense = (scsi_sense *)fCcb->sense; - sense->error_code = SCSIS_CURR_ERROR; - sense->sense_key = error >> 4; - sense->asc = 0; - sense->ascq = 0; + // TODO check ABORT bit if this is useful + if ((tfd >> 8) & 0x04) { // ABRT + fCcb->subsys_status = SCSI_REQ_ABORTED; + } else { + fCcb->device_status = SCSI_STATUS_CHECK_CONDITION; + fCcb->subsys_status |= SCSI_AUTOSNS_VALID; + fCcb->sense_resid = 0; //FIXME + scsi_sense *sense = (scsi_sense *)fCcb->sense; + sense->error_code = SCSIS_CURR_ERROR; + sense->sense_key = error >> 4; + sense->asc = 0; + sense->ascq = 0; + } +*/ } -*/ } gSCSI->finished(fCcb, 1); delete this; @@ -144,7 +160,7 @@ gSCSI->finished(fCcb, 1); delete this; } else { - fCompletionStatus = -1; + fCompletionStatus = ATA_ERR; release_sem(fCompletionSem); } } Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.h 2008-07-01 20:56:23 UTC (rev 26204) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.h 2008-07-01 22:04:33 UTC (rev 26205) @@ -20,7 +20,7 @@ void set_ata28_cmd(uint8 command, uint32 lba, uint8 sectorCount); void set_ata48_cmd(uint8 command, uint64 lba, uint16 sectorCount); - void set_atapi_cmd(); + void set_atapi_cmd(size_t transferLength); bool is_atapi(); scsi_ccb * ccb(); From marcusoverhagen at arcor.de Wed Jul 2 00:08:14 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Wed, 02 Jul 2008 00:08:14 +0200 Subject: [Haiku-commits] r26204 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <200807012056.m61KuOlF021405@sheep.berlios.de> References: <200807012056.m61KuOlF021405@sheep.berlios.de> Message-ID: <486AAACE.6060303@arcor.de> korli at BerliOS schrieb: > Log: > gcc4 build fix > > - }; > + } u; I have used unnamed unions in the ahci driver, and it seems to compile with gcc4. Why doesn't it work with ext2? regards Marcus From bonefish at mail.berlios.de Wed Jul 2 00:13:49 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 2 Jul 2008 00:13:49 +0200 Subject: [Haiku-commits] r26206 - haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807012213.m61MDnv4030660@sheep.berlios.de> Author: bonefish Date: 2008-07-02 00:13:46 +0200 (Wed, 02 Jul 2008) New Revision: 26206 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26206&view=rev Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: Adjusted to current FS interface. Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:04:33 UTC (rev 26205) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:13:46 UTC (rev 26206) @@ -40,6 +40,10 @@ #include "Tree.h" #include "VNode.h" + +extern fs_vnode_ops gReiserFSVnodeOps; + + // min and max // We don't want to include otherwise we also get // and other undesired things. @@ -63,7 +67,7 @@ // constructor Volume::Volume() - : fID(0), + : fFSVolume(NULL), fDevice(-1), fBlockCache(NULL), fTree(NULL), @@ -84,11 +88,11 @@ // Mount status_t -Volume::Mount(dev_t id, const char *path) +Volume::Mount(fs_volume *fsVolume, const char *path) { Unmount(); status_t error = (path ? B_OK : B_BAD_VALUE); - fID = id; + fFSVolume = fsVolume; // load the settings if (error == B_OK) { fSettings = new(nothrow) Settings; @@ -148,8 +152,10 @@ error = FindVNode(REISERFS_ROOT_PARENT_OBJECTID, REISERFS_ROOT_OBJECTID, fRootVNode); REPORT_ERROR(error); - if (error == B_OK) - error = publish_vnode(fID, fRootVNode->GetID(), fRootVNode); + if (error == B_OK) { + error = publish_vnode(fFSVolume, fRootVNode->GetID(), + fRootVNode, &gReiserFSVnodeOps, S_IFDIR, 0); + } REPORT_ERROR(error); } else error = B_NO_MEMORY; @@ -200,7 +206,7 @@ } fNegativeEntries.MakeEmpty(); fHashFunction = NULL; - fID = 0; + fFSVolume = NULL; return B_OK; } @@ -257,14 +263,14 @@ status_t Volume::GetVNode(ino_t id, VNode **node) { - return get_vnode(GetID(), id, (void**)node); + return get_vnode(GetFSVolume(), id, (void**)node); } // PutVNode status_t Volume::PutVNode(ino_t id) { - return put_vnode(GetID(), id); + return put_vnode(GetFSVolume(), id); } // FindVNode Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:04:33 UTC (rev 26205) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:13:46 UTC (rev 26206) @@ -41,10 +41,11 @@ Volume(); ~Volume(); - status_t Mount(dev_t nsid, const char *path); + status_t Mount(fs_volume *fsVolume, const char *path); status_t Unmount(); - dev_t GetID() const { return fID; } + dev_t GetID() const { return fFSVolume->id; } + fs_volume *GetFSVolume() const { return fFSVolume; } off_t GetBlockSize() const; off_t CountBlocks() const; @@ -89,7 +90,7 @@ void _InitNegativeEntries(); private: - dev_t fID; + fs_volume *fFSVolume; int fDevice; BlockCache *fBlockCache; Tree *fTree; Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:04:33 UTC (rev 26205) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:13:46 UTC (rev 26206) @@ -46,7 +46,10 @@ static const size_t kOptimalIOSize = 65536; +extern fs_volume_ops gReiserFSVolumeOps; +extern fs_vnode_ops gReiserFSVnodeOps; + inline static bool is_user_in_group(gid_t gid); @@ -55,8 +58,8 @@ // reiserfs_mount static status_t -reiserfs_mount(dev_t nsid, const char *device, uint32 flags, - const char *parameters, fs_volume *data, ino_t *rootID) +reiserfs_mount(fs_volume *_volume, const char *device, uint32 flags, + const char *parameters, ino_t *rootID) { TOUCH(flags); TOUCH(parameters); FUNCTION_START(); @@ -68,12 +71,13 @@ if (!volume) error = B_NO_MEMORY; if (error == B_OK) - error = volume->Mount(nsid, device); + error = volume->Mount(_volume, device); // set the results if (error == B_OK) { *rootID = volume->GetRootVNode()->GetID(); - *data = volume; + _volume->private_volume = volume; + _volume->ops = &gReiserFSVolumeOps; } // cleanup on failure @@ -82,12 +86,13 @@ RETURN_ERROR(error); } + // reiserfs_unmount static status_t -reiserfs_unmount(fs_volume fs) +reiserfs_unmount(fs_volume* fs) { FUNCTION_START(); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; status_t error = volume->Unmount(); if (error == B_OK) delete volume; @@ -96,10 +101,10 @@ // reiserfs_read_fs_info static status_t -reiserfs_read_fs_info(fs_volume fs, struct fs_info *info) +reiserfs_read_fs_info(fs_volume* fs, struct fs_info *info) { FUNCTION_START(); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; info->flags = B_FS_IS_PERSISTENT | B_FS_IS_READONLY; info->block_size = volume->GetBlockSize(); info->io_size = kOptimalIOSize; @@ -117,12 +122,12 @@ // reiserfs_lookup static status_t -reiserfs_lookup(fs_volume fs, fs_vnode _dir, const char *entryName, - ino_t *vnid, int *type) +reiserfs_lookup(fs_volume* fs, fs_vnode* _dir, const char *entryName, + ino_t *vnid) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *dir = (VNode*)_dir; + Volume *volume = (Volume*)fs->private_volume; + VNode *dir = (VNode*)_dir->private_node; FUNCTION(("dir: (%Ld: %lu, %lu), entry: `%s'\n", dir->GetID(), dir->GetDirID(), dir->GetObjectID(), entryName)); status_t error = B_OK; @@ -161,30 +166,30 @@ } } - // get type - if (error == B_OK) - *type = entryNode->GetStatData()->GetMode() & S_IFMT; - RETURN_ERROR(error); } // reiserfs_read_vnode static status_t -reiserfs_read_vnode(fs_volume fs, ino_t vnid, fs_vnode *node, bool reenter) +reiserfs_read_vnode(fs_volume *fs, ino_t vnid, fs_vnode *node, int *_type, + uint32 *_flags, bool reenter) { TOUCH(reenter); // FUNCTION_START(); FUNCTION(("(%Ld: %lu, %ld)\n", vnid, VNode::GetDirIDFor(vnid), VNode::GetObjectIDFor(vnid))); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; status_t error = B_OK; VNode *foundNode = new(nothrow) VNode; if (foundNode) { error = volume->FindVNode(vnid, foundNode); - if (error == B_OK) - *node = foundNode; - else - delete foundNode;; + if (error == B_OK) { + node->private_node = foundNode; + node->ops = &gReiserFSVnodeOps; + *_type = foundNode->GetStatData()->GetMode() & S_IFMT; + *_flags = 0; + } else + delete foundNode; } else error = B_NO_MEMORY; RETURN_ERROR(error); @@ -192,7 +197,7 @@ // reiserfs_write_vnode static status_t -reiserfs_write_vnode(fs_volume fs, fs_vnode _node, bool reenter) +reiserfs_write_vnode(fs_volume *fs, fs_vnode *_node, bool reenter) { TOUCH(reenter); // DANGER: If dbg_printf() is used, this thread will enter another FS and @@ -201,8 +206,8 @@ // called from another FS may cause the VFS layer to free vnodes and thus // invoke this hook. // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; status_t error = B_OK; if (node != volume->GetRootVNode()) delete node; @@ -216,12 +221,12 @@ // reiserfs_read_symlink static status_t -reiserfs_read_symlink(fs_volume fs, fs_vnode _node, char *buffer, +reiserfs_read_symlink(fs_volume *fs, fs_vnode *_node, char *buffer, size_t *bufferSize) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -236,12 +241,12 @@ // reiserfs_access static status_t -reiserfs_access(fs_volume fs, fs_vnode _node, int mode) +reiserfs_access(fs_volume *fs, fs_vnode *_node, int mode) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; +// Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); // write access requested? @@ -278,11 +283,11 @@ // reiserfs_read_stat static status_t -reiserfs_read_stat(fs_volume fs, fs_vnode _node, struct stat *st) +reiserfs_read_stat(fs_volume *fs, fs_vnode *_node, struct stat *st) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -307,11 +312,11 @@ // reiserfs_open static status_t -reiserfs_open(fs_volume fs, fs_vnode _node, int openMode, fs_cookie *cookie) +reiserfs_open(fs_volume *fs, fs_vnode *_node, int openMode, void **cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -338,11 +343,11 @@ // reiserfs_close static status_t -reiserfs_close(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_close(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -351,11 +356,11 @@ // reiserfs_free_cookie static status_t -reiserfs_free_cookie(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_free_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -366,13 +371,13 @@ // reiserfs_read static status_t -reiserfs_read(fs_volume fs, fs_vnode _node, fs_cookie cookie, off_t pos, +reiserfs_read(fs_volume *fs, fs_vnode *_node, void *cookie, off_t pos, void *buffer, size_t *bufferSize) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)ns; - VNode *node = (VNode*)_node; +// Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("((%Ld: %lu, %lu), %Ld, %p, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID(), pos, buffer, *bufferSize)); @@ -438,11 +443,11 @@ // reiserfs_open_dir static status_t -reiserfs_open_dir(fs_volume fs, fs_vnode _node, fs_cookie *cookie) +reiserfs_open_dir(fs_volume *fs, fs_vnode *_node, void **cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = (node->IsDir() ? B_OK : B_BAD_VALUE); @@ -479,11 +484,11 @@ // reiserfs_close_dir static status_t -reiserfs_close_dir(void *ns, void *_node, void *cookie) +reiserfs_close_dir(fs_volume *fs, fs_vnode *_node, void *cookie) { - TOUCH(ns); TOUCH(cookie); + TOUCH(fs); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -492,11 +497,11 @@ // reiserfs_free_dir_cookie static status_t -reiserfs_free_dir_cookie(void *ns, void *_node, void *cookie) +reiserfs_free_dir_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) { - TOUCH(ns); + TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -507,12 +512,12 @@ // reiserfs_read_dir static status_t -reiserfs_read_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie, +reiserfs_read_dir(fs_volume *fs, fs_vnode *_node, void *cookie, struct dirent *buffer, size_t bufferSize, uint32 *count) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); DirectoryCookie *iterator = (DirectoryCookie*)cookie; @@ -601,11 +606,11 @@ // reiserfs_rewind_dir static status_t -reiserfs_rewind_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_rewind_dir(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -642,6 +647,9 @@ } } + + + static file_system_module_info sReiserFSModuleInfo = { { "file_systems/reiserfs" B_CURRENT_FS_API_VERSION, @@ -653,22 +661,31 @@ "Reiser File System", // pretty_name 0, // DDM flags + // scanning NULL, // identify_partition() NULL, // scan_partition() NULL, // free_identify_partition_cookie() NULL, // free_partition_content_cookie() - &reiserfs_mount, + &reiserfs_mount +}; + + +fs_volume_ops gReiserFSVolumeOps = { &reiserfs_unmount, &reiserfs_read_fs_info, NULL, // &reiserfs_write_fs_info, NULL, // &reiserfs_sync, + &reiserfs_read_vnode +}; + + +fs_vnode_ops gReiserFSVnodeOps = { /* vnode operations */ &reiserfs_lookup, NULL, // &reiserfs_get_vnode_name, - &reiserfs_read_vnode, &reiserfs_write_vnode, NULL, // &reiserfs_remove_vnode, @@ -711,47 +728,10 @@ &reiserfs_close_dir, &reiserfs_free_dir_cookie, &reiserfs_read_dir, - &reiserfs_rewind_dir, - - /* attribute directory operations */ - NULL, // &reiserfs_open_attr_dir, - NULL, // &reiserfs_close_attr_dir, - NULL, // &reiserfs_free_attr_dir_cookie, - NULL, // &reiserfs_read_attr_dir, - NULL, // &reiserfs_rewind_attr_dir, - - /* attribute operations */ - NULL, // &reiserfs_create_attr, - NULL, // &reiserfs_open_attr, - NULL, // &reiserfs_close_attr, - NULL, // &reiserfs_free_attr_cookie, - NULL, // &reiserfs_read_attr, - NULL, // &reiserfs_write_attr, - - NULL, // &reiserfs_read_attr_stat, - NULL, // &reiserfs_write_attr_stat, - NULL, // &reiserfs_rename_attr, - NULL, // &reiserfs_remove_attr, - - /* index directory & index operations */ - NULL, // &reiserfs_open_index_dir, - NULL, // &reiserfs_close_index_dir, - NULL, // &reiserfs_free_index_dir_cookie, - NULL, // &reiserfs_read_index_dir, - NULL, // &reiserfs_rewind_index_dir, - - NULL, // &reiserfs_create_index, - NULL, // &reiserfs_remove_index, - NULL, // &reiserfs_read_index_stat, - - /* query operations */ - NULL, // &reiserfs_open_query, - NULL, // &reiserfs_close_query, - NULL, // &reiserfs_free_query_cookie, - NULL, // &reiserfs_read_query, - NULL, // &reiserfs_rewind_query, + &reiserfs_rewind_dir }; + module_info *modules[] = { (module_info *)&sReiserFSModuleInfo, NULL, From bonefish at mail.berlios.de Wed Jul 2 00:14:34 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 2 Jul 2008 00:14:34 +0200 Subject: [Haiku-commits] r26207 - haiku/branches/developer/bonefish/vm/build/jam Message-ID: <200807012214.m61MEYi2030715@sheep.berlios.de> Author: bonefish Date: 2008-07-02 00:14:32 +0200 (Wed, 02 Jul 2008) New Revision: 26207 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26207&view=rev Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage Log: Added reiserfs add-on to image. Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage =================================================================== --- haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-01 22:13:46 UTC (rev 26206) +++ haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-01 22:14:32 UTC (rev 26207) @@ -135,7 +135,7 @@ BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager agp_gart usb #firewire ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 $(GPL_ONLY)reiserfs ; #googlefs nfs $(GPL_ONLY)ntfs ; From bonefish at mail.berlios.de Wed Jul 2 00:44:43 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 2 Jul 2008 00:44:43 +0200 Subject: [Haiku-commits] r26208 - in haiku/branches/developer/bonefish/vm: build/jam src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807012244.m61MihUR016281@sheep.berlios.de> Author: bonefish Date: 2008-07-02 00:44:39 +0200 (Wed, 02 Jul 2008) New Revision: 26208 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26208&view=rev Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: Reverted r26206 and r26207. Accidentally committed them to my branch. Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage =================================================================== --- haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-01 22:14:32 UTC (rev 26207) +++ haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-01 22:44:39 UTC (rev 26208) @@ -135,7 +135,7 @@ BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager agp_gart usb #firewire ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 $(GPL_ONLY)reiserfs ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 ; #googlefs nfs $(GPL_ONLY)ntfs ; Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:14:32 UTC (rev 26207) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:44:39 UTC (rev 26208) @@ -40,10 +40,6 @@ #include "Tree.h" #include "VNode.h" - -extern fs_vnode_ops gReiserFSVnodeOps; - - // min and max // We don't want to include otherwise we also get // and other undesired things. @@ -67,7 +63,7 @@ // constructor Volume::Volume() - : fFSVolume(NULL), + : fID(0), fDevice(-1), fBlockCache(NULL), fTree(NULL), @@ -88,11 +84,11 @@ // Mount status_t -Volume::Mount(fs_volume *fsVolume, const char *path) +Volume::Mount(dev_t id, const char *path) { Unmount(); status_t error = (path ? B_OK : B_BAD_VALUE); - fFSVolume = fsVolume; + fID = id; // load the settings if (error == B_OK) { fSettings = new(nothrow) Settings; @@ -152,10 +148,8 @@ error = FindVNode(REISERFS_ROOT_PARENT_OBJECTID, REISERFS_ROOT_OBJECTID, fRootVNode); REPORT_ERROR(error); - if (error == B_OK) { - error = publish_vnode(fFSVolume, fRootVNode->GetID(), - fRootVNode, &gReiserFSVnodeOps, S_IFDIR, 0); - } + if (error == B_OK) + error = publish_vnode(fID, fRootVNode->GetID(), fRootVNode); REPORT_ERROR(error); } else error = B_NO_MEMORY; @@ -206,7 +200,7 @@ } fNegativeEntries.MakeEmpty(); fHashFunction = NULL; - fFSVolume = NULL; + fID = 0; return B_OK; } @@ -263,14 +257,14 @@ status_t Volume::GetVNode(ino_t id, VNode **node) { - return get_vnode(GetFSVolume(), id, (void**)node); + return get_vnode(GetID(), id, (void**)node); } // PutVNode status_t Volume::PutVNode(ino_t id) { - return put_vnode(GetFSVolume(), id); + return put_vnode(GetID(), id); } // FindVNode Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:14:32 UTC (rev 26207) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:44:39 UTC (rev 26208) @@ -41,11 +41,10 @@ Volume(); ~Volume(); - status_t Mount(fs_volume *fsVolume, const char *path); + status_t Mount(dev_t nsid, const char *path); status_t Unmount(); - dev_t GetID() const { return fFSVolume->id; } - fs_volume *GetFSVolume() const { return fFSVolume; } + dev_t GetID() const { return fID; } off_t GetBlockSize() const; off_t CountBlocks() const; @@ -90,7 +89,7 @@ void _InitNegativeEntries(); private: - fs_volume *fFSVolume; + dev_t fID; int fDevice; BlockCache *fBlockCache; Tree *fTree; Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:14:32 UTC (rev 26207) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:44:39 UTC (rev 26208) @@ -46,10 +46,7 @@ static const size_t kOptimalIOSize = 65536; -extern fs_volume_ops gReiserFSVolumeOps; -extern fs_vnode_ops gReiserFSVnodeOps; - inline static bool is_user_in_group(gid_t gid); @@ -58,8 +55,8 @@ // reiserfs_mount static status_t -reiserfs_mount(fs_volume *_volume, const char *device, uint32 flags, - const char *parameters, ino_t *rootID) +reiserfs_mount(dev_t nsid, const char *device, uint32 flags, + const char *parameters, fs_volume *data, ino_t *rootID) { TOUCH(flags); TOUCH(parameters); FUNCTION_START(); @@ -71,13 +68,12 @@ if (!volume) error = B_NO_MEMORY; if (error == B_OK) - error = volume->Mount(_volume, device); + error = volume->Mount(nsid, device); // set the results if (error == B_OK) { *rootID = volume->GetRootVNode()->GetID(); - _volume->private_volume = volume; - _volume->ops = &gReiserFSVolumeOps; + *data = volume; } // cleanup on failure @@ -86,13 +82,12 @@ RETURN_ERROR(error); } - // reiserfs_unmount static status_t -reiserfs_unmount(fs_volume* fs) +reiserfs_unmount(fs_volume fs) { FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; + Volume *volume = (Volume*)fs; status_t error = volume->Unmount(); if (error == B_OK) delete volume; @@ -101,10 +96,10 @@ // reiserfs_read_fs_info static status_t -reiserfs_read_fs_info(fs_volume* fs, struct fs_info *info) +reiserfs_read_fs_info(fs_volume fs, struct fs_info *info) { FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; + Volume *volume = (Volume*)fs; info->flags = B_FS_IS_PERSISTENT | B_FS_IS_READONLY; info->block_size = volume->GetBlockSize(); info->io_size = kOptimalIOSize; @@ -122,12 +117,12 @@ // reiserfs_lookup static status_t -reiserfs_lookup(fs_volume* fs, fs_vnode* _dir, const char *entryName, - ino_t *vnid) +reiserfs_lookup(fs_volume fs, fs_vnode _dir, const char *entryName, + ino_t *vnid, int *type) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *dir = (VNode*)_dir->private_node; + Volume *volume = (Volume*)fs; + VNode *dir = (VNode*)_dir; FUNCTION(("dir: (%Ld: %lu, %lu), entry: `%s'\n", dir->GetID(), dir->GetDirID(), dir->GetObjectID(), entryName)); status_t error = B_OK; @@ -166,30 +161,30 @@ } } + // get type + if (error == B_OK) + *type = entryNode->GetStatData()->GetMode() & S_IFMT; + RETURN_ERROR(error); } // reiserfs_read_vnode static status_t -reiserfs_read_vnode(fs_volume *fs, ino_t vnid, fs_vnode *node, int *_type, - uint32 *_flags, bool reenter) +reiserfs_read_vnode(fs_volume fs, ino_t vnid, fs_vnode *node, bool reenter) { TOUCH(reenter); // FUNCTION_START(); FUNCTION(("(%Ld: %lu, %ld)\n", vnid, VNode::GetDirIDFor(vnid), VNode::GetObjectIDFor(vnid))); - Volume *volume = (Volume*)fs->private_volume; + Volume *volume = (Volume*)fs; status_t error = B_OK; VNode *foundNode = new(nothrow) VNode; if (foundNode) { error = volume->FindVNode(vnid, foundNode); - if (error == B_OK) { - node->private_node = foundNode; - node->ops = &gReiserFSVnodeOps; - *_type = foundNode->GetStatData()->GetMode() & S_IFMT; - *_flags = 0; - } else - delete foundNode; + if (error == B_OK) + *node = foundNode; + else + delete foundNode;; } else error = B_NO_MEMORY; RETURN_ERROR(error); @@ -197,7 +192,7 @@ // reiserfs_write_vnode static status_t -reiserfs_write_vnode(fs_volume *fs, fs_vnode *_node, bool reenter) +reiserfs_write_vnode(fs_volume fs, fs_vnode _node, bool reenter) { TOUCH(reenter); // DANGER: If dbg_printf() is used, this thread will enter another FS and @@ -206,8 +201,8 @@ // called from another FS may cause the VFS layer to free vnodes and thus // invoke this hook. // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; status_t error = B_OK; if (node != volume->GetRootVNode()) delete node; @@ -221,12 +216,12 @@ // reiserfs_read_symlink static status_t -reiserfs_read_symlink(fs_volume *fs, fs_vnode *_node, char *buffer, +reiserfs_read_symlink(fs_volume fs, fs_vnode _node, char *buffer, size_t *bufferSize) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -241,12 +236,12 @@ // reiserfs_access static status_t -reiserfs_access(fs_volume *fs, fs_vnode *_node, int mode) +reiserfs_access(fs_volume fs, fs_vnode _node, int mode) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; +// Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); // write access requested? @@ -283,11 +278,11 @@ // reiserfs_read_stat static status_t -reiserfs_read_stat(fs_volume *fs, fs_vnode *_node, struct stat *st) +reiserfs_read_stat(fs_volume fs, fs_vnode _node, struct stat *st) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -312,11 +307,11 @@ // reiserfs_open static status_t -reiserfs_open(fs_volume *fs, fs_vnode *_node, int openMode, void **cookie) +reiserfs_open(fs_volume fs, fs_vnode _node, int openMode, fs_cookie *cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -343,11 +338,11 @@ // reiserfs_close static status_t -reiserfs_close(fs_volume *fs, fs_vnode *_node, void *cookie) +reiserfs_close(fs_volume fs, fs_vnode _node, fs_cookie cookie) { TOUCH(fs); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node->private_node; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -356,11 +351,11 @@ // reiserfs_free_cookie static status_t -reiserfs_free_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) +reiserfs_free_cookie(fs_volume fs, fs_vnode _node, fs_cookie cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node->private_node; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -371,13 +366,13 @@ // reiserfs_read static status_t -reiserfs_read(fs_volume *fs, fs_vnode *_node, void *cookie, off_t pos, +reiserfs_read(fs_volume fs, fs_vnode _node, fs_cookie cookie, off_t pos, void *buffer, size_t *bufferSize) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; +// Volume *volume = (Volume*)ns; + VNode *node = (VNode*)_node; FUNCTION(("((%Ld: %lu, %lu), %Ld, %p, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID(), pos, buffer, *bufferSize)); @@ -443,11 +438,11 @@ // reiserfs_open_dir static status_t -reiserfs_open_dir(fs_volume *fs, fs_vnode *_node, void **cookie) +reiserfs_open_dir(fs_volume fs, fs_vnode _node, fs_cookie *cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = (node->IsDir() ? B_OK : B_BAD_VALUE); @@ -484,11 +479,11 @@ // reiserfs_close_dir static status_t -reiserfs_close_dir(fs_volume *fs, fs_vnode *_node, void *cookie) +reiserfs_close_dir(void *ns, void *_node, void *cookie) { - TOUCH(fs); TOUCH(cookie); + TOUCH(ns); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node->private_node; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -497,11 +492,11 @@ // reiserfs_free_dir_cookie static status_t -reiserfs_free_dir_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) +reiserfs_free_dir_cookie(void *ns, void *_node, void *cookie) { - TOUCH(fs); + TOUCH(ns); // FUNCTION_START(); - VNode *node = (VNode*)_node->private_node; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -512,12 +507,12 @@ // reiserfs_read_dir static status_t -reiserfs_read_dir(fs_volume *fs, fs_vnode *_node, void *cookie, +reiserfs_read_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *count) { // FUNCTION_START(); - Volume *volume = (Volume*)fs->private_volume; - VNode *node = (VNode*)_node->private_node; + Volume *volume = (Volume*)fs; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); DirectoryCookie *iterator = (DirectoryCookie*)cookie; @@ -606,11 +601,11 @@ // reiserfs_rewind_dir static status_t -reiserfs_rewind_dir(fs_volume *fs, fs_vnode *_node, void *cookie) +reiserfs_rewind_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node->private_node; + VNode *node = (VNode*)_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -647,9 +642,6 @@ } } - - - static file_system_module_info sReiserFSModuleInfo = { { "file_systems/reiserfs" B_CURRENT_FS_API_VERSION, @@ -661,31 +653,22 @@ "Reiser File System", // pretty_name 0, // DDM flags - // scanning NULL, // identify_partition() NULL, // scan_partition() NULL, // free_identify_partition_cookie() NULL, // free_partition_content_cookie() - &reiserfs_mount -}; - - -fs_volume_ops gReiserFSVolumeOps = { + &reiserfs_mount, &reiserfs_unmount, &reiserfs_read_fs_info, NULL, // &reiserfs_write_fs_info, NULL, // &reiserfs_sync, - &reiserfs_read_vnode -}; - - -fs_vnode_ops gReiserFSVnodeOps = { /* vnode operations */ &reiserfs_lookup, NULL, // &reiserfs_get_vnode_name, + &reiserfs_read_vnode, &reiserfs_write_vnode, NULL, // &reiserfs_remove_vnode, @@ -728,10 +711,47 @@ &reiserfs_close_dir, &reiserfs_free_dir_cookie, &reiserfs_read_dir, - &reiserfs_rewind_dir + &reiserfs_rewind_dir, + + /* attribute directory operations */ + NULL, // &reiserfs_open_attr_dir, + NULL, // &reiserfs_close_attr_dir, + NULL, // &reiserfs_free_attr_dir_cookie, + NULL, // &reiserfs_read_attr_dir, + NULL, // &reiserfs_rewind_attr_dir, + + /* attribute operations */ + NULL, // &reiserfs_create_attr, + NULL, // &reiserfs_open_attr, + NULL, // &reiserfs_close_attr, + NULL, // &reiserfs_free_attr_cookie, + NULL, // &reiserfs_read_attr, + NULL, // &reiserfs_write_attr, + + NULL, // &reiserfs_read_attr_stat, + NULL, // &reiserfs_write_attr_stat, + NULL, // &reiserfs_rename_attr, + NULL, // &reiserfs_remove_attr, + + /* index directory & index operations */ + NULL, // &reiserfs_open_index_dir, + NULL, // &reiserfs_close_index_dir, + NULL, // &reiserfs_free_index_dir_cookie, + NULL, // &reiserfs_read_index_dir, + NULL, // &reiserfs_rewind_index_dir, + + NULL, // &reiserfs_create_index, + NULL, // &reiserfs_remove_index, + NULL, // &reiserfs_read_index_stat, + + /* query operations */ + NULL, // &reiserfs_open_query, + NULL, // &reiserfs_close_query, + NULL, // &reiserfs_free_query_cookie, + NULL, // &reiserfs_read_query, + NULL, // &reiserfs_rewind_query, }; - module_info *modules[] = { (module_info *)&sReiserFSModuleInfo, NULL, From stippi at mail.berlios.de Wed Jul 2 00:47:07 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 2 Jul 2008 00:47:07 +0200 Subject: [Haiku-commits] r26209 - in haiku/trunk: build/jam src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807012247.m61Ml7iT019095@sheep.berlios.de> Author: stippi Date: 2008-07-02 00:46:54 +0200 (Wed, 02 Jul 2008) New Revision: 26209 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26209&view=rev Modified: haiku/trunk/build/jam/HaikuImage haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: Merge Ingo's reiserfs changes which he accidentally commited to his branch: Adopted reiserfs add-on to the new fs API and added it to the image. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-07-01 22:44:39 UTC (rev 26208) +++ haiku/trunk/build/jam/HaikuImage 2008-07-01 22:46:54 UTC (rev 26209) @@ -135,7 +135,7 @@ BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi config_manager agp_gart usb #firewire ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 $(GPL_ONLY)reiserfs ; #googlefs nfs $(GPL_ONLY)ntfs ; Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:44:39 UTC (rev 26208) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 22:46:54 UTC (rev 26209) @@ -40,6 +40,10 @@ #include "Tree.h" #include "VNode.h" + +extern fs_vnode_ops gReiserFSVnodeOps; + + // min and max // We don't want to include otherwise we also get // and other undesired things. @@ -63,7 +67,7 @@ // constructor Volume::Volume() - : fID(0), + : fFSVolume(NULL), fDevice(-1), fBlockCache(NULL), fTree(NULL), @@ -84,11 +88,11 @@ // Mount status_t -Volume::Mount(dev_t id, const char *path) +Volume::Mount(fs_volume *fsVolume, const char *path) { Unmount(); status_t error = (path ? B_OK : B_BAD_VALUE); - fID = id; + fFSVolume = fsVolume; // load the settings if (error == B_OK) { fSettings = new(nothrow) Settings; @@ -148,8 +152,10 @@ error = FindVNode(REISERFS_ROOT_PARENT_OBJECTID, REISERFS_ROOT_OBJECTID, fRootVNode); REPORT_ERROR(error); - if (error == B_OK) - error = publish_vnode(fID, fRootVNode->GetID(), fRootVNode); + if (error == B_OK) { + error = publish_vnode(fFSVolume, fRootVNode->GetID(), + fRootVNode, &gReiserFSVnodeOps, S_IFDIR, 0); + } REPORT_ERROR(error); } else error = B_NO_MEMORY; @@ -200,7 +206,7 @@ } fNegativeEntries.MakeEmpty(); fHashFunction = NULL; - fID = 0; + fFSVolume = NULL; return B_OK; } @@ -257,14 +263,14 @@ status_t Volume::GetVNode(ino_t id, VNode **node) { - return get_vnode(GetID(), id, (void**)node); + return get_vnode(GetFSVolume(), id, (void**)node); } // PutVNode status_t Volume::PutVNode(ino_t id) { - return put_vnode(GetID(), id); + return put_vnode(GetFSVolume(), id); } // FindVNode Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:44:39 UTC (rev 26208) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 22:46:54 UTC (rev 26209) @@ -41,10 +41,11 @@ Volume(); ~Volume(); - status_t Mount(dev_t nsid, const char *path); + status_t Mount(fs_volume *fsVolume, const char *path); status_t Unmount(); - dev_t GetID() const { return fID; } + dev_t GetID() const { return fFSVolume->id; } + fs_volume *GetFSVolume() const { return fFSVolume; } off_t GetBlockSize() const; off_t CountBlocks() const; @@ -89,7 +90,7 @@ void _InitNegativeEntries(); private: - dev_t fID; + fs_volume *fFSVolume; int fDevice; BlockCache *fBlockCache; Tree *fTree; Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:44:39 UTC (rev 26208) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 22:46:54 UTC (rev 26209) @@ -46,7 +46,10 @@ static const size_t kOptimalIOSize = 65536; +extern fs_volume_ops gReiserFSVolumeOps; +extern fs_vnode_ops gReiserFSVnodeOps; + inline static bool is_user_in_group(gid_t gid); @@ -55,8 +58,8 @@ // reiserfs_mount static status_t -reiserfs_mount(dev_t nsid, const char *device, uint32 flags, - const char *parameters, fs_volume *data, ino_t *rootID) +reiserfs_mount(fs_volume *_volume, const char *device, uint32 flags, + const char *parameters, ino_t *rootID) { TOUCH(flags); TOUCH(parameters); FUNCTION_START(); @@ -68,12 +71,13 @@ if (!volume) error = B_NO_MEMORY; if (error == B_OK) - error = volume->Mount(nsid, device); + error = volume->Mount(_volume, device); // set the results if (error == B_OK) { *rootID = volume->GetRootVNode()->GetID(); - *data = volume; + _volume->private_volume = volume; + _volume->ops = &gReiserFSVolumeOps; } // cleanup on failure @@ -82,12 +86,13 @@ RETURN_ERROR(error); } + // reiserfs_unmount static status_t -reiserfs_unmount(fs_volume fs) +reiserfs_unmount(fs_volume* fs) { FUNCTION_START(); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; status_t error = volume->Unmount(); if (error == B_OK) delete volume; @@ -96,10 +101,10 @@ // reiserfs_read_fs_info static status_t -reiserfs_read_fs_info(fs_volume fs, struct fs_info *info) +reiserfs_read_fs_info(fs_volume* fs, struct fs_info *info) { FUNCTION_START(); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; info->flags = B_FS_IS_PERSISTENT | B_FS_IS_READONLY; info->block_size = volume->GetBlockSize(); info->io_size = kOptimalIOSize; @@ -117,12 +122,12 @@ // reiserfs_lookup static status_t -reiserfs_lookup(fs_volume fs, fs_vnode _dir, const char *entryName, - ino_t *vnid, int *type) +reiserfs_lookup(fs_volume* fs, fs_vnode* _dir, const char *entryName, + ino_t *vnid) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *dir = (VNode*)_dir; + Volume *volume = (Volume*)fs->private_volume; + VNode *dir = (VNode*)_dir->private_node; FUNCTION(("dir: (%Ld: %lu, %lu), entry: `%s'\n", dir->GetID(), dir->GetDirID(), dir->GetObjectID(), entryName)); status_t error = B_OK; @@ -161,30 +166,30 @@ } } - // get type - if (error == B_OK) - *type = entryNode->GetStatData()->GetMode() & S_IFMT; - RETURN_ERROR(error); } // reiserfs_read_vnode static status_t -reiserfs_read_vnode(fs_volume fs, ino_t vnid, fs_vnode *node, bool reenter) +reiserfs_read_vnode(fs_volume *fs, ino_t vnid, fs_vnode *node, int *_type, + uint32 *_flags, bool reenter) { TOUCH(reenter); // FUNCTION_START(); FUNCTION(("(%Ld: %lu, %ld)\n", vnid, VNode::GetDirIDFor(vnid), VNode::GetObjectIDFor(vnid))); - Volume *volume = (Volume*)fs; + Volume *volume = (Volume*)fs->private_volume; status_t error = B_OK; VNode *foundNode = new(nothrow) VNode; if (foundNode) { error = volume->FindVNode(vnid, foundNode); - if (error == B_OK) - *node = foundNode; - else - delete foundNode;; + if (error == B_OK) { + node->private_node = foundNode; + node->ops = &gReiserFSVnodeOps; + *_type = foundNode->GetStatData()->GetMode() & S_IFMT; + *_flags = 0; + } else + delete foundNode; } else error = B_NO_MEMORY; RETURN_ERROR(error); @@ -192,7 +197,7 @@ // reiserfs_write_vnode static status_t -reiserfs_write_vnode(fs_volume fs, fs_vnode _node, bool reenter) +reiserfs_write_vnode(fs_volume *fs, fs_vnode *_node, bool reenter) { TOUCH(reenter); // DANGER: If dbg_printf() is used, this thread will enter another FS and @@ -201,8 +206,8 @@ // called from another FS may cause the VFS layer to free vnodes and thus // invoke this hook. // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; status_t error = B_OK; if (node != volume->GetRootVNode()) delete node; @@ -216,12 +221,12 @@ // reiserfs_read_symlink static status_t -reiserfs_read_symlink(fs_volume fs, fs_vnode _node, char *buffer, +reiserfs_read_symlink(fs_volume *fs, fs_vnode *_node, char *buffer, size_t *bufferSize) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -236,12 +241,12 @@ // reiserfs_access static status_t -reiserfs_access(fs_volume fs, fs_vnode _node, int mode) +reiserfs_access(fs_volume *fs, fs_vnode *_node, int mode) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; +// Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); // write access requested? @@ -278,11 +283,11 @@ // reiserfs_read_stat static status_t -reiserfs_read_stat(fs_volume fs, fs_vnode _node, struct stat *st) +reiserfs_read_stat(fs_volume *fs, fs_vnode *_node, struct stat *st) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -307,11 +312,11 @@ // reiserfs_open static status_t -reiserfs_open(fs_volume fs, fs_vnode _node, int openMode, fs_cookie *cookie) +reiserfs_open(fs_volume *fs, fs_vnode *_node, int openMode, void **cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = B_OK; @@ -338,11 +343,11 @@ // reiserfs_close static status_t -reiserfs_close(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_close(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -351,11 +356,11 @@ // reiserfs_free_cookie static status_t -reiserfs_free_cookie(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_free_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -366,13 +371,13 @@ // reiserfs_read static status_t -reiserfs_read(fs_volume fs, fs_vnode _node, fs_cookie cookie, off_t pos, +reiserfs_read(fs_volume *fs, fs_vnode *_node, void *cookie, off_t pos, void *buffer, size_t *bufferSize) { TOUCH(fs); // FUNCTION_START(); -// Volume *volume = (Volume*)ns; - VNode *node = (VNode*)_node; +// Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("((%Ld: %lu, %lu), %Ld, %p, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID(), pos, buffer, *bufferSize)); @@ -438,11 +443,11 @@ // reiserfs_open_dir static status_t -reiserfs_open_dir(fs_volume fs, fs_vnode _node, fs_cookie *cookie) +reiserfs_open_dir(fs_volume *fs, fs_vnode *_node, void **cookie) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); status_t error = (node->IsDir() ? B_OK : B_BAD_VALUE); @@ -479,11 +484,11 @@ // reiserfs_close_dir static status_t -reiserfs_close_dir(void *ns, void *_node, void *cookie) +reiserfs_close_dir(fs_volume *fs, fs_vnode *_node, void *cookie) { - TOUCH(ns); TOUCH(cookie); + TOUCH(fs); TOUCH(cookie); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -492,11 +497,11 @@ // reiserfs_free_dir_cookie static status_t -reiserfs_free_dir_cookie(void *ns, void *_node, void *cookie) +reiserfs_free_dir_cookie(fs_volume *fs, fs_vnode *_node, void *cookie) { - TOUCH(ns); + TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -507,12 +512,12 @@ // reiserfs_read_dir static status_t -reiserfs_read_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie, +reiserfs_read_dir(fs_volume *fs, fs_vnode *_node, void *cookie, struct dirent *buffer, size_t bufferSize, uint32 *count) { // FUNCTION_START(); - Volume *volume = (Volume*)fs; - VNode *node = (VNode*)_node; + Volume *volume = (Volume*)fs->private_volume; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); DirectoryCookie *iterator = (DirectoryCookie*)cookie; @@ -601,11 +606,11 @@ // reiserfs_rewind_dir static status_t -reiserfs_rewind_dir(fs_volume fs, fs_vnode _node, fs_cookie cookie) +reiserfs_rewind_dir(fs_volume *fs, fs_vnode *_node, void *cookie) { TOUCH(fs); // FUNCTION_START(); - VNode *node = (VNode*)_node; + VNode *node = (VNode*)_node->private_node; FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(), node->GetObjectID())); TOUCH(node); @@ -642,6 +647,9 @@ } } + + + static file_system_module_info sReiserFSModuleInfo = { { "file_systems/reiserfs" B_CURRENT_FS_API_VERSION, @@ -653,22 +661,31 @@ "Reiser File System", // pretty_name 0, // DDM flags + // scanning NULL, // identify_partition() NULL, // scan_partition() NULL, // free_identify_partition_cookie() NULL, // free_partition_content_cookie() - &reiserfs_mount, + &reiserfs_mount +}; + + +fs_volume_ops gReiserFSVolumeOps = { &reiserfs_unmount, &reiserfs_read_fs_info, NULL, // &reiserfs_write_fs_info, NULL, // &reiserfs_sync, + &reiserfs_read_vnode +}; + + +fs_vnode_ops gReiserFSVnodeOps = { /* vnode operations */ &reiserfs_lookup, NULL, // &reiserfs_get_vnode_name, - &reiserfs_read_vnode, &reiserfs_write_vnode, NULL, // &reiserfs_remove_vnode, @@ -711,47 +728,10 @@ &reiserfs_close_dir, &reiserfs_free_dir_cookie, &reiserfs_read_dir, - &reiserfs_rewind_dir, - - /* attribute directory operations */ - NULL, // &reiserfs_open_attr_dir, - NULL, // &reiserfs_close_attr_dir, - NULL, // &reiserfs_free_attr_dir_cookie, - NULL, // &reiserfs_read_attr_dir, - NULL, // &reiserfs_rewind_attr_dir, - - /* attribute operations */ - NULL, // &reiserfs_create_attr, - NULL, // &reiserfs_open_attr, - NULL, // &reiserfs_close_attr, - NULL, // &reiserfs_free_attr_cookie, - NULL, // &reiserfs_read_attr, - NULL, // &reiserfs_write_attr, - - NULL, // &reiserfs_read_attr_stat, - NULL, // &reiserfs_write_attr_stat, - NULL, // &reiserfs_rename_attr, - NULL, // &reiserfs_remove_attr, - - /* index directory & index operations */ - NULL, // &reiserfs_open_index_dir, - NULL, // &reiserfs_close_index_dir, - NULL, // &reiserfs_free_index_dir_cookie, - NULL, // &reiserfs_read_index_dir, - NULL, // &reiserfs_rewind_index_dir, - - NULL, // &reiserfs_create_index, - NULL, // &reiserfs_remove_index, - NULL, // &reiserfs_read_index_stat, - - /* query operations */ - NULL, // &reiserfs_open_query, - NULL, // &reiserfs_close_query, - NULL, // &reiserfs_free_query_cookie, - NULL, // &reiserfs_read_query, - NULL, // &reiserfs_rewind_query, + &reiserfs_rewind_dir }; + module_info *modules[] = { (module_info *)&sReiserFSModuleInfo, NULL, From mmlr at mail.berlios.de Wed Jul 2 01:19:40 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 01:19:40 +0200 Subject: [Haiku-commits] r26210 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200807012319.m61NJeMF023662@sheep.berlios.de> Author: mmlr Date: 2008-07-02 01:19:35 +0200 (Wed, 02 Jul 2008) New Revision: 26210 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26210&view=rev Modified: haiku/trunk/headers/private/kernel/heap.h haiku/trunk/src/system/kernel/heap.cpp Log: Implement heap classes that each have their own range of allocation sizes they serve, bin sizes and page size. This minimizes the amount of "large" allocations made in heaps that don't have a bin for the allocation size (combining multiple pages). This is desirable as such large allocations are generally pretty inefficient, and also because it separates larger from smaller allocations better, making the chance of a heap becoming empty higher. For now there are three heap classes "small", "large" and "huge", with a predefined set of bin sizes for each. This might need some finetuning later on. Reduce the grow size to 4MB though as the allocations should now be spread across heap classes which each grow on their own. Modified: haiku/trunk/headers/private/kernel/heap.h =================================================================== --- haiku/trunk/headers/private/kernel/heap.h 2008-07-01 22:46:54 UTC (rev 26209) +++ haiku/trunk/headers/private/kernel/heap.h 2008-07-01 23:19:35 UTC (rev 26210) @@ -12,10 +12,12 @@ // allocate 16MB initial heap for the kernel #define INITIAL_HEAP_SIZE 16 * 1024 * 1024 -// grow by another 8MB each time the heap runs out of memory -#define HEAP_GROW_SIZE 8 * 1024 * 1024 +// grow by another 4MB each time the heap runs out of memory +#define HEAP_GROW_SIZE 4 * 1024 * 1024 // allocate a dedicated 1MB area for dynamic growing #define HEAP_DEDICATED_GROW_SIZE 1 * 1024 * 1024 +// use areas for allocations bigger than 1MB +#define HEAP_AREA_USE_THRESHOLD 1 * 1024 * 1024 #ifdef __cplusplus Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 22:46:54 UTC (rev 26209) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 23:19:35 UTC (rev 26210) @@ -97,12 +97,35 @@ heap_allocator_s * next; } heap_allocator; +typedef struct heap_class_s { + const char *name; + uint32 initial_percentage; + size_t max_allocation_size; + size_t page_size; + size_t bin_sizes[20]; +} heap_class; + struct DeferredFreeListEntry : DoublyLinkedListLinkImpl { }; typedef DoublyLinkedList DeferredFreeList; -static heap_allocator *sHeapList = NULL; -static heap_allocator *sLastGrowRequest = NULL; +// Heap class configuration +#define HEAP_CLASS_COUNT 3 +static heap_class sHeapClasses[HEAP_CLASS_COUNT] = { + { "small", 50, B_PAGE_SIZE, B_PAGE_SIZE, + { 8, 12, 16, 24, 32, 48, 64, 96, 128, 160, 192, 256, 384, 512, 1024, + 2048, 4096, 0 } + }, + { "large", 30, B_PAGE_SIZE * 32, B_PAGE_SIZE * 32, + { 4096, 5120, 6144, 7168, 8192, 12288, 16384, 24576, 32768, 65536, + 131072, 0 } + }, + { "huge", 20, HEAP_AREA_USE_THRESHOLD, B_PAGE_SIZE * 64, + { 131072, 262144, 0 } + } +}; + +static heap_allocator *sHeapList[HEAP_CLASS_COUNT]; static heap_allocator *sGrowHeapList = NULL; static thread_id sHeapGrowThread = -1; static sem_id sHeapGrowSem = -1; @@ -263,24 +286,30 @@ heap = heap->next; } } else if (strcmp(argv[1], "stats") == 0) { - uint32 heapCount = 0; - heap_allocator *heap = sHeapList; - while (heap) { - heapCount++; - heap = heap->next; + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + uint32 heapCount = 0; + heap_allocator *heap = sHeapList[i]; + while (heap) { + heapCount++; + heap = heap->next; + } + + dprintf("current %s heap count: %ld\n", sHeapClasses[i].name, + heapCount); } - - dprintf("current heap count: %ld\n", heapCount); } else print_debugger_command_usage(argv[0]); return 0; } - heap_allocator *heap = sHeapList; - while (heap) { - dump_allocator(heap); - heap = heap->next; + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + dprintf("dumping list of %s heaps\n", sHeapClasses[i].name); + heap_allocator *heap = sHeapList[i]; + while (heap) { + dump_allocator(heap); + heap = heap->next; + } } return 0; @@ -313,7 +342,8 @@ size_t totalSize = 0; uint32 totalCount = 0; - heap_allocator *heap = sHeapList; + uint32 heapClassIndex = 0; + heap_allocator *heap = sHeapList[0]; while (heap) { // go through all the pages heap_leak_check_info *info = NULL; @@ -390,6 +420,8 @@ } heap = heap->next; + if (heap == NULL && ++heapClassIndex < HEAP_CLASS_COUNT) + heap = sHeapList[heapClassIndex]; } dprintf("total allocations: %lu; total bytes: %lu\n", totalCount, totalSize); @@ -453,7 +485,8 @@ sCallerInfoCount = 0; - heap_allocator *heap = sHeapList; + uint32 heapClassIndex = 0; + heap_allocator *heap = sHeapList[0]; while (heap) { // go through all the pages heap_leak_check_info *info = NULL; @@ -520,6 +553,8 @@ } heap = heap->next; + if (heap == NULL && ++heapClassIndex < HEAP_CLASS_COUNT) + heap = sHeapList[heapClassIndex]; } // sort the array @@ -674,27 +709,31 @@ static heap_allocator * -heap_attach(addr_t base, size_t size) +heap_attach(addr_t base, size_t size, uint32 heapClass) { heap_allocator *heap = (heap_allocator *)base; base += sizeof(heap_allocator); size -= sizeof(heap_allocator); - size_t binSizes[] = { 8, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 1024, 2048, B_PAGE_SIZE }; - uint32 binCount = sizeof(binSizes) / sizeof(binSizes[0]); - heap->page_size = B_PAGE_SIZE; - heap->bin_count = binCount; + heap->page_size = sHeapClasses[heapClass].page_size; heap->bins = (heap_bin *)base; - base += binCount * sizeof(heap_bin); - size -= binCount * sizeof(heap_bin); - for (uint32 i = 0; i < binCount; i++) { - heap_bin *bin = &heap->bins[i]; - bin->element_size = binSizes[i]; - bin->max_free_count = heap->page_size / binSizes[i]; + heap->bin_count = 0; + while (true) { + size_t binSize = sHeapClasses[heapClass].bin_sizes[heap->bin_count]; + if (binSize == 0) + break; + + heap_bin *bin = &heap->bins[heap->bin_count]; + bin->element_size = binSize; + bin->max_free_count = heap->page_size / binSize; bin->page_list = NULL; - } + heap->bin_count++; + }; + base += heap->bin_count * sizeof(heap_bin); + size -= heap->bin_count * sizeof(heap_bin); + uint32 pageCount = size / heap->page_size; size_t pageTableSize = pageCount * sizeof(heap_page); heap->page_table = (heap_page *)base; @@ -726,8 +765,8 @@ mutex_init(&heap->lock, "heap_mutex"); heap->next = NULL; - dprintf("heap_attach: attached to %p - usable range 0x%08lx - 0x%08lx\n", - heap, heap->base, heap->base + heap->size); + dprintf("heap_attach: %s heap attached to %p - usable range 0x%08lx - 0x%08lx\n", + sHeapClasses[heapClass].name, heap, heap->base, heap->base + heap->size); return heap; } @@ -900,6 +939,15 @@ #endif +inline bool +heap_should_grow(heap_allocator *heap) +{ + // suggest growing if it is the last heap and has less than 10% free pages + return (heap->next == NULL) + && heap->free_page_count < heap->page_count / 10; +} + + static void * heap_memalign(heap_allocator *heap, size_t alignment, size_t size, bool *shouldGrow) @@ -932,11 +980,8 @@ TRACE(("memalign(): asked to allocate %lu bytes, returning pointer %p\n", size, address)); - if (heap->next == NULL && shouldGrow) { - // suggest growing if we are the last heap and we have - // less than 10% free pages - *shouldGrow = heap->free_page_count < heap->page_count / 10; - } + if (shouldGrow) + *shouldGrow = heap_should_grow(heap); #if KERNEL_HEAP_LEAK_CHECK size -= sizeof(heap_leak_check_info); @@ -1076,6 +1121,9 @@ } } + if (heap->free_page_count == heap->page_count) + dprintf("heap_free: heap %p is completely empty and could be freed\n", heap); + T(Free((addr_t)address)); mutex_unlock(&heap->lock); return B_OK; @@ -1168,6 +1216,23 @@ } +inline uint32 +heap_class_for(size_t size) +{ +#if KERNEL_HEAP_LEAK_CHECK + // take the extra info size into account + size += sizeof(heap_leak_check_info_s); +#endif + + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + if (size <= sHeapClasses[i].max_allocation_size) + return i; + } + + return HEAP_CLASS_COUNT - 1; +} + + static void deferred_deleter(void *arg, int iteration) { @@ -1191,7 +1256,7 @@ static heap_allocator * -heap_create_new_heap(const char *name, size_t size) +heap_create_new_heap(const char *name, size_t size, uint32 heapClass) { void *heapAddress = NULL; area_id heapArea = create_area(name, &heapAddress, @@ -1202,7 +1267,7 @@ return NULL; } - heap_allocator *newHeap = heap_attach((addr_t)heapAddress, size); + heap_allocator *newHeap = heap_attach((addr_t)heapAddress, size, heapClass); if (newHeap == NULL) { panic("heap: could not attach heap to area!\n"); delete_area(heapArea); @@ -1219,7 +1284,6 @@ static int32 heap_grow_thread(void *) { - heap_allocator *heap = sHeapList; heap_allocator *growHeap = sGrowHeapList; while (true) { // wait for a request to grow the heap list @@ -1234,7 +1298,7 @@ // a new one to make some room. TRACE(("heap_grower: grow heaps will run out of memory soon\n")); heap_allocator *newHeap = heap_create_new_heap( - "additional grow heap", HEAP_DEDICATED_GROW_SIZE); + "additional grow heap", HEAP_DEDICATED_GROW_SIZE, 0); if (newHeap != NULL) { #if PARANOID_VALIDATION heap_validate_heap(newHeap); @@ -1245,24 +1309,25 @@ } } - // find the last heap - while (heap->next) - heap = heap->next; + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + // find the last heap + heap_allocator *heap = sHeapList[i]; + while (heap->next) + heap = heap->next; - if (sLastGrowRequest != heap) { - // we have already grown since the latest request, just ignore - continue; - } - - TRACE(("heap_grower: kernel heap will run out of memory soon, allocating new one\n")); - heap_allocator *newHeap = heap_create_new_heap("additional heap", - HEAP_GROW_SIZE); - if (newHeap != NULL) { + if (heap_should_grow(heap)) { + // grow this heap if it makes sense to + heap_allocator *newHeap = heap_create_new_heap("additional heap", + HEAP_GROW_SIZE, i); + if (newHeap != NULL) { #if PARANOID_VALIDATION - heap_validate_heap(newHeap); + heap_validate_heap(newHeap); #endif - heap->next = newHeap; - TRACE(("heap_grower: new heap linked in\n")); + heap->next = newHeap; + TRACE(("heap_grower: new %s heap linked in\n", + sHeapClasses[i].name)); + } + } } // notify anyone waiting for this request @@ -1276,7 +1341,11 @@ status_t heap_init(addr_t base, size_t size) { - sHeapList = heap_attach(base, size); + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + size_t partSize = size * sHeapClasses[i].initial_percentage / 100; + sHeapList[i] = heap_attach(base, partSize, i); + base += partSize; + } // set up some debug commands add_debugger_command_etc("heap", &dump_heap_list, @@ -1329,7 +1398,7 @@ heap_init_post_thread() { sGrowHeapList = heap_create_new_heap("dedicated grow heap", - HEAP_DEDICATED_GROW_SIZE); + HEAP_DEDICATED_GROW_SIZE, 0); if (sGrowHeapList == NULL) { panic("heap_init_post_thread(): failed to attach dedicated grow heap\n"); return B_ERROR; @@ -1361,19 +1430,18 @@ return NULL; } - if (size > (HEAP_GROW_SIZE * 3) / 4) { - // don't even attempt such a huge allocation + if (size > HEAP_AREA_USE_THRESHOLD) { + // don't even attempt such a huge allocation - use areas instead panic("heap: huge allocation of %lu bytes asked!\n", size); return NULL; } - heap_allocator *heap = sHeapList; + heap_allocator *heap = sHeapList[heap_class_for(size)]; while (heap) { bool shouldGrow = false; void *result = heap_memalign(heap, alignment, size, &shouldGrow); if (heap->next == NULL && (shouldGrow || result == NULL)) { // the last heap will or has run out of memory, notify the grower - sLastGrowRequest = heap; if (result == NULL) { // urgent request, do the request and wait switch_sem(sHeapGrowSem, sHeapGrownNotify); @@ -1429,7 +1497,7 @@ } // try public memory, there might be something available - heap_allocator *heap = sHeapList; + heap_allocator *heap = sHeapList[heap_class_for(size)]; while (heap) { void *result = heap_memalign(heap, 0, size, NULL); if (result != NULL) @@ -1462,20 +1530,22 @@ return; } - heap_allocator *heap = sHeapList; - while (heap) { - if (heap_free(heap, address) == B_OK) { + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + heap_allocator *heap = sHeapList[i]; + while (heap) { + if (heap_free(heap, address) == B_OK) { #if PARANOID_VALIDATION - heap_validate_heap(heap); + heap_validate_heap(heap); #endif - return; + return; + } + + heap = heap->next; } - - heap = heap->next; } // maybe it was allocated from a dedicated grow heap - heap = sGrowHeapList; + heap_allocator *heap = sGrowHeapList; while (heap) { if (heap_free(heap, address) == B_OK) return; @@ -1503,17 +1573,19 @@ return NULL; } - heap_allocator *heap = sHeapList; - while (heap) { - void *newAddress = NULL; - if (heap_realloc(heap, address, &newAddress, newSize) == B_OK) { + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { + heap_allocator *heap = sHeapList[i]; + while (heap) { + void *newAddress = NULL; + if (heap_realloc(heap, address, &newAddress, newSize) == B_OK) { #if PARANOID_VALIDATION - heap_validate_heap(heap); + heap_validate_heap(heap); #endif - return newAddress; + return newAddress; + } + + heap = heap->next; } - - heap = heap->next; } panic("realloc(): failed to realloc address %p to size %lu\n", address, newSize); From stippi at mail.berlios.de Wed Jul 2 01:54:11 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 2 Jul 2008 01:54:11 +0200 Subject: [Haiku-commits] r26211 - haiku/trunk/src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807012354.m61NsB8Z027259@sheep.berlios.de> Author: stippi Date: 2008-07-02 01:54:08 +0200 (Wed, 02 Jul 2008) New Revision: 26211 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26211&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: bonefish+stippi: Implemented the needed fs API hooks to support identifying partitions (so ReiserFS partitions appear in the Tracker Mount menu now). Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 23:19:35 UTC (rev 26210) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-01 23:54:08 UTC (rev 26211) @@ -86,6 +86,19 @@ Unmount(); } +// Identify +status_t +Volume::Identify(int fd, partition_data *partition) +{ + // open disk + fDevice = dup(fd); + if (fDevice < 0) + return B_ERROR; + + // read and analyze super block + return _ReadSuperBlock(); +} + // Mount status_t Volume::Mount(fs_volume *fsVolume, const char *path) Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 23:19:35 UTC (rev 26210) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-01 23:54:08 UTC (rev 26211) @@ -41,6 +41,8 @@ Volume(); ~Volume(); + status_t Identify(int fd, partition_data *partition); + status_t Mount(fs_volume *fsVolume, const char *path); status_t Unmount(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 23:19:35 UTC (rev 26210) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-01 23:54:08 UTC (rev 26211) @@ -44,6 +44,8 @@ #include "Volume.h" +using std::nothrow; + static const size_t kOptimalIOSize = 65536; extern fs_volume_ops gReiserFSVolumeOps; @@ -56,6 +58,57 @@ // #pragma mark - FS +// reiserfs_identify_partition +static float +reiserfs_identify_partition(int fd, partition_data *partition, void **cookie) +{ + Volume* volume = new(nothrow) Volume(); + if (volume == NULL) + return -1.0; + + status_t status = volume->Identify(fd, partition); + if (status != B_OK) { + delete volume; + return -1.0; + } + + *cookie = (void*)volume; + return 0.8; +} + + +// reiserfs_scan_partition +static status_t +reiserfs_scan_partition(int fd, partition_data *partition, void *_cookie) +{ + Volume* volume = (Volume*)_cookie; + + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_FILE_SYSTEM; + partition->content_size = volume->CountBlocks() + * volume->GetBlockSize(); + partition->block_size = volume->GetBlockSize(); + // TODO: Construct name from partition layout? + partition->content_name = strdup("Untitled ReiserFS"); + if (partition->content_name == NULL) + return B_NO_MEMORY; + + return B_OK; +} + + +// reiserfs_free_identify_partition_cookie +static void +reiserfs_free_identify_partition_cookie(partition_data* partition, + void* _cookie) +{ + delete (Volume*)_cookie; +} + + +// #pragma mark - + + // reiserfs_mount static status_t reiserfs_mount(fs_volume *_volume, const char *device, uint32 flags, @@ -663,9 +716,9 @@ // scanning - NULL, // identify_partition() - NULL, // scan_partition() - NULL, // free_identify_partition_cookie() + &reiserfs_identify_partition, + &reiserfs_scan_partition, + &reiserfs_free_identify_partition_cookie, NULL, // free_partition_content_cookie() &reiserfs_mount From mmlr at mail.berlios.de Wed Jul 2 02:59:34 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 02:59:34 +0200 Subject: [Haiku-commits] r26212 - haiku/trunk/src/system/kernel Message-ID: <200807020059.m620xYNR001872@sheep.berlios.de> Author: mmlr Date: 2008-07-02 02:59:32 +0200 (Wed, 02 Jul 2008) New Revision: 26212 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26212&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: The simple alignment trick used before doesn't work with the new heap classes (it didn't really work previously anyway). The only alignment really used seems to be B_PAGE_SIZE, which happened to always work out before, because anything larger would have been allocated using individual pages anyway. Since larger bins are now available and with kernel heap leak checking enabled an allocation of B_PAGE_SIZE with B_PAGE_SIZE alignment is actually a bit bigger than B_PAGE_SIZE, it got into the 5KB bin, which didn't guarantee the alignment anymore. This would have caused a tripple fault on boot when kernel heap leak checking was enabled. The alignment is now taken into account when picking the bin for the allocation. Added a more detailed TODO as to why this isn't the best thing (wastes space) and how it could be changed if deemed necessary. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-01 23:54:08 UTC (rev 26211) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 00:59:32 UTC (rev 26212) @@ -965,18 +965,23 @@ size += sizeof(heap_leak_check_info); #endif - // ToDo: that code "aligns" the buffer because the bins are always - // aligned on their bin size - if (size < alignment) - size = alignment; - uint32 binIndex; for (binIndex = 0; binIndex < heap->bin_count; binIndex++) { - if (size <= heap->bins[binIndex].element_size) + // TODO: The alignment is done by ensuring that the element size + // of the target bin is aligned with the requested alignment. This + // has the problem that it wastes space because a better (smaller) bin + // could possibly be selected. We should pick the best bin and check + // if there is an aligned block in the free list or if a new (page + // aligned) page has to be allocated anyway. + size_t elementSize = heap->bins[binIndex].element_size; + if (size <= elementSize && (alignment == 0 + || (elementSize & (alignment - 1) == 0))) break; } void *address = heap_raw_alloc(heap, size, binIndex); + if (alignment != 0 && ((addr_t)address & (alignment - 1))) + panic("alignment not met at %p with 0x%08lx\n", address, alignment); TRACE(("memalign(): asked to allocate %lu bytes, returning pointer %p\n", size, address)); From korli at users.berlios.de Wed Jul 2 08:32:58 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Wed, 2 Jul 2008 08:32:58 +0200 Subject: [Haiku-commits] r26204 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <486AAACE.6060303@arcor.de> References: <200807012056.m61KuOlF021405@sheep.berlios.de> <486AAACE.6060303@arcor.de> Message-ID: Hi Marcus, 2008/7/2 Marcus Overhagen : > korli at BerliOS schrieb: > >> Log: >> gcc4 build fix >> > >> - }; >> + } u; > > I have used unnamed unions in the ahci driver, and it seems > to compile with gcc4. Why doesn't it work with ext2? > It resulted in the following error : src/add-ons/kernel/file_systems/ext2/ext2.h:155: error: 'struct ext2_inode::::data_stream' invalid; an anonymous union can only have non-static data members Feel free to fix in a better way. Bye, J?r?me From axeld at mail.berlios.de Wed Jul 2 11:15:04 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 Jul 2008 11:15:04 +0200 Subject: [Haiku-commits] r26213 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807020915.m629F4o9005852@sheep.berlios.de> Author: axeld Date: 2008-07-02 11:15:04 +0200 (Wed, 02 Jul 2008) New Revision: 26213 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26213&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Log: * Fixed wrong group block offset computation: the ext2_super_block::first_data_block must be used; the superblock offset doesn't matter if the block size is greater than 2KB. * Fixed block access beyond the 4GB limit - we need to cast the block to a 64 bit type in ext2_get_file_map() before shifting it. * Tested with various larger ext3 disks, and everything seems to work fine. * Added some optional debug output. * Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp 2008-07-02 09:15:04 UTC (rev 26213) @@ -11,6 +11,14 @@ #include "Inode.h" +//#define TRACE_EXT2 +#ifdef TRACE_EXT2 +# define TRACE(x...) dprintf("\33[34mext2:\33[0m " x) +#else +# define TRACE(x...) ; +#endif + + DirectoryIterator::DirectoryIterator(Inode* inode) : fInode(inode), @@ -24,7 +32,7 @@ } -status_t +status_t DirectoryIterator::GetNext(char* name, size_t* _nameLength, ino_t* _id) { if (fOffset + sizeof(ext2_dir_entry) >= fInode->Size()) @@ -48,6 +56,10 @@ fOffset += entry.Length(); } + TRACE("offset %Ld: entry ino %lu, length %u, name length %u, type %u\n", + fOffset, entry.InodeID(), entry.Length(), entry.NameLength(), + entry.FileType()); + // read name size_t length = entry.NameLength(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-02 09:15:04 UTC (rev 26213) @@ -11,6 +11,14 @@ #include "CachedBlock.h" +//#define TRACE_EXT2 +#ifdef TRACE_EXT2 +# define TRACE(x...) dprintf("\33[34mext2:\33[0m " x) +#else +# define TRACE(x...) ; +#endif + + Inode::Inode(Volume* volume, ino_t id) : fVolume(volume), @@ -23,6 +31,7 @@ uint32 block; if (volume->GetInodeBlock(id, block) == B_OK) { + TRACE("inode %Ld at block %lu\n", ID(), block); ext2_inode* inodes = (ext2_inode*)block_cache_get(volume->BlockCache(), block); if (inodes != NULL) @@ -150,7 +159,7 @@ return B_ERROR; } - //dprintf("FindBlock(offset %Ld): %lu\n", offset, block); + TRACE("inode %Ld: FindBlock(offset %Ld): %lu\n", ID(), offset, block); return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-02 09:15:04 UTC (rev 26213) @@ -20,6 +20,14 @@ #include "Inode.h" +//#define TRACE_EXT2 +#ifdef TRACE_EXT2 +# define TRACE(x...) dprintf("\33[34mext2:\33[0m " x) +#else +# define TRACE(x...) ; +#endif + + class DeviceOpener { public: DeviceOpener(int fd, int mode); @@ -268,13 +276,20 @@ // initialize short hands to the super block (to save byte swapping) fBlockShift = fSuperBlock.BlockShift(); fBlockSize = 1UL << fSuperBlock.BlockShift(); + fFirstDataBlock = fSuperBlock.FirstDataBlock(); - fNumGroups = (fSuperBlock.NumBlocks() - fSuperBlock.FirstDataBlock() - 1) + fNumGroups = (fSuperBlock.NumBlocks() - fFirstDataBlock - 1) / fSuperBlock.BlocksPerGroup() + 1; fGroupsPerBlock = fBlockSize / sizeof(ext2_block_group); + TRACE("block size %ld, num groups %ld, groups per block %ld, first %lu\n", + fBlockSize, fNumGroups, fGroupsPerBlock, fFirstDataBlock); + TRACE("features %lx, incompatible features %lx, read-only features %lx\n", + fSuperBlock.CompatibleFeatures(), fSuperBlock.IncompatibleFeatures(), + fSuperBlock.ReadOnlyFeatures()); + uint32 blockCount = (fNumGroups + fGroupsPerBlock - 1) / fGroupsPerBlock; - + fGroupBlocks = (ext2_block_group**)malloc(blockCount * sizeof(void*)); if (fGroupBlocks == NULL) return B_NO_MEMORY; @@ -298,8 +313,9 @@ // all went fine opener.Keep(); return B_OK; - } else - dprintf("ext2: could not create root node: get_vnode() failed!\n"); + } else { + TRACE("could not create root node: get_vnode() failed!\n"); + } return status; } @@ -344,7 +360,7 @@ if ((fSuperBlock.IncompatibleFeatures() & EXT2_INCOMPATIBLE_FEATURE_META_GROUP) == 0 || blockIndex < fSuperBlock.FirstMetaBlockGroup()) - return EXT2_SUPER_BLOCK_OFFSET + fBlockSize * (1 + blockIndex); + return (fFirstDataBlock + blockIndex + 1) << fBlockShift; panic("meta block"); return 0; @@ -380,6 +396,9 @@ } fGroupBlocks[blockIndex] = groupBlock; + + TRACE("group [%ld]: inode table %ld\n", index, + (fGroupBlocks[blockIndex] + index % fGroupsPerBlock)->InodeTable()); } *_group = fGroupBlocks[blockIndex] + index % fGroupsPerBlock; Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-07-02 09:15:04 UTC (rev 26213) @@ -62,6 +62,7 @@ uint32 fFlags; uint32 fBlockSize; uint32 fBlockShift; + uint32 fFirstDataBlock; uint32 fNumGroups; uint32 fGroupsPerBlock; ext2_block_group** fGroupBlocks; Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 09:15:04 UTC (rev 26213) @@ -45,7 +45,7 @@ uint16 block_group; uint32 compatible_features; uint32 incompatible_features; - uint32 readonly_features; + uint32 read_only_features; uint8 uuid[16]; char name[16]; char last_mount_point[64]; @@ -53,7 +53,7 @@ uint8 preallocated_blocks; uint8 preallocated_directory_blocks; uint16 _padding; - + // journaling ext3 support uint8 journal_uuid[16]; uint32 journal_inode; @@ -85,7 +85,7 @@ uint32 CompatibleFeatures() const { return B_LENDIAN_TO_HOST_INT32(compatible_features); } uint32 ReadOnlyFeatures() const - { return B_LENDIAN_TO_HOST_INT32(readonly_features); } + { return B_LENDIAN_TO_HOST_INT32(read_only_features); } uint32 IncompatibleFeatures() const { return B_LENDIAN_TO_HOST_INT32(incompatible_features); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-02 00:59:32 UTC (rev 26212) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-02 09:15:04 UTC (rev 26213) @@ -257,7 +257,7 @@ if (status != B_OK) return status; - off_t blockOffset = block << volume->BlockShift(); + off_t blockOffset = (off_t)block << volume->BlockShift(); uint32 blockLength = volume->BlockSize(); if (index > 0 && vecs[index - 1].offset == blockOffset - blockLength) { From axeld at pinc-software.de Wed Jul 2 11:20:31 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 02 Jul 2008 11:20:31 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26210_-_in_haiku/trunk=3A_headers/priv?= =?utf-8?q?ate/kernel_src/system/kernel?= In-Reply-To: <200807012319.m61NJeMF023662@sheep.berlios.de> Message-ID: <600127430-BeMail@zon> mmlr at mail.berlios.de wrote: > Reduce the grow size to 4MB though as the allocations should now be > spread > across heap classes which each grow on their own. Wouldn't it make sense to have grow size depending on the class? (ie. large allocation heaps would grow faster than small ones) Bye, Axel. From marcusoverhagen at arcor.de Wed Jul 2 11:38:14 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Wed, 2 Jul 2008 11:38:14 +0200 (CEST) Subject: [Haiku-commits] r26213 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <200807020915.m629F4o9005852@sheep.berlios.de> References: <200807020915.m629F4o9005852@sheep.berlios.de> Message-ID: <14262618.1214991494649.JavaMail.ngmail@webmail16.arcor-so.net> ----- Original Nachricht ---- Von: axeld at BerliOS An: haiku-commits at lists.berlios.de Datum: 02.07.2008 11:15 Betreff: [Haiku-commits] r26213 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 > > + return (fFirstDataBlock + blockIndex + 1) << fBlockShift; doesn't this need a cast to off_t before shifting? Jetzt komfortabel bei Arcor-Digital TV einsteigen: Mehr Happy Ends, mehr Herzschmerz, mehr Fernsehen! Erleben Sie 50 digitale TV Programme und optional 60 Pay TV Sender, einen elektronischen Programmf?hrer mit Movie Star Bewertungen von TV Movie. Au?erdem, aktuelle Filmhits und spannende Dokus in der Arcor-Videothek. Infos unter www.arcor.de/tv From axeld at mail.berlios.de Wed Jul 2 11:43:12 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 Jul 2008 11:43:12 +0200 Subject: [Haiku-commits] r26214 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807020943.m629hCQ2008934@sheep.berlios.de> Author: axeld Date: 2008-07-02 11:43:12 +0200 (Wed, 02 Jul 2008) New Revision: 26214 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26214&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp Log: * Seems like GCC4 does not like declaring structures inside unnamed unions; that looks like a compiler bug to me, though. * Pulled struct data_stream out of the union (now called ext2_data_stream), based on a patch by Maurice, thanks! Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-02 09:15:04 UTC (rev 26213) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Inode.cpp 2008-07-02 09:43:12 UTC (rev 26214) @@ -110,12 +110,12 @@ if (index < EXT2_DIRECT_BLOCKS) { // direct blocks - block = B_LENDIAN_TO_HOST_INT32(Node().u.stream.direct[index]); + block = B_LENDIAN_TO_HOST_INT32(Node().stream.direct[index]); } else if ((index -= EXT2_DIRECT_BLOCKS) < perBlock) { // indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().u.stream.indirect)); + Node().stream.indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; @@ -124,7 +124,7 @@ // double indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().u.stream.double_indirect)); + Node().stream.double_indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; @@ -138,7 +138,7 @@ // triple indirect blocks CachedBlock cached(fVolume); uint32* indirectBlocks = (uint32*)cached.SetTo(B_LENDIAN_TO_HOST_INT32( - Node().u.stream.triple_indirect)); + Node().stream.triple_indirect)); if (indirectBlocks == NULL) return B_IO_ERROR; Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 09:15:04 UTC (rev 26213) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 09:43:12 UTC (rev 26214) @@ -138,6 +138,13 @@ #define EXT2_ROOT_NODE 2 #define EXT2_SHORT_SYMLINK_LENGTH 60 +struct ext2_data_stream { + uint32 direct[EXT2_DIRECT_BLOCKS]; + uint32 indirect; + uint32 double_indirect; + uint32 triple_indirect; +}; + struct ext2_inode { uint16 mode; uint16 uid; @@ -152,14 +159,9 @@ uint32 flags; uint32 _reserved1; union { - struct data_stream { - uint32 direct[EXT2_DIRECT_BLOCKS]; - uint32 indirect; - uint32 double_indirect; - uint32 triple_indirect; - } stream; + ext2_data_stream stream; char symlink[EXT2_SHORT_SYMLINK_LENGTH]; - } u; + }; uint32 generation; uint32 file_access_control; union { Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-02 09:15:04 UTC (rev 26213) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp 2008-07-02 09:43:12 UTC (rev 26214) @@ -414,7 +414,7 @@ if (inode->Size() > EXT2_SHORT_SYMLINK_LENGTH) return inode->ReadAt(0, (uint8 *)buffer, _bufferSize); - memcpy(buffer, inode->Node().u.symlink, *_bufferSize); + memcpy(buffer, inode->Node().symlink, *_bufferSize); return B_OK; } From mmlr at mail.berlios.de Wed Jul 2 11:51:01 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 11:51:01 +0200 Subject: [Haiku-commits] r26215 - haiku/trunk/src/system/kernel Message-ID: <200807020951.m629p1b3010139@sheep.berlios.de> Author: mmlr Date: 2008-07-02 11:50:58 +0200 (Wed, 02 Jul 2008) New Revision: 26215 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26215&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Fix subtle logic error that would always cause a needless large allocation if an alignment was given. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 09:43:12 UTC (rev 26214) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 09:50:58 UTC (rev 26215) @@ -975,7 +975,7 @@ // aligned) page has to be allocated anyway. size_t elementSize = heap->bins[binIndex].element_size; if (size <= elementSize && (alignment == 0 - || (elementSize & (alignment - 1) == 0))) + || (elementSize & (alignment - 1)) == 0)) break; } From mmlr at mail.berlios.de Wed Jul 2 12:29:04 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 12:29:04 +0200 Subject: [Haiku-commits] r26216 - haiku/trunk/src/system/kernel Message-ID: <200807021029.m62AT4QA016129@sheep.berlios.de> Author: mmlr Date: 2008-07-02 12:29:02 +0200 (Wed, 02 Jul 2008) New Revision: 26216 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26216&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Implement transparent allocation by area for huge allocations (> 1MB). This does in fact happen, as there are objects used in the kernel that allocate with new, which in turn uses the heap. The OpenHashTable used from the slab allocator hit this case during an svn checkout here, because it grows it's new allocated list by doubling the list size. Added some unconditional debug output for those cases to monitor the usage for now. All of that not yet really tested though. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 09:50:58 UTC (rev 26215) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 10:29:02 UTC (rev 26216) @@ -105,6 +105,17 @@ size_t bin_sizes[20]; } heap_class; +static const uint32 kAreaAllocationMagic = 'AAMG'; +typedef struct area_allocation_info_s { + area_id area; + void * base; + uint32 magic; + size_t size; + size_t allocation_size; + size_t allocation_alignment; + void * allocation_base; +} area_allocation_info; + struct DeferredFreeListEntry : DoublyLinkedListLinkImpl { }; typedef DoublyLinkedList DeferredFreeList; @@ -943,7 +954,7 @@ heap_should_grow(heap_allocator *heap) { // suggest growing if it is the last heap and has less than 10% free pages - return (heap->next == NULL) + return heap->next == NULL && heap->free_page_count < heap->page_count / 10; } @@ -1311,7 +1322,8 @@ growHeap->next = newHeap; sAddGrowHeap = false; TRACE(("heap_grower: new grow heap %p linked in\n", newHeap)); - } + } else + dprintf("heap_grower: failed to create new grow heap\n"); } for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { @@ -1331,7 +1343,8 @@ heap->next = newHeap; TRACE(("heap_grower: new %s heap linked in\n", sHeapClasses[i].name)); - } + } else + dprintf("heap_grower: failed to create new heap\n"); } } @@ -1437,8 +1450,38 @@ if (size > HEAP_AREA_USE_THRESHOLD) { // don't even attempt such a huge allocation - use areas instead - panic("heap: huge allocation of %lu bytes asked!\n", size); - return NULL; + dprintf("heap: using area for huge allocation of %lu bytes!\n", size); + size_t areaSize = size + sizeof(area_allocation_info); + if (alignment != 0) + areaSize = (areaSize + alignment - 1) / alignment; + + void *address = NULL; + areaSize = (areaSize + B_PAGE_SIZE - 1) / B_PAGE_SIZE; + area_id allocationArea = create_area("memalign area", &address, + B_ANY_KERNEL_BLOCK_ADDRESS, areaSize, B_FULL_LOCK, + B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); + if (allocationArea < B_OK) { + dprintf("heap: failed to create area for huge allocation\n"); + return NULL; + } + + area_allocation_info *info = (area_allocation_info *)address; + info->magic = kAreaAllocationMagic; + info->area = allocationArea; + info->base = address; + info->size = areaSize; + info->allocation_size = size; + info->allocation_alignment = alignment; + + address = (void *)((addr_t)address + sizeof(area_allocation_info)); + if (alignment != 0) + address = (void *)(((addr_t)address + alignment - 1) / alignment); + + dprintf("heap: allocated area %ld for huge allocation returning %p\n", + allocationArea, address); + + info->allocation_base = address; + return address; } heap_allocator *heap = sHeapList[heap_class_for(size)]; @@ -1558,6 +1601,23 @@ heap = heap->next; } + // or maybe it was a huge allocation using an area + area_info areaInfo; + area_id area = area_for(address); + if (area >= B_OK && get_area_info(area, &areaInfo) == B_OK) { + area_allocation_info *info = (area_allocation_info *)areaInfo.address; + + // just make extra sure it was allocated by us + if (info->magic == kAreaAllocationMagic && info->area == area + && info->size == areaInfo.size && info->base == areaInfo.address + && info->allocation_size < areaInfo.size) { + delete_area(area); + dprintf("free(): freed huge allocation by deleting area %ld\n", + area); + return; + } + } + panic("free(): free failed for address %p\n", address); } @@ -1593,6 +1653,42 @@ } } + // maybe a huge allocation using an area + area_info areaInfo; + area_id area = area_for(address); + if (area >= B_OK && get_area_info(area, &areaInfo) == B_OK) { + area_allocation_info *info = (area_allocation_info *)areaInfo.address; + + // just make extra sure it was allocated by us + if (info->magic == kAreaAllocationMagic && info->area == area + && info->size == areaInfo.size && info->base == areaInfo.address + && info->allocation_size < areaInfo.size) { + size_t available = info->size - ((addr_t)info->allocation_base + - (addr_t)info->base); + + if (available >= newSize) { + // there is enough room available for the newSize + dprintf("realloc(): new size %ld fits in old area %ld with %ld available", + newSize, area, available); + return address; + } + + // have to allocate/copy/free - TODO maybe resize the area instead? + void *newAddress = memalign(0, newSize); + if (newAddress == NULL) { + dprintf("realloc(): failed to allocate new block of %ld bytes\n", + newSize); + return NULL; + } + + memcpy(newAddress, address, min_c(newSize, info->allocation_size)); + delete_area(area); + dprintf("realloc(): allocated new block %p for size %ld and deleted old area %ld\n", + newAddress, newSize, area); + return newAddress; + } + } + panic("realloc(): failed to realloc address %p to size %lu\n", address, newSize); return NULL; } From axeld at pinc-software.de Wed Jul 2 12:28:17 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 02 Jul 2008 12:28:17 +0200 CEST Subject: [Haiku-commits] r26213 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <14262618.1214991494649.JavaMail.ngmail@webmail16.arcor-so.net> Message-ID: <4666090008-BeMail@zon> Marcus Overhagen wrote: > > + return (fFirstDataBlock + blockIndex + 1) << fBlockShift; > doesn't this need a cast to off_t before shifting? It would if it could span beyond 4GB which it never does (although theoretically it could be 4GB+2). But thanks for the hint, it's better to make it look right :-) Bye, Axel. From axeld at pinc-software.de Wed Jul 2 12:28:57 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 02 Jul 2008 12:28:57 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26204_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/ext2?= In-Reply-To: Message-ID: <4706324484-BeMail@zon> "J?r?me Duval" wrote: > Feel free to fix in a better way. Thanks and done :-) Looks like a compiler bug to me, though. Bye, Axel. From axeld at mail.berlios.de Wed Jul 2 12:33:39 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 Jul 2008 12:33:39 +0200 Subject: [Haiku-commits] r26217 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807021033.m62AXduc021683@sheep.berlios.de> Author: axeld Date: 2008-07-02 12:33:38 +0200 (Wed, 02 Jul 2008) New Revision: 26217 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26217&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp Log: * Cast block before shifting, as suggested by Marcus; it shouldn't have any actual consequences but looks more correct. Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-02 10:29:02 UTC (rev 26216) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-02 10:33:38 UTC (rev 26217) @@ -360,7 +360,7 @@ if ((fSuperBlock.IncompatibleFeatures() & EXT2_INCOMPATIBLE_FEATURE_META_GROUP) == 0 || blockIndex < fSuperBlock.FirstMetaBlockGroup()) - return (fFirstDataBlock + blockIndex + 1) << fBlockShift; + return off_t(fFirstDataBlock + blockIndex + 1) << fBlockShift; panic("meta block"); return 0; From axeld at mail.berlios.de Wed Jul 2 12:38:37 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 Jul 2008 12:38:37 +0200 Subject: [Haiku-commits] r26218 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807021038.m62Acbfx028314@sheep.berlios.de> Author: axeld Date: 2008-07-02 12:38:27 +0200 (Wed, 02 Jul 2008) New Revision: 26218 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26218&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h Log: * Fixed a few problems reported by Marcus - thanks for proofreading! Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 10:33:38 UTC (rev 26217) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/ext2.h 2008-07-02 10:38:27 UTC (rev 26218) @@ -132,7 +132,7 @@ uint32 InodeTable() const { return B_LENDIAN_TO_HOST_INT32(inode_table); } -}; +} _PACKED; #define EXT2_DIRECT_BLOCKS 12 #define EXT2_ROOT_NODE 2 @@ -143,7 +143,7 @@ uint32 indirect; uint32 double_indirect; uint32 triple_indirect; -}; +} _PACKED; struct ext2_inode { uint16 mode; @@ -196,13 +196,13 @@ return B_LENDIAN_TO_HOST_INT32(size); } - uint16 UserID() const + uint32 UserID() const { return B_LENDIAN_TO_HOST_INT16(uid) | (B_LENDIAN_TO_HOST_INT16(uid_high) << 16); } - uint16 GroupID() const + uint32 GroupID() const { return B_LENDIAN_TO_HOST_INT16(gid) | (B_LENDIAN_TO_HOST_INT16(gid_high) << 16); From ingo_weinhold at gmx.de Wed Jul 2 13:09:52 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Wed, 02 Jul 2008 13:09:52 +0200 Subject: [Haiku-commits] r26216 - haiku/trunk/src/system/kernel In-Reply-To: <200807021029.m62AT4QA016129@sheep.berlios.de> References: <200807021029.m62AT4QA016129@sheep.berlios.de> Message-ID: <20080702130952.443.1@knochen-vm.1214995827.fake> On 2008-07-02 at 12:29:04 [+0200], mmlr at mail.berlios.de wrote: > Author: mmlr > Date: 2008-07-02 12:29:02 +0200 (Wed, 02 Jul 2008) > New Revision: 26216 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26216&view=rev > > Modified: > haiku/trunk/src/system/kernel/heap.cpp > Log: > Implement transparent allocation by area for huge allocations (> 1MB). This > does in fact happen, as there are objects used in the kernel that allocate > with new, which in turn uses the heap. The OpenHashTable used from the slab > allocator hit this case during an svn checkout here, because it grows it's > new > allocated list by doubling the list size. Added some unconditional debug > output for those cases to monitor the usage for now. All of that not yet > really > tested though. Out of curiosity, do you know which object cache becomes that big? The one for the blocks of the block cache, I suppose, right? CU, Ingo From mmlr at mlotz.ch Wed Jul 2 13:16:53 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Wed, 02 Jul 2008 13:16:53 +0200 Subject: [Haiku-commits] r26216 - haiku/trunk/src/system/kernel In-Reply-To: <20080702130952.443.1@knochen-vm.1214995827.fake> Message-ID: <886862452-BeMail@primary> Hi Ingo > On 2008-07-02 at 12:29:04 [+0200], mmlr at mail.berlios.de wrote: > > Implement transparent allocation by area for huge allocations (> > > 1MB). This > > does in fact happen, as there are objects used in the kernel that > > allocate > > with new, which in turn uses the heap. The OpenHashTable used from > > the slab > > allocator hit this case during an svn checkout here, because it > > grows it's > > new > > allocated list by doubling the list size. Added some unconditional > > debug > > output for those cases to monitor the usage for now. All of that > > not yet > > really > > tested though. > > Out of curiosity, do you know which object cache becomes that big? > The one > for the blocks of the block cache, I suppose, right? I would guess so, the stack trace looked like this: panic("heap: huge allocation of 2097152 bytes asked!") memalign() malloc() -> inlined operator new() -> inlined OpenHashTable::_Resize() -> inlined OpenHashTable::Insert() HashedObjectCache::PrepareObject() HashedObjectCache::InitSlab() HashedObjectCache::CreateSlab() object_cache_reserve_internal() object_cache_alloc() block_cache::Allocate() block_cache_get_etc() block_cache_get() Journal::_WriteTransactionToLog() Journal::_TransactionDone() Journal::Unlock() bfs_rename() -> syscall apr_file_rename() svn stuff ... Regards Michael From stippi at mail.berlios.de Wed Jul 2 13:20:51 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 2 Jul 2008 13:20:51 +0200 Subject: [Haiku-commits] r26219 - haiku/trunk/src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807021120.m62BKpaj013276@sheep.berlios.de> Author: stippi Date: 2008-07-02 13:20:47 +0200 (Wed, 02 Jul 2008) New Revision: 26219 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26219&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Key.h Log: Applied patch by Urias McCullough: Fixed Big Endian build of ReiserFS. Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Key.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Key.h 2008-07-02 10:38:27 UTC (rev 26218) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Key.h 2008-07-02 11:20:47 UTC (rev 26219) @@ -130,7 +130,7 @@ #else offset_v2 temp; *(uint64*)&temp = h2le(*(uint64*)&u.k_offset_v2); - return tmp.k_offset; + return temp.k_offset; #endif } uint32 _GetType() const @@ -140,7 +140,7 @@ #else offset_v2 temp; *(uint64*)&temp = h2le(*(uint64*)&u.k_offset_v2); - return tmp.k_type; + return temp.k_type; #endif } void _SetOffsetAndType(uint64 offset, uint32 type) From mmlr at mlotz.ch Wed Jul 2 13:26:25 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Wed, 02 Jul 2008 13:26:25 +0200 Subject: [Haiku-commits] r26210 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <600127430-BeMail@zon> Message-ID: <1458104714-BeMail@primary> > mmlr at mail.berlios.de wrote: > > Reduce the grow size to 4MB though as the allocations should now be > > spread > > across heap classes which each grow on their own. > > Wouldn't it make sense to have grow size depending on the class? (ie. > large allocation heaps would grow faster than small ones) That depends. From what I have seen so far large heaps tend to be used heavily only during boot. Later on the small heap is the most frequently used and growing one. So if at all you would want the small heap to grow in bigger chunks to avoid creating a long list of small heaps. If you grow the large allocation heap with a bigger size you would in many cases just allocate a big block that is rarely used. Making the grow size dynamic so it can get bigger the more a heap class is used would be an idea, but this works against the desire to keep the heaps small to make the chance of a heap becoming empty bigger. Not that freeing an empty heap was implemented... The currently common grow size plus the avarge use pattern seem to be pretty balanced, so I don't really think changing grow sizes would bring a real benefit. Keep in mind that we grow by 4MB right now and allocations cannot get bigger than 1MB at a time (otherwise an area is used) and are usually in the < 10KB range, so you don't fill those heaps that quickly. Regards Michael From mmlr at mail.berlios.de Wed Jul 2 13:42:36 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 13:42:36 +0200 Subject: [Haiku-commits] r26220 - haiku/trunk/src/system/kernel Message-ID: <200807021142.m62BgaZ6012463@sheep.berlios.de> Author: mmlr Date: 2008-07-02 13:42:35 +0200 (Wed, 02 Jul 2008) New Revision: 26220 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26220&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Added grow request tracking again. In case an allocation fails due to lack of contiguous pages, it will request growing even if there are still more than 10% free pages available. Previously that case was not handled anymore and the allocation would have just failed. Note that this is a pretty rare case, as there are no "large" allocations happening in either the small or large heap classes, but only in the huge one for allocations between 128KB and 1MB. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 11:20:47 UTC (rev 26219) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 11:42:35 UTC (rev 26220) @@ -137,6 +137,7 @@ }; static heap_allocator *sHeapList[HEAP_CLASS_COUNT]; +static heap_allocator *sLastGrowRequest[HEAP_CLASS_COUNT]; static heap_allocator *sGrowHeapList = NULL; static thread_id sHeapGrowThread = -1; static sem_id sHeapGrowSem = -1; @@ -1332,8 +1333,11 @@ while (heap->next) heap = heap->next; - if (heap_should_grow(heap)) { - // grow this heap if it makes sense to + if (sLastGrowRequest[i] == heap || heap_should_grow(heap)) { + // grow this heap if it is nearly full or if a grow was + // explicitly requested for this heap (happens when a large + // allocation cannot be fulfilled due to lack of contiguous + // pages) heap_allocator *newHeap = heap_create_new_heap("additional heap", HEAP_GROW_SIZE, i); if (newHeap != NULL) { @@ -1362,6 +1366,7 @@ for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { size_t partSize = size * sHeapClasses[i].initial_percentage / 100; sHeapList[i] = heap_attach(base, partSize, i); + sLastGrowRequest[i] = sHeapList[i]; base += partSize; } @@ -1490,6 +1495,7 @@ void *result = heap_memalign(heap, alignment, size, &shouldGrow); if (heap->next == NULL && (shouldGrow || result == NULL)) { // the last heap will or has run out of memory, notify the grower + sLastGrowRequest[heap_class_for(size)] = heap; if (result == NULL) { // urgent request, do the request and wait switch_sem(sHeapGrowSem, sHeapGrownNotify); From axeld at pinc-software.de Wed Jul 2 14:45:07 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 02 Jul 2008 14:45:07 +0200 CEST Subject: [Haiku-commits] r26210 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <1458104714-BeMail@primary> Message-ID: <12876681779-BeMail@zon> "Michael Lotz" wrote: > > mmlr at mail.berlios.de wrote: > > > Reduce the grow size to 4MB though as the allocations should now > > > be > > > spread > > > across heap classes which each grow on their own. > > Wouldn't it make sense to have grow size depending on the class? > > (ie. > > large allocation heaps would grow faster than small ones) > That depends. From what I have seen so far large heaps tend to be > used > heavily only during boot. Later on the small heap is the most > frequently used and growing one. So if at all you would want the > small > heap to grow in bigger chunks to avoid creating a long list of small > heaps. If you grow the large allocation heap with a bigger size you > would in many cases just allocate a big block that is rarely used. Okay, I didn't really think of that. How common are allocations over 128KB anyway? Maybe we want to adapt the initial heap size to values that are actually used, so that as little memory as possible is wasted. Another strategy would be to lazily allocate the pages of the heap, so that they are only actually mapped in when they are used for the first time. Dunno if that pays off, though - it depends again on the actual heap usage, I guess. > Making the grow size dynamic so it can get bigger the more a heap > class > is used would be an idea, but this works against the desire to keep > the > heaps small to make the chance of a heap becoming empty bigger. Not > that freeing an empty heap was implemented... The currently common > grow > size plus the avarge use pattern seem to be pretty balanced, so I > don't > really think changing grow sizes would bring a real benefit. Keep in > mind that we grow by 4MB right now and allocations cannot get bigger > than 1MB at a time (otherwise an area is used) and are usually in the > < > 10KB range, so you don't fill those heaps that quickly. Okay. Bye, Axel. From mmlr at mail.berlios.de Wed Jul 2 15:00:23 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Wed, 2 Jul 2008 15:00:23 +0200 Subject: [Haiku-commits] r26221 - haiku/trunk/src/system/kernel Message-ID: <200807021300.m62D0N0L021312@sheep.berlios.de> Author: mmlr Date: 2008-07-02 15:00:13 +0200 (Wed, 02 Jul 2008) New Revision: 26221 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26221&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: * Fix the broken size/alignment computations for area allocations by replacing them with the ROUNDUP macro that was specifically made for this task so that too tired developers do not mess up the calculations... * Don't use area allocation during kernel startup (not that it really happened). * Minor simplification of similar calculations in heap_attach(). Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 11:42:35 UTC (rev 26220) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 13:00:13 UTC (rev 26221) @@ -753,8 +753,8 @@ size -= pageTableSize; // the rest is now actually usable memory (rounded to the next page) - heap->base = (addr_t)(base + B_PAGE_SIZE - 1) / B_PAGE_SIZE * B_PAGE_SIZE; - heap->size = (size_t)(size / B_PAGE_SIZE) * B_PAGE_SIZE; + heap->base = ROUNDUP(base, B_PAGE_SIZE); + heap->size = (size / B_PAGE_SIZE) * B_PAGE_SIZE; // now we know the real page count pageCount = heap->size / heap->page_size; @@ -1453,15 +1453,15 @@ return NULL; } - if (size > HEAP_AREA_USE_THRESHOLD) { + if (!kernel_startup && size > HEAP_AREA_USE_THRESHOLD) { // don't even attempt such a huge allocation - use areas instead dprintf("heap: using area for huge allocation of %lu bytes!\n", size); size_t areaSize = size + sizeof(area_allocation_info); if (alignment != 0) - areaSize = (areaSize + alignment - 1) / alignment; + areaSize = ROUNDUP(areaSize, alignment); void *address = NULL; - areaSize = (areaSize + B_PAGE_SIZE - 1) / B_PAGE_SIZE; + areaSize = ROUNDUP(areaSize, B_PAGE_SIZE); area_id allocationArea = create_area("memalign area", &address, B_ANY_KERNEL_BLOCK_ADDRESS, areaSize, B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -1480,7 +1480,7 @@ address = (void *)((addr_t)address + sizeof(area_allocation_info)); if (alignment != 0) - address = (void *)(((addr_t)address + alignment - 1) / alignment); + address = (void *)ROUNDUP((addr_t)address, alignment); dprintf("heap: allocated area %ld for huge allocation returning %p\n", allocationArea, address); From mmlr at mlotz.ch Wed Jul 2 15:10:41 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Wed, 02 Jul 2008 15:10:41 +0200 Subject: [Haiku-commits] r26210 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <12876681779-BeMail@zon> Message-ID: <2514597842-BeMail@primary> > "Michael Lotz" wrote: > > > mmlr at mail.berlios.de wrote: > > > > Reduce the grow size to 4MB though as the allocations should > > > > now > > > > be > > > > spread > > > > across heap classes which each grow on their own. > > > Wouldn't it make sense to have grow size depending on the class? > > > (ie. > > > large allocation heaps would grow faster than small ones) > > That depends. From what I have seen so far large heaps tend to be > > used > > heavily only during boot. Later on the small heap is the most > > frequently used and growing one. So if at all you would want the > > small > > heap to grow in bigger chunks to avoid creating a long list of > > small > > heaps. If you grow the large allocation heap with a bigger size you > > would in many cases just allocate a big block that is rarely used. > > Okay, I didn't really think of that. How common are allocations over > 128KB anyway? Maybe we want to adapt the initial heap size to values > that are actually used, so that as little memory as possible is > wasted. > Another strategy would be to lazily allocate the pages of the heap, > so > that they are only actually mapped in when they are used for the > first > time. Dunno if that pays off, though - it depends again on the actual > heap usage, I guess. Allocations of over 128KB should be rare. The only case I saw it happening was in the slab or more correctly in the OpenHashTable it uses that grows it's list considerably when doing large amounts of file traffic like checking out the Haiku sources. About adjusting the initial heap size: I already thought of that and did so :-). In my tests the 16MB of initial heap were pretty much ideal for a complete boot process. Note that not each heap class get's it's own full block of initial heap. The initial heap (16MB) is sliced into pieces for the different heap classes. A percentage determines the amount each class gets. After some experimenting I assigned 50% = 8MB to the small heap, 30% = 4.8MB to the large heap and 20% = 3.2MB to the huge heap class. This seems to work out pretty well. Furhter use/ testing will show if we need to fine tune those numbers some more. Regards Michael From axeld at pinc-software.de Wed Jul 2 16:28:08 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 02 Jul 2008 16:28:08 +0200 CEST Subject: [Haiku-commits] r26221 - haiku/trunk/src/system/kernel In-Reply-To: <200807021300.m62D0N0L021312@sheep.berlios.de> Message-ID: <19057618302-BeMail@zon> mmlr at mail.berlios.de wrote: > + heap->size = (size / B_PAGE_SIZE) * B_PAGE_SIZE; What about: heap->size = size & ~(B_PAGE_SIZE - 1); instead? Bye, Axel. From axeld at mail.berlios.de Wed Jul 2 17:04:11 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 2 Jul 2008 17:04:11 +0200 Subject: [Haiku-commits] r26222 - haiku/trunk/src/system/boot/platform/bios_ia32 Message-ID: <200807021504.m62F4B30002179@sheep.berlios.de> Author: axeld Date: 2008-07-02 17:04:10 +0200 (Wed, 02 Jul 2008) New Revision: 26222 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26222&view=rev Modified: haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp Log: Patch by David Powell: * Turn off text cursor when switching to text mode. * Minor cleanup. Modified: haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp =================================================================== --- haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2008-07-02 13:00:13 UTC (rev 26221) +++ haiku/trunk/src/system/boot/platform/bios_ia32/video.cpp 2008-07-02 15:04:10 UTC (rev 26222) @@ -587,7 +587,7 @@ { // sets 640x480 16 colors graphics mode bios_regs regs; - regs.eax = 0x12; + regs.eax = 0x0012; call_bios(0x10, ®s); } @@ -597,8 +597,13 @@ { // sets 80x25 text console bios_regs regs; - regs.eax = 3; + regs.eax = 0x0003; call_bios(0x10, ®s); + + // turns off text cursor + regs.eax = 0x0100; + regs.ecx = 0x2000; + call_bios(0x10, ®s); } From stippi at mail.berlios.de Wed Jul 2 17:37:39 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 2 Jul 2008 17:37:39 +0200 Subject: [Haiku-commits] r26223 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200807021537.m62Fbdxu005178@sheep.berlios.de> Author: stippi Date: 2008-07-02 17:37:35 +0200 (Wed, 02 Jul 2008) New Revision: 26223 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26223&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp Log: * Fixed a race condition where the interrupt for a command happened before the thread issuing the command called acquire_sem_etc() on the semaphore that the interrupt handler would otherwise release. The semaphore is now released unconditionally, but to prevent the race condition that the B_RELEASE_IF_WAITING_ONLY was trying to avoid, it is released with the spinlock held. * The error interrupt handler did not reset the fCommandsActive flag, but it seemed to us like it should do that. * WaitForTransfer now also acquires the spinlock to reset fCommandsActive, which may be unnecessary but does not harm either. * Cleanup of some long lines, sorry for mixing that with the actual fix. Fixes bug #2359 (long pauses when accessing the disk). Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h 2008-07-02 15:04:10 UTC (rev 26222) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h 2008-07-02 15:37:35 UTC (rev 26223) @@ -196,7 +196,8 @@ uint32 prdtl_flags_cfl; } _PACKED; uint32 prdbc; // PRD Byte Count - uint32 ctba; // command table desciptor base address (alignment 128 byte) + uint32 ctba; // command table desciptor base address + // (alignment 128 byte) uint32 ctbau; // command table desciptor base address upper uint8 res1[0x10]; } _PACKED command_list_entry; @@ -251,7 +252,8 @@ uint32 flags; } device_info; -status_t get_device_info(uint16 vendorID, uint16 deviceID, const char **name, uint32 *flags); +status_t get_device_info(uint16 vendorID, uint16 deviceID, const char **name, + uint32 *flags); extern scsi_sim_interface gAHCISimInterface; Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2008-07-02 15:04:10 UTC (rev 26222) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp 2008-07-02 15:37:35 UTC (rev 26223) @@ -59,12 +59,15 @@ { TRACE("AHCIPort::Init1 port %d\n", fIndex); - size_t size = sizeof(command_list_entry) * COMMAND_LIST_ENTRY_COUNT + sizeof(fis) + sizeof(command_table) + sizeof(prd) * PRD_TABLE_ENTRY_COUNT; + size_t size = sizeof(command_list_entry) * COMMAND_LIST_ENTRY_COUNT + + sizeof(fis) + sizeof(command_table) + + sizeof(prd) * PRD_TABLE_ENTRY_COUNT; char *virtAddr; char *physAddr; - fArea = alloc_mem((void **)&virtAddr, (void **)&physAddr, size, 0, "some AHCI port"); + fArea = alloc_mem((void **)&virtAddr, (void **)&physAddr, size, 0, + "some AHCI port"); if (fArea < B_OK) { TRACE("failed allocating memory for port %d\n", fIndex); return fArea; @@ -167,7 +170,8 @@ // wait for DMA completition if (wait_until_clear(&fRegs->cmd, PORT_CMD_CR, 500000) < B_OK) { - TRACE("AHCIPort::Uninit port %d error DMA engine still running\n", fIndex); + TRACE("AHCIPort::Uninit port %d error DMA engine still running\n", + fIndex); } // disable interrupts @@ -209,7 +213,8 @@ if (fRegs->ssts & 1) { if (wait_until_set(&fRegs->ssts, 0x3, 500000) < B_OK) { - TRACE("AHCIPort::ResetDevice port %d device present but no phy communication\n", fIndex); + TRACE("AHCIPort::ResetDevice port %d device present but no phy " + "communication\n", fIndex); } } @@ -230,7 +235,8 @@ FlushPostedWrites(); if (wait_until_clear(&fRegs->cmd, PORT_CMD_CR, 500000) < B_OK) { - TRACE("AHCIPort::ResetPort port %d error DMA engine doesn't stop\n", fIndex); + TRACE("AHCIPort::ResetPort port %d error DMA engine doesn't stop\n", + fIndex); } bool deviceBusy = fRegs->tfd & (ATA_BSY | ATA_DRQ); @@ -263,7 +269,8 @@ snooze(200000); if ((fRegs->tfd & 0xff) == 0xff) { - TRACE("AHCIPort::PostReset port %d: invalid task file status 0xff\n", fIndex); + TRACE("AHCIPort::PostReset port %d: invalid task file status 0xff\n", + fIndex); return B_ERROR; } @@ -278,7 +285,8 @@ FlushPostedWrites(); TRACE("device signature 0x%08lx (%s)\n", fRegs->sig, - (fRegs->sig == 0xeb140101) ? "ATAPI" : (fRegs->sig == 0x00000101) ? "ATA" : "unknown"); + (fRegs->sig == 0xeb140101) ? "ATAPI" : (fRegs->sig == 0x00000101) ? + "ATA" : "unknown"); return B_OK; } @@ -288,11 +296,16 @@ AHCIPort::DumpD2HFis() { TRACE("D2H FIS:\n"); - TRACE(" DW0 %02x %02x %02x %02x\n", fFIS->rfis[3], fFIS->rfis[2], fFIS->rfis[1], fFIS->rfis[0]); - TRACE(" DW1 %02x %02x %02x %02x\n", fFIS->rfis[7], fFIS->rfis[6], fFIS->rfis[5], fFIS->rfis[4]); - TRACE(" DW2 %02x %02x %02x %02x\n", fFIS->rfis[11], fFIS->rfis[10], fFIS->rfis[9], fFIS->rfis[8]); - TRACE(" DW3 %02x %02x %02x %02x\n", fFIS->rfis[15], fFIS->rfis[14], fFIS->rfis[13], fFIS->rfis[12]); - TRACE(" DW4 %02x %02x %02x %02x\n", fFIS->rfis[19], fFIS->rfis[18], fFIS->rfis[17], fFIS->rfis[16]); + TRACE(" DW0 %02x %02x %02x %02x\n", fFIS->rfis[3], fFIS->rfis[2], + fFIS->rfis[1], fFIS->rfis[0]); + TRACE(" DW1 %02x %02x %02x %02x\n", fFIS->rfis[7], fFIS->rfis[6], + fFIS->rfis[5], fFIS->rfis[4]); + TRACE(" DW2 %02x %02x %02x %02x\n", fFIS->rfis[11], fFIS->rfis[10], + fFIS->rfis[9], fFIS->rfis[8]); + TRACE(" DW3 %02x %02x %02x %02x\n", fFIS->rfis[15], fFIS->rfis[14], + fFIS->rfis[13], fFIS->rfis[12]); + TRACE(" DW4 %02x %02x %02x %02x\n", fFIS->rfis[19], fFIS->rfis[18], + fFIS->rfis[17], fFIS->rfis[16]); } @@ -309,19 +322,16 @@ uint32 ci = fRegs->ci; - RWTRACE("AHCIPort::Interrupt port %d, fCommandsActive 0x%08lx, is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); + RWTRACE("[%lld] %ld AHCIPort::Interrupt port %d, fCommandsActive 0x%08lx, " + "is 0x%08lx, ci 0x%08lx\n", system_time(), find_thread(NULL), + fIndex, fCommandsActive, is, ci); - int release = 0; - acquire_spinlock(&fSpinlock); if ((fCommandsActive & 1) && !(ci & 1)) { - release = 1; fCommandsActive &= ~1; + release_sem_etc(fResponseSem, 1, B_DO_NOT_RESCHEDULE); } release_spinlock(&fSpinlock); - - if (release) - release_sem_etc(fResponseSem, 1, B_RELEASE_IF_WAITING_ONLY | B_DO_NOT_RESCHEDULE); } @@ -330,7 +340,8 @@ { uint32 ci = fRegs->ci; - TRACE("AHCIPort::InterruptErrorHandler port %d, fCommandsActive 0x%08lx, is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); + TRACE("AHCIPort::InterruptErrorHandler port %d, fCommandsActive 0x%08lx, " + "is 0x%08lx, ci 0x%08lx\n", fIndex, fCommandsActive, is, ci); TRACE("ssts 0x%08lx\n", fRegs->ssts); TRACE("sctl 0x%08lx\n", fRegs->sctl); @@ -385,13 +396,20 @@ fResetPort = true; } - if (fError) - release_sem_etc(fResponseSem, 1, B_RELEASE_IF_WAITING_ONLY | B_DO_NOT_RESCHEDULE); + if (fError) { + acquire_spinlock(&fSpinlock); + if ((fCommandsActive & 1)) { + fCommandsActive &= ~1; + release_sem_etc(fResponseSem, 1, B_DO_NOT_RESCHEDULE); + } + release_spinlock(&fSpinlock); + } } status_t -AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const void *data, size_t dataSize) +AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, + const void *data, size_t dataSize) { int peMax = prdMax + 1; physical_entry pe[peMax]; @@ -407,7 +425,8 @@ status_t -AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, const physical_entry *sgTable, int sgCount, size_t dataSize) +AHCIPort::FillPrdTable(volatile prd *prdTable, int *prdCount, int prdMax, + const physical_entry *sgTable, int sgCount, size_t dataSize) { *prdCount = 0; while (sgCount > 0 && dataSize > 0) { @@ -426,7 +445,9 @@ TRACE("AHCIPort::FillPrdTable: prd table exhausted\n"); return B_ERROR; } - FLOW("FillPrdTable: prd-entry %u, addr %p, size %lu\n", *prdCount, address, bytes); + FLOW("FillPrdTable: prd-entry %u, addr %p, size %lu\n", + *prdCount, address, bytes); + prdTable->dba = LO32(address); prdTable->dbau = HI32(address); prdTable->res = 0; @@ -444,7 +465,8 @@ return B_ERROR; } if (dataSize > 0) { - TRACE("AHCIPort::FillPrdTable: sg table %ld bytes too small\n", dataSize); + TRACE("AHCIPort::FillPrdTable: sg table %ld bytes too small\n", + dataSize); return B_ERROR; } return B_OK; @@ -461,9 +483,15 @@ status_t AHCIPort::WaitForTransfer(int *tfd, bigtime_t timeout) { - status_t result = B_OK; - if (acquire_sem_etc(fResponseSem, 1, B_RELATIVE_TIMEOUT, timeout) < B_OK) { + status_t result = acquire_sem_etc(fResponseSem, 1, B_RELATIVE_TIMEOUT, + timeout); + if (result < B_OK) { + cpu_status cpu = disable_interrupts(); + acquire_spinlock(&fSpinlock); fCommandsActive &= ~1; + release_spinlock(&fSpinlock); + restore_interrupts(cpu); + result = B_TIMED_OUT; } else if (fError) { *tfd = fRegs->tfd; @@ -526,7 +554,8 @@ /* uint8 *data = (uint8*) &ataData; for (int i = 0; i < 512; i += 8) { - TRACE(" %02x %02x %02x %02x %02x %02x %02x %02x\n", data[i], data[i+1], data[i+2], data[i+3], data[i+4], data[i+5], data[i+6], data[i+7]); + TRACE(" %02x %02x %02x %02x %02x %02x %02x %02x\n", data[i], data[i+1], + data[i+2], data[i+3], data[i+4], data[i+5], data[i+6], data[i+7]); } */ @@ -547,9 +576,12 @@ scsiData.write_bus16 = true; scsiData.write_bus32 = false; scsiData.relative_address = false; - memcpy(scsiData.vendor_ident, ataData.model_number, sizeof(scsiData.vendor_ident)); - memcpy(scsiData.product_ident, ataData.model_number + 8, sizeof(scsiData.product_ident)); - memcpy(scsiData.product_rev, ataData.serial_number, sizeof(scsiData.product_rev)); + memcpy(scsiData.vendor_ident, ataData.model_number, + sizeof(scsiData.vendor_ident)); + memcpy(scsiData.product_ident, ataData.model_number + 8, + sizeof(scsiData.product_ident)); + memcpy(scsiData.product_rev, ataData.serial_number, + sizeof(scsiData.product_rev)); if (!fIsATAPI) { bool lba = (ataData.words[49] & (1 << 9)) != 0; @@ -559,8 +591,10 @@ fUse48BitCommands = lba && lba48; fSectorSize = 512; fSectorCount = !(lba || sectors) ? 0 : lba48 ? sectors48 : sectors; - TRACE("lba %d, lba48 %d, fUse48BitCommands %d, sectors %lu, sectors48 %llu, size %llu\n", - lba, lba48, fUse48BitCommands, sectors, sectors48, fSectorCount * fSectorSize); + TRACE("lba %d, lba48 %d, fUse48BitCommands %d, sectors %lu, " + "sectors48 %llu, size %llu\n", + lba, lba48, fUse48BitCommands, sectors, sectors48, + fSectorCount * fSectorSize); } #if 0 @@ -586,7 +620,8 @@ TRACE("serial number: %s\n", serialNumber); TRACE("firmware rev.: %s\n", firmwareRev); - if (sg_memcpy(request->sg_list, request->sg_count, &scsiData, sizeof(scsiData)) < B_OK) { + if (sg_memcpy(request->sg_list, request->sg_count, &scsiData, + sizeof(scsiData)) < B_OK) { request->subsys_status = SCSI_DATA_RUN_ERR; } else { request->subsys_status = SCSI_REQ_CMP; @@ -641,7 +676,8 @@ void AHCIPort::ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, bool isWrite) { - RWTRACE("ScsiReadWrite: position %llu, size %lu, isWrite %d\n", lba * 512, sectorCount * 512, isWrite); + RWTRACE("[%lld] %ld ScsiReadWrite: position %llu, size %lu, isWrite %d\n", + system_time(), find_thread(NULL), lba * 512, sectorCount * 512, isWrite); #if 0 if (isWrite) { @@ -684,9 +720,12 @@ int prdEntrys; if (request->ccb() && request->ccb()->data_length) - FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT, request->ccb()->sg_list, request->ccb()->sg_count, request->ccb()->data_length); + FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT, + request->ccb()->sg_list, request->ccb()->sg_count, + request->ccb()->data_length); else if (request->data() && request->size()) - FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT, request->data(), request->size()); + FillPrdTable(fPRDTable, &prdEntrys, PRD_TABLE_ENTRY_COUNT, + request->data(), request->size()); else prdEntrys = 0; @@ -699,7 +738,8 @@ if (request->is_atapi()) { // ATAPI PACKET is a 12 or 16 byte SCSI command memset((char *)fCommandTable->acmd, 0, 32); - memcpy((char *)fCommandTable->acmd, request->ccb()->cdb, request->ccb()->cdb_length); + memcpy((char *)fCommandTable->acmd, request->ccb()->cdb, + request->ccb()->cdb_length); fCommandList->a = 1; } From korli at users.berlios.de Wed Jul 2 19:06:21 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Wed, 2 Jul 2008 19:06:21 +0200 Subject: [Haiku-commits] r26204 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <4706324484-BeMail@zon> References: <4706324484-BeMail@zon> Message-ID: 2008/7/2 Axel D?rfler : > "J?r?me Duval" wrote: >> Feel free to fix in a better way. > > Thanks and done :-) > Looks like a compiler bug to me, though. > Indeed. It would be a hint to update the gcc4, who knows ? :) Bye, J?r?me From anevilyak at gmail.com Wed Jul 2 19:08:03 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Wed, 2 Jul 2008 12:08:03 -0500 Subject: [Haiku-commits] r26204 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: References: <4706324484-BeMail@zon> Message-ID: On Wed, Jul 2, 2008 at 12:06 PM, J?r?me Duval wrote: > > Indeed. It would be a hint to update the gcc4, who knows ? :) I believe Ingo already intended to do that when he gets around to porting the gcc4 Development package to Haiku. Regards, Rene From oruizdorantes at mail.berlios.de Wed Jul 2 20:28:02 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 20:28:02 +0200 Subject: [Haiku-commits] r26224 - haiku/trunk/src/kits/bluetooth Message-ID: <200807021828.m62IS2Da008536@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 20:28:00 +0200 (Wed, 02 Jul 2008) New Revision: 26224 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26224&view=rev Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp Log: Implement RemoteDevice contructor by String Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-02 15:37:35 UTC (rev 26223) +++ haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-02 18:28:00 UTC (rev 26224) @@ -160,8 +160,7 @@ RemoteDevice::RemoteDevice(BString address) { - /* TODO */ - + fBdaddr = bdaddrUtils::FromString((const char *)address.String()); } @@ -180,11 +179,11 @@ } -} - - DeviceClass RemoteDevice::GetDeviceClass() { return fDeviceClass; } + + +} From korli at mail.berlios.de Wed Jul 2 21:13:14 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 Jul 2008 21:13:14 +0200 Subject: [Haiku-commits] r26225 - haiku/trunk/src/add-ons/kernel/drivers/audio/echo/generic Message-ID: <200807021913.m62JDEmk013328@sheep.berlios.de> Author: korli Date: 2008-07-02 21:13:13 +0200 (Wed, 02 Jul 2008) New Revision: 26225 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26225&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h Log: PAGE_SIZE is defined in Haiku limits.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h 2008-07-02 18:28:00 UTC (rev 26224) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h 2008-07-02 19:13:13 UTC (rev 26225) @@ -98,7 +98,9 @@ #define CONST const typedef void ** PPVOID; +#ifndef PAGE_SIZE #define PAGE_SIZE B_PAGE_SIZE +#endif #define WideToSInt64(x) (*((int64*)(&x))) #define WideToUInt64(x) (*((uint64*)(&x))) From korli at mail.berlios.de Wed Jul 2 21:30:50 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 2 Jul 2008 21:30:50 +0200 Subject: [Haiku-commits] r26226 - in haiku/trunk: headers/posix src/add-ons/kernel/bus_managers/acpi/include/platform src/system/kernel/lib src/system/libroot/posix/string Message-ID: <200807021930.m62JUomp015735@sheep.berlios.de> Author: korli Date: 2008-07-02 21:30:46 +0200 (Wed, 02 Jul 2008) New Revision: 26226 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26226&view=rev Added: haiku/trunk/src/system/libroot/posix/string/strlwr.c haiku/trunk/src/system/libroot/posix/string/strupr.c Modified: haiku/trunk/headers/posix/string.h haiku/trunk/src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h haiku/trunk/src/system/kernel/lib/Jamfile haiku/trunk/src/system/libroot/posix/string/Jamfile Log: Applied patch from Mika Lindqvist: This patch implements both strlwr() and strupr() functions in libroot and includes strupr() in kernel build. Modified: haiku/trunk/headers/posix/string.h =================================================================== --- haiku/trunk/headers/posix/string.h 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/headers/posix/string.h 2008-07-02 19:30:46 UTC (rev 26226) @@ -66,8 +66,8 @@ extern size_t strnlen(const char *string, size_t count); -/* extern char *strlwr(char *string); */ -/* extern char *strupr(char *string); */ +extern char *strlwr(char *string); +extern char *strupr(char *string); /* extern char *strsep(char **stringPointer, const char *delimiter); */ Modified: haiku/trunk/src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h 2008-07-02 19:30:46 UTC (rev 26226) @@ -138,6 +138,7 @@ #include #include #include +#include #define asm __asm @@ -206,18 +207,6 @@ } while (0) -/* Kernel doesn't have strupr, should be fixed. */ -static __inline char * -strupr(char *str) -{ - char *c = str; - while(*c) { - *c = toupper(*c); - c++; - } - return(str); -} - #else /* _KERNEL_MODE */ #include Modified: haiku/trunk/src/system/kernel/lib/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/lib/Jamfile 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/src/system/kernel/lib/Jamfile 2008-07-02 19:30:46 UTC (rev 26226) @@ -109,6 +109,7 @@ strspn.c strstr.c strtok.c + strupr.c : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/libroot/posix/string/Jamfile =================================================================== --- haiku/trunk/src/system/libroot/posix/string/Jamfile 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/src/system/libroot/posix/string/Jamfile 2008-07-02 19:30:46 UTC (rev 26226) @@ -25,6 +25,7 @@ strerror.c strlcat.c strlcpy.c + strlwr.c strncat.c strncmp.c strncpy.c @@ -34,6 +35,7 @@ strspn.c strstr.c strtok.c + strupr.c strxfrm.c ; Added: haiku/trunk/src/system/libroot/posix/string/strlwr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strlwr.c 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/src/system/libroot/posix/string/strlwr.c 2008-07-02 19:30:46 UTC (rev 26226) @@ -0,0 +1,19 @@ +/* +** Copyright 2008, Mika Lindqvist. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#include +#include + +char * +strlwr(char *str) +{ + char *c = str; + while(*c) { + *c = tolower(*c); + c++; + } + return(str); +} + Added: haiku/trunk/src/system/libroot/posix/string/strupr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strupr.c 2008-07-02 19:13:13 UTC (rev 26225) +++ haiku/trunk/src/system/libroot/posix/string/strupr.c 2008-07-02 19:30:46 UTC (rev 26226) @@ -0,0 +1,19 @@ +/* +** Copyright 2008, Mika Lindqvist. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#include +#include + +char * +strupr(char *str) +{ + char *c = str; + while(*c) { + *c = toupper(*c); + c++; + } + return(str); +} + From oruizdorantes at mail.berlios.de Wed Jul 2 21:41:51 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 21:41:51 +0200 Subject: [Haiku-commits] r26227 - in haiku/trunk: headers/os/bluetooth src/kits/bluetooth Message-ID: <200807021941.m62JfpmF016546@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 21:41:45 +0200 (Wed, 02 Jul 2008) New Revision: 26227 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26227&view=rev Modified: haiku/trunk/headers/os/bluetooth/LocalDevice.h haiku/trunk/headers/os/bluetooth/RemoteDevice.h haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp haiku/trunk/src/kits/bluetooth/LocalDevice.cpp haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp Log: Cleapups, Fix memory leaks, Patch by Mika Lindqvist. Could we give give him Commit access? I am getting daily patches from him with fixes and new features. Modified: haiku/trunk/headers/os/bluetooth/LocalDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/LocalDevice.h 2008-07-02 19:30:46 UTC (rev 26226) +++ haiku/trunk/headers/os/bluetooth/LocalDevice.h 2008-07-02 19:41:45 UTC (rev 26227) @@ -25,7 +25,7 @@ class DiscoveryAgent; class LocalDevice : public BluetoothDevice { - + public: /* Possible throwing */ static LocalDevice* GetLocalDevice(); @@ -49,17 +49,18 @@ ServiceRecord getRecord(Connection notifier); void updateRecord(ServiceRecord srvRecord); */ - + private: LocalDevice(hci_id hid); + virtual ~LocalDevice(); + hci_id GetID(void) {return hid;} static LocalDevice* RequestLocalDeviceID(BMessage* request); - - static BMessenger* sfMessenger; - BMessenger* fMessenger; + BMessenger* fMessenger; + hci_id hid; - + friend class DiscoveryAgent; friend class RemoteDevice; friend class PincodeWindow; Modified: haiku/trunk/headers/os/bluetooth/RemoteDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/RemoteDevice.h 2008-07-02 19:30:46 UTC (rev 26226) +++ haiku/trunk/headers/os/bluetooth/RemoteDevice.h 2008-07-02 19:41:45 UTC (rev 26227) @@ -28,6 +28,8 @@ static const int WAIT = B_BT_WAIT; static const int SUCCEEDED = B_BT_SUCCEEDED; + virtual ~RemoteDevice(); + bool IsTrustedDevice(); BString GetFriendlyName(bool alwaysAsk); /* Throwing */ BString GetFriendlyName(void); /* Throwing */ @@ -52,6 +54,8 @@ RemoteDevice(BString address); RemoteDevice(bdaddr_t address); + + /* Instances of this class only would be instantiated by Discovery[Listener|Agent] */ friend class DiscoveryListener; void SetLocalDeviceOwner(LocalDevice* ld); @@ -59,6 +63,7 @@ private: LocalDevice* fDiscovererLocalDevice; + BMessenger* fMessenger; uint8 fPageRepetitionMode; uint8 fScanPeriodMode; Modified: haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-02 19:30:46 UTC (rev 26226) +++ haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-02 19:41:45 UTC (rev 26227) @@ -27,7 +27,7 @@ { /* No inquiry process initiated */ if (fLastUsedListener == NULL) - return NULL; // xxx: Fix me + return RemoteDevicesList(); return fLastUsedListener->GetRemoteDevicesList(); } Modified: haiku/trunk/src/kits/bluetooth/LocalDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2008-07-02 19:30:46 UTC (rev 26226) +++ haiku/trunk/src/kits/bluetooth/LocalDevice.cpp 2008-07-02 19:41:45 UTC (rev 26227) @@ -22,29 +22,31 @@ #include "KitSupport.h" -/* TODO: remove me */ -#include namespace Bluetooth { -BMessenger* LocalDevice::sfMessenger = NULL; - LocalDevice* LocalDevice::RequestLocalDeviceID(BMessage* request) -{ +{ BMessage reply; hci_id hid; - - if (sfMessenger->SendMessage(request, &reply) == B_OK && - reply.FindInt32("hci_id", &hid) == B_OK ){ - - if (hid >= 0) { - return new LocalDevice(hid); - } + LocalDevice* lDevice = NULL; + + BMessenger* messenger = _RetrieveBluetoothMessenger(); + + if (messenger == NULL) + return NULL; + + if (messenger->SendMessage(request, &reply) == B_OK && + reply.FindInt32("hci_id", &hid) == B_OK ) { + + if (hid >= 0) + lDevice = new LocalDevice(hid); } - - return NULL; + + delete messenger; + return lDevice; } @@ -55,57 +57,52 @@ LocalDevice* LocalDevice::GetLocalDevice() -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - +{ + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + return RequestLocalDeviceID(&request); } LocalDevice* LocalDevice::GetLocalDevice(hci_id hid) -{ - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); +{ + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); request.AddInt32("hci_id", hid); - + return RequestLocalDeviceID(&request); - } LocalDevice* LocalDevice::GetLocalDevice(bdaddr_t bdaddr) { - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; - - BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); - request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t)); - - - return RequestLocalDeviceID(&request); + + BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE); + request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t)); + + return RequestLocalDeviceID(&request); } uint32 LocalDevice::GetLocalDeviceCount() { - if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL) - return 0; + BMessenger* messenger = _RetrieveBluetoothMessenger(); + uint32 count = 0; - BMessage request(BT_MSG_COUNT_LOCAL_DEVICES); - BMessage reply; + if (messenger != NULL) { - if (sfMessenger->SendMessage(&request, &reply) == B_OK) - return reply.FindInt32("count"); - else - return 0; + BMessage request(BT_MSG_COUNT_LOCAL_DEVICES); + BMessage reply; + + if (messenger->SendMessage(&request, &reply) == B_OK) + count = reply.FindInt32("count"); + + delete messenger; + } + + return count; } @@ -146,7 +143,7 @@ status_t LocalDevice::SetDiscoverable(int mode) { - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) + if (fMessenger == NULL) return B_ERROR; BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); @@ -162,7 +159,7 @@ void* command = buildWriteScan(mode, &size); if (command == NULL) { - return B_NO_MEMORY; + return B_NO_MEMORY; } request.AddData("raw command", B_ANY_TYPE, command, size); @@ -184,8 +181,8 @@ bdaddr_t LocalDevice::GetBluetoothAddress() { - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return bdaddrUtils::NullAddress(); + if (fMessenger == NULL) + return bdaddrUtils::NullAddress(); const bdaddr_t* bdaddr; BMessage request(BT_MSG_GET_ADDRESS); @@ -214,8 +211,8 @@ BString LocalDevice::GetFriendlyName() { - if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL) - return NULL; + if (fMessenger == NULL) + return NULL; BString friendlyname; BMessage request(BT_MSG_GET_FRIENDLY_NAME); @@ -258,7 +255,14 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid) { + fMessenger = _RetrieveBluetoothMessenger(); +} + +LocalDevice::~LocalDevice() +{ + if (fMessenger) + delete fMessenger; } Modified: haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-02 19:30:46 UTC (rev 26226) +++ haiku/trunk/src/kits/bluetooth/RemoteDevice.cpp 2008-07-02 19:41:45 UTC (rev 26227) @@ -38,21 +38,18 @@ if (!alwaysAsk) { // Check if the name is already retrieved + // TODO: Check if It is known from a KnownDevicesList return BString("Not implemented"); - - // TODO: Check if It is known from a KnownDevicesList } if (fDiscovererLocalDevice == NULL) return BString("#NoOwnerError#Not Valid name"); - BMessenger* btsm = NULL; - size_t size; - - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + if (fMessenger == NULL) return BString("#ServerNotReady#Not Valid name"); void* remoteNameCommand = NULL; + size_t size; /* Issue inquiry command */ BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); @@ -71,7 +68,7 @@ request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE); - if (btsm->SendMessage(&request, &reply) == B_OK) + if (fMessenger->SendMessage(&request, &reply) == B_OK) { BString name; int8 status; @@ -155,15 +152,24 @@ RemoteDevice::RemoteDevice(bdaddr_t address) { fBdaddr = address; + fMessenger = _RetrieveBluetoothMessenger(); } RemoteDevice::RemoteDevice(BString address) { fBdaddr = bdaddrUtils::FromString((const char *)address.String()); + fMessenger = _RetrieveBluetoothMessenger(); } +RemoteDevice::~RemoteDevice() +{ + if (fMessenger) + delete fMessenger; +} + + BString RemoteDevice::GetProperty(const char* property) /* Throwing */ { From oruizdorantes at mail.berlios.de Wed Jul 2 22:01:16 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 22:01:16 +0200 Subject: [Haiku-commits] r26228 - haiku/trunk/headers/os/bluetooth Message-ID: <200807022001.m62K1GXQ018329@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 22:01:02 +0200 (Wed, 02 Jul 2008) New Revision: 26228 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26228&view=rev Modified: haiku/trunk/headers/os/bluetooth/BluetoothDevice.h haiku/trunk/headers/os/bluetooth/DeviceClass.h haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h haiku/trunk/headers/os/bluetooth/DiscoveryListener.h haiku/trunk/headers/os/bluetooth/LocalDevice.h haiku/trunk/headers/os/bluetooth/RemoteDevice.h haiku/trunk/headers/os/bluetooth/bdaddrUtils.h haiku/trunk/headers/os/bluetooth/bluetooth.h haiku/trunk/headers/os/bluetooth/bluetooth_error.h haiku/trunk/headers/os/bluetooth/bluetooth_util.h Log: Fix EOL Modified: haiku/trunk/headers/os/bluetooth/BluetoothDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/BluetoothDevice.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/BluetoothDevice.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,46 +1,46 @@ -/* - * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BLUETOOTH_DEVICE_H -#define _BLUETOOTH_DEVICE_H - -#include -#include - - -#include -#include - -#include - - -namespace Bluetooth { - -class BluetoothDevice { - - public: - - virtual BString GetFriendlyName()=0; - virtual DeviceClass GetDeviceClass()=0; - - virtual BString GetProperty(const char* property)=0; - virtual void GetProperty(const char* property, uint32* value)=0; - - virtual bdaddr_t GetBluetoothAddress()=0; - - protected: - bdaddr_t fBdaddr; - DeviceClass fDeviceClass; -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::BluetoothDevice; -#endif - -#endif +/* + * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BLUETOOTH_DEVICE_H +#define _BLUETOOTH_DEVICE_H + +#include +#include + + +#include +#include + +#include + + +namespace Bluetooth { + +class BluetoothDevice { + + public: + + virtual BString GetFriendlyName()=0; + virtual DeviceClass GetDeviceClass()=0; + + virtual BString GetProperty(const char* property)=0; + virtual void GetProperty(const char* property, uint32* value)=0; + + virtual bdaddr_t GetBluetoothAddress()=0; + + protected: + bdaddr_t fBdaddr; + DeviceClass fDeviceClass; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::BluetoothDevice; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/BluetoothDevice.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/DeviceClass.h =================================================================== --- haiku/trunk/headers/os/bluetooth/DeviceClass.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/DeviceClass.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,69 +1,69 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DEVICE_CLASS_H -#define _DEVICE_CLASS_H - -#include - -namespace Bluetooth { - -class DeviceClass { - - public: - - DeviceClass(int record) - { - this->record = record; - } - - DeviceClass() - { - this->record = 0; - } - - - int GetServiceClasses() - { - return (record & 0x00FFE000) >> 13; - } - - - int GetMajorDeviceClass() - { - return (record & 0x00001F00) >> 8; - } - - - void GetMajorDeviceClass(BString* str) - { - - } - - - int GetMinorDeviceClass() - { - return (record & 0x000000FF) >> 2; - } - - - void GetMinorDeviceClass(BString* str) - { - - } - - private: - int record; -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DeviceClass; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DEVICE_CLASS_H +#define _DEVICE_CLASS_H + +#include + +namespace Bluetooth { + +class DeviceClass { + + public: + + DeviceClass(int record) + { + this->record = record; + } + + DeviceClass() + { + this->record = 0; + } + + + int GetServiceClasses() + { + return (record & 0x00FFE000) >> 13; + } + + + int GetMajorDeviceClass() + { + return (record & 0x00001F00) >> 8; + } + + + void GetMajorDeviceClass(BString* str) + { + + } + + + int GetMinorDeviceClass() + { + return (record & 0x000000FF) >> 2; + } + + + void GetMinorDeviceClass(BString* str) + { + + } + + private: + int record; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DeviceClass; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/DeviceClass.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h =================================================================== --- haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,74 +1,74 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DISCOVERY_AGENT_H -#define _DISCOVERY_AGENT_H - -#include -#include - - -#define BT_CACHED 0x00 -#define BT_PREKNOWN 0x01 -#define BT_NOT_DISCOVERABLE 0x01 - -#define BT_GIAC 0x9E8B33 -#define BT_LIAC 0x9E8B00 - -#define BT_MAX_RESPONSES (32) -#define BT_BASE_INQUIRY_TIME (1.28) -#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */ - -namespace Bluetooth { - -class DiscoveryListener; -class RemoteDevice; - -class DiscoveryAgent { - - public: - - static const int GIAC = BT_GIAC; - static const int LIAC = BT_LIAC; - - static const int PREKNOWN = BT_PREKNOWN; - static const int CACHED = BT_CACHED; - static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; - - RemoteDevicesList RetrieveDevices(int option); /* TODO */ - status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ - status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); - status_t CancelInquiry(DiscoveryListener* listener); - - /* - int searchServices(int[] attrSet, - UUID[] uuidSet, - RemoteDevice btDev, - DiscoveryListener discListener); - - bool cancelServiceSearch(int transID); - BString selectService(UUID uuid, int security, boolean master); - */ - - private: - DiscoveryAgent(LocalDevice* ld); - void SetLocalDeviceOwner(LocalDevice* ld); - - DiscoveryListener* fLastUsedListener; - LocalDevice* fLocalDevice; - - friend class LocalDevice; - -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DiscoveryAgent; -#endif - -#endif +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DISCOVERY_AGENT_H +#define _DISCOVERY_AGENT_H + +#include +#include + + +#define BT_CACHED 0x00 +#define BT_PREKNOWN 0x01 +#define BT_NOT_DISCOVERABLE 0x01 + +#define BT_GIAC 0x9E8B33 +#define BT_LIAC 0x9E8B00 + +#define BT_MAX_RESPONSES (32) +#define BT_BASE_INQUIRY_TIME (1.28) +#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */ + +namespace Bluetooth { + +class DiscoveryListener; +class RemoteDevice; + +class DiscoveryAgent { + + public: + + static const int GIAC = BT_GIAC; + static const int LIAC = BT_LIAC; + + static const int PREKNOWN = BT_PREKNOWN; + static const int CACHED = BT_CACHED; + static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; + + RemoteDevicesList RetrieveDevices(int option); /* TODO */ + status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ + status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); + status_t CancelInquiry(DiscoveryListener* listener); + + /* + int searchServices(int[] attrSet, + UUID[] uuidSet, + RemoteDevice btDev, + DiscoveryListener discListener); + + bool cancelServiceSearch(int transID); + BString selectService(UUID uuid, int security, boolean master); + */ + + private: + DiscoveryAgent(LocalDevice* ld); + void SetLocalDeviceOwner(LocalDevice* ld); + + DiscoveryListener* fLastUsedListener; + LocalDevice* fLocalDevice; + + friend class LocalDevice; + +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DiscoveryAgent; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/DiscoveryListener.h =================================================================== --- haiku/trunk/headers/os/bluetooth/DiscoveryListener.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/DiscoveryListener.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,76 +1,76 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DISCOVERY_LISTENER_H -#define _DISCOVERY_LISTENER_H - -#include -#include - -#include - - -#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs -#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X -#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X - - -namespace Bluetooth { - -typedef BObjectList RemoteDevicesList; - -class RemoteDevice; -class DeviceClass; -class LocalDevice; - -class DiscoveryListener : public BLooper { - - public: - - static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED; - static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED; - static const int INQUIRY_ERROR = BT_INQUIRY_ERROR; - - static const int SERVICE_SEARCH_COMPLETED = 0x01; - static const int SERVICE_SEARCH_TERMINATED = 0x02; - static const int SERVICE_SEARCH_ERROR = 0x03; - static const int SERVICE_SEARCH_NO_RECORDS = 0x04; - static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06; - - virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod); - /* - virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord); - virtual void serviceSearchCompleted(int transID, int respCode); - */ - virtual void InquiryCompleted(int discType); - - /* JSR82 non-defined methods */ - virtual void InquiryStarted(status_t status); - - private: - - RemoteDevicesList GetRemoteDevicesList(void); - - void MessageReceived(BMessage* msg); - - LocalDevice* fLocalDevice; - RemoteDevicesList fRemoteDevicesList; - - friend class DiscoveryAgent; - - protected: - DiscoveryListener(); - void SetLocalDeviceOwner(LocalDevice* ld); -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DiscoveryListener; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DISCOVERY_LISTENER_H +#define _DISCOVERY_LISTENER_H + +#include +#include + +#include + + +#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs +#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X +#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X + + +namespace Bluetooth { + +typedef BObjectList RemoteDevicesList; + +class RemoteDevice; +class DeviceClass; +class LocalDevice; + +class DiscoveryListener : public BLooper { + + public: + + static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED; + static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED; + static const int INQUIRY_ERROR = BT_INQUIRY_ERROR; + + static const int SERVICE_SEARCH_COMPLETED = 0x01; + static const int SERVICE_SEARCH_TERMINATED = 0x02; + static const int SERVICE_SEARCH_ERROR = 0x03; + static const int SERVICE_SEARCH_NO_RECORDS = 0x04; + static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06; + + virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod); + /* + virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord); + virtual void serviceSearchCompleted(int transID, int respCode); + */ + virtual void InquiryCompleted(int discType); + + /* JSR82 non-defined methods */ + virtual void InquiryStarted(status_t status); + + private: + + RemoteDevicesList GetRemoteDevicesList(void); + + void MessageReceived(BMessage* msg); + + LocalDevice* fLocalDevice; + RemoteDevicesList fRemoteDevicesList; + + friend class DiscoveryAgent; + + protected: + DiscoveryListener(); + void SetLocalDeviceOwner(LocalDevice* ld); +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DiscoveryListener; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/DiscoveryListener.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/LocalDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/LocalDevice.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/LocalDevice.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,75 +1,75 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _LOCAL_DEVICE_H -#define _LOCAL_DEVICE_H - -#include -#include -#include - -#include - -#include -#include - -#include - - -namespace Bluetooth { - -class DiscoveryAgent; - -class LocalDevice : public BluetoothDevice { - - public: - /* Possible throwing */ - static LocalDevice* GetLocalDevice(); - static uint32 GetLocalDeviceCount(); - - static LocalDevice* GetLocalDevice(hci_id hid); - static LocalDevice* GetLocalDevice(bdaddr_t bdaddr); - - DiscoveryAgent* GetDiscoveryAgent(); - BString GetFriendlyName(); - DeviceClass GetDeviceClass(); - /* Possible throwing */ - status_t SetDiscoverable(int mode); - - BString GetProperty(const char* property); - void GetProperty(const char* property, uint32* value); - - int GetDiscoverable(); - bdaddr_t GetBluetoothAddress(); - /* - ServiceRecord getRecord(Connection notifier); - void updateRecord(ServiceRecord srvRecord); - */ - - private: - LocalDevice(hci_id hid); - virtual ~LocalDevice(); - - hci_id GetID(void) {return hid;} - static LocalDevice* RequestLocalDeviceID(BMessage* request); - - BMessenger* fMessenger; - - hci_id hid; - - friend class DiscoveryAgent; - friend class RemoteDevice; - friend class PincodeWindow; -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::LocalDevice; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _LOCAL_DEVICE_H +#define _LOCAL_DEVICE_H + +#include +#include +#include + +#include + +#include +#include + +#include + + +namespace Bluetooth { + +class DiscoveryAgent; + +class LocalDevice : public BluetoothDevice { + + public: + /* Possible throwing */ + static LocalDevice* GetLocalDevice(); + static uint32 GetLocalDeviceCount(); + + static LocalDevice* GetLocalDevice(hci_id hid); + static LocalDevice* GetLocalDevice(bdaddr_t bdaddr); + + DiscoveryAgent* GetDiscoveryAgent(); + BString GetFriendlyName(); + DeviceClass GetDeviceClass(); + /* Possible throwing */ + status_t SetDiscoverable(int mode); + + BString GetProperty(const char* property); + void GetProperty(const char* property, uint32* value); + + int GetDiscoverable(); + bdaddr_t GetBluetoothAddress(); + /* + ServiceRecord getRecord(Connection notifier); + void updateRecord(ServiceRecord srvRecord); + */ + + private: + LocalDevice(hci_id hid); + virtual ~LocalDevice(); + + hci_id GetID(void) {return hid;} + static LocalDevice* RequestLocalDeviceID(BMessage* request); + + BMessenger* fMessenger; + + hci_id hid; + + friend class DiscoveryAgent; + friend class RemoteDevice; + friend class PincodeWindow; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::LocalDevice; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/LocalDevice.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/RemoteDevice.h =================================================================== --- haiku/trunk/headers/os/bluetooth/RemoteDevice.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/RemoteDevice.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,81 +1,81 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _REMOTE_DEVICE_H -#define _REMOTE_DEVICE_H - -#include -#include - -#include - -#define B_BT_WAIT 0x00 -#define B_BT_SUCCEEDED 0x01 - - -namespace Bluetooth { - -class Connection; -class LocalDevice; - -class RemoteDevice : public BluetoothDevice { - - public: - static const int WAIT = B_BT_WAIT; - static const int SUCCEEDED = B_BT_SUCCEEDED; - - virtual ~RemoteDevice(); - - bool IsTrustedDevice(); - BString GetFriendlyName(bool alwaysAsk); /* Throwing */ - BString GetFriendlyName(void); /* Throwing */ - bdaddr_t GetBluetoothAddress(); - DeviceClass GetDeviceClass(); - - bool Equals(RemoteDevice* obj); - - /*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */ - bool Authenticate(); /* Throwing */ - /* bool Authorize(Connection conn); Throwing */ - /*bool Encrypt(Connection conn, bool on); Throwing */ - bool IsAuthenticated(); /* Throwing */ - /*bool IsAuthorized(Connection conn); Throwing */ - bool IsEncrypted(); /* Throwing */ - - BString GetProperty(const char* property); /* Throwing */ - void GetProperty(const char* property, uint32* value); /* Throwing */ - - LocalDevice* GetLocalDeviceOwner(); - protected: - RemoteDevice(BString address); - RemoteDevice(bdaddr_t address); - - - - /* Instances of this class only would be instantiated by Discovery[Listener|Agent] */ - friend class DiscoveryListener; - void SetLocalDeviceOwner(LocalDevice* ld); - - private: - - LocalDevice* fDiscovererLocalDevice; - BMessenger* fMessenger; - - uint8 fPageRepetitionMode; - uint8 fScanPeriodMode; - uint8 fScanMode; - uint16 fClockOffset; - -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::RemoteDevice; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _REMOTE_DEVICE_H +#define _REMOTE_DEVICE_H + +#include +#include + +#include + +#define B_BT_WAIT 0x00 +#define B_BT_SUCCEEDED 0x01 + + +namespace Bluetooth { + +class Connection; +class LocalDevice; + +class RemoteDevice : public BluetoothDevice { + + public: + static const int WAIT = B_BT_WAIT; + static const int SUCCEEDED = B_BT_SUCCEEDED; + + virtual ~RemoteDevice(); + + bool IsTrustedDevice(); + BString GetFriendlyName(bool alwaysAsk); /* Throwing */ + BString GetFriendlyName(void); /* Throwing */ + bdaddr_t GetBluetoothAddress(); + DeviceClass GetDeviceClass(); + + bool Equals(RemoteDevice* obj); + + /*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */ + bool Authenticate(); /* Throwing */ + /* bool Authorize(Connection conn); Throwing */ + /*bool Encrypt(Connection conn, bool on); Throwing */ + bool IsAuthenticated(); /* Throwing */ + /*bool IsAuthorized(Connection conn); Throwing */ + bool IsEncrypted(); /* Throwing */ + + BString GetProperty(const char* property); /* Throwing */ + void GetProperty(const char* property, uint32* value); /* Throwing */ + + LocalDevice* GetLocalDeviceOwner(); + protected: + RemoteDevice(BString address); + RemoteDevice(bdaddr_t address); + + + + /* Instances of this class only would be instantiated by Discovery[Listener|Agent] */ + friend class DiscoveryListener; + void SetLocalDeviceOwner(LocalDevice* ld); + + private: + + LocalDevice* fDiscovererLocalDevice; + BMessenger* fMessenger; + + uint8 fPageRepetitionMode; + uint8 fScanPeriodMode; + uint8 fScanMode; + uint16 fClockOffset; + +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::RemoteDevice; +#endif + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/RemoteDevice.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/bdaddrUtils.h =================================================================== --- haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2008-07-02 19:41:45 UTC (rev 26227) +++ haiku/trunk/headers/os/bluetooth/bdaddrUtils.h 2008-07-02 20:01:02 UTC (rev 26228) @@ -1,88 +1,88 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BDADDR_UTILS_H -#define _BDADDR_UTILS_H - -#include - -#include - -namespace Bluetooth { - -class bdaddrUtils { - - public: - static inline bdaddr_t NullAddress() - { - - return ((bdaddr_t) {{0, 0, 0, 0, 0, 0}}); - } - - - static inline bdaddr_t LocalAddress() - { - - return ((bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}); - } - - - static inline bdaddr_t BroadcastAddress() - { - - return ((bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}); - } - - - static bool Compare(bdaddr_t* ba1, bdaddr_t* ba2) - { - return (memcmp(ba1, ba2, sizeof(bdaddr_t)) == 0); - } - - - static char* ToString(const bdaddr_t bdaddr) - { - // TODO: not safe - static char str[18]; - - sprintf(str,"%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",bdaddr.b[0], - bdaddr.b[1], - bdaddr.b[2], - bdaddr.b[3], - bdaddr.b[4], - bdaddr.b[5]); - - return str; - } - - static bdaddr_t FromString(const char * addr) - { - int b0, b1, b2, b3, b4, b5; - size_t count = sscanf(addr, "%2X:%2X:%2X:%2X:%2X:%2X", - &b0, - &b1, - &b2, - &b3, - &b4, - &b5); - - if (count == 6) - return ((bdaddr_t) {{b0, b1, b2, b3, b4, b5}}); - - return NullAddress(); - } - -}; - -} [... truncated: 380 lines follow ...] From oruizdorantes at mail.berlios.de Wed Jul 2 23:00:22 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:00:22 +0200 Subject: [Haiku-commits] r26229 - haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic Message-ID: <200807022100.m62L0MaT022945@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 22:59:57 +0200 (Wed, 02 Jul 2008) New Revision: 26229 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26229&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/snet_buffer.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/snet_buffer.h Log: Fix EOL Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h 2008-07-02 20:01:02 UTC (rev 26228) +++ haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h 2008-07-02 20:59:57 UTC (rev 26229) @@ -1,43 +1,43 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _H2CFG_H_ -#define _H2CFG_H_ - - -#define BT_DRIVER_SUPPORTS_CMD 1 -#define BT_DRIVER_SUPPORTS_EVT 1 -#define BT_DRIVER_SUPPORTS_ESCO 0 -#define BT_DRIVER_SUPPORTS_SCO 0 -#define BT_DRIVER_SUPPORTS_ACL 0 - -/* TODO: move exclusive header for drivers*/ -#define BT_DRIVER_RXCOVERAGE (BT_DRIVER_SUPPORTS_EVT+BT_DRIVER_SUPPORTS_ACL+BT_DRIVER_SUPPORTS_SCO+BT_DRIVER_SUPPORTS_ESCO) -#define BT_DRIVER_TXCOVERAGE (BT_DRIVER_SUPPORTS_CMD+BT_DRIVER_SUPPORTS_ACL+BT_DRIVER_SUPPORTS_SCO+BT_DRIVER_SUPPORTS_ESCO) - -#if BT_DRIVER_RXCOVERAGE<1 || BT_DRIVER_TXCOVERAGE<1 -#error incomplete Bluetooth driver Commands and Events should be implemented -#endif - -#define BT_SURVIVE_WITHOUT_HCI -#define BT_SURVIVE_WITHOUT_NET_BUFFERS - -//////////////////////////////////// - -#ifndef BLUETOOTH_DEVICE_TRANSPORT -#error BLUETOOTH_DEVICE_TRANSPORT must be defined to build the publishing path -#endif - -#ifndef BLUETOOTH_DEVICE_NAME -#error BLUETOOTH_DEVICE_NAME must be defined to build the publishing path -#endif - -#define BLUETOOTH_DEVICE_DEVFS_NAME BLUETOOTH_DEVICE_TRANSPORT BLUETOOTH_DEVICE_NAME -#define BLUETOOTH_DEVICE_PATH "bluetooth/" BLUETOOTH_DEVICE_DEVFS_NAME - - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _H2CFG_H_ +#define _H2CFG_H_ + + +#define BT_DRIVER_SUPPORTS_CMD 1 +#define BT_DRIVER_SUPPORTS_EVT 1 +#define BT_DRIVER_SUPPORTS_ESCO 0 +#define BT_DRIVER_SUPPORTS_SCO 0 +#define BT_DRIVER_SUPPORTS_ACL 0 + +/* TODO: move exclusive header for drivers*/ +#define BT_DRIVER_RXCOVERAGE (BT_DRIVER_SUPPORTS_EVT+BT_DRIVER_SUPPORTS_ACL+BT_DRIVER_SUPPORTS_SCO+BT_DRIVER_SUPPORTS_ESCO) +#define BT_DRIVER_TXCOVERAGE (BT_DRIVER_SUPPORTS_CMD+BT_DRIVER_SUPPORTS_ACL+BT_DRIVER_SUPPORTS_SCO+BT_DRIVER_SUPPORTS_ESCO) + +#if BT_DRIVER_RXCOVERAGE<1 || BT_DRIVER_TXCOVERAGE<1 +#error incomplete Bluetooth driver Commands and Events should be implemented +#endif + +#define BT_SURVIVE_WITHOUT_HCI +#define BT_SURVIVE_WITHOUT_NET_BUFFERS + +//////////////////////////////////// + +#ifndef BLUETOOTH_DEVICE_TRANSPORT +#error BLUETOOTH_DEVICE_TRANSPORT must be defined to build the publishing path +#endif + +#ifndef BLUETOOTH_DEVICE_NAME +#error BLUETOOTH_DEVICE_NAME must be defined to build the publishing path +#endif + +#define BLUETOOTH_DEVICE_DEVFS_NAME BLUETOOTH_DEVICE_TRANSPORT BLUETOOTH_DEVICE_NAME +#define BLUETOOTH_DEVICE_PATH "bluetooth/" BLUETOOTH_DEVICE_DEVFS_NAME + + +#endif Property changes on: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-02 20:01:02 UTC (rev 26228) +++ haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-02 20:59:57 UTC (rev 26229) @@ -1,829 +1,829 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "snet_buffer.h" - -#include -#include -#include - -#define BT_DEBUG_THIS_MODULE -#include - -#include "h2generic.h" -#include "h2transactions.h" -#include "h2util.h" - -#include "h2cfg.h" - -int32 api_version = B_CUR_DRIVER_API_VERSION; - -/* Modules */ -static char* usb_name = B_USB_MODULE_NAME; -static char* hci_name = BT_HCI_MODULE_NAME; - -usb_module_info *usb = NULL; -bt_hci_module_info *hci = NULL; -struct net_buffer_module_info *nb = NULL; - -/* Driver Global data */ -static char *publish_names[MAX_BT_GENERIC_USB_DEVICES]; - -int32 dev_count = 0; /* number of connected devices */ -static bt_usb_dev* bt_usb_devices[MAX_BT_GENERIC_USB_DEVICES]; -sem_id dev_table_sem = -1; /* sem to synchronize access to device table */ - -usb_support_descriptor supported_devices[] = -{ - /* Generic Bluetooth USB device */ - /* Class, SubClass, and Protocol codes that describe a Bluetooth device */ - { UDCLASS_WIRELESS, UDSUBCLASS_RF, UDPROTO_BLUETOOTH , 0 , 0 }, - - /* Generic devices */ - /* Broadcom BCM2035 */ - { 0, 0, 0, 0x0a5c, 0x200a }, - { 0, 0, 0, 0x0a5c, 0x2009 }, - - /* Devices taken from the linux Driver */ - /* AVM BlueFRITZ! USB v2.0 */ - { 0, 0, 0, 0x057c , 0x3800 }, - /* Bluetooth Ultraport Module from IBM */ - { 0, 0, 0, 0x04bf , 0x030a }, - /* ALPS Modules with non-standard id */ - { 0, 0, 0, 0x044e , 0x3001 }, - { 0, 0, 0, 0x044e , 0x3002 }, - /* Ericsson with non-standard id */ - { 0, 0, 0, 0x0bdb , 0x1002 } -}; - -/* add a device to the list of connected devices */ -static bt_usb_dev* -spawn_device(const usb_device* usb_dev) -{ - int32 i; - status_t err = B_OK; - bt_usb_dev* new_bt_dev = NULL; - - flowf("add_device()\n"); - - /* 16 usb dongles... u are unsane */ - if (dev_count >= MAX_BT_GENERIC_USB_DEVICES) { - flowf("device table full\n"); - goto exit; - } - - /* try the allocation */ - new_bt_dev = (bt_usb_dev*)malloc(sizeof(bt_usb_dev)); - if ( new_bt_dev == NULL ) { - flowf("no memoery allocating\n"); - goto exit; - } - memset(new_bt_dev, 0, sizeof(bt_usb_dev) ); - - /* We will need this sem for some flow control */ - new_bt_dev->cmd_complete = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "cmd_complete"); - if (new_bt_dev->cmd_complete < 0) { - err = new_bt_dev->cmd_complete; - goto bail0; - } - - /* and this for something else */ - new_bt_dev->lock = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "lock"); - if (new_bt_dev->lock < 0) { - err = new_bt_dev->lock; - goto bail1; - } - - /* find a free slot and fill out the name */ - acquire_sem(dev_table_sem); - for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { - if (bt_usb_devices[i] == NULL) { - bt_usb_devices[i] = new_bt_dev; - sprintf(new_bt_dev->name, "%s/%ld", BLUETOOTH_DEVICE_PATH, i); - new_bt_dev->num = i; - debugf("added device %p %ld %s\n", bt_usb_devices[i] ,new_bt_dev->num,new_bt_dev->name); - break; - } - } - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - - /* In the case we cannot us */ - if (bt_usb_devices[i] != new_bt_dev) { - flowf("Device could not be added\n"); - goto bail2; - } - - new_bt_dev->dev = usb_dev; - /* TODO am i actually gonna use this? */ - new_bt_dev->open_count = 0; - - dev_count++; - return new_bt_dev; - -bail2: - delete_sem(new_bt_dev->lock); -bail1: - delete_sem(new_bt_dev->cmd_complete); -bail0: - free(new_bt_dev); -exit: - return new_bt_dev; -} - - -/* remove a device from the list of connected devices */ -static void -kill_device(bt_usb_dev* dev) -{ - debugf("remove_device(%p)\n", dev); - - delete_sem(dev->lock); - delete_sem(dev->cmd_complete); - - free(dev); - dev_count--; -} - - -bt_usb_dev* -fetch_device(bt_usb_dev* dev, hci_id hid) -{ - int i; - - debugf("(%p)\n", dev); - - acquire_sem(dev_table_sem); - if (dev != NULL) - for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { - /* somehow the device is still around */ - if (bt_usb_devices[i] == dev) { - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - return bt_usb_devices[i]; - } - } - else - for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { - /* somehow the device is still around */ - if (bt_usb_devices[i] != NULL && bt_usb_devices[i]->hdev == hid) { - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - return bt_usb_devices[i]; - } - } - - - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - - return NULL; -} - -#if 0 -#pragma mark - -#endif - -static bt_hci_transport bt_usb_hooks = -{ - NULL, - NULL, - NULL, - NULL, - H2, - "H2 Bluetooth Device" -}; - -/* called by USB Manager when device is added to the USB */ -static status_t -device_added(const usb_device* dev, void** cookie) -{ - const usb_interface_info* interface; - const usb_device_descriptor* desc; - const usb_configuration_info* config; - const usb_interface_info* uif; - const usb_endpoint_info* ep; - - status_t err = B_ERROR; - bt_usb_dev* new_bt_dev = spawn_device(dev); - int e; - - debugf("device_added(%p, %p)\n", dev, new_bt_dev); - - if (new_bt_dev == NULL) { - flowf("Couldn't allocate device record.\n"); - err = ENOMEM; - goto bail_no_mem; - } - - /* we only have 1 configuration number 0 */ - config = usb->get_nth_configuration(dev, 0); - //dump_usb_configuration_info(config); - if (config == NULL) { - flowf("couldn't get default config.\n"); - err = B_ERROR; - goto bail; - } - - debugf("found %ld alt interfaces.\n", config->interface->alt_count); - - /* set first interface */ - interface = &config->interface->alt[0]; - err = usb->set_alt_interface(new_bt_dev->dev, interface); - - if (err != B_OK) { - debugf("set_alt_interface() returned %ld.\n", err); - goto bail; - } - - /* call set_configuration() only after calling set_alt_interface()*/ - err = usb->set_configuration(dev, config); - if (err != B_OK) { - debugf("set_configuration() returned %ld.\n", err); - goto bail; - } - - /* Place to find out whats our concrete device and set up some special info to our driver */ - /* TODO: if this code increases too much reconsider this implementation*/ - desc = usb->get_device_descriptor(dev); - if ( desc->vendor_id == 0x0a5c && desc->product_id == 0x200a && desc->product_id == 0x2009) { - // Tecom Device VENDOR_ID 0x0a5c PRODUCT_ID 0x2035 - new_bt_dev->driver_info = BT_WILL_NEED_A_RESET | BT_SCO_NOT_WORKING; - } - /* - else if ( desc->vendor_id == YOUR_VENDOR_HERE && desc->product_id == YOUR_PRODUCT_HERE ) { - YOUR_SPECIAL_FLAGS_HERE - } - */ - - if (new_bt_dev->driver_info & BT_IGNORE_THIS_DEVICE){ - err = ENODEV; - goto bail; - } - - // security check - if (config->interface->active->descr->interface_number > 0){ - debugf("Strange condition happened %d\n", config->interface->active->descr->interface_number); - err = B_ERROR; - goto bail; - } - - debugf("Found %ld interfaces. Expected 3\n", config->interface_count); - /* Find endpoints that we need */ - uif = config->interface->active; - for (e = 0; e < uif->descr->num_endpoints; e++) { - - ep = &uif->endpoint[e]; - switch (ep->descr->attributes & USB_ENDPOINT_ATTR_MASK) - { - case USB_ENDPOINT_ATTR_INTERRUPT: - if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN) - { - new_bt_dev->intr_in_ep = ep; - new_bt_dev->max_packet_size_intr_in = ep->descr->max_packet_size; - flowf("INT in\n"); - } else - { - ; - flowf("INT out\n"); - } - break; - - case USB_ENDPOINT_ATTR_BULK: - if (ep->descr->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN) - { - new_bt_dev->bulk_in_ep = ep; - new_bt_dev->max_packet_size_bulk_in = ep->descr->max_packet_size;; - flowf("BULK int\n"); - } else - { - new_bt_dev->bulk_out_ep = ep; - new_bt_dev->max_packet_size_bulk_out = ep->descr->max_packet_size;; - flowf("BULK out\n"); - } - break; - } - } - - if (!new_bt_dev->bulk_in_ep || !new_bt_dev->bulk_out_ep || !new_bt_dev->intr_in_ep) { - flowf("Minimal # endpoints for BT not found\n"); - goto bail; - } - - // Look into the devices suported to understand this - if (new_bt_dev->driver_info & BT_DIGIANSWER) - new_bt_dev->ctrl_req = USB_TYPE_VENDOR; - else - new_bt_dev->ctrl_req = USB_TYPE_CLASS; - - new_bt_dev->connected = true; - - /* set the cookie that will be passed to other USB - hook functions (currently device_removed() is the only other) */ - *cookie = new_bt_dev; - debugf("Ok %p\n",bt_usb_devices[0]); - return B_OK; - -bail: - kill_device(new_bt_dev); -bail_no_mem: - *cookie = NULL; - - return err; -} - - -/* called by USB Manager when device is removed from the USB */ -static status_t -device_removed(void* cookie) -{ - int32 i; - void* item; - bt_usb_dev* bdev = (bt_usb_dev*) fetch_device(cookie, 0); - - debugf("device_removed(%p)\n", bdev); - - if (bdev == NULL) { - flowf("Weird condition...\n"); - return B_ERROR; - } - // TODO: Consider some other place - // TX - for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { - if (i == BT_COMMAND) - while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { - snb_free(item); - } - else - while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { - nb_destroy(item); - } - - } - // RX - for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) { - nb_destroy(bdev->nbufferRx[i]); - } - snb_free(bdev->eventRx); - - purge_room(&bdev->eventRoom); - purge_room(&bdev->aclRoom); - // TODO: Consider some other place - - if (hci != NULL) - hci->UnregisterDriver(bdev->hdev); - - bdev->connected = false; - - /* TODO: maybe we still need this struct for close and free hooks */ - kill_device(bdev); - - return B_OK; -} - - -static usb_notify_hooks notify_hooks = -{ - &device_added, - &device_removed -}; - -#if 0 -#pragma mark - -#endif - -/* implements the POSIX open() */ -static status_t -device_open(const char *name, uint32 flags, void **cookie) -{ - status_t err = ENODEV; - bt_usb_dev* bdev = NULL; - hci_id hdev; - int i; - - flowf("device_open()\n"); - - acquire_sem(dev_table_sem); - for (i = 0; i < MAX_BT_GENERIC_USB_DEVICES; i++) { - if (bt_usb_devices[i] && !strcmp(name, bt_usb_devices[i]->name)) { - bdev = bt_usb_devices[i]; - break; - } - } - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - - if (bdev == NULL) { - flowf("Device not found in the open list!"); - *cookie = NULL; - return B_ERROR; - } - - acquire_sem(bdev->lock); - // Set HCI_RUNNING - if ( TEST_AND_SET(&bdev->state, RUNNING) ) { - flowf("dev already running! - reOpened device!\n"); - return B_ERROR; - } - - // TX structures - for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { - list_init(&bdev->nbuffersTx[i]); - bdev->nbuffersPendingTx[i] = 0; - } - - // RX structures - bdev->eventRx = NULL; - for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) { - bdev->nbufferRx[i] = NULL; - } - - - // dumping the USB frames - init_room(&bdev->eventRoom); - init_room(&bdev->aclRoom); - //Init_room(new_bt_dev->scoRoom); - - list_init(&bdev->snetBufferRecycleTrash); - - // Allocate set and register the HCI device - if (hci != NULL) { - // TODO: Fill the transport descriptor - hci->RegisterDriver(&bt_usb_hooks, &hdev, (void*)bdev); - - if ( err != B_OK ) - { - flowf("Impossible to register a hci device.\n"); - hdev = bdev->num; /* XXX: Lets try to go on*/ - } - } - else { - hdev = bdev->num; - } - bdev->hdev = hdev; - - // H: set the special flags - - // EVENTS - err = submit_rx_event(bdev); - if (err != B_OK) - goto unrun; -#if BT_DRIVER_SUPPORTS_ACL - // ACL - for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { - err = submit_rx_acl(bdev); - if (err != B_OK && i == 0 ) - goto unrun; - } -#endif - -#if BT_DRIVER_SUPPORTS_SCO - // TODO: SCO / eSCO -#endif - - *cookie = bdev; - release_sem(bdev->lock); - - flowf(" successful\n"); - return B_OK; - -unrun: - CLEAR_BIT(bdev->state, RUNNING); // Set the flaq in the HCI world - flowf("Queuing failed device stops running\n"); - - return err; -} - - -/* called when a client calls POSIX close() on the driver, but I/O - ** requests may still be pending */ -static status_t -device_close(void *cookie) -{ - bt_usb_dev* bdev = (bt_usb_dev*)cookie; - - if (bdev == NULL) - panic("bad cookie"); - - debugf("device_close() called on %ld\n", bdev->hdev ); - - - if (!TEST_AND_CLEAR(&bdev->state, RUNNING) ) { - flowf("Device wasnt running!!!\n"); - } - - flowf("Stopping device and cancelling queues...\n"); - - if ( bdev->intr_in_ep != NULL ) { - usb->cancel_queued_transfers(bdev->intr_in_ep->handle); - - } else { - flowf("Cancelling impossible EVENTS\n"); - } - - if (bdev->bulk_in_ep!=NULL) { - usb->cancel_queued_transfers(bdev->bulk_in_ep->handle); - } else { - flowf("Cancelling impossible ACL in\n"); - } - - if (bdev->bulk_out_ep!=NULL) { - usb->cancel_queued_transfers(bdev->bulk_out_ep->handle); - } else { - flowf("Cancelling impossible ACL out\n"); - } - - // TODO: Kill if its not connected? - - return B_OK; -} - - -/* called after device_close(), when all pending I/O requests have - * returned */ -static status_t -device_free (void *cookie) -{ - status_t err = B_OK; - bt_usb_dev* dev = (bt_usb_dev*)cookie; - - debugf("device_free() called on %s \n",BLUETOOTH_DEVICE_PATH); - - - if (--dev->open_count == 0) { - - /* GotoLowPower */ - // interesting ..... - } - else { - /* The last client has closed, and the device is no longer - connected, so remove it from the list. */ - - } - - // TODO: Kill if its not connected? - - return err; -} - - -/* implements the POSIX ioctl() */ -static status_t -device_control(void *cookie, uint32 msg, void *params, size_t size) -{ - status_t err = B_ERROR; - bt_usb_dev* bdev = (bt_usb_dev*)cookie; - snet_buffer* snbuf; - TOUCH(size); - - debugf("ioctl() opcode %ld size %ld.\n", msg, size); - - if (bdev == NULL) { - flowf("Bad cookie\n"); - return B_BAD_VALUE; - } - - if (params == NULL) { - flowf("Invalid pointer control\n"); - return B_BAD_VALUE; - } - - acquire_sem(bdev->lock); - - switch (msg) { - case ISSUE_BT_COMMAND: -#ifdef BT_IOCTLS_PASS_SIZE - if (size == 0) { - flowf("Invalid size control\n"); - err = B_BAD_VALUE; - break; - } -#else - size = (*((size_t*)params)); - (*(size_t**)¶ms)++; -#endif - - // TODO: Reuse from some TXcompleted queue - snbuf = snb_create(size); - snb_put(snbuf, params, size); - - err = submit_tx_command(bdev, snbuf); - - break; - - case GET_STATICS: - memcpy(params, &bdev->stat, sizeof(bt_hci_statistics)); - err = B_OK; - break; - - case GET_HCI_ID: - *(hci_id*)params = bdev->hdev; - err = B_OK; - break; - - - default: - debugf("Invalid opcode %ld.\n", msg); - err = B_DEV_INVALID_IOCTL; - break; - } - - release_sem(bdev->lock); - return err; -} - - -/* implements the POSIX read() */ -static status_t -device_read(void *cookie, off_t pos, void *buf, size_t *count) -{ - debugf("Reading... count = %ld\n", *count); - - *count = 0; - return B_OK; -} - - -/* implements the POSIX write() */ -static status_t -device_write(void *cookie, off_t pos, const void *buf, size_t *count) -{ - flowf("device_write()\n"); - - return B_ERROR; -} - -#if 0 -#pragma mark - -#endif - -/* called each time the driver is loaded by the kernel */ -status_t -init_driver(void) -{ - int j; - flowf("init_driver()\n"); - - // HCI MODULE INITS - if (get_module(hci_name,(module_info**)&hci) != B_OK) { - debugf("cannot get module \"%s\"\n", hci_name); -#ifndef BT_SURVIVE_WITHOUT_HCI - return B_ERROR; -#endif - } - debugf("hci module at %p\n", hci); - - // USB MODULE INITS - if (get_module(usb_name,(module_info**)&usb) != B_OK) { - debugf("cannot get module \"%s\"\n", usb_name); - goto err_release; - } - debugf("usb module at %p\n", usb); - - - if (get_module(NET_BUFFER_MODULE_NAME,(module_info**)&nb) != B_OK) { - debugf("cannot get module \"%s\"\n", NET_BUFFER_MODULE_NAME); -#ifndef BT_SURVIVE_WITHOUT_NET_BUFFERS - goto err_release; -#endif - } - debugf("nb module at %p\n", nb); - - // GENERAL INITS - dev_table_sem = create_sem(1, BLUETOOTH_DEVICE_DEVFS_NAME "dev_table_lock"); - if (dev_table_sem < 0) { - goto err; - } - - for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { - bt_usb_devices[j] = NULL; - } - - /* After here device_added and publish devices hooks are called - be carefull USB devs */ - usb->register_driver(BLUETOOTH_DEVICE_DEVFS_NAME, supported_devices, 1, NULL); - usb->install_notify(BLUETOOTH_DEVICE_DEVFS_NAME, ¬ify_hooks); - - return B_OK; - -err: // Releasing - put_module(usb_name); -err_release: - put_module(hci_name); - return B_ERROR; -} - - -/* called just before the kernel unloads the driver */ -void -uninit_driver(void) -{ - int32 j; - - flowf("uninit_driver()\n"); - - for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { - - if (publish_names[j] != NULL) - free(publish_names[j]); - - if (bt_usb_devices[j] != NULL) { - // if (connected_dev != NULL) { - // debugf("Device %p still exists.\n", connected_dev); - // } - kill_device(bt_usb_devices[j]); - bt_usb_devices[j] = NULL; - } - - } - - usb->uninstall_notify(BLUETOOTH_DEVICE_DEVFS_NAME); - - /* Releasing modules */ - put_module(usb_name); - put_module(hci_name); - // TODO: netbuffers - - delete_sem(dev_table_sem); -} - - -const char** -publish_devices(void) -{ - int32 j; - int32 i = 0; - - char* str; - - flowf("publish_devices()\n"); - - for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) { - if (publish_names[j]) { - free(publish_names[j]); - publish_names[j] = NULL; - } - } - - acquire_sem(dev_table_sem); - for (j = 0; j < MAX_BT_GENERIC_USB_DEVICES; j++) - { - if (bt_usb_devices[j] != NULL && bt_usb_devices[j]->connected) - { - str = strdup(bt_usb_devices[j]->name); - if (str) { - publish_names[i++] = str; - debugf("publishing %s\n", bt_usb_devices[j]->name); - } - } - } - release_sem_etc(dev_table_sem, 1, B_DO_NOT_RESCHEDULE); - - publish_names[i] = NULL; - debugf("published %ld devices\n", i); - -// TODO: this method might make better memory use -// dev_names = (char**)malloc(sizeof (char*) * (dev_count+1)); -// if (dev_names) { -// for (i = 0; i < MAX_NUM_DEVS; i++) { -// if ((dev != NULL) && -// (dev_names[i] = (char*)malloc(strlen(DEVICE_PATH)+2/* num + \n */))) { -// sprintf(dev_names[i], "%s%ld", DEVICE_PATH, dev->num); -// debugf("publishing \"%s\"\n", dev_names[i]); -// } -// } - - return (const char**)publish_names; -} - - -static device_hooks hooks = { - device_open, - device_close, - device_free, - device_control, - device_read, - device_write, - NULL, - NULL, - NULL, - NULL -}; - - -device_hooks* -find_device(const char* name) -{ - debugf("find_device(%s)\n", name); - - return &hooks; -} +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "snet_buffer.h" + +#include +#include +#include + +#define BT_DEBUG_THIS_MODULE +#include + +#include "h2generic.h" +#include "h2transactions.h" +#include "h2util.h" + +#include "h2cfg.h" + +int32 api_version = B_CUR_DRIVER_API_VERSION; + +/* Modules */ +static char* usb_name = B_USB_MODULE_NAME; +static char* hci_name = BT_HCI_MODULE_NAME; + +usb_module_info *usb = NULL; +bt_hci_module_info *hci = NULL; +struct net_buffer_module_info *nb = NULL; + +/* Driver Global data */ +static char *publish_names[MAX_BT_GENERIC_USB_DEVICES]; + +int32 dev_count = 0; /* number of connected devices */ +static bt_usb_dev* bt_usb_devices[MAX_BT_GENERIC_USB_DEVICES]; +sem_id dev_table_sem = -1; /* sem to synchronize access to device table */ + +usb_support_descriptor supported_devices[] = +{ + /* Generic Bluetooth USB device */ + /* Class, SubClass, and Protocol codes that describe a Bluetooth device */ + { UDCLASS_WIRELESS, UDSUBCLASS_RF, UDPROTO_BLUETOOTH , 0 , 0 }, + + /* Generic devices */ + /* Broadcom BCM2035 */ + { 0, 0, 0, 0x0a5c, 0x200a }, + { 0, 0, 0, 0x0a5c, 0x2009 }, + + /* Devices taken from the linux Driver */ + /* AVM BlueFRITZ! USB v2.0 */ + { 0, 0, 0, 0x057c , 0x3800 }, + /* Bluetooth Ultraport Module from IBM */ + { 0, 0, 0, 0x04bf , 0x030a }, + /* ALPS Modules with non-standard id */ + { 0, 0, 0, 0x044e , 0x3001 }, + { 0, 0, 0, 0x044e , 0x3002 }, [... truncated: 3256 lines follow ...] From oruizdorantes at mail.berlios.de Wed Jul 2 23:09:25 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:09:25 +0200 Subject: [Haiku-commits] r26230 - haiku/trunk/src/servers/bluetooth Message-ID: <200807022109.m62L9Pab023756@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:09:04 +0200 (Wed, 02 Jul 2008) New Revision: 26230 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26230&view=rev Modified: haiku/trunk/src/servers/bluetooth/BPortNot.cpp haiku/trunk/src/servers/bluetooth/BPortNot.h haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp haiku/trunk/src/servers/bluetooth/BluetoothServer.h haiku/trunk/src/servers/bluetooth/DeviceManager.cpp haiku/trunk/src/servers/bluetooth/DeviceManager.h haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h haiku/trunk/src/servers/bluetooth/HCIDelegate.h haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h haiku/trunk/src/servers/bluetooth/Jamfile haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h haiku/trunk/src/servers/bluetooth/Output.cpp haiku/trunk/src/servers/bluetooth/Output.h haiku/trunk/src/servers/bluetooth/server-bluetooth.rdef Log: Fix EOL Property changes on: haiku/trunk/src/servers/bluetooth/BPortNot.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/BPortNot.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/BluetoothServer.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/DeviceManager.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/DeviceManager.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/HCIDelegate.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-02 20:59:57 UTC (rev 26229) +++ haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-02 21:09:04 UTC (rev 26230) @@ -1,35 +1,35 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - - -#include - -#include "BluetoothServer.h" -#include "HCITransportAccessor.h" -#include "Output.h" - -HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path) -{ - - -} - -status_t -HCITransportAccessor::IssueCommand(raw_command rc, size_t size) -{ - if (GetID() < 0 || fFD < 0) - return B_ERROR; - -printf("### Command going: len = %ld\n", size); -for (uint16 index = 0 ; index < size; index++ ) { - printf("%x:",((uint8*)rc)[index]); -} -printf("### \n"); - - - return ioctl(fFD, ISSUE_BT_COMMAND, rc, size); -} +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + + +#include + +#include "BluetoothServer.h" +#include "HCITransportAccessor.h" +#include "Output.h" + +HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path) +{ + + +} + +status_t +HCITransportAccessor::IssueCommand(raw_command rc, size_t size) +{ + if (GetID() < 0 || fFD < 0) + return B_ERROR; + +printf("### Command going: len = %ld\n", size); +for (uint16 index = 0 ; index < size; index++ ) { + printf("%x:",((uint8*)rc)[index]); +} +printf("### \n"); + + + return ioctl(fFD, ISSUE_BT_COMMAND, rc, size); +} Property changes on: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/Jamfile ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/LocalDeviceImpl.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/Output.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/Output.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/servers/bluetooth/server-bluetooth.rdef ___________________________________________________________________ Name: svn:eol-style + native From oruizdorantes at mail.berlios.de Wed Jul 2 23:10:38 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:10:38 +0200 Subject: [Haiku-commits] r26231 - haiku/trunk/headers/os/bluetooth/HCI Message-ID: <200807022110.m62LAcvI023929@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:10:24 +0200 (Wed, 02 Jul 2008) New Revision: 26231 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26231&view=rev Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI.h haiku/trunk/headers/os/bluetooth/HCI/btHCI_acl.h haiku/trunk/headers/os/bluetooth/HCI/btHCI_command.h haiku/trunk/headers/os/bluetooth/HCI/btHCI_event.h haiku/trunk/headers/os/bluetooth/HCI/btHCI_module.h haiku/trunk/headers/os/bluetooth/HCI/btHCI_transport.h Log: Fix EOL Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI.h =================================================================== --- haiku/trunk/headers/os/bluetooth/HCI/btHCI.h 2008-07-02 21:09:04 UTC (rev 26230) +++ haiku/trunk/headers/os/bluetooth/HCI/btHCI.h 2008-07-02 21:10:24 UTC (rev 26231) @@ -1,41 +1,41 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_H_ -#define _BTHCI_H_ - -/* typedefs */ -typedef int32 hci_id; - -typedef enum { H2 = 2, H3, H4, H5 } transport_type; - -// TODO: something more authomatic here? -#define HCI_NUM_PACKET_TYPES 5 -typedef enum { BT_COMMAND = 0, - BT_EVENT, - BT_ACL, - BT_SCO, - BT_ESCO - } bt_packet_t; - - -/* packets sizes */ -#define HCI_MAX_ACL_SIZE 1024 -#define HCI_MAX_SCO_SIZE 255 -#define HCI_MAX_EVENT_SIZE 260 -#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4) - -/* fields sizes */ -#define HCI_LAP_SIZE 3 /* LAP */ -#define HCI_LINK_KEY_SIZE 16 /* link key */ -#define HCI_PIN_SIZE 16 /* PIN */ -#define HCI_EVENT_MASK_SIZE 8 /* event mask */ -#define HCI_CLASS_SIZE 3 /* class */ -#define HCI_FEATURES_SIZE 8 /* LMP features */ -#define HCI_DEVICE_NAME_SIZE 248 /* unit name size */ - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTHCI_H_ +#define _BTHCI_H_ + +/* typedefs */ +typedef int32 hci_id; + +typedef enum { H2 = 2, H3, H4, H5 } transport_type; + +// TODO: something more authomatic here? +#define HCI_NUM_PACKET_TYPES 5 +typedef enum { BT_COMMAND = 0, + BT_EVENT, + BT_ACL, + BT_SCO, + BT_ESCO + } bt_packet_t; + + +/* packets sizes */ +#define HCI_MAX_ACL_SIZE 1024 +#define HCI_MAX_SCO_SIZE 255 +#define HCI_MAX_EVENT_SIZE 260 +#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4) + +/* fields sizes */ +#define HCI_LAP_SIZE 3 /* LAP */ +#define HCI_LINK_KEY_SIZE 16 /* link key */ +#define HCI_PIN_SIZE 16 /* PIN */ +#define HCI_EVENT_MASK_SIZE 8 /* event mask */ +#define HCI_CLASS_SIZE 3 /* class */ +#define HCI_FEATURES_SIZE 8 /* LMP features */ +#define HCI_DEVICE_NAME_SIZE 248 /* unit name size */ + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/HCI/btHCI.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI_acl.h =================================================================== --- haiku/trunk/headers/os/bluetooth/HCI/btHCI_acl.h 2008-07-02 21:09:04 UTC (rev 26230) +++ haiku/trunk/headers/os/bluetooth/HCI/btHCI_acl.h 2008-07-02 21:10:24 UTC (rev 26231) @@ -1,39 +1,39 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_ACL_H_ -#define _BTHCI_ACL_H_ - -#include -#include - -#define HCI_ACL_HDR_SIZE 4 - -struct hci_acl_header { - uint16 handle; /* Handle & Flags(PB, BC) */ - uint16 alen; -} __attribute__ ((packed)) ; - -/* ACL handle and flags pack/unpack */ -#define pack_acl_handle_flags(h, pb, bc) (((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14)) -#define get_acl_handle(h) ((h) & 0x0fff) -#define get_acl_pb_flag(h) (((h) & 0x3000) >> 12) -#define get_acl_bc_flag(h) (((h) & 0xc000) >> 14) - -/* PB flag values */ -/* 00 - reserved for future use */ -#define HCI_ACL_PACKET_FRAGMENT 0x1 -#define HCI_ACL_PACKET_START 0x2 -/* 11 - reserved for future use */ - -/* BC flag values */ -#define HCI_ACL_POINT2POINT 0x0 /* only Host controller to Host */ -#define HCI_ACL_BROADCAST_ACTIVE 0x1 /* both directions */ -#define HCI_ACL_BROADCAST_PICONET 0x2 /* both directions */ - /* 11 - reserved for future use */ - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTHCI_ACL_H_ +#define _BTHCI_ACL_H_ + +#include +#include + +#define HCI_ACL_HDR_SIZE 4 + +struct hci_acl_header { + uint16 handle; /* Handle & Flags(PB, BC) */ + uint16 alen; +} __attribute__ ((packed)) ; + +/* ACL handle and flags pack/unpack */ +#define pack_acl_handle_flags(h, pb, bc) (((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14)) +#define get_acl_handle(h) ((h) & 0x0fff) +#define get_acl_pb_flag(h) (((h) & 0x3000) >> 12) +#define get_acl_bc_flag(h) (((h) & 0xc000) >> 14) + +/* PB flag values */ +/* 00 - reserved for future use */ +#define HCI_ACL_PACKET_FRAGMENT 0x1 +#define HCI_ACL_PACKET_START 0x2 +/* 11 - reserved for future use */ + +/* BC flag values */ +#define HCI_ACL_POINT2POINT 0x0 /* only Host controller to Host */ +#define HCI_ACL_BROADCAST_ACTIVE 0x1 /* both directions */ +#define HCI_ACL_BROADCAST_PICONET 0x2 /* both directions */ + /* 11 - reserved for future use */ + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/HCI/btHCI_acl.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI_command.h =================================================================== --- haiku/trunk/headers/os/bluetooth/HCI/btHCI_command.h 2008-07-02 21:09:04 UTC (rev 26230) +++ haiku/trunk/headers/os/bluetooth/HCI/btHCI_command.h 2008-07-02 21:10:24 UTC (rev 26231) @@ -1,340 +1,340 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_COMMAND_H_ -#define _BTHCI_COMMAND_H_ - -#include -#include - -#define HCI_COMMAND_HDR_SIZE 3 - -struct hci_command_header { - uint16 opcode; /* OCF & OGF */ - uint8 clen; -} __attribute__ ((packed)); - - -/* Command opcode pack/unpack */ -#define PACK_OPCODE(ogf, ocf) (uint16)((ocf & 0x03ff)|(ogf << 10)) -#define GET_OPCODE_OGF(op) (op >> 10) -#define GET_OPCODE_OCF(op) (op & 0x03ff) - - -/* - Informational Parameters Command definition - */ -#define OGF_INFORMATIONAL_PARAM 0x04 - - #define OCF_READ_LOCAL_VERSION 0x0001 - struct hci_rp_read_loc_version { - uint8 status; - uint8 hci_ver; - uint16 hci_rev; - uint8 lmp_ver; - uint16 manufacturer; - uint16 lmp_subver; - } __attribute__ ((packed)); - - #define OCF_READ_LOCAL_FEATURES 0x0003 - struct hci_rp_read_loc_features { - uint8 status; - uint8 features[8]; - } __attribute__ ((packed)); - - #define OCF_READ_BUFFER_SIZE 0x0005 - struct hci_rp_read_buffer_size { - uint8 status; - uint16 acl_mtu; - uint8 sco_mtu; - uint16 acl_max_pkt; - uint16 sco_max_pkt; - } __attribute__ ((packed)); - - #define OCF_READ_BD_ADDR 0x0009 - struct hci_rp_read_bd_addr { - uint8 status; - bdaddr_t bdaddr; - } __attribute__ ((packed)); - -/* - Host Controller and Baseband Command definition - */ -#define OGF_CONTROL_BASEBAND 0x03 - - #define OCF_RESET 0x0003 - /*struct hci_reset { - void no_fields; - } __attribute__ ((packed));*/ - - #define OCF_SET_EVENT_FLT 0x0005 - struct hci_cp_set_event_flt { - uint8 flt_type; - uint8 cond_type; - uint8 condition[0]; - } __attribute__ ((packed)); - - #define OCF_READ_STORED_LINK_KEY 0x000D - struct hci_read_stored_link_key { - bdaddr_t bdaddr; - uint8 all_keys_flag; - } __attribute__ ((packed)); - struct hci_read_stored_link_key_reply { - uint8 status; - uint16 max_num_keys; - uint16 num_keys_read; - } __attribute__ ((packed)); - - #define OCF_WRITE_STORED_LINK_KEY 0x0011 - struct hci_write_stored_link_key { - uint8 num_keys_to_write; - // these are repeated "num_keys_write" times - bdaddr_t bdaddr; - uint8 key[HCI_LINK_KEY_SIZE]; - } __attribute__ ((packed)); - struct hci_write_stored_link_key_reply { - uint8 status; - uint8 num_keys_written; - } __attribute__ ((packed)); - - - #define OCF_WRITE_LOCAL_NAME 0x0013 - #define OCF_READ_LOCAL_NAME 0x0014 - struct hci_rp_read_local_name { - uint8 status; - char local_name[HCI_DEVICE_NAME_SIZE]; - } __attribute__ ((packed)); - - #define OCF_WRITE_CA_TIMEOUT 0x0016 - #define OCF_WRITE_PG_TIMEOUT 0x0018 - - #define OCF_WRITE_SCAN_ENABLE 0x001A - #define HCI_SCAN_DISABLED 0x00 - #define HCI_SCAN_INQUIRY 0x01 - #define HCI_SCAN_PAGE 0x02 - #define HCI_SCAN_INQUIRY_PAGE 0x03 - struct hci_write_scan_enable { - uint8 scan; - } __attribute__ ((packed)); - - #define OCF_READ_AUTH_ENABLE 0x001F - #define OCF_WRITE_AUTH_ENABLE 0x0020 - #define HCI_AUTH_DISABLED 0x00 - #define HCI_AUTH_ENABLED 0x01 - struct hci_write_authentication_enable { - uint8 authentication; - } __attribute__ ((packed)); - - #define OCF_READ_ENCRYPT_MODE 0x0021 - #define OCF_WRITE_ENCRYPT_MODE 0x0022 - #define HCI_ENCRYPT_DISABLED 0x00 - #define HCI_ENCRYPT_P2P 0x01 - #define HCI_ENCRYPT_BOTH 0x02 - struct hci_write_encryption_mode_enable { - uint8 encryption; - } __attribute__ ((packed)); - - /* Filter types */ - #define HCI_FLT_CLEAR_ALL 0x00 - #define HCI_FLT_INQ_RESULT 0x01 - #define HCI_FLT_CONN_SETUP 0x02 - - /* CONN_SETUP Condition types */ - #define HCI_CONN_SETUP_ALLOW_ALL 0x00 - #define HCI_CONN_SETUP_ALLOW_CLASS 0x01 - #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02 - - /* CONN_SETUP Conditions */ - #define HCI_CONN_SETUP_AUTO_OFF 0x01 - #define HCI_CONN_SETUP_AUTO_ON 0x02 - - #define OCF_READ_CLASS_OF_DEV 0x0023 - - struct hci_read_dev_class_reply { - uint8 status; - uint8 dev_class[3]; - } __attribute__ ((packed)); - - #define OCF_WRITE_CLASS_OF_DEV 0x0024 - struct hci_write_dev_class { - uint8 dev_class[3]; - } __attribute__ ((packed)); - - #define OCF_READ_VOICE_SETTING 0x0025 - struct hci_rp_read_voice_setting { - uint8 status; - uint16 voice_setting; - } __attribute__ ((packed)); - - #define OCF_WRITE_VOICE_SETTING 0x0026 - struct hci_cp_write_voice_setting { - uint16 voice_setting; - } __attribute__ ((packed)); - - #define OCF_HOST_BUFFER_SIZE 0x0033 - struct hci_cp_host_buffer_size { - uint16 acl_mtu; - uint8 sco_mtu; - uint16 acl_max_pkt; - uint16 sco_max_pkt; - } __attribute__ ((packed)); - - /* Link Control Command definition */ - #define OGF_LINK_CONTROL 0x01 - - #define OCF_INQUIRY 0x0001 - struct hci_cp_inquiry { - uint8 lap[3]; - uint8 length; - uint8 num_rsp; - } __attribute__ ((packed)); - - #define OCF_INQUIRY_CANCEL 0x0002 - - #define OCF_CREATE_CONN 0x0005 - struct hci_cp_create_conn { - bdaddr_t bdaddr; - uint16 pkt_type; - uint8 pscan_rep_mode; - uint8 pscan_mode; - uint16 clock_offset; - uint8 role_switch; - } __attribute__ ((packed)); - - #define OCF_DISCONNECT 0x0006 - struct hci_disconnect { - uint16 handle; - uint8 reason; - } __attribute__ ((packed)); - - #define OCF_ADD_SCO 0x0007 - struct hci_cp_add_sco { - uint16 handle; - uint16 pkt_type; - } __attribute__ ((packed)); - - #define OCF_ACCEPT_CONN_REQ 0x0009 - struct hci_cp_accept_conn_req { - bdaddr_t bdaddr; - uint8 role; - } __attribute__ ((packed)); - - #define OCF_REJECT_CONN_REQ 0x000a - struct hci_cp_reject_conn_req { - bdaddr_t bdaddr; - uint8 reason; - } __attribute__ ((packed)); - - #define OCF_LINK_KEY_REPLY 0x000B - struct hci_cp_link_key_reply { - bdaddr_t bdaddr; - uint8 link_key[16]; - } __attribute__ ((packed)); - - #define OCF_LINK_KEY_NEG_REPLY 0x000C - struct hci_cp_link_key_neg_reply { - bdaddr_t bdaddr; - } __attribute__ ((packed)); - - #define OCF_PIN_CODE_REPLY 0x000D - struct hci_cp_pin_code_reply { - bdaddr_t bdaddr; - uint8 pin_len; - uint8 pin_code[HCI_PIN_SIZE]; - } __attribute__ ((packed)); - - #define OCF_PIN_CODE_NEG_REPLY 0x000E - struct hci_cp_pin_code_neg_reply { - bdaddr_t bdaddr; - } __attribute__ ((packed)); - - #define OCF_CHANGE_CONN_PTYPE 0x000F - struct hci_cp_change_conn_ptype { - uint16 handle; - uint16 pkt_type; - } __attribute__ ((packed)); - - #define OCF_AUTH_REQUESTED 0x0011 - struct hci_cp_auth_requested { - uint16 handle; - } __attribute__ ((packed)); - - #define OCF_SET_CONN_ENCRYPT 0x0013 - struct hci_cp_set_conn_encrypt { - uint16 handle; - uint8 encrypt; - } __attribute__ ((packed)); - - #define OCF_CHANGE_CONN_LINK_KEY 0x0015 - struct hci_cp_change_conn_link_key { - uint16 handle; - } __attribute__ ((packed)); - - #define OCF_REMOTE_NAME_REQUEST 0x0019 - struct hci_remote_name_request { - bdaddr_t bdaddr; - uint8 pscan_rep_mode; - uint8 reserved; - uint16 clock_offset; - } __attribute__ ((packed)); - - #define OCF_READ_REMOTE_FEATURES 0x001B - struct hci_cp_read_rmt_features { - uint16 handle; - } __attribute__ ((packed)); - - #define OCF_READ_REMOTE_VERSION 0x001D - struct hci_cp_read_rmt_version { - uint16 handle; - } __attribute__ ((packed)); - - -/* Link Policy Command definition */ -#define OGF_LINK_POLICY 0x02 - - #define OCF_ROLE_DISCOVERY 0x0009 - struct hci_cp_role_discovery { - uint16 handle; - } __attribute__ ((packed)); - struct hci_rp_role_discovery { - uint8 status; - uint16 handle; - uint8 role; - } __attribute__ ((packed)); - - #define OCF_READ_LINK_POLICY 0x000C - struct hci_cp_read_link_policy { - uint16 handle; - } __attribute__ ((packed)); - struct hci_rp_read_link_policy { - uint8 status; - uint16 handle; - uint16 policy; - } __attribute__ ((packed)); - - #define OCF_SWITCH_ROLE 0x000B - struct hci_cp_switch_role { - bdaddr_t bdaddr; - uint8 role; - } __attribute__ ((packed)); - - #define OCF_WRITE_LINK_POLICY 0x000D - struct hci_cp_write_link_policy { - uint16 handle; - uint16 policy; - } __attribute__ ((packed)); - struct hci_rp_write_link_policy { - uint8 status; - uint16 handle; - } __attribute__ ((packed)); - -/* Status params */ -#define OGF_STATUS_PARAM 0x05 - -/* Testing commands */ -#define OGF_TESTING_CMD 0x3E - -/* Vendor specific commands */ -#define OGF_VENDOR_CMD 0x3F - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTHCI_COMMAND_H_ +#define _BTHCI_COMMAND_H_ + +#include +#include + +#define HCI_COMMAND_HDR_SIZE 3 + +struct hci_command_header { + uint16 opcode; /* OCF & OGF */ + uint8 clen; +} __attribute__ ((packed)); + + +/* Command opcode pack/unpack */ +#define PACK_OPCODE(ogf, ocf) (uint16)((ocf & 0x03ff)|(ogf << 10)) +#define GET_OPCODE_OGF(op) (op >> 10) +#define GET_OPCODE_OCF(op) (op & 0x03ff) + + +/* - Informational Parameters Command definition - */ +#define OGF_INFORMATIONAL_PARAM 0x04 + + #define OCF_READ_LOCAL_VERSION 0x0001 + struct hci_rp_read_loc_version { + uint8 status; + uint8 hci_ver; + uint16 hci_rev; + uint8 lmp_ver; + uint16 manufacturer; + uint16 lmp_subver; + } __attribute__ ((packed)); + + #define OCF_READ_LOCAL_FEATURES 0x0003 + struct hci_rp_read_loc_features { + uint8 status; + uint8 features[8]; + } __attribute__ ((packed)); + + #define OCF_READ_BUFFER_SIZE 0x0005 + struct hci_rp_read_buffer_size { + uint8 status; + uint16 acl_mtu; + uint8 sco_mtu; + uint16 acl_max_pkt; + uint16 sco_max_pkt; + } __attribute__ ((packed)); + + #define OCF_READ_BD_ADDR 0x0009 + struct hci_rp_read_bd_addr { + uint8 status; + bdaddr_t bdaddr; + } __attribute__ ((packed)); + +/* - Host Controller and Baseband Command definition - */ +#define OGF_CONTROL_BASEBAND 0x03 + + #define OCF_RESET 0x0003 + /*struct hci_reset { + void no_fields; + } __attribute__ ((packed));*/ + + #define OCF_SET_EVENT_FLT 0x0005 + struct hci_cp_set_event_flt { + uint8 flt_type; + uint8 cond_type; + uint8 condition[0]; + } __attribute__ ((packed)); + + #define OCF_READ_STORED_LINK_KEY 0x000D + struct hci_read_stored_link_key { + bdaddr_t bdaddr; + uint8 all_keys_flag; + } __attribute__ ((packed)); + struct hci_read_stored_link_key_reply { + uint8 status; + uint16 max_num_keys; + uint16 num_keys_read; + } __attribute__ ((packed)); + + #define OCF_WRITE_STORED_LINK_KEY 0x0011 + struct hci_write_stored_link_key { + uint8 num_keys_to_write; + // these are repeated "num_keys_write" times + bdaddr_t bdaddr; + uint8 key[HCI_LINK_KEY_SIZE]; + } __attribute__ ((packed)); + struct hci_write_stored_link_key_reply { + uint8 status; + uint8 num_keys_written; + } __attribute__ ((packed)); + + + #define OCF_WRITE_LOCAL_NAME 0x0013 + #define OCF_READ_LOCAL_NAME 0x0014 + struct hci_rp_read_local_name { + uint8 status; + char local_name[HCI_DEVICE_NAME_SIZE]; + } __attribute__ ((packed)); + + #define OCF_WRITE_CA_TIMEOUT 0x0016 + #define OCF_WRITE_PG_TIMEOUT 0x0018 + + #define OCF_WRITE_SCAN_ENABLE 0x001A + #define HCI_SCAN_DISABLED 0x00 + #define HCI_SCAN_INQUIRY 0x01 + #define HCI_SCAN_PAGE 0x02 + #define HCI_SCAN_INQUIRY_PAGE 0x03 + struct hci_write_scan_enable { + uint8 scan; + } __attribute__ ((packed)); + + #define OCF_READ_AUTH_ENABLE 0x001F + #define OCF_WRITE_AUTH_ENABLE 0x0020 + #define HCI_AUTH_DISABLED 0x00 + #define HCI_AUTH_ENABLED 0x01 + struct hci_write_authentication_enable { + uint8 authentication; + } __attribute__ ((packed)); + + #define OCF_READ_ENCRYPT_MODE 0x0021 + #define OCF_WRITE_ENCRYPT_MODE 0x0022 + #define HCI_ENCRYPT_DISABLED 0x00 + #define HCI_ENCRYPT_P2P 0x01 + #define HCI_ENCRYPT_BOTH 0x02 + struct hci_write_encryption_mode_enable { + uint8 encryption; + } __attribute__ ((packed)); + + /* Filter types */ + #define HCI_FLT_CLEAR_ALL 0x00 + #define HCI_FLT_INQ_RESULT 0x01 + #define HCI_FLT_CONN_SETUP 0x02 + + /* CONN_SETUP Condition types */ + #define HCI_CONN_SETUP_ALLOW_ALL 0x00 + #define HCI_CONN_SETUP_ALLOW_CLASS 0x01 + #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02 + + /* CONN_SETUP Conditions */ + #define HCI_CONN_SETUP_AUTO_OFF 0x01 + #define HCI_CONN_SETUP_AUTO_ON 0x02 + + #define OCF_READ_CLASS_OF_DEV 0x0023 + + struct hci_read_dev_class_reply { + uint8 status; + uint8 dev_class[3]; + } __attribute__ ((packed)); + + #define OCF_WRITE_CLASS_OF_DEV 0x0024 + struct hci_write_dev_class { + uint8 dev_class[3]; + } __attribute__ ((packed)); + + #define OCF_READ_VOICE_SETTING 0x0025 + struct hci_rp_read_voice_setting { + uint8 status; + uint16 voice_setting; + } __attribute__ ((packed)); + + #define OCF_WRITE_VOICE_SETTING 0x0026 + struct hci_cp_write_voice_setting { + uint16 voice_setting; + } __attribute__ ((packed)); + + #define OCF_HOST_BUFFER_SIZE 0x0033 + struct hci_cp_host_buffer_size { + uint16 acl_mtu; + uint8 sco_mtu; + uint16 acl_max_pkt; + uint16 sco_max_pkt; + } __attribute__ ((packed)); + + /* Link Control Command definition */ + #define OGF_LINK_CONTROL 0x01 + + #define OCF_INQUIRY 0x0001 + struct hci_cp_inquiry { + uint8 lap[3]; + uint8 length; + uint8 num_rsp; + } __attribute__ ((packed)); + + #define OCF_INQUIRY_CANCEL 0x0002 + + #define OCF_CREATE_CONN 0x0005 + struct hci_cp_create_conn { + bdaddr_t bdaddr; + uint16 pkt_type; + uint8 pscan_rep_mode; + uint8 pscan_mode; + uint16 clock_offset; + uint8 role_switch; + } __attribute__ ((packed)); + + #define OCF_DISCONNECT 0x0006 + struct hci_disconnect { + uint16 handle; + uint8 reason; + } __attribute__ ((packed)); + + #define OCF_ADD_SCO 0x0007 + struct hci_cp_add_sco { + uint16 handle; + uint16 pkt_type; + } __attribute__ ((packed)); + + #define OCF_ACCEPT_CONN_REQ 0x0009 + struct hci_cp_accept_conn_req { + bdaddr_t bdaddr; + uint8 role; + } __attribute__ ((packed)); + + #define OCF_REJECT_CONN_REQ 0x000a + struct hci_cp_reject_conn_req { + bdaddr_t bdaddr; + uint8 reason; + } __attribute__ ((packed)); + + #define OCF_LINK_KEY_REPLY 0x000B + struct hci_cp_link_key_reply { + bdaddr_t bdaddr; + uint8 link_key[16]; + } __attribute__ ((packed)); + + #define OCF_LINK_KEY_NEG_REPLY 0x000C + struct hci_cp_link_key_neg_reply { + bdaddr_t bdaddr; + } __attribute__ ((packed)); + + #define OCF_PIN_CODE_REPLY 0x000D + struct hci_cp_pin_code_reply { + bdaddr_t bdaddr; + uint8 pin_len; + uint8 pin_code[HCI_PIN_SIZE]; + } __attribute__ ((packed)); + + #define OCF_PIN_CODE_NEG_REPLY 0x000E + struct hci_cp_pin_code_neg_reply { + bdaddr_t bdaddr; + } __attribute__ ((packed)); + + #define OCF_CHANGE_CONN_PTYPE 0x000F + struct hci_cp_change_conn_ptype { + uint16 handle; + uint16 pkt_type; + } __attribute__ ((packed)); + + #define OCF_AUTH_REQUESTED 0x0011 + struct hci_cp_auth_requested { + uint16 handle; + } __attribute__ ((packed)); + + #define OCF_SET_CONN_ENCRYPT 0x0013 + struct hci_cp_set_conn_encrypt { + uint16 handle; + uint8 encrypt; + } __attribute__ ((packed)); + + #define OCF_CHANGE_CONN_LINK_KEY 0x0015 + struct hci_cp_change_conn_link_key { + uint16 handle; + } __attribute__ ((packed)); + + #define OCF_REMOTE_NAME_REQUEST 0x0019 + struct hci_remote_name_request { + bdaddr_t bdaddr; + uint8 pscan_rep_mode; + uint8 reserved; + uint16 clock_offset; + } __attribute__ ((packed)); + + #define OCF_READ_REMOTE_FEATURES 0x001B + struct hci_cp_read_rmt_features { + uint16 handle; + } __attribute__ ((packed)); + + #define OCF_READ_REMOTE_VERSION 0x001D + struct hci_cp_read_rmt_version { + uint16 handle; + } __attribute__ ((packed)); + + +/* Link Policy Command definition */ +#define OGF_LINK_POLICY 0x02 + + #define OCF_ROLE_DISCOVERY 0x0009 + struct hci_cp_role_discovery { + uint16 handle; + } __attribute__ ((packed)); + struct hci_rp_role_discovery { + uint8 status; + uint16 handle; + uint8 role; + } __attribute__ ((packed)); + + #define OCF_READ_LINK_POLICY 0x000C + struct hci_cp_read_link_policy { + uint16 handle; + } __attribute__ ((packed)); + struct hci_rp_read_link_policy { + uint8 status; + uint16 handle; + uint16 policy; + } __attribute__ ((packed)); + + #define OCF_SWITCH_ROLE 0x000B + struct hci_cp_switch_role { + bdaddr_t bdaddr; + uint8 role; + } __attribute__ ((packed)); + + #define OCF_WRITE_LINK_POLICY 0x000D + struct hci_cp_write_link_policy { + uint16 handle; + uint16 policy; + } __attribute__ ((packed)); + struct hci_rp_write_link_policy { + uint8 status; + uint16 handle; + } __attribute__ ((packed)); + +/* Status params */ +#define OGF_STATUS_PARAM 0x05 + +/* Testing commands */ +#define OGF_TESTING_CMD 0x3E + +/* Vendor specific commands */ +#define OGF_VENDOR_CMD 0x3F + +#endif Property changes on: haiku/trunk/headers/os/bluetooth/HCI/btHCI_command.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI_event.h =================================================================== --- haiku/trunk/headers/os/bluetooth/HCI/btHCI_event.h 2008-07-02 21:09:04 UTC (rev 26230) +++ haiku/trunk/headers/os/bluetooth/HCI/btHCI_event.h 2008-07-02 21:10:24 UTC (rev 26231) @@ -1,331 +1,331 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_EVENT_H_ -#define _BTHCI_EVENT_H_ - -#include -#include - -#define HCI_EVENT_HDR_SIZE 2 - -struct hci_event_header { - uint8 ecode; - uint8 elen; -} __attribute__ ((packed)); - - -/* ---- HCI Events ---- */ -#define HCI_EVENT_INQUIRY_COMPLETE 0x01 - -#define HCI_EVENT_INQUIRY_RESULT 0x02 -struct inquiry_info { - bdaddr_t bdaddr; - uint8 pscan_rep_mode; - uint8 pscan_period_mode; - uint8 pscan_mode; - uint8 dev_class[3]; - uint16 clock_offset; -} __attribute__ ((packed)); - -#define HCI_EVENT_CONN_COMPLETE 0x03 -struct hci_ev_conn_complete { - uint8 status; - uint16 handle; - bdaddr_t bdaddr; - uint8 link_type; - uint8 encrypt_mode; -} __attribute__ ((packed)); - -#define HCI_EVENT_CONN_REQUEST 0x04 -struct hci_ev_conn_request { - bdaddr_t bdaddr; - uint8 dev_class[3]; - uint8 link_type; -} __attribute__ ((packed)); - -#define HCI_EVENT_DISCONNECTION_COMPLETE 0x05 -struct hci_disconnection_complete_reply { - uint8 status; - uint16 handle; - uint8 reason; -} __attribute__ ((packed)); - -#define HCI_EVENT_AUTH_COMPLETE 0x06 -struct hci_ev_auth_complete { - uint8 status; - uint16 handle; -} __attribute__ ((packed)); - -#define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07 -struct hci_remote_name_request_complete_reply { - uint8 status; - bdaddr_t bdaddr; - char remote_name[248]; -} __attribute__ ((packed)); - -#define HCI_EVENT_ENCRYPT_CHANGE 0x08 -struct hci_ev_encrypt_change { - uint8 status; - uint16 handle; - uint8 encrypt; -} __attribute__ ((packed)); - -#define HCI_EVENT_CHANGE_CONN_LINK_KEY_COMPLETE 0x09 -struct hci_ev_change_conn_link_key_complete { - uint8 status; - uint16 handle; -} __attribute__ ((packed)); - -#define HCI_EVENT_MASTER_LINK_KEY_COMPL 0x0a -struct hci_ev_master_link_key_complete { - uint8 status; /* 0x00 - success */ - uint16 handle; /* Connection handle */ - uint8 key_flag; /* Key flag */ -} __attribute__ ((packed)); - -#define HCI_EVENT_RMT_FEATURES 0x0B -struct hci_ev_rmt_features { - uint8 status; - uint16 handle; - uint8 features[8]; -} __attribute__ ((packed)); - -#define HCI_EVENT_RMT_VERSION 0x0C -struct hci_ev_rmt_version { - uint8 status; - uint16 handle; - uint8 lmp_ver; - uint16 manufacturer; - uint16 lmp_subver; -} __attribute__ ((packed)); - -#define HCI_EVENT_QOS_SETUP_COMPLETE 0x0D -struct hci_qos { - uint8 service_type; - uint32 token_rate; - uint32 peak_bandwidth; - uint32 latency; - uint32 delay_variation; -} __attribute__ ((packed)); -struct hci_ev_qos_setup_complete { - uint8 status; - uint16 handle; - struct hci_qos qos; -} __attribute__ ((packed)); [... truncated: 854 lines follow ...] From oruizdorantes at mail.berlios.de Wed Jul 2 23:12:11 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:12:11 +0200 Subject: [Haiku-commits] r26232 - haiku/trunk/headers/os/bluetooth/L2CAP Message-ID: <200807022112.m62LCBDp024011@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:12:07 +0200 (Wed, 02 Jul 2008) New Revision: 26232 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26232&view=rev Modified: haiku/trunk/headers/os/bluetooth/L2CAP/btL2CAP.h Log: Fix EOL Modified: haiku/trunk/headers/os/bluetooth/L2CAP/btL2CAP.h =================================================================== --- haiku/trunk/headers/os/bluetooth/L2CAP/btL2CAP.h 2008-07-02 21:10:24 UTC (rev 26231) +++ haiku/trunk/headers/os/bluetooth/L2CAP/btL2CAP.h 2008-07-02 21:12:07 UTC (rev 26232) @@ -1,21 +1,21 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTL2CAP_H_ -#define _BTL2CAP_H_ - -#include - -struct sockaddr_l2cap { - uint8 l2cap_len; /* total length */ - uint8 l2cap_family; /* address family */ - uint16 l2cap_psm; /* PSM (Protocol/Service Multiplexor) */ - bdaddr_t l2cap_bdaddr; /* address */ -}; - - +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTL2CAP_H_ +#define _BTL2CAP_H_ + +#include + +struct sockaddr_l2cap { + uint8 l2cap_len; /* total length */ + uint8 l2cap_family; /* address family */ + uint16 l2cap_psm; /* PSM (Protocol/Service Multiplexor) */ + bdaddr_t l2cap_bdaddr; /* address */ +}; + + #endif \ No newline at end of file Property changes on: haiku/trunk/headers/os/bluetooth/L2CAP/btL2CAP.h ___________________________________________________________________ Name: svn:eol-style + native From oruizdorantes at mail.berlios.de Wed Jul 2 23:18:49 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:18:49 +0200 Subject: [Haiku-commits] r26233 - haiku/trunk/headers/private/bluetooth Message-ID: <200807022118.m62LInAF024291@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:18:43 +0200 (Wed, 02 Jul 2008) New Revision: 26233 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26233&view=rev Modified: haiku/trunk/headers/private/bluetooth/CommandManager.h haiku/trunk/headers/private/bluetooth/ConnectionIncoming.h haiku/trunk/headers/private/bluetooth/PincodeWindow.h haiku/trunk/headers/private/bluetooth/bluetoothserver_p.h haiku/trunk/headers/private/bluetooth/btDebug.h Log: Fix EOL Property changes on: haiku/trunk/headers/private/bluetooth/CommandManager.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/headers/private/bluetooth/ConnectionIncoming.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/headers/private/bluetooth/PincodeWindow.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/headers/private/bluetooth/bluetoothserver_p.h ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/headers/private/bluetooth/btDebug.h ___________________________________________________________________ Name: svn:eol-style + native From oruizdorantes at mail.berlios.de Wed Jul 2 23:26:44 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:26:44 +0200 Subject: [Haiku-commits] r26234 - haiku/trunk/src/kits/bluetooth/UI Message-ID: <200807022126.m62LQiCL024753@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:26:41 +0200 (Wed, 02 Jul 2008) New Revision: 26234 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26234&view=rev Modified: haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp Log: Fix EOL Property changes on: haiku/trunk/src/kits/bluetooth/UI/ConnectionIncoming.cpp ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/kits/bluetooth/UI/PincodeWindow.cpp ___________________________________________________________________ Name: svn:eol-style + native From oruizdorantes at mail.berlios.de Wed Jul 2 23:33:06 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 2 Jul 2008 23:33:06 +0200 Subject: [Haiku-commits] r26235 - in haiku/trunk/src/add-ons/kernel/drivers/bluetooth: . h2 h2/h2generic Message-ID: <200807022133.m62LX6hG025643@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-02 23:32:59 +0200 (Wed, 02 Jul 2008) New Revision: 26235 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26235&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/Jamfile haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/Jamfile haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/Jamfile Log: Fix EOL, last one... sorry for the eolspam Property changes on: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/Jamfile ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/Jamfile ___________________________________________________________________ Name: svn:eol-style + native Property changes on: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/Jamfile ___________________________________________________________________ Name: svn:eol-style + native From axeld at mail.berlios.de Thu Jul 3 00:03:05 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 3 Jul 2008 00:03:05 +0200 Subject: [Haiku-commits] r26236 - haiku/trunk/src/system/libroot/posix/string Message-ID: <200807022203.m62M35SP029162@sheep.berlios.de> Author: axeld Date: 2008-07-03 00:03:04 +0200 (Thu, 03 Jul 2008) New Revision: 26236 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26236&view=rev Modified: haiku/trunk/src/system/libroot/posix/string/strlwr.c haiku/trunk/src/system/libroot/posix/string/strupr.c Log: * Fixed coding style. * Since there is no "Haiku license", I replaced that with a reference to the MIT license as usual. Modified: haiku/trunk/src/system/libroot/posix/string/strlwr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strlwr.c 2008-07-02 21:32:59 UTC (rev 26235) +++ haiku/trunk/src/system/libroot/posix/string/strlwr.c 2008-07-02 22:03:04 UTC (rev 26236) @@ -1,7 +1,7 @@ /* -** Copyright 2008, Mika Lindqvist. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ + * Copyright 2008, Mika Lindqvist. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include @@ -10,10 +10,11 @@ strlwr(char *str) { char *c = str; - while(*c) { + while (*c) { *c = tolower(*c); c++; } - return(str); + + return str; } Modified: haiku/trunk/src/system/libroot/posix/string/strupr.c =================================================================== --- haiku/trunk/src/system/libroot/posix/string/strupr.c 2008-07-02 21:32:59 UTC (rev 26235) +++ haiku/trunk/src/system/libroot/posix/string/strupr.c 2008-07-02 22:03:04 UTC (rev 26236) @@ -1,7 +1,7 @@ /* -** Copyright 2008, Mika Lindqvist. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ + * Copyright 2008, Mika Lindqvist. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include #include @@ -10,10 +10,11 @@ strupr(char *str) { char *c = str; - while(*c) { + while (*c) { *c = toupper(*c); c++; } - return(str); + + return str; } From mmlr at mail.berlios.de Thu Jul 3 03:44:38 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Thu, 3 Jul 2008 03:44:38 +0200 Subject: [Haiku-commits] r26237 - haiku/trunk/src/system/kernel Message-ID: <200807030144.m631icEk010982@sheep.berlios.de> Author: mmlr Date: 2008-07-03 03:44:35 +0200 (Thu, 03 Jul 2008) New Revision: 26237 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26237&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Another partial rewrite of the kernel heap. There are no heap lists anymore, there is only one heap_allocator for each heap class. Instead of adding complete allocators, individual areas can now be added to existing allocators. This removes a lot of complexity in the frontend code and avoids the previous duplications wasting resources (allocator lock, bin sizes, bin list). The pages are now managed in heap_area structures that are attached to areas. They store the page table, page free lists and local variables. The same mechanism as used for heap_pages is now used for heap_areas too, i.e. they are kept in a sorted list where the fullest but not yet completely full area is always at the top. This favors areas to become completely full and other, not as frequently used areas, to become completely empty over time so they can be freed. Full areas are removed from the list, so they do not need to be looked at/skipped when allocating new pages. Through this mechanism and as there are no allocator lists anymore that grow bigger over time, allocations should be far more scalable. Note that actually removing areas once they are not needed anymore is still not implemented, but it is now a relatively easy addition whereas previously it would have killed the whole design. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-02 22:03:04 UTC (rev 26236) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-03 01:44:35 UTC (rev 26237) @@ -60,7 +60,27 @@ static int32 sCallerInfoCount = 0; #endif +typedef struct heap_page_s heap_page; + +typedef struct heap_area_s { + area_id area; + + addr_t base; + size_t size; + + uint32 page_count; + uint32 free_page_count; + + heap_page * free_pages; + heap_page * page_table; + + heap_area_s * prev; + heap_area_s * next; + heap_area_s * all_next; +} heap_area; + typedef struct heap_page_s { + heap_area * area; uint16 index; uint16 bin_index : 5; uint16 free_count : 10; @@ -81,20 +101,17 @@ } heap_bin; typedef struct heap_allocator_s { - addr_t base; - size_t size; mutex lock; - + uint32 heap_class; uint32 bin_count; - uint32 page_count; uint32 page_size; - uint32 free_page_count; - heap_page * free_pages; + uint32 total_pages; + uint32 total_free_pages; + heap_bin * bins; - heap_page * page_table; - - heap_allocator_s * next; + heap_area * areas; // sorted so that the desired area is always first + heap_area * all_areas; // all areas including full ones } heap_allocator; typedef struct heap_class_s { @@ -137,8 +154,9 @@ }; static heap_allocator *sHeapList[HEAP_CLASS_COUNT]; -static heap_allocator *sLastGrowRequest[HEAP_CLASS_COUNT]; -static heap_allocator *sGrowHeapList = NULL; +static uint32 *sLastGrowRequest[HEAP_CLASS_COUNT]; +static uint32 *sLastHandledGrowRequest[HEAP_CLASS_COUNT]; +static heap_allocator *sGrowHeap = NULL; static thread_id sHeapGrowThread = -1; static sem_id sHeapGrowSem = -1; static sem_id sHeapGrownNotify = -1; @@ -272,57 +290,62 @@ static void -dump_allocator(heap_allocator *heap) +dump_bin_list(heap_allocator *heap) { - dprintf("allocator %p: base: 0x%08lx; size: %lu; bin_count: %lu; free_pages: %p (%lu entr%s)\n", - heap, heap->base, heap->size, heap->bin_count, heap->free_pages, - heap->free_page_count, heap->free_page_count == 1 ? "y" : "ies"); - for (uint32 i = 0; i < heap->bin_count; i++) dump_bin(&heap->bins[i]); + dprintf("\n"); +} + +static void +dump_allocator_areas(heap_allocator *heap) +{ + heap_area *area = heap->all_areas; + while (area) { + dprintf("\tarea %p: area: %ld; base: 0x%08lx; size: %lu; free_pages: %p (%lu entr%s)\n", + area, area->area, area->base, area->size, area->free_pages, + area->free_page_count, area->free_page_count == 1 ? "y" : "ies"); + area = area->all_next; + } + dprintf("\n"); } +static void +dump_allocator(heap_allocator *heap, bool areas, bool bins) +{ + dprintf("allocator %p: class: %s; page_size: %lu; bin_count: %lu; pages: %lu; free: %lu\n", heap, + sHeapClasses[heap->heap_class].name, heap->page_size, heap->bin_count, + heap->total_pages, heap->total_free_pages); + + if (areas) + dump_allocator_areas(heap); + if (bins) + dump_bin_list(heap); +} + + static int dump_heap_list(int argc, char **argv) { if (argc == 2) { if (strcmp(argv[1], "grow") == 0) { // only dump dedicated grow heap info - dprintf("dedicated grow heap(s):\n"); - heap_allocator *heap = sGrowHeapList; - while (heap) { - dump_allocator(heap); - heap = heap->next; - } + dprintf("dedicated grow heap:\n"); + dump_allocator(sGrowHeap, true, true); } else if (strcmp(argv[1], "stats") == 0) { - for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - uint32 heapCount = 0; - heap_allocator *heap = sHeapList[i]; - while (heap) { - heapCount++; - heap = heap->next; - } - - dprintf("current %s heap count: %ld\n", sHeapClasses[i].name, - heapCount); - } + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) + dump_allocator(sHeapList[i], false, false); } else print_debugger_command_usage(argv[0]); return 0; } - for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - dprintf("dumping list of %s heaps\n", sHeapClasses[i].name); - heap_allocator *heap = sHeapList[i]; - while (heap) { - dump_allocator(heap); - heap = heap->next; - } - } + for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) + dump_allocator(sHeapList[i], true, true); return 0; } @@ -354,86 +377,88 @@ size_t totalSize = 0; uint32 totalCount = 0; - uint32 heapClassIndex = 0; - heap_allocator *heap = sHeapList[0]; - while (heap) { - // go through all the pages - heap_leak_check_info *info = NULL; - for (uint32 i = 0; i < heap->page_count; i++) { - heap_page *page = &heap->page_table[i]; - if (!page->in_use) - continue; + for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) { + heap_allocator *heap = sHeapList[classIndex]; - addr_t base = heap->base + i * heap->page_size; - if (page->bin_index < heap->bin_count) { - // page is used by a small allocation bin - uint32 elementCount = page->empty_index; - size_t elementSize = heap->bins[page->bin_index].element_size; - for (uint32 j = 0; j < elementCount; j++, base += elementSize) { - // walk the free list to see if this element is in use - bool elementInUse = true; - for (addr_t *temp = page->free_list; temp != NULL; temp = (addr_t *)*temp) { - if ((addr_t)temp == base) { - elementInUse = false; - break; + // go through all the pages in all the areas + heap_area *area = heap->all_areas; + while (area) { + heap_leak_check_info *info = NULL; + for (uint32 i = 0; i < area->page_count; i++) { + heap_page *page = &area->page_table[i]; + if (!page->in_use) + continue; + + addr_t base = area->base + i * heap->page_size; + if (page->bin_index < heap->bin_count) { + // page is used by a small allocation bin + uint32 elementCount = page->empty_index; + size_t elementSize = heap->bins[page->bin_index].element_size; + for (uint32 j = 0; j < elementCount; j++, base += elementSize) { + // walk the free list to see if this element is in use + bool elementInUse = true; + for (addr_t *temp = page->free_list; temp != NULL; temp = (addr_t *)*temp) { + if ((addr_t)temp == base) { + elementInUse = false; + break; + } } + + if (!elementInUse) + continue; + + info = (heap_leak_check_info *)(base + elementSize + - sizeof(heap_leak_check_info)); + + if ((team == -1 || info->team == team) + && (thread == -1 || info->thread == thread) + && (caller == 0 || info->caller == caller)) { + // interesting... + if (!statsOnly) { + dprintf("team: % 6ld; thread: % 6ld; " + "address: 0x%08lx; size: %lu bytes; " + "caller: %#lx\n", info->team, info->thread, + base, info->size, info->caller); + } + + totalSize += info->size; + totalCount++; + } } + } else { + // page is used by a big allocation, find the page count + uint32 pageCount = 1; + while (i + pageCount < area->page_count + && area->page_table[i + pageCount].in_use + && area->page_table[i + pageCount].bin_index == heap->bin_count + && area->page_table[i + pageCount].allocation_id == page->allocation_id) + pageCount++; - if (!elementInUse) - continue; + info = (heap_leak_check_info *)(base + pageCount + * heap->page_size - sizeof(heap_leak_check_info)); - info = (heap_leak_check_info *)(base + elementSize - - sizeof(heap_leak_check_info)); - if ((team == -1 || info->team == team) && (thread == -1 || info->thread == thread) && (caller == 0 || info->caller == caller)) { // interesting... if (!statsOnly) { - dprintf("team: % 6ld; thread: % 6ld; " - "address: 0x%08lx; size: %lu bytes, " - "caller: %#lx\n", info->team, info->thread, + dprintf("team: % 6ld; thread: % 6ld;" + " address: 0x%08lx; size: %lu bytes;" + " caller: %#lx\n", info->team, info->thread, base, info->size, info->caller); } totalSize += info->size; totalCount++; } - } - } else { - // page is used by a big allocation, find the page count - uint32 pageCount = 1; - while (i + pageCount < heap->page_count - && heap->page_table[i + pageCount].in_use - && heap->page_table[i + pageCount].bin_index == heap->bin_count - && heap->page_table[i + pageCount].allocation_id == page->allocation_id) - pageCount++; - info = (heap_leak_check_info *)(base + pageCount - * heap->page_size - sizeof(heap_leak_check_info)); - - if ((team == -1 || info->team == team) - && (thread == -1 || info->thread == thread) - && (caller == 0 || info->caller == caller)) { - // interesting... - if (!statsOnly) { - dprintf("team: % 6ld; thread: % 6ld; address: 0x%08lx;" - " size: %lu bytes, caller: %#lx\n", info->team, - info->thread, base, info->size, info->caller); - } - - totalSize += info->size; - totalCount++; + // skip the allocated pages + i += pageCount - 1; } + } - // skip the allocated pages - i += pageCount - 1; - } + area = area->all_next; } - - heap = heap->next; - if (heap == NULL && ++heapClassIndex < HEAP_CLASS_COUNT) - heap = sHeapList[heapClassIndex]; } dprintf("total allocations: %lu; total bytes: %lu\n", totalCount, totalSize); @@ -497,38 +522,61 @@ sCallerInfoCount = 0; - uint32 heapClassIndex = 0; - heap_allocator *heap = sHeapList[0]; - while (heap) { - // go through all the pages - heap_leak_check_info *info = NULL; - for (uint32 i = 0; i < heap->page_count; i++) { - heap_page *page = &heap->page_table[i]; - if (!page->in_use) - continue; + for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) { + heap_allocator *heap = sHeapList[classIndex]; - addr_t base = heap->base + i * heap->page_size; - if (page->bin_index < heap->bin_count) { - // page is used by a small allocation bin - uint32 elementCount = page->empty_index; - size_t elementSize = heap->bins[page->bin_index].element_size; - for (uint32 j = 0; j < elementCount; j++, base += elementSize) { - // walk the free list to see if this element is in use - bool elementInUse = true; - for (addr_t *temp = page->free_list; temp != NULL; + // go through all the pages in all the areas + heap_area *area = heap->all_areas; + while (area) { + heap_leak_check_info *info = NULL; + for (uint32 i = 0; i < area->page_count; i++) { + heap_page *page = &area->page_table[i]; + if (!page->in_use) + continue; + + addr_t base = area->base + i * heap->page_size; + if (page->bin_index < heap->bin_count) { + // page is used by a small allocation bin + uint32 elementCount = page->empty_index; + size_t elementSize = heap->bins[page->bin_index].element_size; + for (uint32 j = 0; j < elementCount; j++, base += elementSize) { + // walk the free list to see if this element is in use + bool elementInUse = true; + for (addr_t *temp = page->free_list; temp != NULL; temp = (addr_t *)*temp) { - if ((addr_t)temp == base) { - elementInUse = false; - break; + if ((addr_t)temp == base) { + elementInUse = false; + break; + } } + + if (!elementInUse) + continue; + + info = (heap_leak_check_info *)(base + elementSize + - sizeof(heap_leak_check_info)); + + caller_info* callerInfo = get_caller_info(info->caller); + if (callerInfo == NULL) { + kprintf("out of space for caller infos\n"); + return 0; + } + + callerInfo->count++; + callerInfo->size += info->size; } + } else { + // page is used by a big allocation, find the page count + uint32 pageCount = 1; + while (i + pageCount < area->page_count + && area->page_table[i + pageCount].in_use + && area->page_table[i + pageCount].bin_index == heap->bin_count + && area->page_table[i + pageCount].allocation_id == page->allocation_id) + pageCount++; - if (!elementInUse) - continue; + info = (heap_leak_check_info *)(base + pageCount + * heap->page_size - sizeof(heap_leak_check_info)); - info = (heap_leak_check_info *)(base + elementSize - - sizeof(heap_leak_check_info)); - caller_info* callerInfo = get_caller_info(info->caller); if (callerInfo == NULL) { kprintf("out of space for caller infos\n"); @@ -537,36 +585,14 @@ callerInfo->count++; callerInfo->size += info->size; - } - } else { - // page is used by a big allocation, find the page count - uint32 pageCount = 1; - while (i + pageCount < heap->page_count - && heap->page_table[i + pageCount].in_use - && heap->page_table[i + pageCount].bin_index == heap->bin_count - && heap->page_table[i + pageCount].allocation_id == page->allocation_id) - pageCount++; - info = (heap_leak_check_info *)(base + pageCount - * heap->page_size - sizeof(heap_leak_check_info)); - - caller_info* callerInfo = get_caller_info(info->caller); - if (callerInfo == NULL) { - kprintf("out of space for caller infos\n"); - return 0; + // skip the allocated pages + i += pageCount - 1; } + } - callerInfo->count++; - callerInfo->size += info->size; - - // skip the allocated pages - i += pageCount - 1; - } + area = area->all_next; } - - heap = heap->next; - if (heap == NULL && ++heapClassIndex < HEAP_CLASS_COUNT) - heap = sHeapList[heapClassIndex]; } // sort the array @@ -608,63 +634,102 @@ { mutex_lock(&heap->lock); - // validate the free pages list - uint32 freePageCount = 0; - heap_page *lastPage = NULL; - heap_page *page = heap->free_pages; - while (page) { - if ((addr_t)page < (addr_t)&heap->page_table[0] - || (addr_t)page >= (addr_t)&heap->page_table[heap->page_count]) - panic("free page is not part of the page table\n"); + uint32 totalPageCount = 0; + uint32 totalFreePageCount = 0; + heap_area *area = heap->all_areas; + while (area) { + // validate the free pages list + uint32 freePageCount = 0; + heap_page *lastPage = NULL; + heap_page *page = area->free_pages; + while (page) { + if ((addr_t)page < (addr_t)&area->page_table[0] + || (addr_t)page >= (addr_t)&area->page_table[area->page_count]) + panic("free page is not part of the page table\n"); - if (page->index >= heap->page_count) - panic("free page has invalid index\n"); + if (page->index >= area->page_count) + panic("free page has invalid index\n"); - if ((addr_t)&heap->page_table[page->index] != (addr_t)page) - panic("free page index does not lead to target page\n"); + if ((addr_t)&area->page_table[page->index] != (addr_t)page) + panic("free page index does not lead to target page\n"); - if (page->prev != lastPage) - panic("free page entry has invalid prev link\n"); + if (page->prev != lastPage) + panic("free page entry has invalid prev link\n"); - if (page->in_use) - panic("free page marked as in use\n"); + if (page->in_use) + panic("free page marked as in use\n"); - lastPage = page; - page = page->next; - freePageCount++; - } + lastPage = page; + page = page->next; + freePageCount++; + } - if (heap->free_page_count != freePageCount) - panic("free page count doesn't match free page list\n"); + totalPageCount += freePageCount; + totalFreePageCount += freePageCount; + if (area->free_page_count != freePageCount) + panic("free page count doesn't match free page list\n"); - // validate the page table - uint32 usedPageCount = 0; - for (uint32 i = 0; i < heap->page_count; i++) { - if (heap->page_table[i].in_use) - usedPageCount++; + // validate the page table + uint32 usedPageCount = 0; + for (uint32 i = 0; i < area->page_count; i++) { + if (area->page_table[i].in_use) + usedPageCount++; + } + + totalPageCount += usedPageCount; + if (freePageCount + usedPageCount != area->page_count) { + panic("free pages and used pages do not add up (%lu + %lu != %lu)\n", + freePageCount, usedPageCount, area->page_count); + } + + area = area->all_next; } - if (freePageCount + usedPageCount != heap->page_count) { - panic("free pages and used pages do not add up (%lu + %lu != %lu)\n", - freePageCount, usedPageCount, heap->page_count); + // validate the areas + area = heap->areas; + heap_area *lastArea = NULL; + uint32 lastFreeCount = 0; + while (area) { + if (area->free_page_count < lastFreeCount) + panic("ordering of area list broken\n"); + + if (area->prev != lastArea) + panic("area list entry has invalid prev link\n"); + + lastArea = area; + lastFreeCount = area->free_page_count; + area = area->next; } // validate the bins for (uint32 i = 0; i < heap->bin_count; i++) { heap_bin *bin = &heap->bins[i]; - lastPage = NULL; - page = bin->page_list; - int32 lastFreeCount = 0; + heap_page *lastPage = NULL; + heap_page *page = bin->page_list; + lastFreeCount = 0; while (page) { - if ((addr_t)page < (addr_t)&heap->page_table[0] - || (addr_t)page >= (addr_t)&heap->page_table[heap->page_count]) + area = heap->all_areas; + while (area) { + if (area == page->area) + break; + area = area->all_next; + } + + if (area == NULL) { + panic("page area not present in area list\n"); + page = page->next; + continue; + } + + if ((addr_t)page < (addr_t)&area->page_table[0] + || (addr_t)page >= (addr_t)&area->page_table[area->page_count]) panic("used page is not part of the page table\n"); - if (page->index >= heap->page_count) + if (page->index >= area->page_count) panic("used page has invalid index\n"); - if ((addr_t)&heap->page_table[page->index] != (addr_t)page) + if ((addr_t)&area->page_table[page->index] != (addr_t)page) panic("used page index does not lead to target page\n"); if (page->prev != lastPage) @@ -684,7 +749,7 @@ // validate the free list uint32 freeSlotsCount = 0; addr_t *element = page->free_list; - addr_t pageBase = heap->base + page->index * heap->page_size; + addr_t pageBase = area->base + page->index * heap->page_size; while (element) { if ((addr_t)element < pageBase || (addr_t)element >= pageBase + heap->page_size) @@ -720,14 +785,86 @@ // #pragma mark - Heap functions +static void +heap_add_area(heap_allocator *heap, area_id areaID, addr_t base, size_t size) +{ + mutex_lock(&heap->lock); + + heap_area *area = (heap_area *)base; + area->area = areaID; + + base += sizeof(heap_area); + size -= sizeof(heap_area); + + uint32 pageCount = size / heap->page_size; + size_t pageTableSize = pageCount * sizeof(heap_page); + area->page_table = (heap_page *)base; + base += pageTableSize; + size -= pageTableSize; + + // the rest is now actually usable memory (rounded to the next page) + area->base = ROUNDUP(base, B_PAGE_SIZE); + area->size = size & ~(B_PAGE_SIZE - 1); + + // now we know the real page count + pageCount = area->size / heap->page_size; + area->page_count = pageCount; + + // zero out the page table and fill in page indexes + memset((void *)area->page_table, 0, pageTableSize); + for (uint32 i = 0; i < pageCount; i++) { + area->page_table[i].area = area; + area->page_table[i].index = i; + } + + // add all pages up into the free pages list + for (uint32 i = 1; i < pageCount; i++) { + area->page_table[i - 1].next = &area->page_table[i]; + area->page_table[i].prev = &area->page_table[i - 1]; + } + area->free_pages = &area->page_table[0]; + area->free_page_count = pageCount; + area->page_table[0].prev = NULL; + + area->next = NULL; + if (heap->areas == NULL) { + // it's the only (empty) area in that heap + area->prev = NULL; + heap->areas = area; + } else { + // link in this area as the last one as it is completely empty + heap_area *lastArea = heap->areas; + while (lastArea->next != NULL) + lastArea = lastArea->next; + + lastArea->next = area; + area->prev = lastArea; + } + + area->all_next = heap->all_areas; + heap->all_areas = area; + heap->total_pages += area->page_count; + heap->total_free_pages += area->free_page_count; + + mutex_unlock(&heap->lock); + + dprintf("heap_add_area: area added to %s heap %p - usable range 0x%08lx - 0x%08lx\n", + sHeapClasses[heap->heap_class].name, heap, area->base, + area->base + area->size); +} + + static heap_allocator * -heap_attach(addr_t base, size_t size, uint32 heapClass) +heap_create_allocator(addr_t base, size_t size, uint32 heapClass) { heap_allocator *heap = (heap_allocator *)base; base += sizeof(heap_allocator); size -= sizeof(heap_allocator); + heap->heap_class = heapClass; heap->page_size = sHeapClasses[heapClass].page_size; + heap->total_pages = heap->total_free_pages = 0; + heap->areas = heap->all_areas = NULL; heap->bins = (heap_bin *)base; heap->bin_count = 0; @@ -746,40 +883,78 @@ base += heap->bin_count * sizeof(heap_bin); size -= heap->bin_count * sizeof(heap_bin); - uint32 pageCount = size / heap->page_size; - size_t pageTableSize = pageCount * sizeof(heap_page); - heap->page_table = (heap_page *)base; - base += pageTableSize; - size -= pageTableSize; + mutex_init(&heap->lock, "heap_mutex"); - // the rest is now actually usable memory (rounded to the next page) - heap->base = ROUNDUP(base, B_PAGE_SIZE); - heap->size = (size / B_PAGE_SIZE) * B_PAGE_SIZE; + heap_add_area(heap, -1, base, size); + return heap; +} - // now we know the real page count - pageCount = heap->size / heap->page_size; - heap->page_count = pageCount; - // zero out the heap alloc table at the base of the heap - memset((void *)heap->page_table, 0, pageTableSize); - for (uint32 i = 0; i < pageCount; i++) - heap->page_table[i].index = i; +static inline void +heap_free_pages_added(heap_allocator *heap, heap_area *area, uint32 pageCount) +{ + area->free_page_count += pageCount; + heap->total_free_pages += pageCount; - // add all pages up into the free pages list - for (uint32 i = 1; i < pageCount; i++) { - heap->page_table[i - 1].next = &heap->page_table[i]; - heap->page_table[i].prev = &heap->page_table[i - 1]; + if (area->free_page_count == 1) { + // we need to add ourselfs to the area list of the heap + area->prev = NULL; + area->next = heap->areas; + if (area->next) + area->next->prev = area; + heap->areas = area; + } else { + // we might need to move back in the area list + if (area->next && area->next->free_page_count < area->free_page_count) { + // move ourselfs so the list stays ordered + heap_area *insert = area->next; + while (insert->next + && insert->next->free_page_count < area->free_page_count) + insert = insert->next; + + if (area->prev) + area->prev->next = area->next; + if (area->next) + area->next->prev = area->prev; + if (heap->areas == area) { + heap->areas = area->next; + if (area->next) + area->next->prev = NULL; + } + + area->prev = insert; + area->next = insert->next; + if (area->next) + area->next->prev = area; + insert->next = area; + } } - heap->free_pages = &heap->page_table[0]; - heap->free_page_count = pageCount; - heap->page_table[0].prev = NULL; - mutex_init(&heap->lock, "heap_mutex"); + // can and should we free this area? + if (area->free_page_count == area->page_count && area->area >= B_OK) { + uint32 pagesLeft = heap->total_pages - area->page_count; + uint32 freePagesLeft = heap->total_free_pages - area->free_page_count; + if (freePagesLeft > pagesLeft / 10) { + // there are still more than 10% of free pages if we free it + dprintf("heap: should free empty area %ld\n", area->area); + } + } +} - heap->next = NULL; - dprintf("heap_attach: %s heap attached to %p - usable range 0x%08lx - 0x%08lx\n", - sHeapClasses[heapClass].name, heap, heap->base, heap->base + heap->size); - return heap; + +static inline void +heap_free_pages_removed(heap_allocator *heap, heap_area *area, uint32 pageCount) +{ + area->free_page_count -= pageCount; + heap->total_free_pages -= pageCount; + + if (area->free_page_count == 0) { + // the area is now full so we remove it from the area list + heap->areas = area->next; + if (area->next) + area->next->prev = NULL; + area->next = area->prev = NULL; + } } @@ -809,24 +984,93 @@ } +static heap_page * +heap_allocate_contiguous_pages(heap_allocator *heap, uint32 pageCount) +{ + heap_area *area = heap->areas; + while (area) { + bool found = false; + int32 first = -1; + for (uint32 i = 0; i < area->page_count; i++) { + if (area->page_table[i].in_use) { + first = -1; + continue; + } + + if (first > 0) { + if ((i + 1 - first) == pageCount) { + found = true; + break; + } + } else + first = i; + } + + if (!found) { + area = area->next; + continue; + } + + for (uint32 i = first; i < first + pageCount; i++) { + heap_page *page = &area->page_table[i]; + page->in_use = 1; + page->bin_index = heap->bin_count; + + heap_unlink_page(page, &area->free_pages); + + page->next = page->prev = NULL; + page->free_list = NULL; + page->allocation_id = (uint16)first; + } + + heap_free_pages_removed(heap, area, pageCount); + return &area->page_table[first]; + } + + return NULL; +} + + static void * heap_raw_alloc(heap_allocator *heap, size_t size, uint32 binIndex) { - heap_bin *bin = NULL; - if (binIndex < heap->bin_count) - bin = &heap->bins[binIndex]; + if (binIndex < heap->bin_count) { + heap_bin *bin = &heap->bins[binIndex]; + heap_page *page = bin->page_list; + if (page == NULL) { + heap_area *area = heap->areas; + if (area == NULL) { + TRACE(("heap %p: no free pages to allocate %lu bytes\n", heap, + size)); + return NULL; + } - if (bin && bin->page_list != NULL) { + // by design there are only areas in the list that still have + // free pages available + page = area->free_pages; + area->free_pages = page->next; + if (page->next) + page->next->prev = NULL; + + heap_free_pages_removed(heap, area, 1); + page->in_use = 1; + page->bin_index = binIndex; + page->free_count = bin->max_free_count; + page->empty_index = 0; + page->free_list = NULL; + page->next = page->prev = NULL; + bin->page_list = page; + } + // we have a page where we have a free slot void *address = NULL; - heap_page *page = bin->page_list; if (page->free_list) { // there's a previously freed entry we can use address = page->free_list; page->free_list = (addr_t *)*page->free_list; } else { // the page hasn't been fully allocated so use the next empty_index - address = (void *)(heap->base + page->index * heap->page_size + address = (void *)(page->area->base + page->index * heap->page_size + page->empty_index * bin->element_size); page->empty_index++; } @@ -851,93 +1095,24 @@ return address; } - // we don't have anything free right away, we must allocate a new page - if (heap->free_pages == NULL) { - // there are no free pages anymore, we ran out of memory - TRACE(("heap %p: no free pages to allocate %lu bytes\n", heap, size)); + uint32 pageCount = (size + heap->page_size - 1) / heap->page_size; + heap_page *firstPage = heap_allocate_contiguous_pages(heap, pageCount); + if (firstPage == NULL) { + TRACE(("heap %p: found no contiguous pages to allocate %ld bytes\n", + heap, size)); return NULL; } - if (bin) { - // small allocation, just grab the next free page - heap_page *page = heap->free_pages; - heap->free_pages = page->next; - heap->free_page_count--; - if (page->next) - page->next->prev = NULL; - - page->in_use = 1; - page->bin_index = binIndex; - page->free_count = bin->max_free_count - 1; - page->empty_index = 1; - page->free_list = NULL; - page->next = page->prev = NULL; - - if (page->free_count > 0) { - // by design there are no other pages in the bins page list - bin->page_list = page; - } - #if KERNEL_HEAP_LEAK_CHECK - heap_leak_check_info *info = (heap_leak_check_info *)(heap->base - + page->index * heap->page_size + bin->element_size - - sizeof(heap_leak_check_info)); - info->size = size - sizeof(heap_leak_check_info); - info->thread = (kernel_startup ? 0 : thread_get_current_thread_id()); - info->team = (kernel_startup ? 0 : team_get_current_team_id()); - info->caller = get_caller(); -#endif - - // we return the first slot in this page - return (void *)(heap->base + page->index * heap->page_size); - } - - // large allocation, we must search for contiguous slots - bool found = false; - int32 first = -1; - for (uint32 i = 0; i < heap->page_count; i++) { - if (heap->page_table[i].in_use) { - first = -1; - continue; - } - - if (first > 0) { - if ((1 + i - first) * heap->page_size >= size) { - found = true; - break; - } - } else - first = i; - } - - if (!found) { - TRACE(("heap %p: found no contiguous pages to allocate %ld bytes\n", heap, size)); - return NULL; - } - - uint32 pageCount = (size + heap->page_size - 1) / heap->page_size; - for (uint32 i = first; i < first + pageCount; i++) { - heap_page *page = &heap->page_table[i]; - page->in_use = 1; - page->bin_index = binIndex; - - heap_unlink_page(page, &heap->free_pages); - - page->next = page->prev = NULL; - page->free_list = NULL; - page->allocation_id = (uint16)first; - } - heap->free_page_count -= pageCount; - -#if KERNEL_HEAP_LEAK_CHECK - heap_leak_check_info *info = (heap_leak_check_info *)(heap->base - + (first + pageCount) * heap->page_size - sizeof(heap_leak_check_info)); + heap_leak_check_info *info = (heap_leak_check_info *)(firstPage->area->base + + (firstPage->index + pageCount) * heap->page_size + - sizeof(heap_leak_check_info)); info->size = size - sizeof(heap_leak_check_info); info->thread = (kernel_startup ? 0 : thread_get_current_thread_id()); info->team = (kernel_startup ? 0 : team_get_current_team_id()); info->caller = get_caller(); #endif - return (void *)(heap->base + first * heap->page_size); + return (void *)(firstPage->area->base + firstPage->index * heap->page_size); } @@ -954,9 +1129,8 @@ inline bool heap_should_grow(heap_allocator *heap) { - // suggest growing if it is the last heap and has less than 10% free pages - return heap->next == NULL - && heap->free_page_count < heap->page_count / 10; + // suggest growing if there are less than 10% free pages + return heap->total_free_pages < heap->total_pages / 10; } [... truncated: 454 lines follow ...] From stippi at mail.berlios.de Thu Jul 3 13:36:34 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 3 Jul 2008 13:36:34 +0200 Subject: [Haiku-commits] r26238 - haiku/trunk/src/data/beos_mime/text Message-ID: <200807031136.m63BaYK4027920@sheep.berlios.de> Author: stippi Date: 2008-07-03 13:36:28 +0200 (Thu, 03 Jul 2008) New Revision: 26238 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26238&view=rev Modified: haiku/trunk/src/data/beos_mime/text/html haiku/trunk/src/data/beos_mime/text/x-source-code haiku/trunk/src/data/beos_mime/text/x-vnd.be.resourcedef haiku/trunk/src/data/beos_mime/text/xml Log: Tweaked the default preferred apps for some text mime types. The chances are high that Pe is installed, if not, StyledEdit is used anyways. Also Firefox is more likely to be present on these days images than NetPositive. Modified: haiku/trunk/src/data/beos_mime/text/html =================================================================== --- haiku/trunk/src/data/beos_mime/text/html 2008-07-03 01:44:35 UTC (rev 26237) +++ haiku/trunk/src/data/beos_mime/text/html 2008-07-03 11:36:28 UTC (rev 26238) @@ -10,7 +10,7 @@ resource(3, "META:S:DESC") #'MSDC' "HTML File"; -resource(4, "META:PREF_APP") #'MSIG' "application/x-vnd.Be-NPOS"; +resource(4, "META:PREF_APP") #'MSIG' "application/x-vnd.mozilla-firefox"; resource(5, "META:EXTENS") message(234) { "extensions" = "htm", Modified: haiku/trunk/src/data/beos_mime/text/x-source-code =================================================================== --- haiku/trunk/src/data/beos_mime/text/x-source-code 2008-07-03 01:44:35 UTC (rev 26237) +++ haiku/trunk/src/data/beos_mime/text/x-source-code 2008-07-03 11:36:28 UTC (rev 26238) @@ -24,7 +24,7 @@ "type" = "text/x-source-code" }; -resource(5, "META:PREF_APP") #'MSIG' "application/x-vnd.Haiku-StyledEdit"; +resource(5, "META:PREF_APP") #'MSIG' "application/x-vnd.beunited.pe"; resource(6, "META:ICON") #'VICN' array { $"6E6369660505010200060338D2F73CD163BF82B23B84A94B88504870C900B6F5" Modified: haiku/trunk/src/data/beos_mime/text/x-vnd.be.resourcedef =================================================================== --- haiku/trunk/src/data/beos_mime/text/x-vnd.be.resourcedef 2008-07-03 01:44:35 UTC (rev 26237) +++ haiku/trunk/src/data/beos_mime/text/x-vnd.be.resourcedef 2008-07-03 11:36:28 UTC (rev 26238) @@ -15,7 +15,7 @@ "type" = "text/x-vnd.be.resourcedef" }; -//resource(5, "META:PREF_APP") #'MSIG' "application/x-vnd.haiku.styled-edit"; +//resource(5, "META:PREF_APP") #'MSIG' "application/x-vnd.beunited.pe"; resource(4, "META:ICON") #'VICN' array { $"6E63696607050102000603399E0F3D9C0ABF82B23B84A94B88504870C900A5B1" Modified: haiku/trunk/src/data/beos_mime/text/xml =================================================================== --- haiku/trunk/src/data/beos_mime/text/xml 2008-07-03 01:44:35 UTC (rev 26237) +++ haiku/trunk/src/data/beos_mime/text/xml 2008-07-03 11:36:28 UTC (rev 26238) @@ -10,4 +10,4 @@ "type" = "text/xml" }; -resource(4, "META:PREF_APP") #'MSIG' "application/x-vnd.Haiku-StyledEdit"; +resource(4, "META:PREF_APP") #'MSIG' "application/x-vnd.beunited.pe"; From axeld at mail.berlios.de Thu Jul 3 13:52:37 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 3 Jul 2008 13:52:37 +0200 Subject: [Haiku-commits] r26239 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200807031152.m63BqaTx029938@sheep.berlios.de> Author: axeld Date: 2008-07-03 13:52:36 +0200 (Thu, 03 Jul 2008) New Revision: 26239 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26239&view=rev Modified: haiku/trunk/headers/private/kernel/kmodule.h haiku/trunk/src/system/kernel/module.cpp Log: * Preparations for a module listener API - this will be used in the (disk) device managers. * Cleanup. Modified: haiku/trunk/headers/private/kernel/kmodule.h =================================================================== --- haiku/trunk/headers/private/kernel/kmodule.h 2008-07-03 11:36:28 UTC (rev 26238) +++ haiku/trunk/headers/private/kernel/kmodule.h 2008-07-03 11:52:36 UTC (rev 26239) @@ -1,6 +1,5 @@ /* - * Copyright 2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. - * + * Copyright 2005-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_MODULE_H @@ -14,6 +13,16 @@ #ifdef __cplusplus +// C++ only part + +class NotificationListener; + +extern status_t start_watching_modules(const char *prefix, + NotificationListener &listener); +extern status_t stop_watching_modules(const char *prefix, + NotificationListener &listener); + + extern "C" { #endif Modified: haiku/trunk/src/system/kernel/module.cpp =================================================================== --- haiku/trunk/src/system/kernel/module.cpp 2008-07-03 11:36:28 UTC (rev 26238) +++ haiku/trunk/src/system/kernel/module.cpp 2008-07-03 11:52:36 UTC (rev 26239) @@ -17,16 +17,18 @@ #include #include +#include #include +#include #include +#include #include -#include -#include -#include +#include #include #include #include +#include //#define TRACE_MODULE @@ -51,7 +53,7 @@ extern module_info gRootFileSystem; extern module_info gDeviceFileSystem; -static module_info *sBuiltInModules[] = { +static module_info* sBuiltInModules[] = { &gDeviceManagerModule, &gDeviceRootModule, &gFrameBufferConsoleModule, @@ -74,17 +76,17 @@ /* Each loaded module image (which can export several modules) is put * in a hash (gModuleImagesHash) to be easily found when you search * for a specific file name. - * ToDo: Could use only the inode number for hashing. Would probably be + * TODO: Could use only the inode number for hashing. Would probably be * a little bit slower, but would lower the memory foot print quite a lot. */ struct module_image { - struct module_image *next; - module_info **info; /* the module_info we use */ - module_dependency *dependencies; - char *path; /* the full path for the module */ + struct module_image* next; + module_info** info; // the module_info we use + module_dependency* dependencies; + char* path; // the full path for the module image_id image; - int32 ref_count; /* how many ref's to this file */ + int32 ref_count; // how many ref's to this file bool keep_loaded; }; @@ -93,57 +95,99 @@ */ struct module { - struct module *next; - ::module_image *module_image; - char *name; - char *file; + struct module* next; + ::module_image* module_image; + char* name; + char* file; int32 ref_count; - module_info *info; /* will only be valid if ref_count > 0 */ - int32 offset; /* this is the offset in the headers */ - module_state state; /* state of module */ + module_info* info; // will only be valid if ref_count > 0 + int32 offset; // this is the offset in the headers + module_state state; uint32 flags; }; #define B_BUILT_IN_MODULE 2 typedef struct module_path { - const char *name; + const char* name; uint32 base_length; } module_path; typedef struct module_iterator { - module_path *stack; + module_path* stack; int32 stack_size; int32 stack_current; - char *prefix; + char* prefix; size_t prefix_length; - const char *suffix; + const char* suffix; size_t suffix_length; - DIR *current_dir; + DIR* current_dir; status_t status; int32 module_offset; - /* This is used to keep track of which module_info - * within a module we're addressing. */ - ::module_image *module_image; - module_info **current_header; - const char *current_path; + // This is used to keep track of which module_info + // within a module we're addressing. + ::module_image* module_image; + module_info** current_header; + const char* current_path; uint32 path_base_length; - const char *current_module_path; + const char* current_module_path; bool builtin_modules; bool loaded_modules; } module_iterator; +namespace Module { -static bool sDisableUserAddOns = false; +struct module_listener : DoublyLinkedListLink { + NotificationListener* listener; + const char* prefix; +}; -/* locking scheme: there is a global lock only; having several locks - * makes trouble if dependent modules get loaded concurrently -> - * they have to wait for each other, i.e. we need one lock per module; - * also we must detect circular references during init and not dead-lock - */ -static recursive_lock sModulesLock; +typedef DoublyLinkedList ModuleListenerList; +class ModuleNotificationService : public NotificationService { +public: + ModuleNotificationService(); + virtual ~ModuleNotificationService(); + + status_t InitCheck(); + + status_t AddListener(const KMessage* eventSpecifier, + NotificationListener& listener); + status_t UpdateListener(const KMessage* eventSpecifier, + NotificationListener& listener); + status_t RemoveListener(const KMessage* eventSpecifier, + NotificationListener& listener); + + virtual const char* Name() { return "modules"; } + +private: + recursive_lock fLock; + ModuleListenerList fListeners; +}; + +class DirectoryWatcher : public NotificationListener { +public: + DirectoryWatcher(); + virtual ~DirectoryWatcher(); + + virtual void EventOccured(NotificationService& service, + const KMessage* event); +}; + +class ModuleWatcher : public NotificationListener { +public: + ModuleWatcher(); + virtual ~ModuleWatcher(); + + virtual void EventOccured(NotificationService& service, + const KMessage* event); +}; + +} // namespace Module + +using namespace Module; + /* These are the standard base paths where we start to look for modules * to load. Order is important, the last entry here will be searched * first. @@ -158,19 +202,30 @@ / sizeof(kModulePaths[0]); static const uint32 kFirstNonSystemModulePath = 1; + +static ModuleNotificationService sModuleNotificationService; +static bool sDisableUserAddOns = false; + +/* locking scheme: there is a global lock only; having several locks + * makes trouble if dependent modules get loaded concurrently -> + * they have to wait for each other, i.e. we need one lock per module; + * also we must detect circular references during init and not dead-lock + */ +static recursive_lock sModulesLock; + /* We store the loaded modules by directory path, and all known modules * by module name in a hash table for quick access */ -static hash_table *sModuleImagesHash; -static hash_table *sModulesHash; +static hash_table* sModuleImagesHash; +static hash_table* sModulesHash; /*! Calculates hash for a module using its name */ static uint32 -module_hash(void *_module, const void *_key, uint32 range) +module_hash(void* _module, const void* _key, uint32 range) { - module *module = (struct module *)_module; - const char *name = (const char *)_key; + module* module = (struct module*)_module; + const char* name = (const char*)_key; if (module != NULL) return hash_hash_string(module->name) % range; @@ -184,10 +239,10 @@ /*! Compares a module to a given name */ static int -module_compare(void *_module, const void *_key) +module_compare(void* _module, const void* _key) { - module *module = (struct module *)_module; - const char *name = (const char *)_key; + module* module = (struct module*)_module; + const char* name = (const char*)_key; if (name == NULL) return -1; @@ -197,10 +252,10 @@ /*! Calculates the hash of a module image using its path */ static uint32 -module_image_hash(void *_module, const void *_key, uint32 range) +module_image_hash(void* _module, const void* _key, uint32 range) { - module_image *image = (module_image *)_module; - const char *path = (const char *)_key; + module_image* image = (module_image*)_module; + const char* path = (const char*)_key; if (image != NULL) return hash_hash_string(image->path) % range; @@ -214,10 +269,10 @@ /*! Compares a module image to a path */ static int -module_image_compare(void *_module, const void *_key) +module_image_compare(void* _module, const void* _key) { - module_image *image = (module_image *)_module; - const char *path = (const char *)_key; + module_image* image = (module_image*)_module; + const char* path = (const char*)_key; if (path == NULL) return -1; @@ -230,9 +285,9 @@ to the module_image object in "_moduleImage". */ static status_t -load_module_image(const char *path, module_image **_moduleImage) +load_module_image(const char* path, module_image** _moduleImage) { - module_image *moduleImage; + module_image* moduleImage; status_t status; image_id image; @@ -245,14 +300,14 @@ return image; } - moduleImage = (module_image *)malloc(sizeof(module_image)); - if (!moduleImage) { + moduleImage = (module_image*)malloc(sizeof(module_image)); + if (moduleImage == NULL) { status = B_NO_MEMORY; goto err; } if (get_image_symbol(image, "modules", B_SYMBOL_TYPE_DATA, - (void **)&moduleImage->info) != B_OK) { + (void**)&moduleImage->info) != B_OK) { TRACE(("load_module_image: Failed to load \"%s\" due to lack of 'modules' symbol\n", path)); status = B_BAD_TYPE; goto err1; @@ -260,7 +315,7 @@ moduleImage->dependencies = NULL; get_image_symbol(image, "module_dependencies", B_SYMBOL_TYPE_DATA, - (void **)&moduleImage->dependencies); + (void**)&moduleImage->dependencies); // this is allowed to be NULL moduleImage->path = strdup(path); @@ -290,7 +345,7 @@ static status_t -unload_module_image(module_image *moduleImage, const char *path) +unload_module_image(module_image* moduleImage, const char* path) { TRACE(("unload_module_image(image = %p, path = %s)\n", moduleImage, path)); @@ -298,7 +353,7 @@ if (moduleImage == NULL) { // if no image was specified, lookup it up in the hash table - moduleImage = (module_image *)hash_lookup(sModuleImagesHash, path); + moduleImage = (module_image*)hash_lookup(sModuleImagesHash, path); if (moduleImage == NULL) return B_ENTRY_NOT_FOUND; } @@ -321,7 +376,7 @@ static void -put_module_image(module_image *image) +put_module_image(module_image* image) { int32 refCount = atomic_add(&image->ref_count, -1); ASSERT(refCount > 0); @@ -335,15 +390,15 @@ static status_t -get_module_image(const char *path, module_image **_image) +get_module_image(const char* path, module_image** _image) { - struct module_image *image; + struct module_image* image; TRACE(("get_module_image(path = \"%s\")\n", path)); RecursiveLocker _(sModulesLock); - image = (module_image *)hash_lookup(sModuleImagesHash, path); + image = (module_image*)hash_lookup(sModuleImagesHash, path); if (image == NULL) { status_t status = load_module_image(path, &image); if (status < B_OK) @@ -361,9 +416,9 @@ by "info" and create the entries required for access to it's details. */ static status_t -create_module(module_info *info, const char *file, int offset, module **_module) +create_module(module_info* info, const char* file, int offset, module** _module) { - module *module; + module* module; TRACE(("create_module(info = %p, file = \"%s\", offset = %d, _module = %p)\n", info, file, offset, _module)); @@ -371,13 +426,13 @@ if (!info->name) return B_BAD_VALUE; - module = (struct module *)hash_lookup(sModulesHash, info->name); + module = (struct module*)hash_lookup(sModulesHash, info->name); if (module) { FATAL(("Duplicate module name (%s) detected... ignoring new one\n", info->name)); return B_FILE_EXISTS; } - if ((module = (struct module *)malloc(sizeof(struct module))) == NULL) + if ((module = (struct module*)malloc(sizeof(struct module))) == NULL) return B_NO_MEMORY; TRACE(("create_module: name = \"%s\", file = \"%s\"\n", info->name, file)); @@ -421,10 +476,10 @@ "searchedName" is allowed to be NULL (if all modules should be scanned) */ static status_t -check_module_image(const char *path, const char *searchedName) +check_module_image(const char* path, const char* searchedName) { - module_image *image; - module_info **info; + module_image* image; + module_info** info; int index = 0, match = B_ENTRY_NOT_FOUND; TRACE(("check_module_image(path = \"%s\", searchedName = \"%s\")\n", path, @@ -460,8 +515,8 @@ /*! This is only called if we fail to find a module already in our cache... saves us some extra checking here :) */ -static module * -search_module(const char *name) +static module* +search_module(const char* name) { status_t status = B_ENTRY_NOT_FOUND; uint32 i; @@ -496,15 +551,15 @@ if (status != B_OK) return NULL; - return (module *)hash_lookup(sModulesHash, name); + return (module*)hash_lookup(sModulesHash, name); } static status_t -put_dependent_modules(struct module *module) +put_dependent_modules(struct module* module) { - module_image *image = module->module_image; - module_dependency *dependencies; + module_image* image = module->module_image; + module_dependency* dependencies; // built-in modules don't have a module_image structure if (image == NULL @@ -522,10 +577,10 @@ static status_t -get_dependent_modules(struct module *module) +get_dependent_modules(struct module* module) { - module_image *image = module->module_image; - module_dependency *dependencies; + module_image* image = module->module_image; + module_dependency* dependencies; // built-in modules don't have a module_image structure if (image == NULL @@ -550,7 +605,7 @@ /*! Initializes a loaded module depending on its state */ static inline status_t -init_module(module *module) +init_module(module* module) { switch (module->state) { case MODULE_QUERIED: @@ -610,7 +665,7 @@ /*! Uninitializes a module depeding on its state */ static inline int -uninit_module(module *module) +uninit_module(module* module) { TRACE(("uninit_module(%s)\n", module->name)); @@ -660,8 +715,8 @@ } -static const char * -iterator_pop_path_from_stack(module_iterator *iterator, uint32 *_baseLength) +static const char* +iterator_pop_path_from_stack(module_iterator* iterator, uint32* _baseLength) { if (iterator->stack_current <= 0) return NULL; @@ -674,11 +729,12 @@ static status_t -iterator_push_path_on_stack(module_iterator *iterator, const char *path, uint32 baseLength) +iterator_push_path_on_stack(module_iterator* iterator, const char* path, + uint32 baseLength) { if (iterator->stack_current + 1 > iterator->stack_size) { // allocate new space on the stack - module_path *stack = (module_path *)realloc(iterator->stack, + module_path* stack = (module_path*)realloc(iterator->stack, (iterator->stack_size + 8) * sizeof(module_path)); if (stack == NULL) return B_NO_MEMORY; @@ -694,7 +750,7 @@ static bool -match_iterator_suffix(module_iterator *iterator, const char *name) +match_iterator_suffix(module_iterator* iterator, const char* name) { if (iterator->suffix == NULL || iterator->suffix_length == 0) return true; @@ -709,8 +765,8 @@ static status_t -iterator_get_next_module(module_iterator *iterator, char *buffer, - size_t *_bufferSize) +iterator_get_next_module(module_iterator* iterator, char* buffer, + size_t* _bufferSize) { status_t status; @@ -737,7 +793,7 @@ hash_iterator hashIterator; hash_open(sModulesHash, &hashIterator); - struct module *module = (struct module *)hash_next(sModulesHash, + struct module* module = (struct module*)hash_next(sModulesHash, &hashIterator); for (int32 i = 0; module != NULL; i++) { if (i >= iterator->module_offset) { @@ -752,7 +808,7 @@ return B_OK; } } - module = (struct module *)hash_next(sModulesHash, &hashIterator); + module = (struct module*)hash_next(sModulesHash, &hashIterator); } hash_close(sModulesHash, &hashIterator, false); @@ -765,14 +821,14 @@ nextPath: if (iterator->current_dir == NULL) { // get next directory path from the stack - const char *path = iterator_pop_path_from_stack(iterator, + const char* path = iterator_pop_path_from_stack(iterator, &iterator->path_base_length); if (path == NULL) { // we are finished, there are no more entries on the stack return B_ENTRY_NOT_FOUND; } - free((void *)iterator->current_path); + free((char*)iterator->current_path); iterator->current_path = path; iterator->current_dir = opendir(path); TRACE(("open directory at %s -> %p\n", path, iterator->current_dir)); @@ -790,7 +846,7 @@ errno = 0; - struct dirent *dirent; + struct dirent* dirent; if ((dirent = readdir(iterator->current_dir)) == NULL) { closedir(iterator->current_dir); iterator->current_dir = NULL; @@ -832,15 +888,15 @@ return B_BUFFER_OVERFLOW; // find out if it's a directory or a file - struct stat st; - if (stat(path.Path(), &st) < 0) + struct stat stat; + if (::stat(path.Path(), &stat) < 0) return errno; iterator->current_module_path = strdup(path.Path()); if (iterator->current_module_path == NULL) return B_NO_MEMORY; - if (S_ISDIR(st.st_mode)) { + if (S_ISDIR(stat.st_mode)) { status = iterator_push_path_on_stack(iterator, iterator->current_module_path, iterator->path_base_length); if (status < B_OK) @@ -850,14 +906,14 @@ goto nextModuleImage; } - if (!S_ISREG(st.st_mode)) + if (!S_ISREG(stat.st_mode)) return B_BAD_TYPE; TRACE(("open module at %s\n", path.Path())); status = get_module_image(path.Path(), &iterator->module_image); if (status < B_OK) { - free((void *)iterator->current_module_path); + free((char*)iterator->current_module_path); iterator->current_module_path = NULL; goto nextModuleImage; } @@ -868,9 +924,9 @@ // search the current module image until we've got a match while (*iterator->current_header != NULL) { - module_info *info = *iterator->current_header; + module_info* info = *iterator->current_header; - // TODO: we might want to create a module here and cache it in the + // TODO: we mightS want to create a module here and cache it in the // hash table iterator->current_header++; @@ -887,7 +943,7 @@ // leave this module and get the next one iterator->current_header = NULL; - free((void *)iterator->current_module_path); + free((char*)iterator->current_module_path); iterator->current_module_path = NULL; put_module_image(iterator->module_image); @@ -898,7 +954,7 @@ static void -register_builtin_modules(struct module_info **info) +register_builtin_modules(struct module_info** info) { for (; *info; info++) { (*info)->flags |= B_BUILT_IN_MODULE; @@ -911,10 +967,10 @@ static status_t -register_preloaded_module_image(struct preloaded_image *image) +register_preloaded_module_image(struct preloaded_image* image) { - module_image *moduleImage; - struct module_info **info; + module_image* moduleImage; + struct module_info** info; status_t status; int32 index = 0; @@ -925,12 +981,12 @@ if (image->id < 0) return B_BAD_VALUE; - moduleImage = (module_image *)malloc(sizeof(module_image)); + moduleImage = (module_image*)malloc(sizeof(module_image)); if (moduleImage == NULL) return B_NO_MEMORY; if (get_image_symbol(image->id, "modules", B_SYMBOL_TYPE_DATA, - (void **)&moduleImage->info) != B_OK) { + (void**)&moduleImage->info) != B_OK) { status = B_BAD_TYPE; goto error; } @@ -939,7 +995,7 @@ moduleImage->dependencies = NULL; get_image_symbol(image->id, "module_dependencies", B_SYMBOL_TYPE_DATA, - (void **)&moduleImage->dependencies); + (void**)&moduleImage->dependencies); // this is allowed to be NULL // Try to recreate the full module path, so that we don't try to load the @@ -951,7 +1007,8 @@ // (it always assumes the preloaded add-ons to be in the system // directory) char path[B_FILE_NAME_LENGTH]; - const char *name, *suffix; + const char* suffix; + const char* name; if (moduleImage->info[0] && (suffix = strstr(name = moduleImage->info[0]->name, image->name)) != NULL) { @@ -1015,16 +1072,16 @@ static int -dump_modules(int argc, char **argv) +dump_modules(int argc, char** argv) { hash_iterator iterator; - struct module_image *image; - struct module *module; + struct module_image* image; + struct module* module; hash_rewind(sModulesHash, &iterator); dprintf("-- known modules:\n"); - while ((module = (struct module *)hash_next(sModulesHash, &iterator)) != NULL) { + while ((module = (struct module*)hash_next(sModulesHash, &iterator)) != NULL) { dprintf("%p: \"%s\", \"%s\" (%ld), refcount = %ld, state = %d, mimage = %p\n", module, module->name, module->file, module->offset, module->ref_count, module->state, module->module_image); @@ -1033,7 +1090,7 @@ hash_rewind(sModuleImagesHash, &iterator); dprintf("\n-- loaded module images:\n"); - while ((image = (struct module_image *)hash_next(sModuleImagesHash, &iterator)) != NULL) { + while ((image = (struct module_image*)hash_next(sModuleImagesHash, &iterator)) != NULL) { dprintf("%p: \"%s\" (image_id = %ld), info = %p, refcount = %ld, %s\n", image, image->path, image->image, image->info, image->ref_count, image->keep_loaded ? "keep loaded" : "can be unloaded"); @@ -1042,6 +1099,108 @@ } +// #pragma mark - DirectoryWatcher + + +DirectoryWatcher::DirectoryWatcher() +{ +} + + +DirectoryWatcher::~DirectoryWatcher() +{ +} + + +void +DirectoryWatcher::EventOccured(NotificationService& service, + const KMessage* event) +{ + int32 opcode = event->GetInt32("opcode", -1); + dev_t device = event->GetInt32("device", -1); + ino_t directory = event->GetInt64("directory", -1); + const char *name = event->GetString("name", NULL); + + if (opcode == B_ENTRY_MOVED) { + // Determine wether it's a move within, out of, or into one + // of our watched directories. + ino_t from = event->GetInt64("from directory", -1); + ino_t to = event->GetInt64("to directory", -1); + } + + KPath path(B_PATH_NAME_LENGTH + 1); + if (path.InitCheck() != B_OK || vfs_entry_ref_to_path(device, directory, + name, path.LockBuffer(), path.BufferSize()) != B_OK) + return; + + path.UnlockBuffer(); + + dprintf("module \"%s\" %s\n", path.Leaf(), + opcode == B_ENTRY_CREATED ? "added" : "removed"); +} + + +// #pragma mark - ModuleWatcher + + +ModuleWatcher::ModuleWatcher() +{ +} + + +ModuleWatcher::~ModuleWatcher() +{ +} + + +void +ModuleWatcher::EventOccured(NotificationService& service, const KMessage* event) +{ + if (event->GetInt32("opcode", -1) != B_STAT_CHANGED + || (event->GetInt32("fields", 0) & B_STAT_MODIFICATION_TIME) == 0) + return; +} + + +// #pragma mark - ModuleNotificationService + + +ModuleNotificationService::ModuleNotificationService() +{ + recursive_lock_init(&fLock, "module notifications"); +} + + +ModuleNotificationService::~ModuleNotificationService() +{ + recursive_lock_destroy(&fLock); +} + + +status_t +ModuleNotificationService::AddListener(const KMessage* eventSpecifier, + NotificationListener& listener) +{ + return B_ERROR; +} + + +status_t +ModuleNotificationService::UpdateListener(const KMessage* eventSpecifier, + NotificationListener& listener) +{ + return B_ERROR; +} + + +status_t +ModuleNotificationService::RemoveListener(const KMessage* eventSpecifier, + NotificationListener& listener) +{ + return B_ERROR; +} + + // #pragma mark - Exported Kernel API (private part) @@ -1049,12 +1208,12 @@ to load_module(). */ status_t -unload_module(const char *path) +unload_module(const char* path) { - struct module_image *moduleImage; + struct module_image* moduleImage; recursive_lock_lock(&sModulesLock); - moduleImage = (module_image *)hash_lookup(sModuleImagesHash, path); + moduleImage = (module_image*)hash_lookup(sModuleImagesHash, path); recursive_lock_unlock(&sModulesLock); if (moduleImage == NULL) @@ -1074,9 +1233,9 @@ add-on won't be unloaded until the last put_module(). */ status_t -load_module(const char *path, module_info ***_modules) +load_module(const char* path, module_info*** _modules) { - module_image *moduleImage; + module_image* moduleImage; status_t status = get_module_image(path, &moduleImage); if (status != B_OK) return status; @@ -1086,13 +1245,37 @@ } +status_t +start_watching_modules(const char* prefix, NotificationListener& listener) +{ + KMessage specifier; + status_t status = specifier.AddString("prefix", prefix); + if (status != B_OK) + return status; + + return sModuleNotificationService.AddListener(&specifier, listener); +} + + +status_t +stop_watching_modules(const char* prefix, NotificationListener& listener) +{ + KMessage specifier; + status_t status = specifier.AddString("prefix", prefix); + if (status != B_OK) + return status; + + return sModuleNotificationService.RemoveListener(&specifier, listener); +} + + /*! Setup the module structures and data for use - must be called before any other module call. */ status_t -module_init(kernel_args *args) +module_init(kernel_args* args) { - struct preloaded_image *image; + struct preloaded_image* image; recursive_lock_init(&sModulesLock, "modules rlock"); @@ -1119,6 +1302,8 @@ } } + new(&sModuleNotificationService) ModuleNotificationService(); + sDisableUserAddOns = get_safemode_boolean(B_SAFEMODE_DISABLE_USER_ADD_ONS, false); @@ -1140,8 +1325,8 @@ The structure is then used by read_next_module_name(), and must be freed by calling close_module_list(). */ -void * -open_module_list_etc(const char *prefix, const char *suffix) +void* +open_module_list_etc(const char* prefix, const char* suffix) { TRACE(("open_module_list(prefix = %s)\n", prefix)); @@ -1150,9 +1335,9 @@ return NULL; } - module_iterator *iterator = (module_iterator *)malloc( + module_iterator* iterator = (module_iterator*)malloc( sizeof(module_iterator)); - if (!iterator) + if (iterator == NULL) return NULL; memset(iterator, 0, sizeof(module_iterator)); @@ -1189,7 +1374,7 @@ pathBuffer.Append("kernel"); // Copy base path onto the iterator stack - char *path = strdup(pathBuffer.Path()); + char* path = strdup(pathBuffer.Path()); if (path == NULL) continue; @@ -1202,7 +1387,7 @@ #if 0 // Build path component: base path + '/' + prefix size_t length = strlen(sModulePaths[i]); - char *path = (char *)malloc(length + iterator->prefix_length + 2); + char* path = (char*)malloc(length + iterator->prefix_length + 2); if (path == NULL) { // ToDo: should we abort the whole operation here? // if we do, don't forget to empty the stack @@ -1223,12 +1408,12 @@ iterator->loaded_modules = true; } - return (void *)iterator; + return (void*)iterator; } -void * -open_module_list(const char *prefix) +void* +open_module_list(const char* prefix) { return open_module_list_etc(prefix, NULL); } @@ -1236,10 +1421,10 @@ /*! Frees the cookie allocated by open_module_list() */ status_t -close_module_list(void *cookie) +close_module_list(void* cookie) { - module_iterator *iterator = (module_iterator *)cookie; - const char *path; + module_iterator* iterator = (module_iterator*)cookie; + const char* path; TRACE(("close_module_list()\n")); @@ -1248,7 +1433,7 @@ // free stack while ((path = iterator_pop_path_from_stack(iterator, NULL)) != NULL) - free((void *)path); + free((char*)path); // close what have been left open if (iterator->module_image != NULL) @@ -1258,8 +1443,8 @@ closedir(iterator->current_dir); free(iterator->stack); - free((void *)iterator->current_path); - free((void *)iterator->current_module_path); + free((char*)iterator->current_path); + free((char*)iterator->current_module_path); free(iterator->prefix); free(iterator); @@ -1274,9 +1459,9 @@ when done. */ status_t -read_next_module_name(void *cookie, char *buffer, size_t *_bufferSize) +read_next_module_name(void* cookie, char* buffer, size_t* _bufferSize) { [... truncated: 83 lines follow ...] From superstippi at gmx.de Thu Jul 3 14:11:16 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 03 Jul 2008 14:11:16 +0200 Subject: [Haiku-commits] r26239 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <200807031152.m63BqaTx029938@sheep.berlios.de> References: <200807031152.m63BqaTx029938@sheep.berlios.de> Message-ID: <20080703141116.24553.8@stippis2.1215077519.fake> axeld at BerliOS wrote: > - // TODO: we might want to create a module here and cache it in the > + // TODO: we mightS want to create a module here and cache it in the Did you ever try to save the file and wondered why it wasn't saved? :-) Best regards, -Stephan From korli at users.berlios.de Thu Jul 3 14:41:13 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 3 Jul 2008 14:41:13 +0200 Subject: [Haiku-commits] r26239 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <20080703141116.24553.8@stippis2.1215077519.fake> References: <200807031152.m63BqaTx029938@sheep.berlios.de> <20080703141116.24553.8@stippis2.1215077519.fake> Message-ID: 2008/7/3 Stephan Assmus : > > axeld at BerliOS wrote: >> - // TODO: we might want to create a module here and cache it in the >> + // TODO: we mightS want to create a module here and cache it in the > > Did you ever try to save the file and wondered why it wasn't saved? :-) > Mitts ? :) Bye, J?r?me From axeld at pinc-software.de Thu Jul 3 17:46:34 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 03 Jul 2008 17:46:34 +0200 CEST Subject: [Haiku-commits] r26239 - in haiku/trunk: headers/private/kernel src/system/kernel In-Reply-To: <20080703141116.24553.8@stippis2.1215077519.fake> Message-ID: <29738988845-BeMail@zon> Stephan Assmus wrote: > axeld at BerliOS wrote: > > - // TODO: we might want to create a module here and cache it in > > the > > + // TODO: we mightS want to create a module here and cache it in > > the > Did you ever try to save the file and wondered why it wasn't saved? : > -) Obviously, thanks! :-) Bye, Axel. From bonefish at mail.berlios.de Thu Jul 3 22:37:11 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 3 Jul 2008 22:37:11 +0200 Subject: [Haiku-commits] r26240 - in haiku/trunk/src/system/kernel: . arch/x86 Message-ID: <200807032037.m63KbB84001939@sheep.berlios.de> Author: bonefish Date: 2008-07-03 22:37:08 +0200 (Thu, 03 Jul 2008) New Revision: 26240 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26240&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp haiku/trunk/src/system/kernel/thread.cpp Log: stippi + bonefish: * Missing backslash in UPDATE_THREAD_KERNEL_TIME() macro. Caused the thread's kernel time never to be updated when the thread left the kernel. The time would be added to the user time instead. * Changed semantics of thread_at_kernel_exit(). It leaves interrupts disabled when returning, now. All code using it would disable interrupts afterwards anyway, and inbetween the thread could be interrupted causing two more time updates (or actually not causing them erroneously). * The code in x86's interrupt handler entry (int_bottom) also checks thread::in_kernel now, to determine whether the thread was already considered to be in userland. This is necessary since the sysexit instruction doesn't reenable interrupts, so that we have to do that with the preceeding instruction. Hence an interrupt can occur inbetween, which would incorrectly add the interrupt's kernel time to the thread's user time. * For userland threads team_create_thread_start() didn't invoke thread_at_kernel_exit() or any equivalent. We do that in arch_thread_enter_userspace() now. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S 2008-07-03 11:52:36 UTC (rev 26239) +++ haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S 2008-07-03 20:37:08 UTC (rev 26240) @@ -53,7 +53,7 @@ call system_time; \ \ movl %eax, %ebx; /* save for later */ \ - movl %edx, %ecx; + movl %edx, %ecx; \ \ /* thread->kernel_time += now - thread->last_time; */ \ sub THREAD_last_time(%edi), %eax; \ @@ -248,9 +248,18 @@ testl $0x20000, IFRAME_flags(%ebp) // VM86 mode jnz int_bottom_vm86 - cmp $USER_CODE_SEG, IFRAME_cs(%ebp) + cmp $USER_CODE_SEG, IFRAME_cs(%ebp) // user mode je int_bottom_user + // We need to recheck user mode using the thread's in_kernel flag, since + // sysexit introduces a raced condition: It doesn't reenable interrupts, + // so that we have to do it in the instruction before, thus opening a + // window for an interrupt while still being in the kernel, but having set + // up everything for userland already. + movl %dr3, %edi // thread pointer + cmpb $0, THREAD_in_kernel(%edi) + je int_bottom_user + // disable interrupts -- the handler will enable them, if necessary cli @@ -474,8 +483,7 @@ // make sure interrupts are enabled (they are, when coming from a syscall // but otherwise they might be disabled) sti - call thread_at_kernel_exit - cli // disable interrupts + call thread_at_kernel_exit // also disables interrupts jmp kernel_exit_work_done bad_syscall_params: Modified: haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2008-07-03 11:52:36 UTC (rev 26239) +++ haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2008-07-03 20:37:08 UTC (rev 26240) @@ -409,7 +409,8 @@ if (user_memcpy((void *)stackTop, args, sizeof(args)) < B_OK) return B_BAD_ADDRESS; - disable_interrupts(); + thread_at_kernel_exit(); + // also disables interrupts i386_set_tss_and_kstack(t->kernel_stack_top); Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-07-03 11:52:36 UTC (rev 26239) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-07-03 20:37:08 UTC (rev 26240) @@ -331,9 +331,6 @@ { struct thread *thread = thread_get_current_thread(); - // a signal may have been delivered here - thread_at_kernel_exit(); - // jump to the entry point in user space arch_thread_enter_userspace(thread, (addr_t)thread->entry, thread->args1, thread->args2); @@ -1571,6 +1568,8 @@ /*! Called whenever a thread exits kernel space to user space. Tracks time, handles signals, ... + Interrupts must be enabled. When the function returns, interrupts will be + disabled. */ void thread_at_kernel_exit(void) @@ -1584,7 +1583,7 @@ scheduler_reschedule(); } - cpu_status state = disable_interrupts(); + disable_interrupts(); thread->in_kernel = false; @@ -1592,14 +1591,12 @@ bigtime_t now = system_time(); thread->kernel_time += now - thread->last_time; thread->last_time = now; - - restore_interrupts(state); } /*! The quick version of thread_kernel_exit(), in case no signals are pending and no debugging shall be done. - Interrupts are disabled in this case. + Interrupts must be disabled. */ void thread_at_kernel_exit_no_signals(void) From axeld at mail.berlios.de Thu Jul 3 22:41:32 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 3 Jul 2008 22:41:32 +0200 Subject: [Haiku-commits] r26241 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 Message-ID: <200807032041.m63KfWxD002351@sheep.berlios.de> Author: axeld Date: 2008-07-03 22:41:31 +0200 (Thu, 03 Jul 2008) New Revision: 26241 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26241&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h Log: * Now prints the disk size as part of the default name so that different volumes are easier to differentiate. Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-03 20:37:08 UTC (rev 26240) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-03 20:41:31 UTC (rev 26241) @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -242,7 +243,7 @@ if (fSuperBlock.name[0]) return fSuperBlock.name; - return "Unnamed Ext2 Volume"; + return fName; } @@ -309,15 +310,31 @@ return B_ERROR; status = get_vnode(fFSVolume, EXT2_ROOT_NODE, (void**)&fRootNode); - if (status == B_OK) { - // all went fine - opener.Keep(); - return B_OK; - } else { + if (status != B_OK) { TRACE("could not create root node: get_vnode() failed!\n"); + return status; } - return status; + // all went fine + opener.Keep(); + + if (!fSuperBlock.name[0]) { + // generate a more or less descriptive volume name + uint32 divisor = 1UL << 30; + char unit = 'G'; + if (diskSize < divisor) { + divisor = 1UL << 20; + unit = 'M'; + } + + double size = double((10 * diskSize + divisor - 1) / divisor); + // %g in the kernel does not support precision... + + snprintf(fName, sizeof(fName), "%g %cB Ext2 Volume", + size / 10, unit); + } + + return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-07-03 20:37:08 UTC (rev 26240) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h 2008-07-03 20:41:31 UTC (rev 26241) @@ -59,6 +59,7 @@ fs_volume* fFSVolume; int fDevice; ext2_super_block fSuperBlock; + char fName[32]; uint32 fFlags; uint32 fBlockSize; uint32 fBlockShift; From axeld at mail.berlios.de Thu Jul 3 22:44:58 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 3 Jul 2008 22:44:58 +0200 Subject: [Haiku-commits] r26242 - haiku/trunk/src/kits/tracker Message-ID: <200807032044.m63KiwTR002794@sheep.berlios.de> Author: axeld Date: 2008-07-03 22:44:57 +0200 (Thu, 03 Jul 2008) New Revision: 26242 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26242&view=rev Modified: haiku/trunk/src/kits/tracker/MountMenu.cpp Log: * Unnamed volumes now get the disk size instead of "unnamed" in their mount menu name, ie. "(unnamed Ext2 File System)" could become "(12.5 GB Ext2 File System)". * Minor cleanup. Modified: haiku/trunk/src/kits/tracker/MountMenu.cpp =================================================================== --- haiku/trunk/src/kits/tracker/MountMenu.cpp 2008-07-03 20:41:31 UTC (rev 26241) +++ haiku/trunk/src/kits/tracker/MountMenu.cpp 2008-07-03 20:44:57 UTC (rev 26242) @@ -109,9 +109,18 @@ if (type == NULL) return false; - name = "(unnamed "; - name << type; - name << ")"; + uint32 divisor = 1UL << 30; + char unit = 'G'; + if (partition->Size() < divisor) { + divisor = 1UL << 20; + unit = 'M'; + } + + char* buffer = name.LockBuffer(256); + snprintf(buffer, 256, "(%.1f %cB %s)", + 1.0 * partition->Size() / divisor, unit, type); + + name.UnlockBuffer(); } } @@ -167,7 +176,7 @@ AddOneAsMenuItemParams *params = (AddOneAsMenuItemParams *)castToParams; BBitmap *icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8); - get_device_icon(partition->GetDevice()->Name(), icon->Bits(), B_MINI_ICON); + get_device_icon(partition->GetDevice()->Name(), icon->Bits(), B_MINI_ICON); const char *name = partition->GetDevice()->DisplayName(); @@ -182,21 +191,21 @@ BMessage *message = new BMessage; - if (partition->Mounted() == kMounted) { - message->what = kUnmountVolume; + if (partition->Mounted() == kMounted) { + message->what = kUnmountVolume; message->AddInt32("device_id", partition->VolumeDeviceID()); } else { message->what = kMountVolume; - + // - // Floppies have an ID of -1, because they don't have + // Floppies have an ID of -1, because they don't have // partition (and hence no parititon ID). // if (partition->GetDevice()->IsFloppy()) message->AddInt32("id", kFloppyID); else message->AddInt32("id", partition->UniqueID()); - } + } BMenuItem *item = new IconMenuItem(name, message, icon); if (partition->Mounted() == kMounted) @@ -277,12 +286,12 @@ // Use the shared icon instead of the device icon if (get_device_icon(info.device_name, icon->Bits(), B_MINI_ICON) != B_OK) GetTrackerResources()->GetIconResource(kResShareIcon, B_MINI_ICON, icon); - + BMessage *message = new BMessage(kUnmountVolume); message->AddInt32("device_id", volume.Device()); char volumeName[B_FILE_NAME_LENGTH]; volume.GetName(volumeName); - + BMenuItem *item = new IconMenuItem(volumeName, message, icon); item->SetMarked(true); AddItem(item); @@ -303,12 +312,12 @@ BMenuItem *mountAll = new BMenuItem("Mount All", new BMessage(kMountAllNow)); AddItem(mountAll); - BMenuItem *mountSettings = new BMenuItem("Settings"B_UTF8_ELLIPSIS, + BMenuItem *mountSettings = new BMenuItem("Settings" B_UTF8_ELLIPSIS, new BMessage(kRunAutomounterSettings)); AddItem(mountSettings); SetTargetForItems(be_app); - + #ifndef __HAIKU__ if (rescanItem) rescanItem->SetTarget(autoMounter); From ingo_weinhold at gmx.de Thu Jul 3 22:51:09 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Thu, 03 Jul 2008 22:51:09 +0200 Subject: [Haiku-commits] r26241 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <200807032041.m63KfWxD002351@sheep.berlios.de> References: <200807032041.m63KfWxD002351@sheep.berlios.de> Message-ID: <20080703225109.829.1@knochen-vm.nameserver> On 2008-07-03 at 22:41:32 [+0200], axeld at BerliOS wrote: > Author: axeld > Date: 2008-07-03 22:41:31 +0200 (Thu, 03 Jul 2008) > New Revision: 26241 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26241&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp > haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.h > Log: > * Now prints the disk size as part of the default name so that different > volumes are easier to differentiate. BTW, I intended to introduce a generic DDM service call constructing a name for an unnamed partition, since there are no volume names in ReiserFS and probably other FSs either. I'm not sure how nice it is to include the position in the device and partition tree as well -- I guess the FS size is sufficient in most cases, though not very helpful if one has several partitions with the same size. CU, Ingo From axeld at pinc-software.de Thu Jul 3 23:12:19 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 03 Jul 2008 23:12:19 +0200 CEST Subject: [Haiku-commits] r26241 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <20080703225109.829.1@knochen-vm.nameserver> Message-ID: <49283267548-BeMail@zon> Ingo Weinhold wrote: > On 2008-07-03 at 22:41:32 [+0200], axeld at BerliOS < > axeld at mail.berlios.de> > wrote: > > * Now prints the disk size as part of the default name so that > > different > > volumes are easier to differentiate. > BTW, I intended to introduce a generic DDM service call constructing > a name > for an unnamed partition, since there are no volume names in ReiserFS > and > probably other FSs either. I'm not sure how nice it is to include the That's a nice idea! :-) > position in the device and partition tree as well -- I guess the FS > size is > sufficient in most cases, though not very helpful if one has several > partitions with the same size. We could add the size in a first pass, and if there are still partitions with the same name, we could add more information (like the partition number or USB vs. SCSI/IDE/...), as well. BTW I thought that it might be nice to have a (possibly userland situated) service that recognizes partition types/file systems (with volume name if possible) that are otherwise not supported. At least that would look much better in apps like DriveSetup. Bye, Axel. From bonefish at mail.berlios.de Thu Jul 3 23:14:55 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 3 Jul 2008 23:14:55 +0200 Subject: [Haiku-commits] r26243 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200807032114.m63LEtIC005387@sheep.berlios.de> Author: bonefish Date: 2008-07-03 23:14:54 +0200 (Thu, 03 Jul 2008) New Revision: 26243 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26243&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S Log: The stack layout changed in r23983. Since then user_debug_post_syscall() wouldn't be passed the syscall start time anymore. Fixes weird syscall timings when using strace. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S 2008-07-03 20:44:57 UTC (rev 26242) +++ haiku/trunk/src/system/kernel/arch/x86/arch_interrupts.S 2008-07-03 21:14:54 UTC (rev 26243) @@ -357,7 +357,8 @@ movl %eax,%ds movl %eax,%es - lea 4(%esp), %ebp // stack frame pointer is the iframe + lea 4(%esp), %ebp // skipping the return address, the stack + // frame pointer is the iframe movl %dr3, %edi // thread pointer // disable breakpoints, if installed @@ -437,8 +438,8 @@ // post syscall debugging testl $THREAD_FLAGS_DEBUGGER_INSTALLED, THREAD_flags(%edi) jz 1f - pushl -4(%ebp) // syscall start time - pushl -8(%ebp) + pushl -8(%ebp) // syscall start time + pushl -12(%ebp) movl IFRAME_edx(%ebp), %edx // syscall return value movl IFRAME_eax(%ebp), %eax push %edx From mmlr at mail.berlios.de Fri Jul 4 00:57:30 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 00:57:30 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel Message-ID: <200807032257.m63MvUZ8016225@sheep.berlios.de> Author: mmlr Date: 2008-07-04 00:57:27 +0200 (Fri, 04 Jul 2008) New Revision: 26244 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26244&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: * Implement freeing of empty heap areas. When a heap_area becomes completely empty and there is another empty area already, it is now removed from the heap and the underlying area is deleted. * Fix grow suggestions to be based on 20% of a grow size instead of 10% of the current page count, as the current page count obviously gets larger over time making 10% of it larger than the grow size itself. * Fix non-urgent grow request handling so that not two areas at once get added. * Made some of the debug output more useful, turned off some other and fixed some comments. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-03 21:14:54 UTC (rev 26243) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-03 22:57:27 UTC (rev 26244) @@ -108,6 +108,7 @@ uint32 total_pages; uint32 total_free_pages; + uint32 empty_areas; heap_bin * bins; heap_area * areas; // sorted so that the desired area is always first @@ -303,9 +304,10 @@ { heap_area *area = heap->all_areas; while (area) { - dprintf("\tarea %p: area: %ld; base: 0x%08lx; size: %lu; free_pages: %p (%lu entr%s)\n", - area, area->area, area->base, area->size, area->free_pages, - area->free_page_count, area->free_page_count == 1 ? "y" : "ies"); + dprintf("\tarea %p: area: %ld; base: 0x%08lx; size: %lu; page_count: %lu; free_pages: %p (%lu entr%s)\n", + area, area->area, area->base, area->size, area->page_count, + area->free_pages, area->free_page_count, + area->free_page_count == 1 ? "y" : "ies"); area = area->all_next; } @@ -316,9 +318,9 @@ static void dump_allocator(heap_allocator *heap, bool areas, bool bins) { - dprintf("allocator %p: class: %s; page_size: %lu; bin_count: %lu; pages: %lu; free: %lu\n", heap, + dprintf("allocator %p: class: %s; page_size: %lu; bin_count: %lu; pages: %lu; free_pages: %lu; empty_areas: %lu\n", heap, sHeapClasses[heap->heap_class].name, heap->page_size, heap->bin_count, - heap->total_pages, heap->total_free_pages); + heap->total_pages, heap->total_free_pages, heap->empty_areas); if (areas) dump_allocator_areas(heap); @@ -846,14 +848,73 @@ heap->total_pages += area->page_count; heap->total_free_pages += area->free_page_count; + if (areaID >= B_OK) { + // this later on deletable area is yet empty - the empty count will be + // decremented as soon as this area is used for the first time + heap->empty_areas++; + } + mutex_unlock(&heap->lock); - dprintf("heap_add_area: area added to %s heap %p - usable range 0x%08lx - 0x%08lx\n", - sHeapClasses[heap->heap_class].name, heap, area->base, + dprintf("heap_add_area: area %ld added to %s heap %p - usable range 0x%08lx - 0x%08lx\n", + area->area, sHeapClasses[heap->heap_class].name, heap, area->base, area->base + area->size); } +static status_t +heap_remove_area(heap_allocator *heap, heap_area *area, bool locked) +{ + if (!locked) + mutex_lock(&heap->lock); + + if (area->free_page_count != area->page_count) { + panic("tried removing heap area that has still pages in use"); + return B_ERROR; + } + + if (area->prev == NULL && area->next == NULL) { + panic("tried removing the last non-full heap area"); + return B_ERROR; + } + + if (heap->areas == area) + heap->areas = area->next; + if (area->prev != NULL) + area->prev->next = area->next; + if (area->next != NULL) + area->next->prev = area->prev; + + if (heap->all_areas == area) + heap->all_areas = area->all_next; + else { + heap_area *previous = heap->all_areas; + while (previous) { + if (previous->all_next == area) { + previous->all_next = area->all_next; + break; + } + + previous = previous->all_next; + } + + if (previous == NULL) + panic("removing heap area that is not in all list"); + } + + heap->total_pages -= area->page_count; + heap->total_free_pages -= area->free_page_count; + + if (!locked) + mutex_unlock(&heap->lock); + + dprintf("heap_remove_area: area %ld with range 0x%08lx - 0x%08lx removed from %s heap %p\n", + area->area, area->base, area->base + area->size, + sHeapClasses[heap->heap_class].name, heap); + return B_OK; +} + + static heap_allocator * heap_create_allocator(addr_t base, size_t size, uint32 heapClass) { @@ -863,7 +924,7 @@ heap->heap_class = heapClass; heap->page_size = sHeapClasses[heapClass].page_size; - heap->total_pages = heap->total_free_pages = 0; + heap->total_pages = heap->total_free_pages = heap->empty_areas = 0; heap->areas = heap->all_areas = NULL; heap->bins = (heap_bin *)base; @@ -890,7 +951,7 @@ } -static inline void +static inline area_id heap_free_pages_added(heap_allocator *heap, heap_area *area, uint32 pageCount) { area->free_page_count += pageCount; @@ -932,19 +993,31 @@ // can and should we free this area? if (area->free_page_count == area->page_count && area->area >= B_OK) { - uint32 pagesLeft = heap->total_pages - area->page_count; - uint32 freePagesLeft = heap->total_free_pages - area->free_page_count; - if (freePagesLeft > pagesLeft / 10) { - // there are still more than 10% of free pages if we free it - dprintf("heap: should free empty area %ld\n", area->area); + if (heap->empty_areas > 0) { + // we already have at least another empty area, just free this one + if (heap_remove_area(heap, area, true) == B_OK) { + // we cannot delete the area here, because it would result + // in calls to free, which would necessarily deadlock as we + // are locked at this point + return area->area; + } } + + heap->empty_areas++; } + + return -1; } static inline void heap_free_pages_removed(heap_allocator *heap, heap_area *area, uint32 pageCount) { + if (area->free_page_count == area->page_count && area->area >= B_OK) { + // this area was completely empty + heap->empty_areas--; + } + area->free_page_count -= pageCount; heap->total_free_pages -= pageCount; @@ -1129,8 +1202,8 @@ inline bool heap_should_grow(heap_allocator *heap) { - // suggest growing if there are less than 10% free pages - return heap->total_free_pages < heap->total_pages / 10; + // suggest growing if there is less than 20% of a grow size available + return heap->total_free_pages * heap->page_size < HEAP_GROW_SIZE / 5; } @@ -1234,6 +1307,7 @@ return B_ERROR; } + area_id areaToDelete = -1; if (page->bin_index < heap->bin_count) { // small allocation heap_bin *bin = &heap->bins[page->bin_index]; @@ -1279,7 +1353,7 @@ heap_unlink_page(page, &bin->page_list); page->in_use = 0; heap_link_page(page, &area->free_pages); - heap_free_pages_added(heap, area, 1); + areaToDelete = heap_free_pages_added(heap, area, 1); } else if (page->free_count == 1) { // we need to add ourselfs to the page list of the bin heap_link_page(page, &bin->page_list); @@ -1321,11 +1395,18 @@ pageCount++; } - heap_free_pages_added(heap, area, pageCount); + areaToDelete = heap_free_pages_added(heap, area, pageCount); } T(Free((addr_t)address)); mutex_unlock(&heap->lock); + + if (areaToDelete >= B_OK) { + // adding free pages caused an area to become empty and freeable that + // we can now delete as we don't hold the heap lock anymore + delete_area(areaToDelete); + } + return B_OK; } @@ -1493,8 +1574,8 @@ continue; if (sAddGrowHeap) { - // the last grow heap is going to run full soon, try to allocate - // a new one to make some room. + // the grow heap is going to run full soon, try to allocate a new + // one to make some room. TRACE(("heap_grower: grow heaps will run out of memory soon\n")); if (heap_create_new_heap_area(sGrowHeap, "additional grow heap", HEAP_DEDICATED_GROW_SIZE) != B_OK) @@ -1502,7 +1583,6 @@ } for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - // find the last heap heap_allocator *heap = sHeapList[i]; if (sLastGrowRequest[i] > sLastHandledGrowRequest[i] || heap_should_grow(heap)) { @@ -1629,7 +1709,6 @@ if (!kernel_startup && size > HEAP_AREA_USE_THRESHOLD) { // don't even attempt such a huge allocation - use areas instead - dprintf("heap: using area for huge allocation of %lu bytes!\n", size); size_t areaSize = size + sizeof(area_allocation_info); if (alignment != 0) areaSize = ROUNDUP(areaSize, alignment); @@ -1656,28 +1735,27 @@ if (alignment != 0) address = (void *)ROUNDUP((addr_t)address, alignment); - dprintf("heap: allocated area %ld for huge allocation returning %p\n", - allocationArea, address); + dprintf("heap: allocated area %ld for huge allocation of %lu bytes\n", + allocationArea, size); info->allocation_base = address; return address; } - heap_allocator *heap = sHeapList[heap_class_for(size)]; + uint32 heapClass = heap_class_for(size); + heap_allocator *heap = sHeapList[heapClass]; bool shouldGrow = false; void *result = heap_memalign(heap, alignment, size, &shouldGrow); - if (shouldGrow || result == NULL) { - // the heap will or has run out of memory, notify the grower - sLastGrowRequest[heap_class_for(size)]++; - if (result == NULL) { - // urgent request, do the request and wait - switch_sem(sHeapGrowSem, sHeapGrownNotify); - // try again now - result = heap_memalign(heap, alignment, size, NULL); - } else { - // not so urgent, just notify the grower - release_sem_etc(sHeapGrowSem, 1, B_DO_NOT_RESCHEDULE); - } + if (result == NULL) { + // request an urgent grow and wait + sLastGrowRequest[heapClass]++; + switch_sem(sHeapGrowSem, sHeapGrownNotify); + + // and then try again + result = heap_memalign(heap, alignment, size, NULL); + } else if (shouldGrow) { + // should grow sometime soon, notify the grower + release_sem_etc(sHeapGrowSem, 1, B_DO_NOT_RESCHEDULE); } #if PARANOID_VALIDATION From mmlr at mail.berlios.de Fri Jul 4 16:41:21 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 16:41:21 +0200 Subject: [Haiku-commits] r26245 - haiku/trunk/src/system/kernel/vm Message-ID: <200807041441.m64EfLVA018137@sheep.berlios.de> Author: mmlr Date: 2008-07-04 16:41:17 +0200 (Fri, 04 Jul 2008) New Revision: 26245 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26245&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: Spotted this while reading through page code. The usage_count would be set for wrong pages when allocating a page run unless the run started at page 0 as the start offset was missing. Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2008-07-03 22:57:27 UTC (rev 26244) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2008-07-04 14:41:17 UTC (rev 26245) @@ -1799,7 +1799,7 @@ sPages[start + i].is_cleared = sPages[start + i].state == PAGE_STATE_CLEAR; set_page_state_nolock(&sPages[start + i], PAGE_STATE_BUSY); - sPages[i].usage_count = 2; + sPages[start + i].usage_count = 2; } firstPage = &sPages[start]; break; From mmlr at mail.berlios.de Fri Jul 4 16:49:31 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 16:49:31 +0200 Subject: [Haiku-commits] r26246 - haiku/trunk/src/system/kernel/vm Message-ID: <200807041449.m64EnV57018883@sheep.berlios.de> Author: mmlr Date: 2008-07-04 16:49:25 +0200 (Fri, 04 Jul 2008) New Revision: 26246 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26246&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp Log: * Avoid calling vm_unreserve_memory() if there is no change in the commited size. Removes a bit of overhead (call and mutex_lock / mutex_unlock). * Don't fail if there is exactly enough memory available to satisfy the reserve request. Not that it would really matter as it's rather an edge case... Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 14:41:17 UTC (rev 26245) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 14:49:25 UTC (rev 26246) @@ -4761,7 +4761,7 @@ //dprintf("try to reserve %lu bytes, %Lu left\n", amount, sAvailableMemory); - if (sAvailableMemory > amount) { + if (sAvailableMemory >= amount) { sAvailableMemory -= amount; status = B_OK; } else Modified: haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-04 14:41:17 UTC (rev 26245) +++ haiku/trunk/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-04 14:49:25 UTC (rev 26246) @@ -66,6 +66,9 @@ size = precommitted; } + if (size == store->vm.committed_size) + return B_OK; + // Check to see how much we could commit - we need real memory if (size > store->vm.committed_size) { From bonefish at mail.berlios.de Fri Jul 4 17:20:57 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Fri, 4 Jul 2008 17:20:57 +0200 Subject: [Haiku-commits] r26247 - haiku/trunk/src/tests/system/kernel Message-ID: <200807041520.m64FKvEq022227@sheep.berlios.de> Author: bonefish Date: 2008-07-04 17:20:43 +0200 (Fri, 04 Jul 2008) New Revision: 26247 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26247&view=rev Added: haiku/trunk/src/tests/system/kernel/page_fault_cache_merge_test.cpp Modified: haiku/trunk/src/tests/system/kernel/Jamfile Log: Test to quickly reproduce bug #2471. Modified: haiku/trunk/src/tests/system/kernel/Jamfile =================================================================== --- haiku/trunk/src/tests/system/kernel/Jamfile 2008-07-04 14:49:25 UTC (rev 26246) +++ haiku/trunk/src/tests/system/kernel/Jamfile 2008-07-04 15:20:43 UTC (rev 26247) @@ -15,6 +15,8 @@ : be ; +SimpleTest page_fault_cache_merge_test : page_fault_cache_merge_test.cpp ; + SimpleTest port_close_test_1 : port_close_test_1.cpp ; SimpleTest port_close_test_2 : port_close_test_2.cpp ; Added: haiku/trunk/src/tests/system/kernel/page_fault_cache_merge_test.cpp =================================================================== --- haiku/trunk/src/tests/system/kernel/page_fault_cache_merge_test.cpp 2008-07-04 14:49:25 UTC (rev 26246) +++ haiku/trunk/src/tests/system/kernel/page_fault_cache_merge_test.cpp 2008-07-04 15:20:43 UTC (rev 26247) @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#include + + +static const int kAreaPagesCount = 4 * 1024; // 16 MB + + +int +main() +{ + while (true) { + uint8* address; + area_id area = create_area("test area", (void**)&address, B_ANY_ADDRESS, + kAreaPagesCount * B_PAGE_SIZE, B_NO_LOCK, + B_READ_AREA | B_WRITE_AREA); + if (area < 0) { + fprintf(stderr, "Creating the area failed: %s", strerror(area)); + exit(1); + } + + // touch half of the pages + for (int i = 0; i < kAreaPagesCount / 2; i++) + address[i * B_PAGE_SIZE] = 42; + + // fork + pid_t child = fork(); + if (child < 0) { + perror("fork() failed"); + exit(1); + } + + if (child == 0) { + // child + + // delete the copied area + delete_area(area_for(address)); + + exit(0); + } + + // parent + + // touch the other half of the pages + for (int i = kAreaPagesCount / 2; i < kAreaPagesCount; i++) + address[i * B_PAGE_SIZE] = 42; + + int status; + while (wait(&status) != child); + + delete_area(area); + } + + return 0; +} From bonefish at mail.berlios.de Fri Jul 4 17:46:31 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Fri, 4 Jul 2008 17:46:31 +0200 Subject: [Haiku-commits] r26248 - haiku/trunk/src/system/kernel/vm Message-ID: <200807041546.m64FkVOU024542@sheep.berlios.de> Author: bonefish Date: 2008-07-04 17:46:27 +0200 (Fri, 04 Jul 2008) New Revision: 26248 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26248&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp Log: fault_find_page(): When the source of the top cache is busy, we may find our own dummy page. This is equivalent to not finding a page at all. Fixes #2471. Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 15:20:43 UTC (rev 26247) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 15:46:27 UTC (rev 26248) @@ -4321,6 +4321,9 @@ cache = nextCache; } + if (page == &dummyPage) + page = NULL; + if (page == NULL) { // there was no adequate page, determine the cache for a clean one if (cache == NULL) { From mmlr at mail.berlios.de Fri Jul 4 18:10:34 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 18:10:34 +0200 Subject: [Haiku-commits] r26249 - in haiku/trunk/src/system/kernel: util vm Message-ID: <200807041610.m64GAYLe026737@sheep.berlios.de> Author: mmlr Date: 2008-07-04 18:10:25 +0200 (Fri, 04 Jul 2008) New Revision: 26249 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26249&view=rev Modified: haiku/trunk/src/system/kernel/util/cbuf.c haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_page.cpp Log: Remove a few unused variables. Modified: haiku/trunk/src/system/kernel/util/cbuf.c =================================================================== --- haiku/trunk/src/system/kernel/util/cbuf.c 2008-07-04 15:46:27 UTC (rev 26248) +++ haiku/trunk/src/system/kernel/util/cbuf.c 2008-07-04 16:10:25 UTC (rev 26249) @@ -127,8 +127,6 @@ cbuf *buffer = NULL; cbuf *lastBuffer = NULL; cbuf *headBuffer = NULL; - int i; - int count; size_t foundSize; size = PAGE_ALIGN(size); @@ -944,7 +942,6 @@ status_t cbuf_init(void) { - cbuf *buffer; int i; // add the debug command Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 15:46:27 UTC (rev 26248) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 16:10:25 UTC (rev 26249) @@ -2336,8 +2336,6 @@ { vm_store *store; vm_cache *upperCache; - vm_page *page; - status_t status; TRACE(("vm_copy_on_write_area(cache = %p)\n", lowerCache)); @@ -3939,8 +3937,6 @@ status_t vm_init_post_sem(kernel_args *args) { - vm_area *area; - // This frees all unused boot loader resources and makes its space available again arch_vm_init_end(args); unreserve_boot_loader_ranges(args); @@ -4605,7 +4601,6 @@ vm_cache *topCache = vm_area_get_locked_cache(area); off_t cacheOffset = address - area->base + area->cache_offset; - int32 changeCount = addressSpace->change_count; atomic_add(&area->no_cache_change, 1); // make sure the area's cache isn't replaced during the page fault Modified: haiku/trunk/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_page.cpp 2008-07-04 15:46:27 UTC (rev 26248) +++ haiku/trunk/src/system/kernel/vm/vm_page.cpp 2008-07-04 16:10:25 UTC (rev 26249) @@ -596,7 +596,6 @@ dump_page_stats(int argc, char **argv) { uint32 counter[8]; - int32 totalActive; addr_t i; memset(counter, 0, sizeof(counter)); @@ -785,7 +784,6 @@ snooze(100000); // 100ms if (sFreePageQueue.count > 0) { - cpu_status state; vm_page *page[SCRUB_SIZE]; int32 i, scrubCount; @@ -1432,8 +1430,6 @@ for (VMCachePagesTree::Iterator it = cache->pages.GetIterator(firstPage, true, true); vm_page *page = it.Next();) { - bool dequeuedPage = false; - if (page->cache_offset >= endPage) break; @@ -1669,7 +1665,6 @@ vm_page * vm_page_allocate_page(int pageState, bool reserved) { - ConditionVariableEntry freeConditionEntry; page_queue *queue; page_queue *otherQueue; From mmlr at mlotz.ch Fri Jul 4 18:13:43 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Fri, 4 Jul 2008 18:13:43 +0200 Subject: [Haiku-commits] r26249 - in haiku/trunk/src/system/kernel: util vm In-Reply-To: <200807041610.m64GAYLe026737@sheep.berlios.de> References: <200807041610.m64GAYLe026737@sheep.berlios.de> Message-ID: <20080704161101.M70509@mlotz.ch> On Fri, 4 Jul 2008 18:10:34 +0200, mmlr wrote > Author: mmlr > Date: 2008-07-04 18:10:25 +0200 (Fri, 04 Jul 2008) > New Revision: 26249 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26249&view=rev > > Modified: > haiku/trunk/src/system/kernel/util/cbuf.c > haiku/trunk/src/system/kernel/vm/vm.cpp > haiku/trunk/src/system/kernel/vm/vm_page.cpp > Log: > Remove a few unused variables. These do not show up because we are supplying "-Wno-unused" in quite a few of the kernel Jamfiles. Is there any specific reason for this or could these "-Wno-unused" flags be removed so that this kind of leftover shows up as warnings as in other places? Regards Michael From bonefish at mail.berlios.de Fri Jul 4 18:36:19 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Fri, 4 Jul 2008 18:36:19 +0200 Subject: [Haiku-commits] r26250 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm Message-ID: <200807041636.m64GaJdR004595@sheep.berlios.de> Author: bonefish Date: 2008-07-04 18:35:50 +0200 (Fri, 04 Jul 2008) New Revision: 26250 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26250&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/cache/vnode_store.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h Log: * Renamed VMCache::virtual_size to virtual_end to avoid confusion. * Added cache type argument to VMCache::Init(). The type is no longer set by the one creating the cache. * VMCache::Commit() is passed the actual size to be committed, now, not virtual_end. * Added VMCache::Delete(), moved the cleanup code from the destructor there, and used it in all places instead of the destructor. * Added VMCache::MergeStore(). It is called when a cache is merged with its only consumer. * Implemented VMAnonymousCache::MergeStore(). The remaining cache takes over the memory commitment of its source that is going to be deleted. This does at least improve the situation, that after fork() + exec*() the parent's RAM areas caches don't have any memory commitment anymore. We definitely need a more consistent commitment strategy, particularly for CoW. * vm_resize_area(): when growing the area, resize the cache first, since that can fail. Resize the cache back on error. Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h 2008-07-04 16:35:50 UTC (rev 26250) @@ -171,8 +171,10 @@ VMCache(); virtual ~VMCache(); - status_t Init(); + status_t Init(uint32 cacheType); + virtual void Delete(); + // backing store operations virtual status_t Commit(off_t size); virtual bool HasPage(off_t offset); @@ -184,6 +186,8 @@ virtual status_t Fault(struct vm_address_space *aspace, off_t offset); + virtual void MergeStore(VMCache* source); + virtual status_t AcquireUnreferencedStoreRef(); virtual void AcquireStoreRef(); virtual void ReleaseStoreRef(); @@ -198,8 +202,7 @@ VMCachePagesTree pages; VMCache *source; off_t virtual_base; - off_t virtual_size; - // the size is absolute, and independent from virtual_base + off_t virtual_end; off_t committed_size; // TODO: Remove! uint32 page_count; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -373,7 +373,7 @@ addr_t last = (addr_t)vecs[vecCount - 1].iov_base + vecs[vecCount - 1].iov_len - B_PAGE_SIZE; - if (offset + pageOffset + bufferSize == ref->cache->virtual_size) { + if (offset + pageOffset + bufferSize == ref->cache->virtual_end) { // the space in the page after this write action needs to be cleaned memset((void *)(last + lastPageOffset), 0, B_PAGE_SIZE - lastPageOffset); @@ -551,7 +551,7 @@ file_cache_ref *ref = (file_cache_ref *)_cacheRef; vm_cache *cache = ref->cache; - off_t fileSize = cache->virtual_size; + off_t fileSize = cache->virtual_end; bool useBuffer = buffer != 0; TRACE(("cache_io(ref = %p, offset = %Ld, buffer = %p, size = %lu, %s)\n", @@ -767,7 +767,7 @@ file_cache_ref *ref = (struct file_cache_ref *) ((vnode_store *)cache->store)->file_cache_ref; - off_t fileSize = cache->virtual_size; + off_t fileSize = cache->virtual_end; if (size > fileSize) size = fileSize; @@ -859,7 +859,7 @@ if (cache != NULL) { file_cache_ref *ref = ((VMVnodeCache*)cache)->FileCacheRef(); if (ref != NULL) - size = cache->virtual_size; + size = cache->virtual_end; } sCacheModule->node_opened(vnode, fdType, mountID, parentID, vnodeID, name, @@ -949,7 +949,7 @@ if (vfs_get_vnode_cache(ref->vnode, &ref->cache, true) != B_OK) goto err1; - ref->cache->virtual_size = size; + ref->cache->virtual_end = size; ((VMVnodeCache*)ref->cache)->SetFileCacheRef(ref); return ref; @@ -986,7 +986,7 @@ MutexLocker _(ref->cache->lock); - off_t offset = ref->cache->virtual_size; + off_t offset = ref->cache->virtual_end; off_t size = newSize; if (offset > newSize) { size = offset - newSize; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/vnode_store.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/vnode_store.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/vnode_store.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -16,7 +16,7 @@ status_t VMVnodeCache::Init(struct vnode *vnode) { - status_t error = VMCache::Init(); + status_t error = VMCache::Init(CACHE_TYPE_VNODE); if (error != B_OK) return error; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -2794,7 +2794,7 @@ continue; kprintf("%p%4ld%10Ld %p %8Ld%8ld\n", vnode, vnode->device, vnode->id, - vnode->cache, (vnode->cache->virtual_size + B_PAGE_SIZE - 1) + vnode->cache, (vnode->cache->virtual_end + B_PAGE_SIZE - 1) / B_PAGE_SIZE, vnode->cache->page_count); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -1394,18 +1394,17 @@ goto err1; mutex_lock(&newCache->lock); - newCache->type = CACHE_TYPE_RAM; newCache->temporary = 1; newCache->scan_skip = cache->scan_skip; newCache->virtual_base = offset; - newCache->virtual_size = offset + size; + newCache->virtual_end = offset + size; vm_cache_add_consumer_locked(cache, newCache); cache = newCache; } - status = vm_cache_set_minimal_commitment_locked(cache, offset + size); + status = vm_cache_set_minimal_commitment_locked(cache, size); if (status != B_OK) goto err2; @@ -1628,8 +1627,7 @@ goto err1; cache->temporary = 1; - cache->type = CACHE_TYPE_RAM; - cache->virtual_size = size; + cache->virtual_end = size; switch (wiring) { case B_LAZY_LOCK: @@ -1844,8 +1842,7 @@ // tell the page scanner to skip over this area, it's pages are special cache->scan_skip = 1; - cache->type = CACHE_TYPE_DEVICE; - cache->virtual_size = size; + cache->virtual_end = size; mutex_lock(&cache->lock); @@ -1918,8 +1915,7 @@ // tell the page scanner to skip over this area, no pages will be mapped here cache->scan_skip = 1; - cache->type = CACHE_TYPE_NULL; - cache->virtual_size = size; + cache->virtual_end = size; mutex_lock(&cache->lock); @@ -1943,18 +1939,9 @@ The vnode has to be marked busy when calling this function. */ status_t -vm_create_vnode_cache(struct vnode *vnode, struct VMCache **_cache) +vm_create_vnode_cache(struct vnode *vnode, struct VMCache **cache) { - // create a vnode cache - vm_cache* cache; - status_t status = VMCacheFactory::CreateVnodeCache(cache, vnode); - if (status != B_OK) - return status; - - cache->type = CACHE_TYPE_VNODE; - - *_cache = cache; - return B_OK; + return VMCacheFactory::CreateVnodeCache(*cache, vnode); } @@ -2299,11 +2286,10 @@ mutex_lock(&upperCache->lock); - upperCache->type = CACHE_TYPE_RAM; upperCache->temporary = 1; upperCache->scan_skip = lowerCache->scan_skip; upperCache->virtual_base = lowerCache->virtual_base; - upperCache->virtual_size = lowerCache->virtual_size; + upperCache->virtual_end = lowerCache->virtual_end; // transfer the lower cache areas to the upper cache mutex_lock(&sAreaCacheLock); @@ -2474,8 +2460,7 @@ // we can change the cache's commitment to take only those pages // into account that really are in this cache. - status = cache->Commit( - cache->virtual_base + cache->page_count * B_PAGE_SIZE); + status = cache->Commit(cache->page_count * B_PAGE_SIZE); // ToDo: we may be able to join with our source cache, if count == 0 } @@ -2493,7 +2478,8 @@ // No consumers, so we don't need to insert a new one. if (cache->source != NULL && cache->temporary) { // the cache's commitment must contain all possible pages - status = cache->Commit(cache->virtual_size); + status = cache->Commit(cache->virtual_end + - cache->virtual_base); } if (status == B_OK && cache->source != NULL) { @@ -3109,7 +3095,7 @@ kprintf("%p: type: %s, base: %lld, size: %lld, pages: %lu", cache, cache_type_to_string(cache->type), cache->virtual_base, - cache->virtual_size, cache->page_count); + cache->virtual_end, cache->page_count); if (level == 0) kprintf("/%lu", info.page_count); @@ -3238,7 +3224,7 @@ kprintf(" source: %p\n", cache->source); kprintf(" type: %s\n", cache_type_to_string(cache->type)); kprintf(" virtual_base: 0x%Lx\n", cache->virtual_base); - kprintf(" virtual_size: 0x%Lx\n", cache->virtual_size); + kprintf(" virtual_end: 0x%Lx\n", cache->virtual_end); kprintf(" temporary: %ld\n", cache->temporary); kprintf(" scan_skip: %ld\n", cache->scan_skip); kprintf(" lock: %p\n", &cache->lock); @@ -4832,13 +4818,11 @@ for (vm_area* current = cache->areas; current != NULL; current = current->cache_next) { - if (current->address_space_next - && current->address_space_next->base <= (current->base - + newSize)) { + vm_area *next = current->address_space_next; + if (next != NULL && next->base <= (current->base + newSize)) { // If the area was created inside a reserved area, it can // also be resized in that area // ToDo: if there is free space after the reserved area, it could be used as well... - vm_area *next = current->address_space_next; if (next->id == RESERVED_AREA_ID && next->cache_offset <= current->base && next->base - 1 + next->size >= current->base - 1 + newSize) @@ -4851,11 +4835,17 @@ // Okay, looks good so far, so let's do it + if (oldSize < newSize) { + // Growing the cache can fail, so we do it first. + status = vm_cache_resize(cache, newSize); + if (status != B_OK) + return status; + } + for (vm_area* current = cache->areas; current != NULL; current = current->cache_next) { - if (current->address_space_next - && current->address_space_next->base <= (current->base + newSize)) { - vm_area *next = current->address_space_next; + vm_area *next = current->address_space_next; + if (next != NULL && next->base <= (current->base + newSize)) { if (next->id == RESERVED_AREA_ID && next->cache_offset <= current->base && next->base - 1 + next->size >= current->base - 1 + newSize) { @@ -4869,6 +4859,8 @@ next->base += offset; } } else { + panic("resize situation for area %p has changed although we " + "should have the address space lock", current); status = B_ERROR; break; } @@ -4883,7 +4875,8 @@ } } - if (status == B_OK) + // shrinking the cache can't fail, so we do it now + if (status == B_OK && newSize < oldSize) status = vm_cache_resize(cache, newSize); if (status < B_OK) { @@ -4892,6 +4885,8 @@ current = current->cache_next) { current->size = oldSize; } + + vm_cache_resize(cache, oldSize); } // TODO: we must honour the lock restrictions of this area Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -126,7 +126,7 @@ Resize(VMCache* cache, off_t size) : VMCacheTraceEntry(cache), - fOldSize(cache->virtual_size), + fOldSize(cache->virtual_end), fSize(size) { Initialized(); @@ -436,6 +436,9 @@ } } + // merge the backing store + consumer->MergeStore(cache); + // The remaining consumer has got a new source. if (cache->source != NULL) { VMCache* newSource = cache->source; @@ -535,7 +538,7 @@ // delete this cache - delete cache; + cache->Delete(); } @@ -684,16 +687,16 @@ vm_cache_resize(VMCache* cache, off_t newSize) { TRACE(("vm_cache_resize(cache %p, newSize %Ld) old size %Ld\n", - cache, newSize, cache->virtual_size)); + cache, newSize, cache->virtual_end)); ASSERT_LOCKED_MUTEX(&cache->lock); T(Resize(cache, newSize)); - status_t status = cache->Commit(newSize); + status_t status = cache->Commit(newSize - cache->virtual_base); if (status != B_OK) return status; - uint32 oldPageCount = (uint32)((cache->virtual_size + B_PAGE_SIZE - 1) + uint32 oldPageCount = (uint32)((cache->virtual_end + B_PAGE_SIZE - 1) >> PAGE_SHIFT); uint32 newPageCount = (uint32)((newSize + B_PAGE_SIZE - 1) >> PAGE_SHIFT); @@ -731,7 +734,7 @@ } } - cache->virtual_size = newSize; + cache->virtual_end = newSize; return B_OK; } @@ -848,6 +851,46 @@ VMCache::~VMCache() { + mutex_destroy(&lock); +} + + +status_t +VMCache::Init(uint32 cacheType) +{ + mutex_init(&lock, "vm_cache"); + list_init_etc(&consumers, offsetof(VMCache, consumer_link)); + areas = NULL; + ref_count = 1; + source = NULL; + virtual_base = 0; + virtual_end = 0; + committed_size = 0; + temporary = 0; + scan_skip = 0; + page_count = 0; + busy = false; + type = cacheType; + +#if DEBUG_CACHE_LIST + mutex_lock(&sCacheListLock); + + if (gDebugCacheList) + gDebugCacheList->debug_previous = this; + debug_previous = NULL; + debug_next = gDebugCacheList; + gDebugCacheList = this; + + mutex_unlock(&sCacheListLock); +#endif + + return B_OK; +} + + +void +VMCache::Delete() +{ if (areas != NULL) panic("cache %p to be deleted still has areas", this); if (!list_is_empty(&consumers)) @@ -892,43 +935,11 @@ mutex_unlock(&sCacheListLock); - mutex_destroy(&lock); + delete this; } status_t -VMCache::Init() -{ - mutex_init(&lock, "vm_cache"); - list_init_etc(&consumers, offsetof(VMCache, consumer_link)); - areas = NULL; - ref_count = 1; - source = NULL; - virtual_base = 0; - virtual_size = 0; - committed_size = 0; - temporary = 0; - scan_skip = 0; - page_count = 0; - busy = false; - -#if DEBUG_CACHE_LIST - mutex_lock(&sCacheListLock); - - if (gDebugCacheList) - gDebugCacheList->debug_previous = this; - debug_previous = NULL; - debug_next = gDebugCacheList; - gDebugCacheList = this; - - mutex_unlock(&sCacheListLock); -#endif - - return B_OK; -} - - -status_t VMCache::Commit(off_t size) { committed_size = size; @@ -939,7 +950,7 @@ bool VMCache::HasPage(off_t offset) { - return offset >= virtual_base && offset <= virtual_size; + return offset >= virtual_base && offset <= virtual_end; } @@ -966,6 +977,12 @@ } +void +VMCache::MergeStore(VMCache* source) +{ +} + + status_t VMCache::AcquireUnreferencedStoreRef() { @@ -1008,7 +1025,7 @@ status_t error = cache->Init(canOvercommit, numPrecommittedPages, numGuardPages); if (error != B_OK) { - delete cache; + cache->Delete(); return error; } @@ -1026,7 +1043,7 @@ status_t error = cache->Init(vnode); if (error != B_OK) { - delete cache; + cache->Delete(); return error; } @@ -1044,7 +1061,7 @@ status_t error = cache->Init(baseAddress); if (error != B_OK) { - delete cache; + cache->Delete(); return error; } @@ -1062,7 +1079,7 @@ status_t error = cache->Init(); if (error != B_OK) { - delete cache; + cache->Delete(); return error; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -1397,7 +1397,7 @@ vm_page_write_modified_pages(vm_cache *cache, bool fsReenter) { return vm_page_write_modified_page_range(cache, 0, - (cache->virtual_size + B_PAGE_SIZE - 1) >> PAGE_SHIFT, fsReenter); + (cache->virtual_end + B_PAGE_SIZE - 1) >> PAGE_SHIFT, fsReenter); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -43,7 +43,7 @@ TRACE(("VMAnonymousCache::Init(canOvercommit = %s, numGuardPages = %ld) " "at %p\n", canOvercommit ? "yes" : "no", numGuardPages, store)); - status_t error = VMCache::Init(); + status_t error = VMCache::Init(CACHE_TYPE_RAM); if (error != B_OK) return error; @@ -59,9 +59,6 @@ status_t VMAnonymousCache::Commit(off_t size) { - size -= virtual_base; - // anonymous stores don't need to span over their whole source - // if we can overcommit, we don't commit here, but in anonymous_fault() if (fCanOvercommit) { if (fHasPrecommitted) @@ -150,3 +147,24 @@ // This will cause vm_soft_fault() to handle the fault return B_BAD_HANDLER; } + + +void +VMAnonymousCache::MergeStore(VMCache* source) +{ + if (source->type != CACHE_TYPE_RAM) { + panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache " + "requested", source); + return; + } + + // take over the source' committed size + committed_size += source->committed_size; + source->committed_size = 0; + + off_t actualSize = virtual_end - virtual_base; + if (committed_size > actualSize) { + vm_unreserve_memory(committed_size - actualSize); + committed_size = actualSize; + } +} Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h 2008-07-04 16:35:50 UTC (rev 26250) @@ -29,6 +29,8 @@ virtual status_t Fault(struct vm_address_space *aspace, off_t offset); + virtual void MergeStore(VMCache* source); + private: bool fCanOvercommit; bool fHasPrecommitted; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -13,7 +13,7 @@ VMDeviceCache::Init(addr_t baseAddress) { fBaseAddress = baseAddress; - return VMCache::Init(); + return VMCache::Init(CACHE_TYPE_DEVICE); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp 2008-07-04 16:35:50 UTC (rev 26250) @@ -5,4 +5,9 @@ #include "vm_store_null.h" -// TODO: Remove! + +status_t +VMNullCache::Init() +{ + return VMCache::Init(CACHE_TYPE_NULL); +} Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h 2008-07-04 16:10:25 UTC (rev 26249) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h 2008-07-04 16:35:50 UTC (rev 26250) @@ -13,6 +13,8 @@ class VMNullCache : public VMCache { +public: + status_t Init(); }; From mmlr at mail.berlios.de Fri Jul 4 19:38:40 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 19:38:40 +0200 Subject: [Haiku-commits] r26251 - haiku/trunk/src/system/kernel Message-ID: <200807041738.m64HcejD021426@sheep.berlios.de> Author: mmlr Date: 2008-07-04 19:38:34 +0200 (Fri, 04 Jul 2008) New Revision: 26251 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26251&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Fix missing newline. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-04 16:35:50 UTC (rev 26250) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-04 17:38:34 UTC (rev 26251) @@ -1900,7 +1900,7 @@ if (available >= newSize) { // there is enough room available for the newSize - dprintf("realloc(): new size %ld fits in old area %ld with %ld available", + dprintf("realloc(): new size %ld fits in old area %ld with %ld available\n", newSize, area, available); return address; } From anevilyak at gmail.com Fri Jul 4 20:40:20 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Fri, 4 Jul 2008 13:40:20 -0500 Subject: [Haiku-commits] r26248 - haiku/trunk/src/system/kernel/vm In-Reply-To: <200807041546.m64FkVOU024542@sheep.berlios.de> References: <200807041546.m64FkVOU024542@sheep.berlios.de> Message-ID: Nice! I'm curious, are you handling this situation differently in your branch work? I noticed your commit there didn't seem to include this change. On 7/4/08, bonefish at mail.berlios.de wrote: > Author: bonefish > Date: 2008-07-04 17:46:27 +0200 (Fri, 04 Jul 2008) > New Revision: 26248 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26248&view=rev > > Modified: > haiku/trunk/src/system/kernel/vm/vm.cpp > Log: > fault_find_page(): When the source of the top cache is busy, we may > find our own dummy page. This is equivalent to not finding a page at > all. Fixes #2471. > > > Modified: haiku/trunk/src/system/kernel/vm/vm.cpp > =================================================================== > --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 15:20:43 UTC (rev > 26247) > +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-04 15:46:27 UTC (rev > 26248) > @@ -4321,6 +4321,9 @@ > cache = nextCache; > } > > + if (page == &dummyPage) > + page = NULL; > + > if (page == NULL) { > // there was no adequate page, determine the cache for a clean one > if (cache == NULL) { > > _______________________________________________ > Haiku-commits mailing list > Haiku-commits at lists.berlios.de > https://lists.berlios.de/mailman/listinfo/haiku-commits > From ingo_weinhold at gmx.de Fri Jul 4 22:46:46 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Fri, 04 Jul 2008 22:46:46 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel In-Reply-To: <200807032257.m63MvUZ8016225@sheep.berlios.de> References: <200807032257.m63MvUZ8016225@sheep.berlios.de> Message-ID: <20080704224646.456.1@knochen-vm.nameserver> On 2008-07-04 at 00:57:30 [+0200], mmlr at mail.berlios.de wrote: > Author: mmlr > Date: 2008-07-04 00:57:27 +0200 (Fri, 04 Jul 2008) > New Revision: 26244 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26244&view=rev > > Modified: > haiku/trunk/src/system/kernel/heap.cpp > Log: > * Implement freeing of empty heap areas. When a heap_area becomes completely > empty and there is another empty area already, it is now removed from the > heap and the underlying area is deleted. > * Fix grow suggestions to be based on 20% of a grow size instead of 10% of > the > current page count, as the current page count obviously gets larger over > time > making 10% of it larger than the grow size itself. > * Fix non-urgent grow request handling so that not two areas at once get > added. > * Made some of the debug output more useful, turned off some other and fixed > some comments. While all those changes are very nice, wasn't the intention to switch to the slab allocator as backend for the kernel heap earlier or later? CU, Ingo From ingo_weinhold at gmx.de Fri Jul 4 23:00:02 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Fri, 04 Jul 2008 23:00:02 +0200 Subject: [Haiku-commits] r26248 - haiku/trunk/src/system/kernel/vm In-Reply-To: References: <200807041546.m64FkVOU024542@sheep.berlios.de> Message-ID: <20080704230002.517.3@knochen-vm.nameserver> On 2008-07-04 at 20:40:20 [+0200], Rene Gollent wrote: > Nice! I'm curious, are you handling this situation differently in your > branch work? I noticed your commit there didn't seem to include this > change. Right, I intend to abolish the "busy" state of caches completely. It's not really needed, and this will simplify things quite a bit in fault_find_page(), also avoiding the situation that led to bug #2471. CU, Ingo From mmlr at mail.berlios.de Fri Jul 4 23:05:48 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Fri, 4 Jul 2008 23:05:48 +0200 Subject: [Haiku-commits] r26252 - haiku/trunk/src/system/kernel Message-ID: <200807042105.m64L5m8q008328@sheep.berlios.de> Author: mmlr Date: 2008-07-04 23:05:46 +0200 (Fri, 04 Jul 2008) New Revision: 26252 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26252&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: * Give the heaps a name so the grow heap can be distinguished from the small one. * Rename sHeapList[] to sHeaps[], as there are no heap lists anymore. * Rename the debug defines to be even more obvious. * Also initialize allocations by area with non-null values when being paranoid. * Disabled some debug output. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-04 17:38:34 UTC (rev 26251) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-04 21:05:46 UTC (rev 26252) @@ -33,11 +33,11 @@ #endif // initialize newly allocated memory with something non zero -#define PARANOID_KMALLOC 1 +#define PARANOID_KERNEL_MALLOC 1 // check for double free, and fill freed memory with 0xdeadbeef -#define PARANOID_KFREE 1 +#define PARANOID_KERNEL_FREE 1 // validate sanity of the heap after each operation (slow!) -#define PARANOID_VALIDATION 0 +#define PARANOID_HEAP_VALIDATION 0 // store size, thread and team info at the end of each allocation block #define KERNEL_HEAP_LEAK_CHECK 0 @@ -102,6 +102,8 @@ typedef struct heap_allocator_s { mutex lock; + + const char *name; uint32 heap_class; uint32 bin_count; uint32 page_size; @@ -154,7 +156,7 @@ } }; -static heap_allocator *sHeapList[HEAP_CLASS_COUNT]; +static heap_allocator *sHeaps[HEAP_CLASS_COUNT]; static uint32 *sLastGrowRequest[HEAP_CLASS_COUNT]; static uint32 *sLastHandledGrowRequest[HEAP_CLASS_COUNT]; static heap_allocator *sGrowHeap = NULL; @@ -318,9 +320,9 @@ static void dump_allocator(heap_allocator *heap, bool areas, bool bins) { - dprintf("allocator %p: class: %s; page_size: %lu; bin_count: %lu; pages: %lu; free_pages: %lu; empty_areas: %lu\n", heap, - sHeapClasses[heap->heap_class].name, heap->page_size, heap->bin_count, - heap->total_pages, heap->total_free_pages, heap->empty_areas); + dprintf("allocator %p: name: %s; page_size: %lu; bin_count: %lu; pages: %lu; free_pages: %lu; empty_areas: %lu\n", heap, + heap->name, heap->page_size, heap->bin_count, heap->total_pages, + heap->total_free_pages, heap->empty_areas); if (areas) dump_allocator_areas(heap); @@ -339,7 +341,7 @@ dump_allocator(sGrowHeap, true, true); } else if (strcmp(argv[1], "stats") == 0) { for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) - dump_allocator(sHeapList[i], false, false); + dump_allocator(sHeaps[i], false, false); } else print_debugger_command_usage(argv[0]); @@ -347,7 +349,7 @@ } for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) - dump_allocator(sHeapList[i], true, true); + dump_allocator(sHeaps[i], true, true); return 0; } @@ -380,7 +382,7 @@ size_t totalSize = 0; uint32 totalCount = 0; for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) { - heap_allocator *heap = sHeapList[classIndex]; + heap_allocator *heap = sHeaps[classIndex]; // go through all the pages in all the areas heap_area *area = heap->all_areas; @@ -525,7 +527,7 @@ sCallerInfoCount = 0; for (uint32 classIndex = 0; classIndex < HEAP_CLASS_COUNT; classIndex++) { - heap_allocator *heap = sHeapList[classIndex]; + heap_allocator *heap = sHeaps[classIndex]; // go through all the pages in all the areas heap_area *area = heap->all_areas; @@ -630,7 +632,7 @@ #endif // KERNEL_HEAP_LEAK_CHECK -#if PARANOID_VALIDATION +#if PARANOID_HEAP_VALIDATION static void heap_validate_heap(heap_allocator *heap) { @@ -781,7 +783,7 @@ mutex_unlock(&heap->lock); } -#endif // PARANOID_VALIDATION +#endif // PARANOID_HEAP_VALIDATION // #pragma mark - Heap functions @@ -857,8 +859,7 @@ mutex_unlock(&heap->lock); dprintf("heap_add_area: area %ld added to %s heap %p - usable range 0x%08lx - 0x%08lx\n", - area->area, sHeapClasses[heap->heap_class].name, heap, area->base, - area->base + area->size); + area->area, heap->name, heap, area->base, area->base + area->size); } @@ -909,19 +910,20 @@ mutex_unlock(&heap->lock); dprintf("heap_remove_area: area %ld with range 0x%08lx - 0x%08lx removed from %s heap %p\n", - area->area, area->base, area->base + area->size, - sHeapClasses[heap->heap_class].name, heap); + area->area, area->base, area->base + area->size, heap->name, heap); return B_OK; } static heap_allocator * -heap_create_allocator(addr_t base, size_t size, uint32 heapClass) +heap_create_allocator(const char *name, addr_t base, size_t size, + uint32 heapClass) { heap_allocator *heap = (heap_allocator *)base; base += sizeof(heap_allocator); size -= sizeof(heap_allocator); + heap->name = name; heap->heap_class = heapClass; heap->page_size = sHeapClasses[heapClass].page_size; heap->total_pages = heap->total_free_pages = heap->empty_areas = 0; @@ -1256,14 +1258,14 @@ if (address == NULL) return address; -#if PARANOID_KFREE +#if PARANOID_KERNEL_FREE // make sure 0xdeadbeef is cleared if we do not overwrite the memory // and the user does not clear it if (((uint32 *)address)[1] == 0xdeadbeef) ((uint32 *)address)[1] = 0xcccccccc; #endif -#if PARANOID_KMALLOC +#if PARANOID_KERNEL_MALLOC memset(address, 0xcc, size); #endif @@ -1318,7 +1320,7 @@ return B_ERROR; } -#if PARANOID_KFREE +#if PARANOID_KERNEL_FREE if (((uint32 *)address)[1] == 0xdeadbeef) { // This block looks like it was freed already, walk the free list // on this page to make sure this address doesn't exist. @@ -1558,7 +1560,7 @@ } heap_add_area(heap, heapArea, (addr_t)address, size); -#if PARANOID_VALIDATION +#if PARANOID_HEAP_VALIDATION heap_validate_heap(heap); #endif return B_OK; @@ -1583,7 +1585,7 @@ } for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - heap_allocator *heap = sHeapList[i]; + heap_allocator *heap = sHeaps[i]; if (sLastGrowRequest[i] > sLastHandledGrowRequest[i] || heap_should_grow(heap)) { // grow this heap if it is nearly full or if a grow was @@ -1610,7 +1612,7 @@ { for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { size_t partSize = size * sHeapClasses[i].initial_percentage / 100; - sHeapList[i] = heap_create_allocator(base, partSize, i); + sHeaps[i] = heap_create_allocator(sHeapClasses[i].name, base, partSize, i); sLastGrowRequest[i] = sLastHandledGrowRequest[i] = 0; base += partSize; } @@ -1674,7 +1676,7 @@ return growHeapArea; } - sGrowHeap = heap_create_allocator((addr_t)address, + sGrowHeap = heap_create_allocator("grow", (addr_t)address, HEAP_DEDICATED_GROW_SIZE, 0); if (sGrowHeap == NULL) { panic("heap_init_post_thread(): failed to create dedicated grow heap\n"); @@ -1735,15 +1737,19 @@ if (alignment != 0) address = (void *)ROUNDUP((addr_t)address, alignment); - dprintf("heap: allocated area %ld for huge allocation of %lu bytes\n", - allocationArea, size); + TRACE(("heap: allocated area %ld for huge allocation of %lu bytes\n", + allocationArea, size)); info->allocation_base = address; + +#if PARANOID_KERNEL_MALLOC + memset(address, 0xcc, size); +#endif return address; } uint32 heapClass = heap_class_for(size); - heap_allocator *heap = sHeapList[heapClass]; + heap_allocator *heap = sHeaps[heapClass]; bool shouldGrow = false; void *result = heap_memalign(heap, alignment, size, &shouldGrow); if (result == NULL) { @@ -1758,7 +1764,7 @@ release_sem_etc(sHeapGrowSem, 1, B_DO_NOT_RESCHEDULE); } -#if PARANOID_VALIDATION +#if PARANOID_HEAP_VALIDATION heap_validate_heap(heap); #endif @@ -1789,7 +1795,7 @@ } // try public memory, there might be something available - heap_allocator *heap = sHeapList[heap_class_for(size)]; + heap_allocator *heap = sHeaps[heap_class_for(size)]; void *result = heap_memalign(heap, 0, size, NULL); if (result != NULL) return result; @@ -1820,9 +1826,9 @@ } for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - heap_allocator *heap = sHeapList[i]; + heap_allocator *heap = sHeaps[i]; if (heap_free(heap, address) == B_OK) { -#if PARANOID_VALIDATION +#if PARANOID_HEAP_VALIDATION heap_validate_heap(heap); #endif return; @@ -1844,8 +1850,7 @@ && info->size == areaInfo.size && info->base == areaInfo.address && info->allocation_size < areaInfo.size) { delete_area(area); - dprintf("free(): freed huge allocation by deleting area %ld\n", - area); + TRACE(("free(): freed huge allocation by deleting area %ld\n", area)); return; } } @@ -1872,9 +1877,9 @@ void *newAddress = NULL; for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - heap_allocator *heap = sHeapList[i]; + heap_allocator *heap = sHeaps[i]; if (heap_realloc(heap, address, &newAddress, newSize) == B_OK) { -#if PARANOID_VALIDATION +#if PARANOID_HEAP_VALIDATION heap_validate_heap(heap); #endif return newAddress; @@ -1900,8 +1905,8 @@ if (available >= newSize) { // there is enough room available for the newSize - dprintf("realloc(): new size %ld fits in old area %ld with %ld available\n", - newSize, area, available); + TRACE(("realloc(): new size %ld fits in old area %ld with %ld available\n", + newSize, area, available)); return address; } @@ -1915,8 +1920,8 @@ memcpy(newAddress, address, min_c(newSize, info->allocation_size)); delete_area(area); - dprintf("realloc(): allocated new block %p for size %ld and deleted old area %ld\n", - newAddress, newSize, area); + TRACE(("realloc(): allocated new block %p for size %ld and deleted old area %ld\n", + newAddress, newSize, area)); return newAddress; } } From mmlr at mlotz.ch Fri Jul 4 23:21:58 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Fri, 04 Jul 2008 23:21:58 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel In-Reply-To: <20080704224646.456.1@knochen-vm.nameserver> Message-ID: <10020885252-BeMail@primary> Hi Ingo > On 2008-07-04 at 00:57:30 [+0200], mmlr at mail.berlios.de wrote: > > Author: mmlr > > Date: 2008-07-04 00:57:27 +0200 (Fri, 04 Jul 2008) > > New Revision: 26244 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26244&view=rev > > > > Modified: > > haiku/trunk/src/system/kernel/heap.cpp > > While all those changes are very nice, wasn't the intention to switch > to the > slab allocator as backend for the kernel heap earlier or later? I would say this should entirely depend on the performance. The heap as it is by now is very efficient and scales very well too. Also it is nicely self contained and has few external dependencies and little overhead. It's got quite a few nice debugging facilities too... I agree that for large amounts of common-sized memory chunks a slab is definitely the better way to manage memory. But for random sized general purpose dynamic memory I think a specialized and optimized implementation is still a better fit. In the end the performance should be the deciding factor. If it turns out that this heap implementation does not perform well, be that speed, scale or memory waste wise, compared to a slab based one, we should replace it. I would however say that beating the current heap could proof to be pretty tough :-) Regards Michael From ingo_weinhold at gmx.de Sat Jul 5 00:32:12 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sat, 05 Jul 2008 00:32:12 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel In-Reply-To: <10020885252-BeMail@primary> References: <10020885252-BeMail@primary> Message-ID: <20080705003212.647.6@knochen-vm.nameserver> On 2008-07-04 at 23:21:58 [+0200], Michael Lotz wrote: > > On 2008-07-04 at 00:57:30 [+0200], mmlr at mail.berlios.de wrote: > > > Author: mmlr > > > Date: 2008-07-04 00:57:27 +0200 (Fri, 04 Jul 2008) > > > New Revision: 26244 > > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26244&view=rev > > > > > > Modified: > > > haiku/trunk/src/system/kernel/heap.cpp > > > > While all those changes are very nice, wasn't the intention to switch > > to the > > slab allocator as backend for the kernel heap earlier or later? > > I would say this should entirely depend on the performance. The heap as > it is by now is very efficient and scales very well too. Also it is > nicely self contained and has few external dependencies and little > overhead. It's got quite a few nice debugging facilities too... > > I agree that for large amounts of common-sized memory chunks a slab is > definitely the better way to manage memory. But for random sized > general purpose dynamic memory I think a specialized and optimized > implementation is still a better fit. I don't think there's any difference in this respect. The current implementation uses bins for different allocation sizes, a slab allocator based implementation uses a set of object caches with different object sizes. > In the end the performance should be the deciding factor. If it turns > out that this heap implementation does not perform well, be that speed, > scale or memory waste wise, compared to a slab based one, we should > replace it. I would however say that beating the current heap could > proof to be pretty tough :-) I certainly don't doubt that you did a good job and the current heap implementation performs pretty well. In fact I think it's a bit similar to a slab allocator. The latter has a few optimizations (like per-CPU magazines and slab coloring), though, that will probably give it an edge. I haven't looked closely at our slab allocator implementation, but IIRC it still needs some work (e.g. object depots are disabled). Just in case you're looking for a task... :-P CU, Ingo From mmlr at mail.berlios.de Sat Jul 5 01:14:47 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 5 Jul 2008 01:14:47 +0200 Subject: [Haiku-commits] r26253 - in haiku/trunk/src/system/kernel: arch/x86 cache debug device_manager disk_device_manager fs messaging posix slab util vm Message-ID: <200807042314.m64NElbP006364@sheep.berlios.de> Author: mmlr Date: 2008-07-05 01:14:19 +0200 (Sat, 05 Jul 2008) New Revision: 26253 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26253&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/Jamfile haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp haiku/trunk/src/system/kernel/arch/x86/arch_debug_console.c haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp haiku/trunk/src/system/kernel/arch/x86/arch_user_debugger.cpp haiku/trunk/src/system/kernel/cache/Jamfile haiku/trunk/src/system/kernel/debug/Jamfile haiku/trunk/src/system/kernel/debug/debug.cpp haiku/trunk/src/system/kernel/debug/debug_commands.cpp haiku/trunk/src/system/kernel/debug/debug_variables.cpp haiku/trunk/src/system/kernel/debug/user_debugger.cpp haiku/trunk/src/system/kernel/device_manager/Jamfile haiku/trunk/src/system/kernel/device_manager/devfs.cpp haiku/trunk/src/system/kernel/device_manager/device_manager.cpp haiku/trunk/src/system/kernel/device_manager/legacy_drivers.cpp haiku/trunk/src/system/kernel/disk_device_manager/Jamfile haiku/trunk/src/system/kernel/fs/Jamfile haiku/trunk/src/system/kernel/fs/fd.cpp haiku/trunk/src/system/kernel/fs/socket.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/fs/vfs_net_boot.cpp haiku/trunk/src/system/kernel/messaging/Jamfile haiku/trunk/src/system/kernel/messaging/MessagingService.cpp haiku/trunk/src/system/kernel/posix/Jamfile haiku/trunk/src/system/kernel/slab/Jamfile haiku/trunk/src/system/kernel/util/Jamfile haiku/trunk/src/system/kernel/vm/Jamfile Log: * Removed -Wno-unused from all KernelMergeObjects in kernel Jamfiles. * Fixed most of the warnings resulting from that by removing actually not used variables or moving declaration into the #IF. Left unused functions there though, as I wouldn't know if they are supposed to be used again. * Fixed two statements with no effect (clamping to MAX_ANCILLARY_DATA_LEN in socket.cpp and unsetting fCounterSem in MessagingService.cpp). * Some style cleanups. Modified: haiku/trunk/src/system/kernel/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -38,7 +38,7 @@ generic_vm_physical_page_mapper.cpp : - $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + $(TARGET_KERNEL_PIC_CCFLAGS) ; CreateAsmStructOffsetsHeader asm_offsets.h : asm_offsets.cpp ; Modified: haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/arch_cpu.c 2008-07-04 23:14:19 UTC (rev 26253) @@ -159,8 +159,6 @@ void x86_set_mtrr(uint32 index, uint64 base, uint64 length, uint8 type) { - cpu_status state; - struct set_mtrr_parameter parameter; parameter.index = index; parameter.base = base; @@ -242,89 +240,89 @@ { str[0] = 0; - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FPU) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FPU) strlcat(str, "fpu ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_VME) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_VME) strlcat(str, "vme ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DE) strlcat(str, "de ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE) strlcat(str, "pse ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TSC) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TSC) strlcat(str, "tsc ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MSR) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MSR) strlcat(str, "msr ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAE) strlcat(str, "pae ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCE) strlcat(str, "mce ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CX8) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CX8) strlcat(str, "cx8 ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_APIC) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_APIC) strlcat(str, "apic ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SEP) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SEP) strlcat(str, "sep ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MTRR) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MTRR) strlcat(str, "mtrr ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PGE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PGE) strlcat(str, "pge ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCA) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MCA) strlcat(str, "mca ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CMOV) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CMOV) strlcat(str, "cmov ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAT) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PAT) strlcat(str, "pat ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE36) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSE36) strlcat(str, "pse36 ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSN) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PSN) strlcat(str, "psn ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CLFSH) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_CLFSH) strlcat(str, "clfsh ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DS) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_DS) strlcat(str, "ds ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_ACPI) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_ACPI) strlcat(str, "acpi ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MMX) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_MMX) strlcat(str, "mmx ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FXSR) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_FXSR) strlcat(str, "fxsr ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE) strlcat(str, "sse ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE2) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SSE2) strlcat(str, "sse2 ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SS) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_SS) strlcat(str, "ss ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_HTT) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_HTT) strlcat(str, "htt ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TM) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_TM) strlcat(str, "tm ", strlen); - if(cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PBE) + if (cpu->arch.feature[FEATURE_COMMON] & IA32_FEATURE_PBE) strlcat(str, "pbe ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_SSE3) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_SSE3) strlcat(str, "sse3 ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_MONITOR) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_MONITOR) strlcat(str, "monitor ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_DSCPL) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_DSCPL) strlcat(str, "dscpl ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_EST) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_EST) strlcat(str, "est ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_TM2) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_TM2) strlcat(str, "tm2 ", strlen); - if(cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_CNXTID) + if (cpu->arch.feature[FEATURE_EXT] & IA32_FEATURE_EXT_CNXTID) strlcat(str, "cnxtid ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_SYSCALL) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_SYSCALL) strlcat(str, "syscall ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_NX) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_NX) strlcat(str, "nx ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_MMXEXT) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_MMXEXT) strlcat(str, "mmxext ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_FFXSR) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_FFXSR) strlcat(str, "ffxsr ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_LONG) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_LONG) strlcat(str, "long ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOWEXT) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOWEXT) strlcat(str, "3dnowext ", strlen); - if(cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOW) + if (cpu->arch.feature[FEATURE_EXT_AMD] & IA32_FEATURE_AMD_EXT_3DNOW) strlcat(str, "3dnow ", strlen); } @@ -333,7 +331,6 @@ detect_cpu(int curr_cpu) { cpuid_info cpuid; - unsigned int data[4]; char vendor_str[17]; int i; cpu_ent *cpu = get_cpu_struct(); @@ -369,13 +366,13 @@ // figure out what vendor we have here - for(i=0; iarch.vendor = i; cpu->arch.vendor_name = vendor_info[i].vendor; break; } - if(vendor_info[i].ident_string[1] && !strcmp(vendor_str, vendor_info[i].ident_string[1])) { + if (vendor_info[i].ident_string[1] && !strcmp(vendor_str, vendor_info[i].ident_string[1])) { cpu->arch.vendor = i; cpu->arch.vendor_name = vendor_info[i].vendor; break; @@ -384,7 +381,7 @@ // see if we can get the model name get_current_cpuid(&cpuid, 0x80000000); - if(cpuid.eax_0.max_eax >= 0x80000004) { + if (cpuid.eax_0.max_eax >= 0x80000004) { // build the model string (need to swap ecx/edx data before copying) unsigned int temp; memset(cpu->arch.model_name, 0, sizeof(cpu->arch.model_name)); @@ -399,9 +396,9 @@ memcpy(cpu->arch.model_name + 32, cpuid.as_chars, sizeof(cpuid.as_chars)); // some cpus return a right-justified string - for(i = 0; cpu->arch.model_name[i] == ' '; i++) + for (i = 0; cpu->arch.model_name[i] == ' '; i++) ; - if(i > 0) { + if (i > 0) { memmove(cpu->arch.model_name, &cpu->arch.model_name[i], strlen(&cpu->arch.model_name[i]) + 1); @@ -417,7 +414,7 @@ get_current_cpuid(&cpuid, 1); cpu->arch.feature[FEATURE_COMMON] = cpuid.eax_1.features; // edx cpu->arch.feature[FEATURE_EXT] = cpuid.eax_1.extended_features; // ecx - if(cpu->arch.vendor == VENDOR_AMD) { + if (cpu->arch.vendor == VENDOR_AMD) { get_current_cpuid(&cpuid, 0x80000001); cpu->arch.feature[FEATURE_EXT_AMD] = cpuid.regs.edx; // edx } Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -270,7 +270,7 @@ struct thread *thread = NULL; addr_t oldPageDirectory = 0; uint32 ebp = x86_read_ebp(); - int32 i, num = 0, last = 0; + int32 num = 0, last = 0; setup_for_thread(argc == 2 ? argv[1] : NULL, &thread, &ebp, &oldPageDirectory); @@ -490,7 +490,6 @@ } struct thread *thread = NULL; - int32 i; if (argc < 2) { thread = thread_get_current_thread(); Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug_console.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_debug_console.c 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/arch_debug_console.c 2008-07-04 23:14:19 UTC (rev 26253) @@ -186,7 +186,7 @@ static bool altPressed = false; static uint8 special = 0; static uint8 special2 = 0; - uint8 key, ascii = 0; + uint8 key = 0; if (special & 0x80) { special &= ~0x80; Modified: haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/arch_thread.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -310,7 +310,6 @@ arch_thread_init_tls(struct thread *thread) { uint32 tls[TLS_USER_THREAD_SLOT + 1]; - int32 i; thread->user_local_storage = thread->user_stack_base + thread->user_stack_size; Modified: haiku/trunk/src/system/kernel/arch/x86/arch_user_debugger.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_user_debugger.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/arch/x86/arch_user_debugger.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -530,8 +530,6 @@ arch_set_debug_cpu_state(const struct debug_cpu_state *cpuState) { if (struct iframe *frame = i386_get_user_iframe()) { - struct thread *thread = thread_get_current_thread(); - i386_frstor(cpuState->extended_regs); // For this to be correct the calling function must not use these // registers (not even indirectly). @@ -564,8 +562,6 @@ arch_get_debug_cpu_state(struct debug_cpu_state *cpuState) { if (struct iframe *frame = i386_get_user_iframe()) { - struct thread *thread = thread_get_current_thread(); - i386_fnsave(cpuState->extended_regs); // For this to be correct the calling function must not use these // registers (not even indirectly). Modified: haiku/trunk/src/system/kernel/cache/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/cache/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/cache/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -6,5 +6,5 @@ file_map.cpp vnode_store.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/debug/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/debug/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/debug/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -17,5 +17,5 @@ tracing.cpp user_debugger.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/debug/debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/debug.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/debug/debug.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -87,7 +87,6 @@ #define HISTORY_SIZE 16 static char sLineBuffer[HISTORY_SIZE][LINE_BUFFER_SIZE] = { "", }; -static char sParseLine[LINE_BUFFER_SIZE]; static int32 sCurrentLine = 0; #define distance(a, b) ((a) < (b) ? (b) - (a) : (a) - (b)) @@ -880,8 +879,6 @@ syslog_write(revisionBuffer, length); return B_OK; -err3: - free(sSyslogBuffer); err2: free(sSyslogMessage); err1: Modified: haiku/trunk/src/system/kernel/debug/debug_commands.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/debug_commands.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/debug/debug_commands.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -392,7 +392,6 @@ } if (strcmp((*command)->name, nextCommand->name) > 0) { - debugger_command* tmpCommand = nextCommand->next; (*command)->next = nextCommand->next; nextCommand->next = *command; *command = nextCommand; Modified: haiku/trunk/src/system/kernel/debug/debug_variables.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/debug_variables.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/debug/debug_variables.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -109,9 +109,6 @@ static Variable* get_variable(const char* variableName, bool create) { - Variable* variables; - int variableCount; - // find the variable in the respective array and a free slot, we can // use, if it doesn't exist yet Variable* freeSlot = NULL; Modified: haiku/trunk/src/system/kernel/debug/user_debugger.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/user_debugger.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/debug/user_debugger.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -2214,7 +2214,6 @@ _user_debugger(const char *userMessage) { // install the default debugger, if there is none yet - struct thread *thread = thread_get_current_thread(); port_id nubPort; status_t error = ensure_debugger_installed(B_CURRENT_TEAM, &nubPort); if (error != B_OK) { Modified: haiku/trunk/src/system/kernel/device_manager/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/device_manager/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/device_manager/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -13,5 +13,5 @@ # probe.cpp settings.cpp : - $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/device_manager/devfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/devfs.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/device_manager/devfs.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -1190,7 +1190,6 @@ size_t *_bufferSize) { struct devfs_vnode *link = (struct devfs_vnode *)_link->private_node; - size_t bufferSize = *_bufferSize; if (!S_ISLNK(link->stream.type)) return B_BAD_VALUE; @@ -1461,7 +1460,6 @@ devfs_ioctl(fs_volume *_volume, fs_vnode *_vnode, void *_cookie, ulong op, void *buffer, size_t length) { - struct devfs *fs = (struct devfs *)_volume->private_volume; struct devfs_vnode *vnode = (struct devfs_vnode *)_vnode->private_node; struct devfs_cookie *cookie = (struct devfs_cookie *)_cookie; @@ -1499,8 +1497,8 @@ case B_GET_DRIVER_FOR_DEVICE: { - const char* path; #if 0 + const char* path; if (!vnode->stream.u.dev.driver) return B_ENTRY_NOT_FOUND; path = vnode->stream.u.dev.driver->path; @@ -1531,7 +1529,6 @@ case B_GET_PATH_FOR_DEVICE: { char path[256]; - status_t err; /* TODO: we might want to actually find the mountpoint * of that instance of devfs... * but for now we assume it's mounted on /dev Modified: haiku/trunk/src/system/kernel/device_manager/device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/device_manager.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/device_manager/device_manager.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -194,9 +194,7 @@ static recursive_lock sLock; static const char* sGenericContextPath; -static uint32 sDriverUpdateCycle = 1; - // #pragma mark - Modified: haiku/trunk/src/system/kernel/device_manager/legacy_drivers.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/legacy_drivers.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/device_manager/legacy_drivers.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -178,7 +178,6 @@ static status_t load_driver(legacy_driver *driver); -static int32 sDefaultApiVersion = 1; static hash_table* sDriverHash; static DriverWatcher sDriverWatcher; static int32 sDriverEvents; @@ -334,8 +333,6 @@ { status_t (*init_hardware)(void); status_t (*init_driver)(void); - const char **devicePaths; - int32 exported = 0; status_t status; driver->binary_updated = false; @@ -417,10 +414,6 @@ driver->image = image; return republish_driver(driver); -error3: - if (driver->uninit_driver) - driver->uninit_driver(); - error2: if (driver->uninit_hardware) driver->uninit_hardware(); @@ -679,10 +672,8 @@ static void -handle_driver_events(void *_fs, int /*iteration*/) +handle_driver_events(void */*_fs*/, int /*iteration*/) { - struct devfs *fs = (devfs *)_fs; - if (atomic_and(&sDriverEvents, 0) == 0) return; Modified: haiku/trunk/src/system/kernel/disk_device_manager/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/disk_device_manager/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -33,7 +33,7 @@ # disk device types DiskDeviceTypes.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; # KFileDiskDevice.cpp needs the virtualdrive.h Header. Add it here to not Modified: haiku/trunk/src/system/kernel/fs/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/fs/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/fs/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -17,5 +17,5 @@ vfs_boot.cpp vfs_net_boot.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/fs/fd.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/fd.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/fs/fd.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -856,8 +856,6 @@ status_t _user_ioctl(int fd, ulong op, void *buffer, size_t length) { - struct file_descriptor *descriptor; - if (!IS_USER_ADDRESS(buffer)) return B_BAD_ADDRESS; Modified: haiku/trunk/src/system/kernel/fs/socket.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/socket.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/fs/socket.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -946,7 +946,7 @@ if (message.msg_controllen < 0) return B_BAD_VALUE; if (message.msg_controllen > MAX_ANCILLARY_DATA_LEN) - message.msg_controllen > MAX_ANCILLARY_DATA_LEN; + message.msg_controllen = MAX_ANCILLARY_DATA_LEN; message.msg_control = ancillary = malloc(message.msg_controllen); if (message.msg_control == NULL) Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -169,8 +169,6 @@ } }; -static mutex sFileSystemsMutex = MUTEX_INITIALIZER("vfs_lock"); - /*! \brief Guards sMountsTable. The holder is allowed to read/write access the sMountsTable. @@ -539,7 +537,6 @@ get_mount(dev_t id, struct fs_mount **_mount) { struct fs_mount *mount; - status_t status; MutexLocker nodeLocker(sVnodeMutex); MutexLocker mountLocker(sMountMutex); @@ -1042,8 +1039,6 @@ // Write back the modified pages of some unused vnodes and free them - uint32 freeCount = count; - for (uint32 i = 0; i < count; i++) { mutex_lock(&sVnodeMutex); struct vnode *vnode = (struct vnode *)list_remove_head_item( @@ -1846,7 +1841,6 @@ while (true) { struct vnode *nextVnode; - ino_t vnodeID; char *nextPath; TRACE(("vnode_path_to_vnode: top of loop. p = %p, p = '%s'\n", path, path)); @@ -4215,8 +4209,6 @@ static status_t vfs_resize_fd_table(struct io_context *context, const int newSize) { - struct file_descriptor **fds; - if (newSize <= 0 || newSize > MAX_FD_TABLE_SIZE) return EINVAL; @@ -4278,7 +4270,6 @@ static status_t vfs_resize_monitor_table(struct io_context *context, const int newSize) { - void *fds; int status = B_OK; if (newSize <= 0 || newSize > MAX_NODE_MONITORS) @@ -7208,8 +7199,6 @@ status_t _kern_read_link(int fd, const char *path, char *buffer, size_t *_bufferSize) { - status_t status; - if (path) { KPath pathBuffer(path, false, B_PATH_NAME_LENGTH + 1); if (pathBuffer.InitCheck() != B_OK) @@ -7837,7 +7826,6 @@ } // read link - struct stat st; if (HAS_FS_CALL(fileVnode, read_symlink)) { size_t bufferSize = B_PATH_NAME_LENGTH - 1; error = FS_CALL(fileVnode, read_symlink, path, &bufferSize); Modified: haiku/trunk/src/system/kernel/fs/vfs_net_boot.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs_net_boot.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/fs/vfs_net_boot.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -121,8 +121,6 @@ return; } - status_t error = B_OK; - while (dirent* entry = readdir(dir)) { // skip "." and ".." if (strcmp(entry->d_name, ".") == 0 Modified: haiku/trunk/src/system/kernel/messaging/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/messaging/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/messaging/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -12,5 +12,5 @@ KMessage.cpp MessagingService.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/messaging/MessagingService.cpp =================================================================== --- haiku/trunk/src/system/kernel/messaging/MessagingService.cpp 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/messaging/MessagingService.cpp 2008-07-04 23:14:19 UTC (rev 26253) @@ -377,7 +377,7 @@ // unset the other members fLockSem = -1; - fCounterSem -1; + fCounterSem = -1; fServerTeam = -1; return B_OK; Modified: haiku/trunk/src/system/kernel/posix/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/posix/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/posix/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -5,5 +5,5 @@ KernelMergeObject kernel_posix.o : realtime_sem.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/slab/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/slab/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/slab/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -6,5 +6,5 @@ allocator.cpp Slab.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; Modified: haiku/trunk/src/system/kernel/util/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/util/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/util/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -11,5 +11,5 @@ queue.c ring_buffer.cpp - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused -DUSING_LIBGCC + : $(TARGET_KERNEL_PIC_CCFLAGS) -DUSING_LIBGCC ; Modified: haiku/trunk/src/system/kernel/vm/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/vm/Jamfile 2008-07-04 21:05:46 UTC (rev 26252) +++ haiku/trunk/src/system/kernel/vm/Jamfile 2008-07-04 23:14:19 UTC (rev 26253) @@ -14,5 +14,5 @@ vm_store_null.c #vm_tests.c - : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : $(TARGET_KERNEL_PIC_CCFLAGS) ; From bonefish at mail.berlios.de Sat Jul 5 02:09:43 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 5 Jul 2008 02:09:43 +0200 Subject: [Haiku-commits] r26254 - haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager Message-ID: <200807050009.m6509ht5012079@sheep.berlios.de> Author: bonefish Date: 2008-07-05 02:09:34 +0200 (Sat, 05 Jul 2008) New Revision: 26254 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26254&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp Log: devfs::lock is a recursive_lock. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp 2008-07-04 23:14:19 UTC (rev 26253) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp 2008-07-05 00:09:34 UTC (rev 26254) @@ -573,7 +573,7 @@ new_node(struct devfs *fs, const char *path, struct devfs_vnode **_node, struct devfs_vnode **_dir) { - ASSERT_LOCKED_MUTEX(&fs->lock); + ASSERT_LOCKED_RECURSIVE(&fs->lock); // copy the path over to a temp buffer so we can munge it KPath tempPath(path); From bonefish at mail.berlios.de Sat Jul 5 02:10:20 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 5 Jul 2008 02:10:20 +0200 Subject: [Haiku-commits] r26255 - haiku/branches/developer/bonefish/vm/src/system/kernel Message-ID: <200807050010.m650AKCR012194@sheep.berlios.de> Author: bonefish Date: 2008-07-05 02:10:13 +0200 (Sat, 05 Jul 2008) New Revision: 26255 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26255&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/elf.cpp Log: Check the mutex only when not in KDL. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/elf.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/elf.cpp 2008-07-05 00:09:34 UTC (rev 26254) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/elf.cpp 2008-07-05 00:10:13 UTC (rev 26255) @@ -127,7 +127,10 @@ struct hash_iterator iterator; struct elf_image_info *image; - ASSERT_LOCKED_MUTEX(&sImageMutex); +#if KDEBUG + if (!debug_debugger_running()) + ASSERT_LOCKED_MUTEX(&sImageMutex); +#endif hash_open(sImagesHash, &iterator); From bonefish at mail.berlios.de Sat Jul 5 02:14:32 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 5 Jul 2008 02:14:32 +0200 Subject: [Haiku-commits] r26256 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807050014.m650EWM2013156@sheep.berlios.de> Author: bonefish Date: 2008-07-05 02:14:26 +0200 (Sat, 05 Jul 2008) New Revision: 26256 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26256&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp Log: * We need to lock the cache in vm_cache_release_ref() when deleting the cache. * Moved the destruction of the VMCache lock from the destructor to VMCache::Delete(), while still holding the global cache list lock. Will be necessary soon. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-05 00:10:13 UTC (rev 26255) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-05 00:14:26 UTC (rev 26256) @@ -538,6 +538,7 @@ // delete this cache + mutex_lock(&cache->lock); cache->Delete(); } @@ -851,7 +852,6 @@ VMCache::~VMCache() { - mutex_destroy(&lock); } @@ -933,6 +933,8 @@ gDebugCacheList = debug_next; #endif + mutex_destroy(&lock); + mutex_unlock(&sCacheListLock); delete this; From bonefish at mail.berlios.de Sat Jul 5 02:17:16 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 5 Jul 2008 02:17:16 +0200 Subject: [Haiku-commits] r26257 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel Message-ID: <200807050017.m650HGRD013894@sheep.berlios.de> Author: bonefish Date: 2008-07-05 02:17:00 +0200 (Sat, 05 Jul 2008) New Revision: 26257 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26257&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp Log: * Reenabled ASSERT_LOCKED_{MUTEX,RECURSIVE}() macros. * Added mutex_switch_lock(), which unlocks one lock and locks another one in an atomic manner (similar to switch_sem()). Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h 2008-07-05 00:14:26 UTC (rev 26256) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h 2008-07-05 00:17:00 UTC (rev 26257) @@ -52,13 +52,13 @@ #define RW_LOCK_FLAG_CLONE_NAME 0x1 -#if 0 && KDEBUG // XXX disable this for now, it causes problems when including thread.h here -# include -#define ASSERT_LOCKED_RECURSIVE(r) { ASSERT(thread_get_current_thread_id() == (r)->holder); } -#define ASSERT_LOCKED_MUTEX(m) { ASSERT(thread_get_current_thread_id() == (m)->holder); } +#if KDEBUG +# define ASSERT_LOCKED_RECURSIVE(r) \ + { ASSERT(find_thread(NULL) == (r)->lock.holder); } +# define ASSERT_LOCKED_MUTEX(m) { ASSERT(find_thread(NULL) == (m)->holder); } #else -#define ASSERT_LOCKED_RECURSIVE(r) -#define ASSERT_LOCKED_MUTEX(m) +# define ASSERT_LOCKED_RECURSIVE(r) do {} while (false) +# define ASSERT_LOCKED_MUTEX(m) do {} while (false) #endif @@ -100,10 +100,15 @@ // name is *not* cloned nor freed in mutex_destroy() extern void mutex_init_etc(mutex* lock, const char* name, uint32 flags); extern void mutex_destroy(mutex* lock); +extern status_t mutex_switch_lock(mutex* from, mutex* to); + // Unlocks "from" and locks "to" such that unlocking and starting to wait + // for the lock is atomically. I.e. if "from" guards the object "to" belongs + // to, the operation is safe as long as "from" is held while destroying + // "to". // implementation private: extern status_t _mutex_lock(mutex* lock, bool threadsLocked); -extern void _mutex_unlock(mutex* lock); +extern void _mutex_unlock(mutex* lock, bool threadsLocked); extern status_t _mutex_trylock(mutex* lock); @@ -149,12 +154,10 @@ static inline void mutex_unlock(mutex* lock) { -#ifdef KDEBUG - _mutex_unlock(lock); -#else +#if !defined(KDEBUG) if (atomic_add(&lock->count, 1) < -1) - _mutex_unlock(lock); #endif + _mutex_unlock(lock, false); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp 2008-07-05 00:14:26 UTC (rev 26256) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp 2008-07-05 00:17:00 UTC (rev 26257) @@ -385,6 +385,20 @@ status_t +mutex_switch_lock(mutex* from, mutex* to) +{ + InterruptsSpinLocker locker(thread_spinlock); + +#if !defined(KDEBUG) + if (atomic_add(&from->count, 1) < -1) +#endif + _mutex_unlock(from, true); + + return mutex_lock_threads_locked(to); +} + + +status_t _mutex_lock(mutex* lock, bool threadsLocked) { #ifdef KDEBUG @@ -441,9 +455,10 @@ void -_mutex_unlock(mutex* lock) +_mutex_unlock(mutex* lock, bool threadsLocked) { - InterruptsSpinLocker _(thread_spinlock); + // lock only, if !threadsLocked + InterruptsSpinLocker locker(thread_spinlock, false, !threadsLocked); #ifdef KDEBUG if (thread_get_current_thread_id() != lock->holder) { From mmlr at mail.berlios.de Sat Jul 5 03:12:36 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Sat, 5 Jul 2008 03:12:36 +0200 Subject: [Haiku-commits] r26258 - haiku/trunk/src/system/kernel Message-ID: <200807050112.m651Cas2020950@sheep.berlios.de> Author: mmlr Date: 2008-07-05 03:12:34 +0200 (Sat, 05 Jul 2008) New Revision: 26258 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26258&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: Make the all_areas list ordered by base and take advantage of this ordering when looking up the target area on free(). This makes free() scale better with large area counts, as the lookup can abort early when it knows that no area below the only candidate can contain the address. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-05 00:17:00 UTC (rev 26257) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-05 01:12:34 UTC (rev 26258) @@ -641,7 +641,7 @@ uint32 totalPageCount = 0; uint32 totalFreePageCount = 0; heap_area *area = heap->all_areas; - while (area) { + while (area != NULL) { // validate the free pages list uint32 freePageCount = 0; heap_page *lastPage = NULL; @@ -693,9 +693,9 @@ area = heap->areas; heap_area *lastArea = NULL; uint32 lastFreeCount = 0; - while (area) { + while (area != NULL) { if (area->free_page_count < lastFreeCount) - panic("ordering of area list broken\n"); + panic("size ordering of area list broken\n"); if (area->prev != lastArea) panic("area list entry has invalid prev link\n"); @@ -705,6 +705,16 @@ area = area->next; } + lastArea = NULL; + area = heap->all_areas; + while (area != NULL) { + if (lastArea != NULL && lastArea->base < area->base) + panic("base ordering of all_areas list broken\n"); + + lastArea = area; + area = area->all_next; + } + // validate the bins for (uint32 i = 0; i < heap->bin_count; i++) { heap_bin *bin = &heap->bins[i]; @@ -845,8 +855,19 @@ area->prev = lastArea; } - area->all_next = heap->all_areas; - heap->all_areas = area; + // insert this area in the all_areas list so it stays ordered by base + if (heap->all_areas == NULL || heap->all_areas->base < area->base) { + area->all_next = heap->all_areas; + heap->all_areas = area; + } else { + heap_area *insert = heap->all_areas; + while (insert->all_next && insert->all_next->base > area->base) + insert = insert->all_next; + + area->all_next = insert->all_next; + insert->all_next = area; + } + heap->total_pages += area->page_count; heap->total_free_pages += area->free_page_count; @@ -1283,9 +1304,19 @@ heap_area *area = heap->all_areas; while (area) { - if ((addr_t)address >= area->base - && (addr_t)address < area->base + area->size) + // since the all_areas list is ordered by base with the biggest + // base at the top, we need only find the first area with a base + // smaller than our address to become our only candidate for freeing + if (area->base <= (addr_t)address) { + if ((addr_t)address >= area->base + area->size) { + // the only candidate area doesn't contain the address, + // set it to NULL so we return below (none of the other areas + // can contain the address as the list is ordered) + area = NULL; + } + break; + } area = area->all_next; } From mmlr at mlotz.ch Sat Jul 5 15:06:53 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Sat, 05 Jul 2008 15:06:53 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel In-Reply-To: <20080705003212.647.6@knochen-vm.nameserver> Message-ID: <12295930101-BeMail@primary> Hi again > I don't think there's any difference in this respect. The current > implementation uses bins for different allocation sizes, a slab > allocator > based implementation uses a set of object caches with different > object > sizes. Yes, but that's quite a big difference in fact. One heap_allocator can have multiple bins of different sizes. It employs a address -> heap_page -> bin translation to directly look up in what page and bin an allocation resides. With a set of object caches this is more involved, as you have to search through those to find in which one an allocation resides, as with a bog standard free() you don't know the allocation size. That's in fact the single most problematic thing - not knowing the allocation size. There are ways around that by employing a boundary tag to store the allocation size, but that is neither safe nor space efficient. Especially when doing aligned allocations of B_PAGE_SIZE this can get pretty wasteful. > implementation performs pretty well. In fact I think it's a bit > similar to > a slab allocator. The latter has a few optimizations (like per-CPU > magazines and slab coloring), though, that will probably give it an > edge. In fact it has become (unintentionally even ;-) mostly the same as a slab. It has a cache (heap_allocator), slabs (heap_pages), objects (the actual allocations) and depots (heap_area). It does a few optimizations by removing the full lists for example (as they are not really needed as you can't do anything with a full page/area) and through bins it has the above mentioned advantage over a set of individual object_caches. This makes it just more fit to the task at hand. And really adding per-CPU allocators is just a matter of adding a [< cpuCount>] dimension to sHeaps and taking the current CPU into account when choosing the heap to allocate from. Coloring can be done by simply rotating the start offset of a bin per page. So I'd rather add those two things to the heap than changing the heap to a not exactly fitting mechanism. > I haven't looked closely at our slab allocator implementation, but > IIRC it > still needs some work (e.g. object depots are disabled). Just in case > you're looking for a task... :-P I have taken a closer look at our slab and the block_allocator it provides, and it just isn't as efficient (space wise, it uses said boundary tag). In fact since the heap is so similar to a slab now, you could just as well suggest replacing the slab with the heap. By simply removing the bins from the heap (making the element size global per allocator) and adding constructors/destructors, you'd get a perfectly capable slab... But really in the sense of "the best tool for the job" I think we just shouldn't mix both approaches. Each has it's own set of problems and mechanism to solve them. Using one for the other would undoubtatly work, but why would you use a slab for something that isn't really the task of a slab by wrapping around glue code and using extra memory when you have a perfectly capable heap that is specifically designed for the task and doesn't need either workaround? It's not even like you could remove a lot of code, as the heap is pretty compact and self contained. Regards Michael From axeld at mail.berlios.de Sat Jul 5 15:38:39 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 5 Jul 2008 15:38:39 +0200 Subject: [Haiku-commits] r26259 - haiku/trunk/src/system/kernel/cache Message-ID: <200807051338.m65Dcdef002526@sheep.berlios.de> Author: axeld Date: 2008-07-05 15:38:38 +0200 (Sat, 05 Jul 2008) New Revision: 26259 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26259&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp Log: * Implemented binary search for the disk offsets. * Moved the file_extent array into its own structure (unnamed union problem with GCC4), and added max_count field (currently unused). * Minor cleanup. Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-05 01:12:34 UTC (rev 26258) +++ haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-05 13:38:38 UTC (rev 26259) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -39,18 +39,25 @@ file_io_vec disk; }; +struct file_extent_array { + file_extent *array; + size_t max_count; +}; + struct file_map { file_map(off_t size); ~file_map(); file_extent *operator[](uint32 index); file_extent *ExtentAt(uint32 index); + file_extent *FindExtent(off_t offset, uint32 *_index); status_t Add(file_io_vec *vecs, size_t vecCount, off_t &lastOffset); + void Invalidate(off_t offset, off_t size); void Free(); union { file_extent direct[CACHED_FILE_EXTENTS]; - file_extent *array; + file_extent_array indirect; }; size_t count; struct vnode *vnode; @@ -60,7 +67,7 @@ file_map::file_map(off_t _size) { - array = NULL; + indirect.array = NULL; count = 0; size = _size; } @@ -86,16 +93,45 @@ return NULL; if (count > CACHED_FILE_EXTENTS) - return &array[index]; + return &indirect.array[index]; return &direct[index]; } +file_extent * +file_map::FindExtent(off_t offset, uint32 *_index) +{ + int32 left = 0; + int32 right = count - 1; + + while (left <= right) { + int32 index = (left + right) / 2; + file_extent *extent = ExtentAt(index); + + if (extent->offset > offset) { + // search in left part + right = index - 1; + } else if (extent->offset + extent->disk.length <= offset) { + // search in right part + left = index + 1; + } else { + // found extent + if (_index) + *_index = index; + + return extent; + } + } + + return NULL; +} + + status_t file_map::Add(file_io_vec *vecs, size_t vecCount, off_t &lastOffset) { - TRACE(("file_map::Add(vecCount = %ld)\n", vecCount)); + TRACE(("file_map@%p::Add(vecCount = %ld)\n", this, vecCount)); off_t offset = 0; @@ -105,12 +141,12 @@ // TODO: once we can invalidate only parts of the file map, // we might need to copy the previously cached file extends // from the direct range - file_extent *newMap = (file_extent *)realloc(array, + file_extent *newMap = (file_extent *)realloc(indirect.array, (count + vecCount) * sizeof(file_extent)); if (newMap == NULL) return B_NO_MEMORY; - array = newMap; + indirect.array = newMap; if (count != 0) { file_extent *extent = ExtentAt(count - 1); @@ -131,7 +167,7 @@ } #ifdef TRACE_FILE_MAP - for (uint32 i = 0; i < count; i++) { + for (uint32 i = start; i < count; i++) { file_extent *extent = ExtentAt(i); dprintf("[%ld] extend offset %Ld, disk offset %Ld, length %Ld\n", i, extent->offset, extent->disk.offset, extent->disk.length); @@ -144,36 +180,21 @@ void -file_map::Free() +file_map::Invalidate(off_t offset, off_t size) { - if (count > CACHED_FILE_EXTENTS) - free(array); - - array = NULL; - count = 0; + // TODO: honour offset/size parameters + Free(); } -// #pragma mark - - - -static file_extent * -find_file_extent(file_map &map, off_t offset, uint32 *_index) +void +file_map::Free() { - // TODO: do binary search + if (count > CACHED_FILE_EXTENTS) + free(indirect.array); - for (uint32 index = 0; index < map.count; index++) { - file_extent *extent = map[index]; - - if (extent->offset <= offset - && extent->offset + extent->disk.length > offset) { - if (_index) - *_index = index; - return extent; - } - } - - return NULL; + indirect.array = NULL; + count = 0; } @@ -219,10 +240,11 @@ if (_map == NULL) return; - // TODO: honour offset/size parameters file_map *map = (file_map *)_map; -// if (size < map->size) - map->Free(); + + if (size < map->size) + map->Invalidate(size, map->size - size); + map->size = size; } @@ -233,9 +255,8 @@ if (_map == NULL) return; - // TODO: honour offset/size parameters file_map *map = (file_map *)_map; - map->Free(); + map->Invalidate(offset, size); } @@ -298,7 +319,7 @@ // translate it for the requested access. uint32 index; - file_extent *fileExtent = find_file_extent(map, offset, &index); + file_extent *fileExtent = map.FindExtent(offset, &index); if (fileExtent == NULL) { // access outside file bounds? But that's not our problem *_count = 0; From axeld at mail.berlios.de Sat Jul 5 19:58:48 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Sat, 5 Jul 2008 19:58:48 +0200 Subject: [Haiku-commits] r26260 - haiku/trunk/src/system/kernel/cache Message-ID: <200807051758.m65HwmVM010114@sheep.berlios.de> Author: axeld Date: 2008-07-05 19:58:47 +0200 (Sat, 05 Jul 2008) New Revision: 26260 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26260&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp Log: Vastly improved the file map implementation: * adjacent vecs are now joined. * partial invalidation no longer frees all cached extents. * the array can now be larger than the needed number of entries, allowing for a saner array allocation policy. * it does no longer read the whole file map when the first translation is requested, but only as much as required (it will still ask the file system for the maximum file size, but it won't traverse further as long as the initial request is fulfilled). * This should help a lot with the ext2 file system that doesn't support real file extents (but keeps a list of blocks). Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-05 13:38:38 UTC (rev 26259) +++ haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-05 17:58:47 UTC (rev 26260) @@ -55,6 +55,8 @@ void Invalidate(off_t offset, off_t size); void Free(); + status_t _MakeSpace(size_t amount); + union { file_extent direct[CACHED_FILE_EXTENTS]; file_extent_array indirect; @@ -129,47 +131,94 @@ status_t +file_map::_MakeSpace(size_t amount) +{ + if (amount <= CACHED_FILE_EXTENTS) { + // just use the reserved area in the file_cache_ref structure + if (amount <= CACHED_FILE_EXTENTS && count > CACHED_FILE_EXTENTS) { + // the new size is smaller than the minimal array size + file_extent *array = indirect.array; + memcpy(direct, array, sizeof(file_extent) * amount); + free(array); + } + } else { + // resize array if needed + file_extent *oldArray = NULL; + size_t maxCount = CACHED_FILE_EXTENTS; + if (count > CACHED_FILE_EXTENTS) { + oldArray = indirect.array; + maxCount = indirect.max_count; + } + + if (amount > maxCount) { + // allocate new array + while (maxCount < amount) { + if (maxCount < 32768) + maxCount <<= 1; + else + maxCount += 32768; + } + + file_extent *newArray = (file_extent *)realloc(oldArray, + maxCount * sizeof(file_extent)); + if (newArray == NULL) + return B_NO_MEMORY; + + if (count > 0 && count <= CACHED_FILE_EXTENTS) + memcpy(newArray, direct, sizeof(file_extent) * count); + + indirect.array = newArray; + indirect.max_count = maxCount; + } + } + + count = amount; + return B_OK; +} + + +status_t file_map::Add(file_io_vec *vecs, size_t vecCount, off_t &lastOffset) { TRACE(("file_map@%p::Add(vecCount = %ld)\n", this, vecCount)); + uint32 start = count; off_t offset = 0; - if (vecCount <= CACHED_FILE_EXTENTS && count == 0) { - // just use the reserved area in the file_cache_ref structure - } else { - // TODO: once we can invalidate only parts of the file map, - // we might need to copy the previously cached file extends - // from the direct range - file_extent *newMap = (file_extent *)realloc(indirect.array, - (count + vecCount) * sizeof(file_extent)); - if (newMap == NULL) - return B_NO_MEMORY; + status_t status = _MakeSpace(count + vecCount); + if (status != B_OK) + return status; - indirect.array = newMap; + file_extent *lastExtent = NULL; + if (start != 0) { + lastExtent = ExtentAt(start - 1); + offset = lastExtent->offset + lastExtent->disk.length; + } - if (count != 0) { - file_extent *extent = ExtentAt(count - 1); - offset = extent->offset + extent->disk.length; + for (uint32 i = 0; i < vecCount; i++) { + if (lastExtent != NULL) { + if (lastExtent->disk.offset + lastExtent->disk.length + == vecs[i].offset) { + lastExtent->disk.length += vecs[i].length; + offset += vecs[i].length; + start--; + _MakeSpace(count - 1); + continue; + } } - } - int32 start = count; - count += vecCount; - - for (uint32 i = 0; i < vecCount; i++) { file_extent *extent = ExtentAt(start + i); - extent->offset = offset; extent->disk = vecs[i]; offset += extent->disk.length; + lastExtent = extent; } #ifdef TRACE_FILE_MAP - for (uint32 i = start; i < count; i++) { + for (uint32 i = 0; i < count; i++) { file_extent *extent = ExtentAt(i); - dprintf("[%ld] extend offset %Ld, disk offset %Ld, length %Ld\n", + dprintf("[%ld] extent offset %Ld, disk offset %Ld, length %Ld\n", i, extent->offset, extent->disk.offset, extent->disk.length); } #endif @@ -179,11 +228,25 @@ } +/*! Invalidates or removes the specified part of the file map. +*/ void file_map::Invalidate(off_t offset, off_t size) { - // TODO: honour offset/size parameters - Free(); + // TODO: honour size, we currently always remove everything after "offset" + if (offset == 0) { + Free(); + return; + } + + uint32 index; + file_extent *extent = FindExtent(offset, &index); + if (extent != NULL) { + _MakeSpace(index); + + if (extent->offset + extent->disk.length > offset) + extent->disk.length = offset - extent->offset; + } } @@ -193,7 +256,6 @@ if (count > CACHED_FILE_EXTENTS) free(indirect.array); - indirect.array = NULL; count = 0; } @@ -281,50 +343,45 @@ if (offset + size > map.size) size = map.size - offset; - if (map.count == 0) { - // we don't yet have the map of this file, so let's grab it - // (ordered by offset, so that we can do a binary search on them) - size_t vecCount = maxVecs; - off_t mapOffset = 0; + // First, we need to make sure that we have already cached all file + // extents needed for this request. - while (true) { - status = vfs_get_file_map(map.vnode, mapOffset, ~0UL, vecs, - &vecCount); - if (status < B_OK && status != B_BUFFER_OVERFLOW) - return status; + file_extent *lastExtent = NULL; + if (map.count > 0) + lastExtent = map.ExtentAt(map.count - 1); - status_t addStatus = map.Add(vecs, vecCount, mapOffset); - if (addStatus != B_OK) { - // only clobber the status in case of failure - status = addStatus; - } + off_t mapOffset = 0; + if (lastExtent != NULL) + mapOffset = lastExtent->offset + lastExtent->disk.length; - if (status != B_BUFFER_OVERFLOW) - break; + off_t end = offset + size; - // when we are here, the map has been stored in the array, and - // the array size was still too small to cover the whole file - vecCount = maxVecs; + while (mapOffset < end) { + // We don't have the requested extents yet, retrieve them + size_t vecCount = maxVecs; + status = vfs_get_file_map(map.vnode, mapOffset, ~0UL, vecs, + &vecCount); + if (status < B_OK && status != B_BUFFER_OVERFLOW) + return status; + + status_t addStatus = map.Add(vecs, vecCount, mapOffset); + if (addStatus != B_OK) { + // only clobber the status in case of failure + status = addStatus; } + + if (status != B_BUFFER_OVERFLOW) + break; } - if (status != B_OK) { - // We must invalidate the (part of the) map we already - // have, as we cannot know if it's complete or not - map.Free(); + if (status != B_OK) return status; - } - // We now have cached the map of this file, we now need to - // translate it for the requested access. + // We now have cached the map of this file as far as we need it, now + // we need to translate it for the requested access. uint32 index; file_extent *fileExtent = map.FindExtent(offset, &index); - if (fileExtent == NULL) { - // access outside file bounds? But that's not our problem - *_count = 0; - return B_OK; - } offset -= fileExtent->offset; vecs[0].offset = fileExtent->disk.offset + offset; From stippi at mail.berlios.de Sat Jul 5 20:22:42 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 5 Jul 2008 20:22:42 +0200 Subject: [Haiku-commits] r26261 - in haiku/trunk/src/apps/mediaplayer: . supplier Message-ID: <200807051822.m65IMgXg011844@sheep.berlios.de> Author: stippi Date: 2008-07-05 20:22:37 +0200 (Sat, 05 Jul 2008) New Revision: 26261 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26261&view=rev Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp haiku/trunk/src/apps/mediaplayer/Controller.h haiku/trunk/src/apps/mediaplayer/MainWin.cpp haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h Log: * The window would not reset the audio/video track to 0 on a new file if the Controller would keep the last audio/video track index across files (which would be nice for certain situations). * Better error message for unsupported files, especially for the B_MEDIA_NO_HANDLER error. * In the Controller, try to obtain the track duration and ignore tracks that return a bogus duration. I have some MP3 files on ZETA that are obviously not handled correctly by the ZETA mp3 decoder. Previously, the player would just sit there and appeared to have some other internal error. Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.cpp 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/Controller.cpp 2008-07-05 18:22:37 UTC (rev 26261) @@ -125,6 +125,10 @@ int64 Controller::Duration() { + // TODO: It is not so nice that the MediaPlayer still measures + // in video frames if only playing audio. Here for example, it will + // return a duration of 0 if the audio clip happens to be shorter than + // one video frame at 25 fps. return (int64)((double)fDuration * fVideoFrameRate / 1000000.0); } @@ -195,7 +199,7 @@ status_t err; - BMediaFile *mf = new BMediaFile(&ref); + BMediaFile* mf = new BMediaFile(&ref); ObjectDeleter mediaFileDeleter(mf); err = mf->InitCheck(); @@ -213,19 +217,21 @@ } for (int i = 0; i < trackcount; i++) { - BMediaTrack *t = mf->TrackAt(i); + BMediaTrack* t = mf->TrackAt(i); media_format f; err = t->EncodedFormat(&f); - if (err != B_OK) { + if (err != B_OK || t->Duration() <= 0) { printf("Controller::SetTo: EncodedFormat failed for track index %d, error 0x%08lx (%s)\n", i, err, strerror(err)); mf->ReleaseTrack(t); continue; } if (f.IsAudio()) { - fAudioTrackList.AddItem(t); + if (!fAudioTrackList.AddItem(t)) + return B_NO_MEMORY; } else if (f.IsVideo()) { - fVideoTrackList.AddItem(t); + if (!fVideoTrackList.AddItem(t)) + return B_NO_MEMORY; } else { printf("Controller::SetTo: track index %d has unknown type\n", i); mf->ReleaseTrack(t); @@ -326,7 +332,7 @@ return B_ERROR; ObjectDeleter deleter(fAudioTrackSupplier); - fAudioTrackSupplier = new MediaTrackAudioSupplier(track); + fAudioTrackSupplier = new MediaTrackAudioSupplier(track, n); bigtime_t a = fAudioTrackSupplier->Duration(); bigtime_t v = fVideoTrackSupplier ? fVideoTrackSupplier->Duration() : 0;; @@ -334,10 +340,6 @@ DurationChanged(); // TODO: notify duration changed! - // TODO: Not good, because the ProxyAudioSupplier currently - // uses the supplier without locking the Controller! - // This is only a problem when selecting a different audio track - // from the interface menu. fAudioSupplier->SetSupplier(fAudioTrackSupplier, fVideoFrameRate); _NotifyAudioTrackChanged(n); @@ -345,6 +347,18 @@ } +int +Controller::CurrentAudioTrack() +{ + BAutolock _(this); + + if (fAudioTrackSupplier == NULL) + return -1; + + return fAudioTrackSupplier->TrackIndex(); +} + + status_t Controller::SelectVideoTrack(int n) { @@ -356,7 +370,7 @@ status_t initStatus; ObjectDeleter deleter(fVideoTrackSupplier); - fVideoTrackSupplier = new MediaTrackVideoSupplier(track, initStatus); + fVideoTrackSupplier = new MediaTrackVideoSupplier(track, n, initStatus); if (initStatus < B_OK) { delete fVideoTrackSupplier; fVideoTrackSupplier = NULL; @@ -383,6 +397,18 @@ } +int +Controller::CurrentVideoTrack() +{ + BAutolock _(this); + + if (fVideoTrackSupplier == NULL) + return -1; + + return fVideoTrackSupplier->TrackIndex(); +} + + // #pragma mark - Modified: haiku/trunk/src/apps/mediaplayer/Controller.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.h 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/Controller.h 2008-07-05 18:22:37 UTC (rev 26261) @@ -83,7 +83,9 @@ int VideoTrackCount(); status_t SelectAudioTrack(int n); + int CurrentAudioTrack(); status_t SelectVideoTrack(int n); + int CurrentVideoTrack(); void Stop(); void Play(); Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-05 18:22:37 UTC (rev 26261) @@ -709,10 +709,21 @@ if (err != B_OK) { if (fPlaylist->CountItems() == 1) { // display error if this is the only file we're supposed to play - char s[300]; - sprintf(s, "Can't open file\n\n%s\n\nError 0x%08lx\n(%s)\n", - ref.name, err, strerror(err)); - (new BAlert("error", s, "OK"))->Go(); + BString message; + message << "The file '"; + message << ref.name; + message << "' could not be opened.\n\n"; + + if (err == B_MEDIA_NO_HANDLER) { + // give a more detailed message for the most likely of all + // errors + message << "There is no decoder installed to handle the " + "file format, or the decoder has trouble with the specific " + "version of the format."; + } else { + message << "Error: " << strerror(err); + } + (new BAlert("error", message.String(), "OK"))->Go(); } else { // just go to the next file and don't bother user fPlaylist->SetCurrentRefIndex(fPlaylist->CurrentRefIndex() + 1); @@ -828,9 +839,6 @@ // Enable both if a file was loaded fAudioTrackMenu->SetEnabled(fHasFile); fVideoTrackMenu->SetEnabled(fHasFile); - // Select first track (might be "none") in both - fAudioTrackMenu->ItemAt(0)->SetMarked(true); - fVideoTrackMenu->ItemAt(0)->SetMarked(true); fVideoMenu->SetEnabled(fHasVideo); fAudioMenu->SetEnabled(fHasAudio); @@ -847,6 +855,8 @@ } _UpdateControlsEnabledStatus(); + // TODO: Don't if the video size did not change! Also don't + // exit full screen mode. _ResizeWindow(100); fVideoView->MakeFocus(); @@ -958,26 +968,36 @@ fAudioTrackMenu->RemoveItems(0, fAudioTrackMenu->CountItems(), true); fVideoTrackMenu->RemoveItems(0, fVideoTrackMenu->CountItems(), true); - int c, i; char s[100]; - c = fController->AudioTrackCount(); - for (i = 0; i < c; i++) { + int count = fController->AudioTrackCount(); + int current = fController->CurrentAudioTrack(); + for (int i = 0; i < count; i++) { sprintf(s, "Track %d", i + 1); - fAudioTrackMenu->AddItem(new BMenuItem(s, - new BMessage(M_SELECT_AUDIO_TRACK + i))); + BMenuItem* item = new BMenuItem(s, + new BMessage(M_SELECT_AUDIO_TRACK + i)); + item->SetMarked(i == current); + fAudioTrackMenu->AddItem(item); } - if (!c) + if (!count) { fAudioTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); + fAudioTrackMenu->ItemAt(0)->SetMarked(true); + } - c = fController->VideoTrackCount(); - for (i = 0; i < c; i++) { + + count = fController->VideoTrackCount(); + current = fController->CurrentVideoTrack(); + for (int i = 0; i < count; i++) { sprintf(s, "Track %d", i + 1); - fVideoTrackMenu->AddItem(new BMenuItem(s, - new BMessage(M_SELECT_VIDEO_TRACK + i))); + BMenuItem* item = new BMenuItem(s, + new BMessage(M_SELECT_VIDEO_TRACK + i)); + item->SetMarked(i == current); + fVideoTrackMenu->AddItem(item); } - if (!c) + if (!count) { fVideoTrackMenu->AddItem(new BMenuItem("none", new BMessage(M_DUMMY))); + fVideoTrackMenu->ItemAt(0)->SetMarked(true); + } } Modified: haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/AudioTrackSupplier.h 2008-07-05 18:22:37 UTC (rev 26261) @@ -23,6 +23,8 @@ const = 0; virtual status_t GetCodecInfo(media_codec_info* info) const = 0; virtual bigtime_t Duration() const = 0; + + virtual int32 TrackIndex() const = 0; }; #endif // AUDIO_TRACK_SUPPLIER_H Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-07-05 18:22:37 UTC (rev 26261) @@ -54,7 +54,8 @@ // #pragma mark - MediaTrackAudioSupplier -MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack) +MediaTrackAudioSupplier::MediaTrackAudioSupplier(BMediaTrack* mediaTrack, + int32 trackIndex) : AudioTrackSupplier(), fMediaTrack(mediaTrack), fBuffer(NULL), @@ -63,7 +64,8 @@ fBuffers(10), fHasKeyFrames(false), fCountFrames(0), - fReportSeekError(true) + fReportSeekError(true), + fTrackIndex(trackIndex) { _InitFromTrack(); } @@ -104,6 +106,7 @@ bigtime_t MediaTrackAudioSupplier::Duration() const { + fMediaTrack, fMediaTrack ? fMediaTrack->Duration() : 0LL, fCountFrames); if (!fMediaTrack) return 0; @@ -199,6 +202,9 @@ // get the length of the track fCountFrames = fMediaTrack->CountFrames(); + + TRACE("MediaTrackAudioSupplier: keyframes: %d, frame count: %lld\n", + fHasKeyFrames, fCountFrames); } else fMediaTrack = NULL; } Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h 2008-07-05 18:22:37 UTC (rev 26261) @@ -16,7 +16,8 @@ class MediaTrackAudioSupplier : public AudioTrackSupplier { public: - MediaTrackAudioSupplier(BMediaTrack* track); + MediaTrackAudioSupplier(BMediaTrack* track, + int32 trackIndex); virtual ~MediaTrackAudioSupplier(); virtual const media_format& Format() const; @@ -30,6 +31,9 @@ virtual status_t InitCheck() const; + virtual int32 TrackIndex() const + { return fTrackIndex; } + private: struct Buffer; void _InitFromTrack(); @@ -84,6 +88,7 @@ bool fHasKeyFrames; int64 fCountFrames; bool fReportSeekError; + int32 fTrackIndex; }; #endif // MEDIA_TRACK_AUDIO_SUPPLIER_H Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp 2008-07-05 18:22:37 UTC (rev 26261) @@ -24,13 +24,15 @@ // constructor MediaTrackVideoSupplier::MediaTrackVideoSupplier(BMediaTrack* track, - status_t& initStatus) + int32 trackIndex, status_t& initStatus) : VideoTrackSupplier() , fVideoTrack(track) , fPerformanceTime(0) , fDuration(0) , fCurrentFrame(0) + + , fTrackIndex(trackIndex) { if (!fVideoTrack) { printf("MediaTrackVideoSupplier() - no video track\n"); Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h 2008-07-05 18:22:37 UTC (rev 26261) @@ -17,7 +17,7 @@ class MediaTrackVideoSupplier : public VideoTrackSupplier { public: MediaTrackVideoSupplier(BMediaTrack* track, - status_t& initStatus); + int32 trackIndex, status_t& initStatus); virtual ~MediaTrackVideoSupplier(); virtual const media_format& Format() const; @@ -42,6 +42,9 @@ virtual color_space ColorSpace() const; virtual uint32 BytesPerRow() const; + virtual int32 TrackIndex() const + { return fTrackIndex; } + private: status_t _SwitchFormat(color_space format, uint32 bytesPerRow); @@ -55,6 +58,8 @@ bigtime_t fPerformanceTime; bigtime_t fDuration; int64 fCurrentFrame; + + int32 fTrackIndex; }; #endif // MEDIA_TRACK_VIDEO_SUPPLIER_H Modified: haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h 2008-07-05 17:58:47 UTC (rev 26260) +++ haiku/trunk/src/apps/mediaplayer/supplier/VideoTrackSupplier.h 2008-07-05 18:22:37 UTC (rev 26261) @@ -31,6 +31,8 @@ virtual bigtime_t Position() const = 0; virtual bigtime_t Duration() const = 0; virtual int64 CurrentFrame() const = 0; + + virtual int32 TrackIndex() const = 0; }; #endif // VIDEO_TRACK_SUPPLIER_H From stippi at mail.berlios.de Sat Jul 5 20:23:54 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 5 Jul 2008 20:23:54 +0200 Subject: [Haiku-commits] r26262 - haiku/trunk/src/apps/mediaplayer/supplier Message-ID: <200807051823.m65INs82011887@sheep.berlios.de> Author: stippi Date: 2008-07-05 20:23:52 +0200 (Sat, 05 Jul 2008) New Revision: 26262 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26262&view=rev Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp Log: * Accidentally left some dirt when removing debug output. Modified: haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-07-05 18:22:37 UTC (rev 26261) +++ haiku/trunk/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp 2008-07-05 18:23:52 UTC (rev 26262) @@ -106,7 +106,6 @@ bigtime_t MediaTrackAudioSupplier::Duration() const { - fMediaTrack, fMediaTrack ? fMediaTrack->Duration() : 0LL, fCountFrames); if (!fMediaTrack) return 0; From stippi at mail.berlios.de Sat Jul 5 21:19:41 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 5 Jul 2008 21:19:41 +0200 Subject: [Haiku-commits] r26263 - haiku/trunk/src/apps/mediaplayer/playlist Message-ID: <200807051919.m65JJfHA016340@sheep.berlios.de> Author: stippi Date: 2008-07-05 21:19:39 +0200 (Sat, 05 Jul 2008) New Revision: 26263 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26263&view=rev Modified: haiku/trunk/src/apps/mediaplayer/playlist/ListViews.cpp Log: Small clean up. Modified: haiku/trunk/src/apps/mediaplayer/playlist/ListViews.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/ListViews.cpp 2008-07-05 18:23:52 UTC (rev 26262) +++ haiku/trunk/src/apps/mediaplayer/playlist/ListViews.cpp 2008-07-05 19:19:39 UTC (rev 26263) @@ -338,7 +338,7 @@ fDropIndex = -1; } } else { - switch ( message->what ) { + switch (message->what) { case MSG_TICK: { float scrollV = 0.0; BRect rect(Bounds()); From stippi at mail.berlios.de Sat Jul 5 21:21:46 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 5 Jul 2008 21:21:46 +0200 Subject: [Haiku-commits] r26264 - in haiku/trunk/src/apps/mediaplayer: . playlist Message-ID: <200807051921.m65JLk91016568@sheep.berlios.de> Author: stippi Date: 2008-07-05 21:21:38 +0200 (Sat, 05 Jul 2008) New Revision: 26264 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26264&view=rev Added: haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.h Modified: haiku/trunk/src/apps/mediaplayer/Jamfile haiku/trunk/src/apps/mediaplayer/MainApp.cpp haiku/trunk/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.cpp haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.h haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp Log: * Added "Randomize" feature to Playlist window (Edit menu). It randomizes either the selected items, or the entire list if nothing is selected. * Small cleanups here and there. Modified: haiku/trunk/src/apps/mediaplayer/Jamfile =================================================================== --- haiku/trunk/src/apps/mediaplayer/Jamfile 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/Jamfile 2008-07-05 19:21:38 UTC (rev 26264) @@ -61,6 +61,7 @@ PlaylistListView.cpp PlaylistObserver.cpp PlaylistWindow.cpp + RandomizePLItemsCommand.cpp RemovePLItemsCommand.cpp # settings Modified: haiku/trunk/src/apps/mediaplayer/MainApp.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainApp.cpp 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/MainApp.cpp 2008-07-05 19:21:38 UTC (rev 26264) @@ -28,6 +28,7 @@ #include #include +#include #include #include "EventQueue.h" @@ -225,6 +226,8 @@ { EventQueue::CreateDefault(); + srand(system_time()); + gMainApp = new MainApp; gMainApp->Run(); delete gMainApp; Modified: haiku/trunk/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp 2008-07-05 19:21:38 UTC (rev 26264) @@ -43,6 +43,7 @@ int32 itemsBeforeIndex = 0; for (int32 i = 0; i < fCount; i++) { if (fPlaylist->GetRefAt(fIndices[i], &fRefs[i]) < B_OK) { + // indicate a bad object state delete[] fRefs; fRefs = NULL; return; @@ -64,7 +65,7 @@ status_t MovePLItemsCommand::InitCheck() { - if (!fPlaylist || !fRefs || !fIndices) + if (!fRefs) return B_NO_INIT; // analyse the move, don't return B_OK in case Modified: haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h 2008-07-05 19:21:38 UTC (rev 26264) @@ -52,7 +52,7 @@ // list functionality void MakeEmpty(); int32 CountItems() const; - + void Sort(); bool AddRef(const entry_ref& ref); Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.cpp 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.cpp 2008-07-05 19:21:38 UTC (rev 26264) @@ -26,6 +26,7 @@ #include "PlaybackState.h" #include "Playlist.h" #include "PlaylistObserver.h" +#include "RandomizePLItemsCommand.h" #include "RemovePLItemsCommand.h" using std::nothrow; @@ -375,6 +376,41 @@ } +void +PlaylistListView::Randomize() +{ + int32 count = CountItems(); + if (count == 0) + return; + + BList indices; + + // add current selection + count = 0; + while (true) { + int32 index = CurrentSelection(count); + if (index < 0) + break; + if (!indices.AddItem((void*)index)) + return; + count++; + } + + // was anything selected? + if (count == 0) { + // no selection, simply add all items + count = CountItems(); + for (int32 i = 0; i < count; i++) { + if (!indices.AddItem((void*)i)) + return; + } + } + + fCommandStack->Perform(new (nothrow) RandomizePLItemsCommand(fPlaylist, + (int32*)indices.Items(), indices.CountItems())); +} + + // #pragma mark - Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.h 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistListView.h 2008-07-05 19:21:38 UTC (rev 26264) @@ -44,6 +44,8 @@ void RefsReceived(BMessage* message, int32 appendIndex); + void Randomize(); + private: void _FullSync(); void _AddItem(const entry_ref& ref, int32 index); Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp 2008-07-05 19:21:38 UTC (rev 26264) @@ -31,9 +31,13 @@ #define DEBUG 1 enum { - M_PLAYLIST_OPEN = 'open', - M_PLAYLIST_SAVE = 'save', - M_PLAYLIST_EMPTY = 'emty' + // file + M_PLAYLIST_OPEN = 'open', + M_PLAYLIST_SAVE = 'save', + + // edit + M_PLAYLIST_EMPTY = 'emty', + M_PLAYLIST_RANDOMIZE = 'rand' }; #define SPACE 5 @@ -144,9 +148,14 @@ fOpenPanel = new BFilePanel(B_OPEN_PANEL); fOpenPanel->Show(); break; + case M_PLAYLIST_EMPTY: fListView->RemoveAll(); - break; + break; + case M_PLAYLIST_RANDOMIZE: + fListView->Randomize(); + break; + default: BWindow::MessageReceived(message); break; @@ -180,6 +189,8 @@ editMenu->AddSeparatorItem(); editMenu->AddItem(new BMenuItem("Make Empty", new BMessage(M_PLAYLIST_EMPTY), 'N')); + editMenu->AddItem(new BMenuItem("Randomize", + new BMessage(M_PLAYLIST_RANDOMIZE), 'R')); menuBar->AddItem(editMenu); AddChild(menuBar); Added: haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp 2008-07-05 19:21:38 UTC (rev 26264) @@ -0,0 +1,135 @@ +/* + * Copyright ? 2008 Stephan A?mus. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "RandomizePLItemsCommand.h" + +#include +#include +#include + +#include + +#include "Playlist.h" + + +using std::nothrow; + + +RandomizePLItemsCommand::RandomizePLItemsCommand(Playlist* playlist, + const int32* indices, int32 count) + : Command() + , fPlaylist(playlist) + , fRefs(count > 0 ? new (nothrow) entry_ref[count] : NULL) + , fListIndices(count > 0 ? new (nothrow) int32[count] : NULL) + , fRandomInternalIndices(count > 0 ? new (nothrow) int32[count] : NULL) + , fCount(count) +{ + if (!indices || !fPlaylist || !fRefs || !fListIndices + || !fRandomInternalIndices) { + // indicate a bad object state + delete[] fRefs; + fRefs = NULL; + return; + } + + memcpy(fListIndices, indices, fCount * sizeof(int32)); + + // put the available indices into a "set" + BList indexSet; + for (int32 i = 0; i < fCount; i++) { + if (fPlaylist->GetRefAt(fListIndices[i], &fRefs[i]) < B_OK + || !indexSet.AddItem((void*)i)) { + // indicate a bad object state + delete[] fRefs; + fRefs = NULL; + return; + } + } + + // remove the indices from the set in random order + for (int32 i = 0; i < fCount; i++) { + int32 randomSetIndex = rand() % indexSet.CountItems(); + fRandomInternalIndices[i] = (int32)indexSet.RemoveItem(randomSetIndex); + } +} + + +RandomizePLItemsCommand::~RandomizePLItemsCommand() +{ + delete[] fRefs; + delete[] fListIndices; + delete[] fRandomInternalIndices; +} + + +status_t +RandomizePLItemsCommand::InitCheck() +{ + if (!fRefs) + return B_NO_INIT; + + return B_OK; +} + + +status_t +RandomizePLItemsCommand::Perform() +{ + return _Sort(true); +} + + +status_t +RandomizePLItemsCommand::Undo() +{ + return _Sort(false); +} + + +void +RandomizePLItemsCommand::GetName(BString& name) +{ + name << "Randomize Entries"; +} + + +status_t +RandomizePLItemsCommand::_Sort(bool random) +{ + BAutolock _(fPlaylist); + + // remember currently playling ref in case we move it + entry_ref currentRef; + bool adjustCurrentRef = fPlaylist->GetRefAt(fPlaylist->CurrentRefIndex(), + ¤tRef) == B_OK; + + // remove refs from playlist + for (int32 i = 0; i < fCount; i++) { + // "- i" to account for the items already removed + fPlaylist->RemoveRef(fListIndices[i] - i, false); + } + + // add refs to playlist at the randomized indices + if (random) { + for (int32 i = 0; i < fCount; i++) { + if (!fPlaylist->AddRef(fRefs[fRandomInternalIndices[i]], + fListIndices[i])) { + return B_NO_MEMORY; + } + } + } else { + for (int32 i = 0; i < fCount; i++) { + if (!fPlaylist->AddRef(fRefs[i], fListIndices[i])) { + return B_NO_MEMORY; + } + } + } + + // take care about currently played ref + if (adjustCurrentRef) + fPlaylist->SetCurrentRefIndex(fPlaylist->IndexOf(currentRef)); + + return B_OK; +} Added: haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.h 2008-07-05 19:19:39 UTC (rev 26263) +++ haiku/trunk/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.h 2008-07-05 19:21:38 UTC (rev 26264) @@ -0,0 +1,39 @@ +/* + * Copyright ? 2008 Stephan A?mus. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef RANDOMIZE_PL_ITEMS_COMMAND_H +#define RANDOMIZE_PL_ITEMS_COMMAND_H + + +#include "Command.h" + +class Playlist; +struct entry_ref; + +class RandomizePLItemsCommand : public Command { + public: + RandomizePLItemsCommand( + Playlist* playlist, + const int32* indices, + int32 count); + virtual ~RandomizePLItemsCommand(); + + virtual status_t InitCheck(); + + virtual status_t Perform(); + virtual status_t Undo(); + + virtual void GetName(BString& name); + + private: + status_t _Sort(bool random); + + Playlist* fPlaylist; + entry_ref* fRefs; + int32* fListIndices; + int32* fRandomInternalIndices; + int32 fCount; +}; + +#endif // RANDOMIZE_PL_ITEMS_COMMAND_H From revol at free.fr Wed Jul 2 00:25:55 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 02 Jul 2008 00:25:55 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r26187_-_in_haiku/trunk/src/add-?= =?windows-1252?q?ons/kernel/file=5Fsystems=3A_=2E_ext2?= In-Reply-To: <200807011012.m61ACKEU005427@sheep.berlios.de> Message-ID: <4199439652-BeMail@laptop> > * Implemented a read-only ext2 file system. Great, one less thing on my list. I want read write though :) Fran?ois. From jackburton at mail.berlios.de Sat Jul 5 22:40:09 2008 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sat, 5 Jul 2008 22:40:09 +0200 Subject: [Haiku-commits] r26265 - in haiku/trunk: headers/private/kernel headers/private/kernel/arch/x86 src/system/kernel/arch/x86 src/system/kernel/arch/x86/timers Message-ID: <200807052040.m65Ke9iP022171@sheep.berlios.de> Author: jackburton Date: 2008-07-05 22:40:06 +0200 (Sat, 05 Jul 2008) New Revision: 26265 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26265&view=rev Added: haiku/trunk/src/system/kernel/arch/x86/timers/ haiku/trunk/src/system/kernel/arch/x86/timers/apic.h haiku/trunk/src/system/kernel/arch/x86/timers/hpet.h haiku/trunk/src/system/kernel/arch/x86/timers/pit.h haiku/trunk/src/system/kernel/arch/x86/timers/x86_apic.c haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c haiku/trunk/src/system/kernel/arch/x86/timers/x86_pit.c Modified: haiku/trunk/headers/private/kernel/arch/x86/timer.h haiku/trunk/headers/private/kernel/timer.h haiku/trunk/src/system/kernel/arch/x86/Jamfile haiku/trunk/src/system/kernel/arch/x86/arch_hpet.c haiku/trunk/src/system/kernel/arch/x86/arch_smp.c haiku/trunk/src/system/kernel/arch/x86/arch_timer.c Log: Patch by Dustin Howett which 'modularizes' timers. The best timer is automatically selected at boot time. Pit and Apic timers are implemented for now. Thanks Dustin! Modified: haiku/trunk/headers/private/kernel/arch/x86/timer.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/x86/timer.h 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/headers/private/kernel/arch/x86/timer.h 2008-07-05 20:40:06 UTC (rev 26265) @@ -2,10 +2,12 @@ ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Distributed under the terms of the NewOS License. */ -#ifndef _NEWOS_KERNEL_ARCH_I386_TIMER -#define _NEWOS_KERNEL_ARCH_I386_TIMER +#ifndef _KERNEL_ARCH_X86_TIMER +#define _KERNEL_ARCH_X86_TIMER -int apic_timer_interrupt(void); +#define ISA_TIMER_MODULE_NAME "timers/x86/isa/v1" +#define APIC_TIMER_MODULE_NAME "timers/x86/apic/v1" +#define HPET_TIMER_MODULE_NAME "timers/x86/hpet/v1" #endif Modified: haiku/trunk/headers/private/kernel/timer.h =================================================================== --- haiku/trunk/headers/private/kernel/timer.h 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/headers/private/kernel/timer.h 2008-07-05 20:40:06 UTC (rev 26265) @@ -18,6 +18,18 @@ #define B_TIMER_ACQUIRE_THREAD_LOCK 0x8000 #define B_TIMER_FLAGS B_TIMER_ACQUIRE_THREAD_LOCK +/* Timer info structure */ +struct timer_info { + char *name; + int (*get_priority)(void); + status_t (*set_hardware_timer)(bigtime_t timeout); + status_t (*clear_hardware_timer)(void); + status_t (*init)(struct kernel_args *args); +}; + +typedef struct timer_info timer_info; + + /* kernel functions */ status_t timer_init(struct kernel_args *); int32 timer_interrupt(void); Modified: haiku/trunk/src/system/kernel/arch/x86/Jamfile =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/Jamfile 2008-07-05 20:40:06 UTC (rev 26265) @@ -4,18 +4,20 @@ # for syscall_numbers.h SubDirHdrs $(HAIKU_TOP) src add-ons kernel bus_managers ps2 ; SubDirHdrs $(SUBDIR) $(DOTDOT) generic ; +SubDirHdrs $(SUBDIR) timers ; UsePrivateKernelHeaders ; SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ; +SEARCH_SOURCE += [ FDirName $(SUBDIR) timers ] ; + KernelMergeObject kernel_arch_x86.o : arch_commpage.cpp arch_cpu.c arch_debug.cpp arch_debug_console.c arch_elf.c - arch_hpet.c arch_int.c arch_platform.c # arch_selector.c @@ -35,6 +37,10 @@ cpuid.S syscall.S vm86.cpp + + x86_pit.c + x86_apic.c + x86_hpet.c generic_vm_physical_page_mapper.cpp : Modified: haiku/trunk/src/system/kernel/arch/x86/arch_hpet.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_hpet.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/arch_hpet.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -1,6 +0,0 @@ -/* - * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. - * Distributed under the terms of the MIT License. - */ - -#include Modified: haiku/trunk/src/system/kernel/arch/x86/arch_smp.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_smp.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/arch_smp.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -17,6 +17,8 @@ #include #include +#include + #include #include #include @@ -39,25 +41,15 @@ # define TRACE_TIMER(x) ; #endif +extern timer_info gAPICTimer; static void *apic = NULL; static uint32 cpu_apic_id[B_MAX_CPU_COUNT] = {0, 0}; static uint32 cpu_os_id[B_MAX_CPU_COUNT] = {0, 0}; static uint32 cpu_apic_version[B_MAX_CPU_COUNT] = {0, 0}; static void *ioapic = NULL; -static uint32 apic_timer_tics_per_sec = 0; - static int32 -i386_timer_interrupt(void *data) -{ - arch_smp_ack_interrupt(); - - return apic_timer_interrupt(); -} - - -static int32 i386_ici_interrupt(void *data) { // genuine inter-cpu interrupt @@ -147,17 +139,8 @@ } #endif - /* setup timer */ - config = apic_read(APIC_LVT_TIMER) & APIC_LVT_TIMER_MASK; - config |= 0xfb | APIC_LVT_MASKED; // vector 0xfb, timer masked - apic_write(APIC_LVT_TIMER, config); + apic_smp_init_timer(args, cpu); - apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the clock - - config = apic_read(APIC_TIMER_DIVIDE_CONFIG) & 0xfffffff0; - config |= APIC_TIMER_DIVIDE_CONFIG_1; // clock division by 1 - apic_write(APIC_TIMER_DIVIDE_CONFIG, config); - /* setup error vector to 0xfe */ config = (apic_read(APIC_LVT_ERROR) & 0xffffff00) | 0xfe; apic_write(APIC_LVT_ERROR, config); @@ -185,7 +168,6 @@ memcpy(cpu_apic_id, args->arch_args.cpu_apic_id, sizeof(args->arch_args.cpu_apic_id)); memcpy(cpu_os_id, args->arch_args.cpu_os_id, sizeof(args->arch_args.cpu_os_id)); memcpy(cpu_apic_version, args->arch_args.cpu_apic_version, sizeof(args->arch_args.cpu_apic_version)); - apic_timer_tics_per_sec = args->arch_args.apic_time_cv_factor; // setup regions that represent the apic & ioapic map_physical_memory("local apic", (void *)args->arch_args.apic_phys, B_PAGE_SIZE, @@ -197,7 +179,6 @@ arch_smp_per_cpu_init(args, 0); // I/O interrupts start at ARCH_INTERRUPT_BASE, so all interrupts are shifted - install_io_interrupt_handler(0xfb - ARCH_INTERRUPT_BASE, &i386_timer_interrupt, NULL, B_NO_LOCK_VECTOR); install_io_interrupt_handler(0xfd - ARCH_INTERRUPT_BASE, &i386_ici_interrupt, NULL, B_NO_LOCK_VECTOR); install_io_interrupt_handler(0xfe - ARCH_INTERRUPT_BASE, &i386_smp_error_interrupt, NULL, B_NO_LOCK_VECTOR); install_io_interrupt_handler(0xff - ARCH_INTERRUPT_BASE, &i386_spurious_interrupt, NULL, B_NO_LOCK_VECTOR); @@ -268,63 +249,3 @@ { apic_write(APIC_EOI, 0); } - -#define MIN_TIMEOUT 1000 - -status_t -arch_smp_set_apic_timer(bigtime_t relativeTimeout) -{ - cpu_status state; - uint32 config; - uint32 ticks; - - if (apic == NULL) - return B_ERROR; - - if (relativeTimeout < MIN_TIMEOUT) - relativeTimeout = MIN_TIMEOUT; - - // calculation should be ok, since it's going to be 64-bit - ticks = ((relativeTimeout * apic_timer_tics_per_sec) / 1000000); - - state = disable_interrupts(); - - config = apic_read(APIC_LVT_TIMER) | APIC_LVT_MASKED; // mask the timer - apic_write(APIC_LVT_TIMER, config); - - apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the timer - - config = apic_read(APIC_LVT_TIMER) & ~APIC_LVT_MASKED; // unmask the timer - apic_write(APIC_LVT_TIMER, config); - - TRACE_TIMER(("arch_smp_set_apic_timer: config 0x%lx, timeout %Ld, tics/sec %lu, tics %lu\n", - config, relativeTimeout, apic_timer_tics_per_sec, ticks)); - - apic_write(APIC_INITIAL_TIMER_COUNT, ticks); // start it up - - restore_interrupts(state); - - return B_OK; -} - - -status_t -arch_smp_clear_apic_timer(void) -{ - cpu_status state; - uint32 config; - - if (apic == NULL) - return B_ERROR; - - state = disable_interrupts(); - - config = apic_read(APIC_LVT_TIMER) | APIC_LVT_MASKED; // mask the timer - apic_write(APIC_LVT_TIMER, config); - - apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the timer - - restore_interrupts(state); - return B_OK; -} - Modified: haiku/trunk/src/system/kernel/arch/x86/arch_timer.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_timer.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/arch_timer.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -32,60 +32,24 @@ # define TRACE(x) ; #endif +extern timer_info gPITTimer; +extern timer_info gAPICTimer; +extern timer_info gHPETTimer; -#define PIT_CLOCK_RATE 1193180 -#define PIT_MAX_TIMER_INTERVAL (0xffff * 1000000ll / PIT_CLOCK_RATE) +static timer_info *sTimers[] = { + &gPITTimer, + &gAPICTimer, + &gHPETTimer, + NULL +}; +static timer_info *sTimer = NULL; -static void -set_isa_hardware_timer(bigtime_t relative_timeout) -{ - uint16 next_event_clocks; - - if (relative_timeout <= 0) - next_event_clocks = 2; - else if (relative_timeout < PIT_MAX_TIMER_INTERVAL) - next_event_clocks = relative_timeout * PIT_CLOCK_RATE / 1000000; - else - next_event_clocks = 0xffff; - - out8(0x30, 0x43); - out8(next_event_clocks & 0xff, 0x40); - out8((next_event_clocks >> 8) & 0xff, 0x40); - - arch_int_enable_io_interrupt(0); -} - - -static void -clear_isa_hardware_timer(void) -{ - // mask out the timer - arch_int_disable_io_interrupt(0); -} - - -static int32 -isa_timer_interrupt(void *data) -{ - return timer_interrupt(); -} - - -int -apic_timer_interrupt(void) -{ - return timer_interrupt(); -} - - void arch_timer_set_hardware_timer(bigtime_t timeout) { TRACE(("arch_timer_set_hardware_timer: timeout %lld\n", timeout)); - // try the apic timer first - if (arch_smp_set_apic_timer(timeout) != B_OK) - set_isa_hardware_timer(timeout); + sTimer->set_hardware_timer(timeout); } @@ -93,21 +57,42 @@ arch_timer_clear_hardware_timer(void) { TRACE(("arch_timer_clear_hardware_timer\n")); - if (arch_smp_clear_apic_timer() != B_OK) - clear_isa_hardware_timer(); + sTimer->clear_hardware_timer(); } int arch_init_timer(kernel_args *args) { - //dprintf("arch_init_timer: entry\n"); + int i = 0; + int bestPriority = -1; + timer_info *timer = NULL; + cpu_status state = disable_interrupts(); - install_io_interrupt_handler(0, &isa_timer_interrupt, NULL, 0); - clear_isa_hardware_timer(); + for (i = 0; (timer = sTimers[i]) != NULL; i++) { + int priority; + if (timer->init(args) != B_OK) { + TRACE(("arch_init_timer: %s failed init. Skipping.\n", timer->name)); + continue; + } - // apic timer interrupt set up by smp code + priority = timer->get_priority(); + if (priority > bestPriority) { + bestPriority = priority; + sTimer = timer; + TRACE(("arch_init_timer: %s is now best timer module with prio %d.\n", timer->name, bestPriority)); + } + } + + if (sTimer != NULL) { + dprintf("arch_init_timer: using %s timer.\n", sTimer->name); + } else { + panic("No system timers were found usable.\n"); + } + + restore_interrupts(state); + return 0; } Added: haiku/trunk/src/system/kernel/arch/x86/timers/apic.h =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/apic.h 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/apic.h 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,17 @@ +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_x86_TIMERS_APIC_H +#define _KERNEL_ARCH_x86_TIMERS_APIC_H + +#include + +/* Method Prototypes */ +static int apic_get_prio(void); +static status_t apic_set_hardware_timer(bigtime_t relativeTimeout); +static status_t apic_clear_hardware_timer(void); +static status_t apic_init(struct kernel_args *args); +status_t apic_smp_init_timer(struct kernel_args *args, int32 cpu); + +#endif /* _KERNEL_ARCH_x86_TIMERS_APIC_H */ Added: haiku/trunk/src/system/kernel/arch/x86/timers/hpet.h =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/hpet.h 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/hpet.h 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,63 @@ +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_x86_TIMERS_HPET_H +#define _KERNEL_ARCH_x86_TIMERS_HPET_H + +#include + +/* All masks are 64 bits wide to represent bit locations; + the HPET registers are 64 bits wide. */ + +/* Global Capability Register Masks */ +#define HPET_CAP_MASK_ID 0x00000000000000FF +#define HPET_CAP_MASK_NUMTIMERS 0x0000000000001F00 +#define HPET_CAP_MASK_WIDTH 0x0000000000002000 +#define HPET_CAP_MASK_LEGACY 0x0000000000008000 +#define HPET_CAP_MASK_VENDOR_ID 0x00000000FFFF0000 +#define HPET_CAP_MASK_PERIOD 0xFFFFFFFF00000000 + +/* Convenience macros for Capability masks */ +#define HPET_GET_ID(regs) ((regs)->caps & HPET_CAP_MASK_ID) +#define HPET_GET_NUM_TIMERS(regs) (((regs)->caps & HPET_CAP_MASK_NUMTIMERS) >> 8) +#define HPET_IS_64BIT_CAPABLE(regs) (((regs)->caps & HPET_CAP_MASK_WIDTH) >> 13) +#define HPET_IS_LEGACY_CAPABLE(regs) (((regs)->caps & HPET_CAP_MASK_LEGACY) >> 15) +#define HPET_GET_VENDOR_ID(regs) (((regs)->caps & HPET_CAP_MASK_VENDOR_ID) >> 16) +#define HPET_GET_PERIOD(regs) (((regs)->caps & HPET_CAP_MASK_PERIOD) >> 32) + +/* Global Configuration Masks */ +#define HPET_CONF_MASK_ENABLED 0x0000000000000001 +#define HPET_CONF_MASK_LEGACY 0x0000000000000002 + +/* Convenience macros for Config masks */ +#define HPET_IS_ENABLED(regs) ((regs)->config & HPET_CONF_MASK_ENABLED) +#define HPET_IS_LEGACY(regs) (((regs)->config & HPET_CONF_MASK_LEGACY) >> 1) + +struct hpet_timer { + uint64 config; /* Timer configuration and capabilities */ + uint64 comparator; /* Comparator value */ + uint64 introute; /* FSB Interrupt Routing */ + uint64 reserved; +}; + + +struct hpet_regs { + uint64 caps; /* HPET Capabilities and ID */ + uint64 reserved1; + uint64 config; /* General Configuration */ + uint64 reserved2; + uint64 intstatus; /* General Interrupt Status */ + uint8 reserved3[200]; + uint64 mainvalue; /* Main Counter Value */ + uint64 reserved4; + struct hpet_timer timers[1]; /* Timers */ +}; + +/* Method prototypes */ +static int hpet_get_prio(void); +static status_t hpet_set_hardware_timer(bigtime_t relativeTimeout); +static status_t hpet_clear_hardware_timer(void); +static status_t hpet_init(struct kernel_args *args); + +#endif /* _KERNEL_ARCH_x86_TIMERS_HPET_H */ Added: haiku/trunk/src/system/kernel/arch/x86/timers/pit.h =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/pit.h 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/pit.h 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,16 @@ +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_ARCH_x86_TIMERS_PIT_H +#define _KERNEL_ARCH_x86_TIMERS_PIT_H + +#include + +/* Method Prototypes */ +static int pit_get_prio(void); +static status_t pit_set_hardware_timer(bigtime_t relativeTimeout); +static status_t pit_clear_hardware_timer(void); +static status_t pit_init(struct kernel_args *args); + +#endif /* _KERNEL_ARCH_x86_TIMERS_PIT_H */ Added: haiku/trunk/src/system/kernel/arch/x86/timers/x86_apic.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/x86_apic.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/x86_apic.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,170 @@ +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Copyright 2002-2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include +#include + +#include +#include + +#include +#include + +#include "apic.h" + +static void *sApicPtr = NULL; +static uint32 sApicTicsPerSec = 0; + +struct timer_info gAPICTimer = { + "APIC", + &apic_get_prio, + &apic_set_hardware_timer, + &apic_clear_hardware_timer, + &apic_init +}; + + +static int +apic_get_prio(void) +{ + return 2; +} + + +static uint32 +_apic_read(uint32 offset) +{ + return *(volatile uint32 *)((char *)sApicPtr + offset); +} + + +static void +_apic_write(uint32 offset, uint32 data) +{ + *(volatile uint32 *)((char *)sApicPtr + offset) = data; +} + + +static void +_apic_acknowledge_interrupt(void) +{ + _apic_write(APIC_EOI, 0); +} + + +static int32 +apic_timer_interrupt(void *data) +{ + _apic_acknowledge_interrupt(); + return timer_interrupt(); +} + + +#define MIN_TIMEOUT 1000 + +static status_t +apic_set_hardware_timer(bigtime_t relativeTimeout) +{ + cpu_status state; + uint32 config; + uint32 ticks; + + if (sApicPtr == NULL) + return B_ERROR; + + if (relativeTimeout < MIN_TIMEOUT) + relativeTimeout = MIN_TIMEOUT; + + // calculation should be ok, since it's going to be 64-bit + ticks = ((relativeTimeout * sApicTicsPerSec) / 1000000); + + state = disable_interrupts(); + + config = _apic_read(APIC_LVT_TIMER) | APIC_LVT_MASKED; // mask the timer + _apic_write(APIC_LVT_TIMER, config); + + _apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the timer + + config = _apic_read(APIC_LVT_TIMER) & ~APIC_LVT_MASKED; // unmask the timer + _apic_write(APIC_LVT_TIMER, config); + + //TRACE_TIMER(("arch_smp_set_apic_timer: config 0x%lx, timeout %Ld, tics/sec %lu, tics %lu\n", + // config, relativeTimeout, sApicTicsPerSec, ticks)); + + _apic_write(APIC_INITIAL_TIMER_COUNT, ticks); // start it up + + restore_interrupts(state); + + return B_OK; +} + + +static status_t +apic_clear_hardware_timer(void) +{ + cpu_status state; + uint32 config; + + if (sApicPtr == NULL) + return B_ERROR; + + state = disable_interrupts(); + + config = _apic_read(APIC_LVT_TIMER) | APIC_LVT_MASKED; // mask the timer + _apic_write(APIC_LVT_TIMER, config); + + _apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the timer + + restore_interrupts(state); + return B_OK; +} + + +static status_t +apic_init(struct kernel_args *args) +{ + /* If we're in this method, arch_smp called the special init function. + Therefore, if we got here with sApicPtr NULL, there is no APIC! */ + if (sApicPtr == NULL) + return B_ERROR; + + return B_OK; +} + + +status_t +apic_smp_init_timer(struct kernel_args *args, int32 cpu) +{ + uint32 config; + + if (args->arch_args.apic == NULL) { + return B_ERROR; + } + + /* This is in place of apic_preinit; if we're not already initialized, + register the interrupt handler and set the pointers */ + if (sApicPtr == NULL) { + sApicPtr = (void *)args->arch_args.apic; + sApicTicsPerSec = args->arch_args.apic_time_cv_factor; + install_io_interrupt_handler(0xfb - ARCH_INTERRUPT_BASE, &apic_timer_interrupt, NULL, B_NO_LOCK_VECTOR); + } + + /* setup timer */ + config = _apic_read(APIC_LVT_TIMER) & APIC_LVT_TIMER_MASK; + config |= 0xfb | APIC_LVT_MASKED; // vector 0xfb, timer masked + _apic_write(APIC_LVT_TIMER, config); + + _apic_write(APIC_INITIAL_TIMER_COUNT, 0); // zero out the clock + + config = _apic_read(APIC_TIMER_DIVIDE_CONFIG) & 0xfffffff0; + config |= APIC_TIMER_DIVIDE_CONFIG_1; // clock division by 1 + _apic_write(APIC_TIMER_DIVIDE_CONFIG, config); + + return B_OK; +} Added: haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/x86_hpet.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,89 @@ + +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include +#include + +#include "hpet.h" + +static int32 sHPETAddr; +static struct hpet_regs *sHPETRegs; + +struct timer_info gHPETTimer = { + "HPET", + &hpet_get_prio, + &hpet_set_hardware_timer, + &hpet_clear_hardware_timer, + &hpet_init +}; + + +static int +hpet_get_prio(void) +{ + return 3; +} + + +/* TODO: Implement something similar to smp_acpi_probe from boot/.../smp.cpp- + we need to get the hpet base address without talking to the acpi module, + because there's no guarantee that it's actually present at this early point. */ + +static int +hpet_set_enabled(struct hpet_regs *regs, bool enabled) +{ + if (enabled) + regs->config |= HPET_CONF_MASK_ENABLED; + else + regs->config &= ~HPET_CONF_MASK_ENABLED; + return B_OK; +} + + +static int +hpet_set_legacy(struct hpet_regs *regs, bool enabled) +{ + if (!HPET_IS_LEGACY_CAPABLE(regs)) + return B_NOT_SUPPORTED; + + if (enabled) + regs->config |= HPET_CONF_MASK_LEGACY; + else + regs->config &= ~HPET_CONF_MASK_LEGACY; + return B_OK; +} + + +static int32 +hpet_timer_interrupt(void *data) +{ + return timer_interrupt(); +} + + +static status_t +hpet_set_hardware_timer(bigtime_t relative_timeout) +{ + return B_ERROR; +} + + +static status_t +hpet_clear_hardware_timer(void) +{ + return B_ERROR; +} + + +static status_t +hpet_init(struct kernel_args *args) +{ + /* hpet_acpi_probe() through a similar "scan spots" table to that of smp.cpp. + Seems to be the most elegant solution right now. */ + + /* There is no hpet support proper, so error out on init */ + return B_ERROR; +} Added: haiku/trunk/src/system/kernel/arch/x86/timers/x86_pit.c =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/timers/x86_pit.c 2008-07-05 19:21:38 UTC (rev 26264) +++ haiku/trunk/src/system/kernel/arch/x86/timers/x86_pit.c 2008-07-05 20:40:06 UTC (rev 26265) @@ -0,0 +1,88 @@ +/* + * Copyright 2008, Dustin Howett, dustin.howett at gmail.com. All rights reserved. + * Copyright 2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Copyright 2001, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include +#include + +#include +#include + +#include "pit.h" + +#define PIT_CLOCK_RATE 1193180 +#define PIT_MAX_TIMER_INTERVAL (0xffff * 1000000ll / PIT_CLOCK_RATE) + +static bool sPITTimerInitialized = false; + +struct timer_info gPITTimer = { + "PIT", + &pit_get_prio, + &pit_set_hardware_timer, + &pit_clear_hardware_timer, + &pit_init +}; + + +static int +pit_get_prio(void) +{ + return 1; +} + + +static int32 +pit_timer_interrupt(void *data) +{ + return timer_interrupt(); +} + + +static status_t +pit_set_hardware_timer(bigtime_t relativeTimeout) +{ + uint16 nextEventClocks; + + if (relativeTimeout <= 0) + nextEventClocks = 2; + else if (relativeTimeout < PIT_MAX_TIMER_INTERVAL) + nextEventClocks = relativeTimeout * PIT_CLOCK_RATE / 1000000; + else + nextEventClocks = 0xffff; + + out8(0x30, 0x43); + out8(nextEventClocks & 0xff, 0x40); + out8((nextEventClocks >> 8) & 0xff, 0x40); + + arch_int_enable_io_interrupt(0); + return B_OK; +} + + +static status_t +pit_clear_hardware_timer(void) +{ + arch_int_disable_io_interrupt(0); + return B_OK; +} + + +static status_t +pit_init(struct kernel_args *args) +{ + if (sPITTimerInitialized) { + return B_OK; + } + + install_io_interrupt_handler(0, &pit_timer_interrupt, NULL, 0); + pit_clear_hardware_timer(); + + sPITTimerInitialized = true; + + return B_OK; +} From jackburton at mail.berlios.de Sat Jul 5 22:45:24 2008 From: jackburton at mail.berlios.de (jackburton at BerliOS) Date: Sat, 5 Jul 2008 22:45:24 +0200 Subject: [Haiku-commits] r26266 - haiku/trunk/headers/private/kernel/arch/x86 Message-ID: <200807052045.m65KjOo9022740@sheep.berlios.de> Author: jackburton Date: 2008-07-05 22:45:17 +0200 (Sat, 05 Jul 2008) New Revision: 26266 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26266&view=rev Removed: haiku/trunk/headers/private/kernel/arch/x86/arch_hpet.h Log: should've been part of the previous commit. Deleted: haiku/trunk/headers/private/kernel/arch/x86/arch_hpet.h From korli at mail.berlios.de Sun Jul 6 00:26:21 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 6 Jul 2008 00:26:21 +0200 Subject: [Haiku-commits] r26267 - haiku/trunk/src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807052226.m65MQLEQ032542@sheep.berlios.de> Author: korli Date: 2008-07-06 00:26:21 +0200 (Sun, 06 Jul 2008) New Revision: 26267 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26267&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: reads now returns B_IS_A_DIRECTORY instead of B_BAD_VALUE for directories Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-05 20:45:17 UTC (rev 26266) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-05 22:26:21 UTC (rev 26267) @@ -436,8 +436,13 @@ *bufferSize)); status_t error = B_OK; // don't read anything but files - if (!node->IsFile()) - error = B_BAD_VALUE; + if (!node->IsFile()) { + if (node->IsDir()) + error = B_IS_A_DIRECTORY; + else + error = B_BAD_VALUE; + } + // read StreamReader *reader = (StreamReader*)cookie; if (error == B_OK) { From zooey at mail.berlios.de Sun Jul 6 00:27:05 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Sun, 6 Jul 2008 00:27:05 +0200 Subject: [Haiku-commits] r26268 - haiku/trunk/src/tests/kits/net Message-ID: <200807052227.m65MR5Hm032595@sheep.berlios.de> Author: zooey Date: 2008-07-06 00:27:05 +0200 (Sun, 06 Jul 2008) New Revision: 26268 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26268&view=rev Added: haiku/trunk/src/tests/kits/net/NetAddressTest.cpp Modified: haiku/trunk/src/tests/kits/net/Jamfile Log: * added a test for BNetAddress that exposes a couple of problems with the current implementation (especially byte-order problems) Modified: haiku/trunk/src/tests/kits/net/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/net/Jamfile 2008-07-05 22:26:21 UTC (rev 26267) +++ haiku/trunk/src/tests/kits/net/Jamfile 2008-07-05 22:27:05 UTC (rev 26268) @@ -14,6 +14,9 @@ SimpleTest tcp_connection_test : tcp_connection_test.cpp : $(TARGET_NETWORK_LIBS) ; +SimpleTest NetAddressTest : NetAddressTest.cpp + : $(TARGET_NETWORK_LIBS) $(HAIKU_NETAPI_LIB) ; + SubInclude HAIKU_TOP src tests kits net DialUpPreflet ; SubInclude HAIKU_TOP src tests kits net multicast ; SubInclude HAIKU_TOP src tests kits net netperf ; Added: haiku/trunk/src/tests/kits/net/NetAddressTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/net/NetAddressTest.cpp 2008-07-05 22:26:21 UTC (rev 26267) +++ haiku/trunk/src/tests/kits/net/NetAddressTest.cpp 2008-07-05 22:27:05 UTC (rev 26268) @@ -0,0 +1,94 @@ +/* + * Copyright 2008, Oliver Tappe, zooey at hirschkaefer.de. + * Distributed under the terms of the MIT license. + */ + + +#include + +#include +#include +#include +#include +#include + + +void +checkNetAddr(const BNetAddress& netAddr, uint32 nwAddr, uint16 nwPort) +{ + int32 status; + in_addr addr; + unsigned short port; + if ((status = netAddr.GetAddr(addr, &port)) != B_OK) { + fprintf(stderr, + "failed to get in_addr/port from localhost address: %s\n", + strerror(status)); + exit(1); + } + if (addr.s_addr != nwAddr) { + fprintf(stderr, "expected in_addr %lx - got %x\n", nwAddr, addr.s_addr); + exit(1); + } + uint16 hostPort = ntohs(nwPort); + if (port != hostPort) { + fprintf(stderr, "expected port %u - got %u\n", hostPort, port); + exit(1); + } + + sockaddr_in sockaddr; + if ((status = netAddr.GetAddr(sockaddr)) != B_OK) { + fprintf(stderr, + "failed to get sockaddr_in from netAddr: %s\n", + strerror(status)); + exit(1); + } + if (sockaddr.sin_family != AF_INET) { + fprintf(stderr, "expected sockaddr-family %u - got %u\n", AF_INET, + sockaddr.sin_family); + exit(1); + } + if (sockaddr.sin_port != nwPort) { + fprintf(stderr, "expected sockaddr-port %x - got %x\n", nwPort, + sockaddr.sin_port); + exit(1); + } + if (sockaddr.sin_addr.s_addr != nwAddr) { + fprintf(stderr, "expected sockaddr-address %lx - got %x\n", nwAddr, + sockaddr.sin_addr.s_addr); + exit(1); + } +} + + +int +main(int argc, const char* const* argv) +{ + BNetAddress netAddr; + if (sizeof(netAddr) != 52) { + fprintf(stderr, "expected sizeof(netAddr) to be 52 - is %ld\n", + sizeof(netAddr)); + exit(1); + } + + netAddr.SetTo("localhost", 123); + checkNetAddr(netAddr, htonl(0x7F000001), htons(123)); + + netAddr.SetTo(htonl(0x7F000001), 123); + checkNetAddr(netAddr, htonl(0x7F000001), htons(123)); + + in_addr addr; + addr.s_addr = htonl(0x7F000001); + netAddr.SetTo(addr, 54321); + checkNetAddr(netAddr, htonl(0x7F000001), htons(54321)); + + sockaddr_in sockaddr; + sockaddr.sin_family = AF_INET; + sockaddr.sin_addr.s_addr = htonl(0x7F000001); + sockaddr.sin_port = htons(54321); + netAddr.SetTo(sockaddr); + checkNetAddr(netAddr, htonl(0x7F000001), htons(54321)); + + printf("Everything went fine.\n"); + + return 0; +} From zooey at mail.berlios.de Sun Jul 6 00:37:08 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Sun, 6 Jul 2008 00:37:08 +0200 Subject: [Haiku-commits] r26269 - in haiku/trunk: headers/os/net src/kits/network/libnetapi Message-ID: <200807052237.m65Mb8UM011105@sheep.berlios.de> Author: zooey Date: 2008-07-06 00:37:06 +0200 (Sun, 06 Jul 2008) New Revision: 26269 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26269&view=rev Modified: haiku/trunk/headers/os/net/NetAddress.h haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp Log: Resolved a couple of problems in BNetAddress implementation: * fixed several byte order inconsistencies, it does not make sense to always convert the byte order input/output values - no we convert where it can be expected and leave it where it is confusing * fixed size inconsistencies with respect to family and port, both of which were sometimes handled as int8, as int16 and as int32 in different places (now they are always int16) These fixes make Beam connect to the correct address and port, but it still doesn't work, as it seems to be using UDP instead of TCP (doh!). Will look into that tomorrow. Modified: haiku/trunk/headers/os/net/NetAddress.h =================================================================== --- haiku/trunk/headers/os/net/NetAddress.h 2008-07-05 22:27:05 UTC (rev 26268) +++ haiku/trunk/headers/os/net/NetAddress.h 2008-07-05 22:37:06 UTC (rev 26269) @@ -52,10 +52,10 @@ virtual void _ReservedBNetAddressFBCCruft6(); status_t fInit; - int32 fFamily; - int32 fPort; + int16 fFamily; + int16 fPort; int32 fAddress; - int32 fPrivateData[6]; + int32 fPrivateData[7]; }; #endif // H_NETADDRESS Modified: haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp =================================================================== --- haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-05 22:27:05 UTC (rev 26268) +++ haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-05 22:37:06 UTC (rev 26269) @@ -1,17 +1,18 @@ /* - * Copyright 2002-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2006,2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Scott T. Mansfield, thephantom at mac.com + * Oliver Tappe, zooey at hirschkaefer.de */ /*! NetAddress.cpp -- Implementation of the BNetAddress class. Remarks: - * In all accessors, address and port are converted from network to + * In all accessors, non-struct output values are converted from network to host byte order. - * In all mutators, address and port are converted from host to + * In all mutators, non-struct input values are converted from host to network byte order. * No trouts were harmed during the development of this class. */ @@ -76,16 +77,16 @@ BNetAddress::BNetAddress(BMessage* archive) { - int8 int8value; - if (archive->FindInt8("bnaddr_family", &int8value) != B_OK) + int16 int16value; + if (archive->FindInt16("bnaddr_family", &int16value) != B_OK) return; - fFamily = int8value; + fFamily = int16value; - if (archive->FindInt8("bnaddr_port", &int8value) != B_OK) + if (archive->FindInt16("bnaddr_port", &int16value) != B_OK) return; - fPort = int8value; + fPort = int16value; if (archive->FindInt32("bnaddr_addr", &fAddress) != B_OK) return; @@ -187,9 +188,9 @@ return B_NO_INIT; } - sa.sin_family = ( uint8 )fFamily; - sa.sin_port = ( uint8 )fPort; - sa.sin_addr.s_addr = ( in_addr_t )fAddress; + sa.sin_family = fFamily; + sa.sin_port = fPort; + sa.sin_addr.s_addr = fAddress; return B_OK; } @@ -208,22 +209,18 @@ * B_OK for success, B_NO_INIT if instance was not properly constructed. * * Remarks: - * Output parameters will be in network byte order, so it is not - * necessary to call htons after calling this method. + * Output port will be in host byte order, but addr will be in the usual + * network byte order (ready to be used by other network functions). */ status_t BNetAddress::GetAddr( in_addr& addr, unsigned short* port ) const { if ( fInit != B_OK ) - { return B_NO_INIT; - } addr.s_addr = fAddress; if ( port != NULL ) - { - *port = fPort; - } + *port = ntohs(fPort); return B_OK; } @@ -261,24 +258,16 @@ status_t BNetAddress::Archive( BMessage* into, bool deep ) const { if ( fInit != B_OK ) - { return B_NO_INIT; - } - if ( into->AddInt8( "bnaddr_family", fFamily ) != B_OK ) - { + if ( into->AddInt16( "bnaddr_family", fFamily ) != B_OK ) return B_ERROR; - } - if ( into->AddInt8( "bnaddr_port", fPort ) != B_OK ) - { + if ( into->AddInt16( "bnaddr_port", fPort ) != B_OK ) return B_ERROR; - } if ( into->AddInt32( "bnaddr_addr", fAddress ) != B_OK ) - { return B_ERROR; - } return B_OK; } @@ -354,7 +343,7 @@ fFamily = AF_INET; fPort = htons(port); - fAddress = htonl(addr); + fAddress = addr; return fInit = B_OK; } @@ -370,8 +359,8 @@ BNetAddress::SetTo(const struct sockaddr_in& addr) { fFamily = addr.sin_family; - fPort = htons(addr.sin_port); - fAddress = htonl(addr.sin_addr.s_addr); + fPort = addr.sin_port; + fAddress = addr.sin_addr.s_addr; return fInit = B_OK; } @@ -389,8 +378,8 @@ BNetAddress::SetTo(in_addr addr, int port) { fFamily = AF_INET; - fPort = htons(port); - fAddress = htonl(addr.s_addr); + fPort = htons((short)port); + fAddress = addr.s_addr; return fInit = B_OK; } @@ -408,8 +397,8 @@ BNetAddress::SetTo(uint32 addr, int port) { fFamily = AF_INET; - fPort = htons(port); - fAddress = htonl(addr); + fPort = htons((short)port); + fAddress = addr; return fInit = B_OK; } From bonefish at mail.berlios.de Sun Jul 6 02:44:20 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 6 Jul 2008 02:44:20 +0200 Subject: [Haiku-commits] r26270 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807060044.m660iKfc003197@sheep.berlios.de> Author: bonefish Date: 2008-07-06 02:44:17 +0200 (Sun, 06 Jul 2008) New Revision: 26270 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26270&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp Log: Fixed warning. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-05 22:37:06 UTC (rev 26269) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-06 00:44:17 UTC (rev 26270) @@ -153,7 +153,7 @@ VMAnonymousCache::MergeStore(VMCache* source) { if (source->type != CACHE_TYPE_RAM) { - panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache " + panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache %p " "requested", source); return; } From bonefish at mail.berlios.de Sun Jul 6 03:07:44 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 6 Jul 2008 03:07:44 +0200 Subject: [Haiku-commits] r26271 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm Message-ID: <200807060107.m6617ivY006133@sheep.berlios.de> Author: bonefish Date: 2008-07-06 03:07:31 +0200 (Sun, 06 Jul 2008) New Revision: 26271 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26271&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_cache.h haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_daemons.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp Log: * Turned most of the vm_cache_*() functions into VMCache methods. * Changed the VMCache ref count and locking concept. References can only be acquired or released with the cache locked. A cache is destroyed when it has no more references when being unlocked. Unlocking is also the point when a cache is merged with its only consumer. It must have ref count 1 in this case. * Removed VMCache::busy. It is no longer needed due to the ref count/locking changes. Merging only happens when no one else has reference to the cache. This also simplifies fault_find_page(). Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_cache.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_cache.h 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_cache.h 2008-07-06 01:07:31 UTC (rev 26271) @@ -15,30 +15,14 @@ struct kernel_args; -//typedef struct vm_store vm_store; - #ifdef __cplusplus extern "C" { #endif status_t vm_cache_init(struct kernel_args *args); -void vm_cache_acquire_ref(struct VMCache *cache); -void vm_cache_release_ref(struct VMCache *cache); -struct VMCache *vm_cache_acquire_page_cache_ref(struct vm_page *page); -struct vm_page *vm_cache_lookup_page(struct VMCache *cache, off_t page); -void vm_cache_insert_page(struct VMCache *cache, struct vm_page *page, - off_t offset); -void vm_cache_remove_page(struct VMCache *cache, struct vm_page *page); -void vm_cache_remove_consumer(struct VMCache *cache, struct VMCache *consumer); -void vm_cache_add_consumer_locked(struct VMCache *cache, - struct VMCache *consumer); -status_t vm_cache_write_modified(struct VMCache *cache, bool fsReenter); -status_t vm_cache_set_minimal_commitment_locked(struct VMCache *cache, - off_t commitment); -status_t vm_cache_resize(struct VMCache *cache, off_t newSize); -status_t vm_cache_insert_area_locked(struct VMCache *cache, vm_area *area); -status_t vm_cache_remove_area(struct VMCache *cache, struct vm_area *area); +struct VMCache *vm_cache_acquire_locked_page_cache(struct vm_page *page, + bool dontWait); #ifdef __cplusplus } Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_types.h 2008-07-06 01:07:31 UTC (rev 26271) @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -175,6 +176,42 @@ virtual void Delete(); + bool Lock() + { return mutex_lock(&fLock) == B_OK; } + bool TryLock() + { return mutex_trylock(&fLock) == B_OK; } + bool SwitchLock(mutex* from) + { return mutex_switch_lock(from, &fLock) == B_OK; } + void Unlock(); + void AssertLocked() + { ASSERT_LOCKED_MUTEX(&fLock); } + + void AcquireRefLocked(); + void AcquireRef(); + void ReleaseRefLocked(); + void ReleaseRef(); + void ReleaseRefAndUnlock() + { ReleaseRefLocked(); Unlock(); } + + vm_page* LookupPage(off_t offset); + void InsertPage(vm_page* page, off_t offset); + void RemovePage(vm_page* page); + + void AddConsumer(VMCache* consumer); + + status_t InsertAreaLocked(vm_area* area); + status_t RemoveArea(vm_area* area); + + status_t WriteModified(bool fsReenter); + status_t SetMinimalCommitment(off_t commitment); + status_t Resize(off_t newSize); + + // for debugging only + mutex* GetLock() + { return &fLock; } + int32 RefCount() const + { return fRefCount; } + // backing store operations virtual status_t Commit(off_t size); virtual bool HasPage(off_t offset); @@ -192,10 +229,15 @@ virtual void AcquireStoreRef(); virtual void ReleaseStoreRef(); +private: + inline bool _IsMergeable() const; + + void _MergeWithOnlyConsumer(); + void _RemoveConsumer(VMCache* consumer); + + public: - mutex lock; struct vm_area *areas; - vint32 ref_count; struct list_link consumer_link; struct list consumers; // list of caches that use this cache as a source @@ -208,13 +250,16 @@ uint32 page_count; uint32 temporary : 1; uint32 scan_skip : 1; - uint32 busy : 1; - uint32 type : 5; + uint32 type : 6; #if DEBUG_CACHE_LIST struct VMCache* debug_previous; struct VMCache* debug_next; #endif + +private: + int32 fRefCount; + mutex fLock; }; typedef VMCache vm_cache; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-06 01:07:31 UTC (rev 26271) @@ -119,7 +119,7 @@ { if (vm_low_memory_state() != B_NO_LOW_MEMORY) { vm_cache *cache = ref->cache; - mutex_lock(&cache->lock); + cache->Lock(); if (list_is_empty(&cache->consumers) && cache->areas == NULL && access_is_sequential(ref)) { @@ -144,14 +144,14 @@ (page = it.Next()) != NULL && left > 0;) { if (page->state != PAGE_STATE_MODIFIED && page->state != PAGE_STATE_BUSY) { - vm_cache_remove_page(cache, page); + cache->RemovePage(page); vm_page_set_state(page, PAGE_STATE_FREE); left--; } } } } - mutex_unlock(&cache->lock); + cache->Unlock(); } vm_page_reserve_pages(reservePages); @@ -194,7 +194,7 @@ busyConditions[pageIndex - 1].Publish(page, "page"); - vm_cache_insert_page(cache, page, offset + pos); + cache->InsertPage(page, offset + pos); addr_t virtualAddress; if (vm_get_physical_page(page->physical_page_number * B_PAGE_SIZE, @@ -206,7 +206,7 @@ } push_access(ref, offset, bufferSize, false); - mutex_unlock(&cache->lock); + cache->Unlock(); vm_page_unreserve_pages(lastReservedPages); // read file into reserved pages @@ -227,11 +227,11 @@ } } - mutex_lock(&cache->lock); + cache->Lock(); for (int32 i = 0; i < pageIndex; i++) { busyConditions[i].Unpublish(); - vm_cache_remove_page(cache, pages[i]); + cache->RemovePage(pages[i]); vm_page_set_state(pages[i], PAGE_STATE_FREE); } @@ -261,7 +261,7 @@ } reserve_pages(ref, reservePages, false); - mutex_lock(&cache->lock); + cache->Lock(); // make the pages accessible in the cache for (int32 i = pageIndex; i-- > 0;) { @@ -290,7 +290,7 @@ vec.iov_len = bufferSize; push_access(ref, offset, bufferSize, false); - mutex_unlock(&ref->cache->lock); + ref->cache->Unlock(); vm_page_unreserve_pages(lastReservedPages); status_t status = vfs_read_pages(ref->vnode, cookie, offset + pageOffset, @@ -298,7 +298,7 @@ if (status == B_OK) reserve_pages(ref, reservePages, false); - mutex_lock(&ref->cache->lock); + ref->cache->Lock(); return status; } @@ -338,7 +338,7 @@ PAGE_STATE_FREE, true); busyConditions[pageIndex - 1].Publish(page, "page"); - vm_cache_insert_page(ref->cache, page, offset + pos); + ref->cache->InsertPage(page, offset + pos); addr_t virtualAddress; vm_get_physical_page(page->physical_page_number * B_PAGE_SIZE, @@ -349,7 +349,7 @@ } push_access(ref, offset, bufferSize, true); - mutex_unlock(&ref->cache->lock); + ref->cache->Unlock(); vm_page_unreserve_pages(lastReservedPages); // copy contents (and read in partially written pages first) @@ -431,7 +431,7 @@ if (status == B_OK) reserve_pages(ref, reservePages, true); - mutex_lock(&ref->cache->lock); + ref->cache->Lock(); // unmap the pages again @@ -480,7 +480,7 @@ vec.iov_len = bufferSize; push_access(ref, offset, bufferSize, true); - mutex_unlock(&ref->cache->lock); + ref->cache->Unlock(); vm_page_unreserve_pages(lastReservedPages); status_t status = B_OK; @@ -508,7 +508,7 @@ if (status == B_OK) reserve_pages(ref, reservePages, true); - mutex_lock(&ref->cache->lock); + ref->cache->Lock(); return status; } @@ -604,11 +604,11 @@ size_t reservePages = 0; reserve_pages(ref, lastReservedPages, doWrite); - MutexLocker locker(cache->lock); + AutoLocker locker(cache); while (bytesLeft > 0) { // check if this page is already in memory - vm_page *page = vm_cache_lookup_page(cache, offset); + vm_page *page = cache->LookupPage(offset); if (page != NULL) { // The page may be busy - since we need to unlock the cache sometime // in the near future, we need to satisfy the request of the pages @@ -969,7 +969,7 @@ TRACE(("file_cache_delete(ref = %p)\n", ref)); - vm_cache_release_ref(ref->cache); + ref->cache->ReleaseRef(); delete ref; } @@ -984,7 +984,7 @@ if (ref == NULL) return B_OK; - MutexLocker _(ref->cache->lock); + AutoLocker _(ref->cache); off_t offset = ref->cache->virtual_end; off_t size = newSize; @@ -994,7 +994,7 @@ } else size = newSize - offset; - return vm_cache_resize(ref->cache, newSize); + return ref->cache->Resize(newSize); } @@ -1005,7 +1005,7 @@ if (ref == NULL) return B_BAD_VALUE; - return vm_cache_write_modified(ref->cache, true); + return ref->cache->WriteModified(true); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-06 01:07:31 UTC (rev 26271) @@ -770,7 +770,7 @@ // if we have a vm_cache attached, remove it if (vnode->cache) - vm_cache_release_ref(vnode->cache); + vnode->cache->ReleaseRef(); vnode->cache = NULL; @@ -1059,7 +1059,7 @@ mutex_unlock(&sVnodeMutex); if (vnode->cache != NULL) - vm_cache_write_modified(vnode->cache, false); + vnode->cache->WriteModified(false); dec_vnode_ref_count(vnode, true, false); // this should free the vnode when it's still unused @@ -3920,7 +3920,7 @@ vfs_get_vnode_cache(struct vnode *vnode, vm_cache **_cache, bool allocate) { if (vnode->cache != NULL) { - vm_cache_acquire_ref(vnode->cache); + vnode->cache->AcquireRef(); *_cache = vnode->cache; return B_OK; } @@ -3946,12 +3946,13 @@ status = B_BAD_VALUE; } + mutex_unlock(&sVnodeMutex); + if (status == B_OK) { - vm_cache_acquire_ref(vnode->cache); + vnode->cache->AcquireRef(); *_cache = vnode->cache; } - mutex_unlock(&sVnodeMutex); return status; } @@ -6705,7 +6706,7 @@ put_vnode(previousVnode); if (vnode->cache != NULL) - vm_cache_write_modified(vnode->cache, false); + vnode->cache->WriteModified(false); // the next vnode might change until we lock the vnode list again, // but this vnode won't go away since we keep a reference to it. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-06 01:07:31 UTC (rev 26271) @@ -1239,7 +1239,7 @@ // If no one else uses the area's cache, we can resize it, too. if (cache->areas == area && area->cache_next == NULL && list_is_empty(&cache->consumers)) { - status_t error = vm_cache_resize(cache, newSize); + status_t error = cache->Resize(newSize); if (error != B_OK) return error; } @@ -1298,7 +1298,7 @@ } // We need a cache reference for the new area. - vm_cache_acquire_ref(cache); + cache->AcquireRefLocked(); if (_secondArea != NULL) *_secondArea = secondArea; @@ -1372,7 +1372,7 @@ TRACE(("map_backing_store: aspace %p, cache %p, *vaddr %p, offset 0x%Lx, size %lu, addressSpec %ld, wiring %d, protection %d, _area %p, area_name '%s'\n", addressSpace, cache, *_virtualAddress, offset, size, addressSpec, wiring, protection, _area, areaName)); - ASSERT_LOCKED_MUTEX(&cache->lock); + cache->AssertLocked(); vm_area *area = create_area_struct(addressSpace, areaName, wiring, protection); @@ -1393,18 +1393,18 @@ if (status != B_OK) goto err1; - mutex_lock(&newCache->lock); + newCache->Lock(); newCache->temporary = 1; newCache->scan_skip = cache->scan_skip; newCache->virtual_base = offset; newCache->virtual_end = offset + size; - vm_cache_add_consumer_locked(cache, newCache); + cache->AddConsumer(newCache); cache = newCache; } - status = vm_cache_set_minimal_commitment_locked(cache, size); + status = cache->SetMinimalCommitment(size); if (status != B_OK) goto err2; @@ -1432,9 +1432,9 @@ area->cache_offset = offset; // point the cache back to the area - vm_cache_insert_area_locked(cache, area); + cache->InsertAreaLocked(area); if (mapping == REGION_PRIVATE_MAP) - mutex_unlock(&cache->lock); + cache->Unlock(); // insert the area in the global area hash table acquire_sem_etc(sAreaHashLock, WRITE_COUNT, 0 ,0); @@ -1451,11 +1451,10 @@ if (mapping == REGION_PRIVATE_MAP) { // We created this cache, so we must delete it again. Note, that we // need to temporarily unlock the source cache or we'll otherwise - // deadlock, since vm_cache_remove_consumer will try to lock it too. - mutex_unlock(&cache->lock); - mutex_unlock(&sourceCache->lock); - vm_cache_release_ref(cache); - mutex_lock(&sourceCache->lock); + // deadlock, since VMCache::_RemoveConsumer() will try to lock it, too. + sourceCache->Unlock(); + cache->ReleaseRefAndUnlock(); + sourceCache->Lock(); } err1: free(area->name); @@ -1641,19 +1640,19 @@ break; } - mutex_lock(&cache->lock); + cache->Lock(); status = map_backing_store(addressSpace, cache, address, 0, size, addressSpec, wiring, protection, REGION_NO_PRIVATE_MAP, &area, name, unmapAddressRange, kernel); - mutex_unlock(&cache->lock); - if (status < B_OK) { - vm_cache_release_ref(cache); + cache->ReleaseRefAndUnlock(); goto err1; } + cache->Unlock(); + locker.DegradeToReadLock(); switch (wiring) { @@ -1670,7 +1669,7 @@ vm_page_reserve_pages(reservePages); // Allocate and map all pages for this area - mutex_lock(&cache->lock); + cache->Lock(); off_t offset = 0; for (addr_t address = area->base; address < area->base + (area->size - 1); @@ -1691,11 +1690,11 @@ panic("couldn't fulfill B_FULL lock!"); } - vm_cache_insert_page(cache, page, offset); + cache->InsertPage(page, offset); vm_map_page(area, page, address, protection); } - mutex_unlock(&cache->lock); + cache->Unlock(); vm_page_unreserve_pages(reservePages); break; } @@ -1711,7 +1710,7 @@ if (!kernel_startup) panic("ALREADY_WIRED flag used outside kernel startup\n"); - mutex_lock(&cache->lock); + cache->Lock(); map->ops->lock(map); for (addr_t virtualAddress = area->base; virtualAddress < area->base @@ -1734,11 +1733,11 @@ page->wired_count++; // TODO: needs to be atomic on all platforms! vm_page_set_state(page, PAGE_STATE_WIRED); - vm_cache_insert_page(cache, page, offset); + cache->InsertPage(page, offset); } map->ops->unlock(map); - mutex_unlock(&cache->lock); + cache->Unlock(); break; } @@ -1754,7 +1753,7 @@ off_t offset = 0; vm_page_reserve_pages(reservePages); - mutex_lock(&cache->lock); + cache->Lock(); map->ops->lock(map); for (virtualAddress = area->base; virtualAddress < area->base @@ -1772,11 +1771,11 @@ page->wired_count++; // TODO: needs to be atomic on all platforms! vm_page_set_state(page, PAGE_STATE_WIRED); - vm_cache_insert_page(cache, page, offset); + cache->InsertPage(page, offset); } map->ops->unlock(map); - mutex_unlock(&cache->lock); + cache->Unlock(); vm_page_unreserve_pages(reservePages); break; } @@ -1844,17 +1843,17 @@ cache->scan_skip = 1; cache->virtual_end = size; - mutex_lock(&cache->lock); + cache->Lock(); status = map_backing_store(locker.AddressSpace(), cache, _address, 0, size, addressSpec & ~B_MTR_MASK, B_FULL_LOCK, protection, REGION_NO_PRIVATE_MAP, &area, name, false, true); - mutex_unlock(&cache->lock); - if (status < B_OK) - vm_cache_release_ref(cache); + cache->ReleaseRefLocked(); + cache->Unlock(); + if (status >= B_OK && (addressSpec & B_MTR_MASK) != 0) { // set requested memory type status = arch_vm_set_memory_type(area, physicalAddress, @@ -1917,19 +1916,19 @@ cache->scan_skip = 1; cache->virtual_end = size; - mutex_lock(&cache->lock); + cache->Lock(); status = map_backing_store(locker.AddressSpace(), cache, address, 0, size, addressSpec, 0, B_KERNEL_READ_AREA, REGION_NO_PRIVATE_MAP, &area, name, false, true); - mutex_unlock(&cache->lock); - if (status < B_OK) { - vm_cache_release_ref(cache); + cache->ReleaseRefAndUnlock(); return status; } + cache->Unlock(); + area->cache_type = CACHE_TYPE_NULL; return area->id; } @@ -2005,19 +2004,20 @@ if (status < B_OK) return status; - mutex_lock(&cache->lock); + cache->Lock(); vm_area *area; status = map_backing_store(locker.AddressSpace(), cache, _address, offset, size, addressSpec, 0, protection, mapping, &area, name, addressSpec == B_EXACT_ADDRESS, kernel); - mutex_unlock(&cache->lock); - if (status < B_OK || mapping == REGION_PRIVATE_MAP) { // map_backing_store() cannot know we no longer need the ref - vm_cache_release_ref(cache); + cache->ReleaseRefLocked(); } + + cache->Unlock(); + if (status < B_OK) return status; @@ -2041,21 +2041,27 @@ vm_cache * vm_area_get_locked_cache(vm_area *area) { - MutexLocker locker(sAreaCacheLock); + mutex_lock(&sAreaCacheLock); + while (true) { vm_cache* cache = area->cache; - vm_cache_acquire_ref(cache); - locker.Unlock(); - mutex_lock(&cache->lock); + if (!cache->SwitchLock(&sAreaCacheLock)) { + // cache has been deleted + mutex_lock(&sAreaCacheLock); + continue; + } - locker.Lock(); - if (cache == area->cache) + mutex_lock(&sAreaCacheLock); + + if (cache == area->cache) { + cache->AcquireRefLocked(); + mutex_unlock(&sAreaCacheLock); return cache; + } // the cache changed in the meantime - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); + cache->Unlock(); } } @@ -2063,8 +2069,7 @@ void vm_area_put_locked_cache(vm_cache *cache) { - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); + cache->ReleaseRefAndUnlock(); } @@ -2121,10 +2126,10 @@ } if (status == B_OK && mapping != REGION_PRIVATE_MAP) { // If the mapping is REGION_PRIVATE_MAP, map_backing_store() needed - // to create a new ref, and has therefore already acquired a reference + // to create a new cache, and has therefore already acquired a reference // to the source cache - but otherwise it has no idea that we need // one. - vm_cache_acquire_ref(cache); + cache->AcquireRefLocked(); } if (status == B_OK && newArea->wiring == B_FULL_LOCK) { // we need to map in everything at this point @@ -2226,14 +2231,14 @@ vm_unmap_pages(area, area->base, area->size, !area->cache->temporary); if (!area->cache->temporary) - vm_cache_write_modified(area->cache, false); + area->cache->WriteModified(false); arch_vm_unset_memory_type(area); remove_area_from_address_space(addressSpace, area); vm_put_address_space(addressSpace); - vm_cache_remove_area(area->cache, area); - vm_cache_release_ref(area->cache); + area->cache->RemoveArea(area); + area->cache->ReleaseRef(); free(area->name); free(area); @@ -2284,7 +2289,7 @@ if (status != B_OK) return status; - mutex_lock(&upperCache->lock); + upperCache->Lock(); upperCache->temporary = 1; upperCache->scan_skip = lowerCache->scan_skip; @@ -2302,13 +2307,13 @@ ASSERT(!tempArea->no_cache_change); tempArea->cache = upperCache; - atomic_add(&upperCache->ref_count, 1); - atomic_add(&lowerCache->ref_count, -1); + upperCache->AcquireRefLocked(); + lowerCache->ReleaseRefLocked(); } mutex_unlock(&sAreaCacheLock); - vm_cache_add_consumer_locked(lowerCache, upperCache); + lowerCache->AddConsumer(upperCache); // We now need to remap all pages from all of the cache's areas read-only, so that // a copy will be created on next write access @@ -2382,7 +2387,7 @@ if (sharedArea) { // The new area uses the old area's cache, but map_backing_store() // hasn't acquired a ref. So we have to do that now. - vm_cache_acquire_ref(cache); + cache->AcquireRefLocked(); } // If the source area is writable, we need to move it one layer up as well @@ -3220,16 +3225,16 @@ cache = (vm_cache *)address; kprintf("CACHE %p:\n", cache); - kprintf(" ref_count: %ld\n", cache->ref_count); + kprintf(" ref_count: %ld\n", cache->RefCount()); kprintf(" source: %p\n", cache->source); kprintf(" type: %s\n", cache_type_to_string(cache->type)); kprintf(" virtual_base: 0x%Lx\n", cache->virtual_base); kprintf(" virtual_end: 0x%Lx\n", cache->virtual_end); kprintf(" temporary: %ld\n", cache->temporary); kprintf(" scan_skip: %ld\n", cache->scan_skip); - kprintf(" lock: %p\n", &cache->lock); + kprintf(" lock: %p\n", cache->GetLock()); #ifdef KDEBUG - kprintf(" lock.holder: %ld\n", cache->lock.holder); + kprintf(" lock.holder: %ld\n", cache->GetLock()->holder); #endif kprintf(" areas:\n"); @@ -4033,23 +4038,13 @@ static inline status_t fault_acquire_locked_source(vm_cache *cache, vm_cache **_source) { -retry: vm_cache *source = cache->source; if (source == NULL) return B_ERROR; - if (source->busy) - return B_BUSY; - vm_cache_acquire_ref(source); + source->Lock(); + source->AcquireRefLocked(); - mutex_lock(&source->lock); - - if (source->busy) { - mutex_unlock(&source->lock); - vm_cache_release_ref(source); - goto retry; - } - *_source = source; return B_OK; } @@ -4064,8 +4059,8 @@ off_t cacheOffset) { dummyPage.state = PAGE_STATE_BUSY; - vm_cache_acquire_ref(cache); - vm_cache_insert_page(cache, &dummyPage, cacheOffset); + cache->AcquireRefLocked(); + cache->InsertPage(&dummyPage, cacheOffset); dummyPage.busy_condition.Publish(&dummyPage, "page"); } @@ -4079,18 +4074,18 @@ { vm_cache *cache = dummyPage.cache; if (!isLocked) - mutex_lock(&cache->lock); + cache->Lock(); if (dummyPage.state == PAGE_STATE_BUSY) { - vm_cache_remove_page(cache, &dummyPage); + cache->RemovePage(&dummyPage); dummyPage.state = PAGE_STATE_INACTIVE; dummyPage.busy_condition.Unpublish(); } - if (!isLocked) - mutex_unlock(&cache->lock); + cache->ReleaseRefLocked(); - vm_cache_release_ref(cache); + if (!isLocked) + cache->Unlock(); } @@ -4112,20 +4107,20 @@ vm_cache *lastCache = NULL; vm_page *page = NULL; - vm_cache_acquire_ref(cache); - mutex_lock(&cache->lock); + cache->Lock(); + cache->AcquireRefLocked(); // we release this later in the loop while (cache != NULL) { if (lastCache != NULL) - vm_cache_release_ref(lastCache); + lastCache->ReleaseRefAndUnlock(); // we hold the lock of the cache at this point lastCache = cache; for (;;) { - page = vm_cache_lookup_page(cache, cacheOffset); + page = cache->LookupPage(cacheOffset); if (page != NULL && page->state != PAGE_STATE_BUSY) { // we found the page break; @@ -4137,23 +4132,10 @@ { ConditionVariableEntry entry; entry.Add(page); - mutex_unlock(&cache->lock); + cache->Unlock(); entry.Wait(); - mutex_lock(&cache->lock); + cache->Lock(); } - - if (cache->busy) { - // The cache became busy, which means, it is about to be - // removed by vm_cache_remove_consumer(). We start again with - // the top cache. - ConditionVariableEntry entry; - entry.Add(cache); - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); - entry.Wait(); - *_restart = true; - return B_OK; - } } if (page != NULL && page != &dummyPage) @@ -4165,12 +4147,12 @@ if (cache->HasPage(cacheOffset)) { // insert a fresh page and mark it busy -- we're going to read it in page = vm_page_allocate_page(PAGE_STATE_FREE, true); - vm_cache_insert_page(cache, page, cacheOffset); + cache->InsertPage(page, cacheOffset); ConditionVariable busyCondition; busyCondition.Publish(page, "page"); - mutex_unlock(&cache->lock); + cache->Unlock(); // get a virtual address for the page iovec vec; @@ -4185,7 +4167,7 @@ map->ops->put_physical_page((addr_t)vec.iov_base); - mutex_lock(&cache->lock); + cache->Lock(); if (status < B_OK) { // on error remove and free the page @@ -4193,11 +4175,10 @@ cache, strerror(status)); busyCondition.Unpublish(); - vm_cache_remove_page(cache, page); + cache->RemovePage(page); vm_page_set_state(page, PAGE_STATE_FREE); - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); + cache->ReleaseRefAndUnlock(); return status; } @@ -4215,76 +4196,41 @@ vm_cache *nextCache; status_t status = fault_acquire_locked_source(cache, &nextCache); - if (status == B_BUSY) { - // the source cache is currently in the process of being merged - // with his only consumer (cacheRef); since its pages are moved - // upwards, too, we try this cache again - mutex_unlock(&cache->lock); - thread_yield(true); - mutex_lock(&cache->lock); - if (cache->busy) { - // The cache became busy, which means, it is about to be - // removed by vm_cache_remove_consumer(). We start again with - // the top cache. - ConditionVariableEntry entry; - entry.Add(cache); - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); - entry.Wait(); - *_restart = true; - return B_OK; - } - lastCache = NULL; - continue; - } else if (status < B_OK) + if (status < B_OK) nextCache = NULL; - mutex_unlock(&cache->lock); - // at this point, we still hold a ref to this cache (through lastCacheRef) + // at this point, we still hold a ref to this cache (through lastCacheRef) cache = nextCache; } if (page == NULL) { // there was no adequate page, determine the cache for a clean one - if (cache == NULL) { - // We rolled off the end of the cache chain, so we need to decide which - // cache will get the new page we're about to create. - cache = isWrite ? topCache : lastCache; - // Read-only pages come in the deepest cache - only the - // top most cache may have direct write access. - vm_cache_acquire_ref(cache); - mutex_lock(&cache->lock); - if (cache->busy) { - // The cache became busy, which means, it is about to be - // removed by vm_cache_remove_consumer(). We start again with - // the top cache. - ConditionVariableEntry entry; - entry.Add(cache); - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); - entry.Wait(); - *_restart = true; - } else { - vm_page* newPage = vm_cache_lookup_page(cache, cacheOffset); - if (newPage && newPage != &dummyPage) { - // A new page turned up. It could be the one we're looking - // for, but it could as well be a dummy page from someone - // else or an otherwise busy page. We can't really handle - // that here. Hence we completely restart this functions. - mutex_unlock(&cache->lock); - vm_cache_release_ref(cache); - *_restart = true; - } - } + ASSERT(cache == NULL); + + // We rolled off the end of the cache chain, so we need to decide which + // cache will get the new page we're about to create. + cache = isWrite ? topCache : lastCache; + // Read-only pages come in the deepest cache - only the + // top most cache may have direct write access. + if (cache != lastCache) { + lastCache->ReleaseRefAndUnlock(); + cache->Lock(); + cache->AcquireRefLocked(); } - // release the reference of the last vm_cache we still have from the loop above - if (lastCache != NULL) - vm_cache_release_ref(lastCache); + vm_page* newPage = cache->LookupPage(cacheOffset); + if (newPage && newPage != &dummyPage) { + // A new page turned up. It could be the one we're looking + // for, but it could as well be a dummy page from someone + // else or an otherwise busy page. We can't really handle + // that here. Hence we completely restart this functions. + cache->ReleaseRefAndUnlock(); + *_restart = true; + } } else { - // we still own a reference to the cache + // we still own reference and lock to the cache } *_pageCache = cache; [... truncated: 1373 lines follow ...] From laplace at mail.berlios.de Sun Jul 6 09:45:11 2008 From: laplace at mail.berlios.de (laplace at BerliOS) Date: Sun, 6 Jul 2008 09:45:11 +0200 Subject: [Haiku-commits] r26272 - in haiku/trunk: build/jam src/add-ons/kernel/bus_managers/firewire Message-ID: <200807060745.m667jB67030858@sheep.berlios.de> Author: laplace Date: 2008-07-06 09:45:09 +0200 (Sun, 06 Jul 2008) New Revision: 26272 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26272&view=rev Modified: haiku/trunk/build/jam/HaikuImage haiku/trunk/src/add-ons/kernel/bus_managers/firewire/firewire.c Log: Patch by JiSheng Zhang to fix firewire gcc4 build instability. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-07-06 01:07:31 UTC (rev 26271) +++ haiku/trunk/build/jam/HaikuImage 2008-07-06 07:45:09 UTC (rev 26272) @@ -30,7 +30,7 @@ csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname draggers driveinfo dstcheck du echo eject env error expand expr expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp ftpd - funzip #fwcontrol + funzip fwcontrol gawk $(X86_ONLY)gdb grep groups gzip gzexe hd head hey hostname id ident ideinfo idestatus ifconfig install installsound iroster isvolume join keymap kill less lessecho lesskey link listarea listattr listimage listdev @@ -171,7 +171,7 @@ random tty zero ; AddDriversToHaikuImage audio hmulti : $(BEOS_ADD_ONS_DRIVERS_AUDIO) ; AddDriversToHaikuImage midi : $(BEOS_ADD_ONS_DRIVERS_MIDI) ; -AddDriversToHaikuImage bus : usb_raw ; # fw_raw +AddDriversToHaikuImage bus : usb_raw fw_raw ; AddDriversToHaikuImage disk floppy : $(X86_ONLY)pc_floppy ; AddDriversToHaikuImage disk scsi : scsi_cd scsi_disk ; AddDriversToHaikuImage disk usb : usb_disk ; Modified: haiku/trunk/src/add-ons/kernel/bus_managers/firewire/firewire.c =================================================================== --- haiku/trunk/src/add-ons/kernel/bus_managers/firewire/firewire.c 2008-07-06 01:07:31 UTC (rev 26271) +++ haiku/trunk/src/add-ons/kernel/bus_managers/firewire/firewire.c 2008-07-06 07:45:09 UTC (rev 26272) @@ -344,14 +344,12 @@ */ if (watchdog_clock > WATCHDOG_HZ * 15) // taskqueue_enqueue(fc->taskqueue, &fc->task_timeout); - gDpc->queue_dpc(fc->taskqueue, firewire_xfer_timeout, fc); + firewire_xfer_timeout(fc); else watchdog_clock ++; // callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ, // (void *)firewire_watchdog, (void *)fc); - fc->timeout_callout = create_timer(firewire_watchdog, fc, - hz/WATCHDOG_HZ, B_ONE_SHOT_RELATIVE_TIMER); } #if 0//to do @@ -447,7 +445,7 @@ // callout_reset(&sc->fc->timeout_callout, hz, // (void *)firewire_watchdog, (void *)sc->fc); fc->timeout_callout = create_timer(firewire_watchdog, fc, - hz/WATCHDOG_HZ, B_ONE_SHOT_RELATIVE_TIMER); + hz/WATCHDOG_HZ, B_PERIODIC_TIMER); /* create thread */ // kthread_create(fw_bus_probe_thread, (void *)fc, &fc->probe_thread, From laplace at mail.berlios.de Sun Jul 6 11:15:16 2008 From: laplace at mail.berlios.de (laplace at BerliOS) Date: Sun, 6 Jul 2008 11:15:16 +0200 Subject: [Haiku-commits] r26273 - haiku/trunk/build/jam Message-ID: <200807060915.m669FGTX005033@sheep.berlios.de> Author: laplace Date: 2008-07-06 11:15:14 +0200 (Sun, 06 Jul 2008) New Revision: 26273 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26273&view=rev Modified: haiku/trunk/build/jam/HaikuImage Log: Forgot to enable firewire bus manager. Thanks to JiSheng for the notification. Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2008-07-06 07:45:09 UTC (rev 26272) +++ haiku/trunk/build/jam/HaikuImage 2008-07-06 09:15:14 UTC (rev 26273) @@ -133,7 +133,7 @@ ; #BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button ; BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi - config_manager agp_gart usb #firewire + config_manager agp_gart usb firewire ; BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 $(GPL_ONLY)reiserfs ; #googlefs nfs $(GPL_ONLY)ntfs ; From julun at mail.berlios.de Sun Jul 6 12:21:43 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 6 Jul 2008 12:21:43 +0200 Subject: [Haiku-commits] r26274 - haiku/trunk/src/kits/interface Message-ID: <200807061021.m66ALhIk011935@sheep.berlios.de> Author: julun Date: 2008-07-06 12:21:41 +0200 (Sun, 06 Jul 2008) New Revision: 26274 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26274&view=rev Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: * remove whitespaces, no functional change Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2008-07-06 09:15:14 UTC (rev 26273) +++ haiku/trunk/src/kits/interface/ListView.cpp 2008-07-06 10:21:41 UTC (rev 26274) @@ -2,7 +2,7 @@ * Copyright (c) 2001-2008, Haiku, Inc. * Distributed under the terms of the MIT license. * - * Authors: + * Authors: * Ulrich Wimboeck * Marc Flerackers (mflerackers at androme.be) * Stephan Assmus @@ -32,35 +32,35 @@ static property_info sProperties[] = { { "Item", { B_COUNT_PROPERTIES, 0 }, { B_DIRECT_SPECIFIER, 0 }, - "Returns the number of BListItems currently in the list.", 0, { B_INT32_TYPE } + "Returns the number of BListItems currently in the list.", 0, { B_INT32_TYPE } }, { "Item", { B_EXECUTE_PROPERTY, 0 }, { B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER, B_RANGE_SPECIFIER, B_REVERSE_RANGE_SPECIFIER, 0 }, - "Select and invoke the specified items, first removing any existing selection." + "Select and invoke the specified items, first removing any existing selection." }, { "Selection", { B_COUNT_PROPERTIES, 0 }, { B_DIRECT_SPECIFIER, 0 }, - "Returns int32 count of items in the selection.", 0, { B_INT32_TYPE } + "Returns int32 count of items in the selection.", 0, { B_INT32_TYPE } }, { "Selection", { B_EXECUTE_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 }, - "Invoke items in selection." + "Invoke items in selection." }, { "Selection", { B_GET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 }, - "Returns int32 indices of all items in the selection.", 0, { B_INT32_TYPE } + "Returns int32 indices of all items in the selection.", 0, { B_INT32_TYPE } }, { "Selection", { B_SET_PROPERTY, 0 }, { B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER, B_RANGE_SPECIFIER, B_REVERSE_RANGE_SPECIFIER, 0 }, "Extends current selection or deselects specified items. Boolean field \"data\" " - "chooses selection or deselection.", 0, { B_BOOL_TYPE } + "chooses selection or deselection.", 0, { B_BOOL_TYPE } }, { "Selection", { B_SET_PROPERTY, 0 }, { B_DIRECT_SPECIFIER, 0 }, "Select or deselect all items in the selection. Boolean field \"data\" chooses " - "selection or deselection.", 0, { B_BOOL_TYPE } + "selection or deselection.", 0, { B_BOOL_TYPE } }, }; @@ -105,7 +105,7 @@ int32 i = 0; BMessage subData; - + while (archive->FindMessage("_l_items", i++, &subData)) { BArchivable *object = instantiate_object(&subData); if (!object) @@ -498,8 +498,8 @@ item->Update(this, &font); - _RecalcItemTops(index); - + _RecalcItemTops(index); + _FixupScrollBar(); _InvalidateFrom(index); } @@ -515,14 +515,14 @@ return false; // No need to adapt selection, as this item is the last in the list - + if (Window()) { BFont font; GetFont(&font); item->Update(this, &font); - _RecalcItemTops(CountItems() - 1); + _RecalcItemTops(CountItems() - 1); _FixupScrollBar(); InvalidateItem(CountItems() - 1); @@ -549,12 +549,12 @@ if (Window()) { BFont font; GetFont(&font); - - for (int32 i = index; i <= (index + list->CountItems() - 1); i++) + + for (int32 i = index; i <= (index + list->CountItems() - 1); i++) ItemAt(i)->Update(this, &font); - + _RecalcItemTops(index); - + _FixupScrollBar(); Invalidate(); // TODO } @@ -582,15 +582,15 @@ if (!fList.RemoveItem(item)) return NULL; - + if (fFirstSelected != -1 && index < fFirstSelected) fFirstSelected--; if (fLastSelected != -1 && index < fLastSelected) fLastSelected--; - + _RecalcItemTops(index); - + _InvalidateFrom(index); _FixupScrollBar(); @@ -711,14 +711,14 @@ mid = (low + high) / 2; frameTop = ItemAt(mid)->Top(); frameBottom = ItemAt(mid)->Bottom(); - if (point.y < frameTop) + if (point.y < frameTop) high = mid - 1; - else if (point.y > frameBottom) + else if (point.y > frameBottom) low = mid + 1; else return mid; - } - + } + return -1; } @@ -884,7 +884,7 @@ if (!message && !notify) message = Message(); - + if (!message) { if (!IsWatched()) return err; @@ -956,7 +956,7 @@ void -BListView::SortItems(int (*cmp)(const void *, const void *)) +BListView::SortItems(int (*cmp)(const void *, const void *)) { if (_DeselectAll(-1, -1)) { SelectionChanged(); @@ -1013,7 +1013,7 @@ if (!Messenger().IsValid()) SetTarget(Window(), NULL); - + _FixupScrollBar(); } @@ -1062,13 +1062,13 @@ { if (data == NULL) return B_BAD_VALUE; - + status_t err = data->AddString("suites", "suite/vnd.Be-list-view"); BPropertyInfo propertyInfo(sProperties); if (err == B_OK) err = data->AddFlat("messages", &propertyInfo); - + if (err == B_OK) return BView::GetSupportedSuites(data); return err; @@ -1116,13 +1116,13 @@ int32 count = CountItems(); if (count > 0) { - float maxWidth = 0.0; + float maxWidth = 0.0; for (int32 i = 0; i < count; i++) { float itemWidth = ItemAt(i)->Width(); if (itemWidth > maxWidth) - maxWidth = itemWidth; + maxWidth = itemWidth; } - + *width = maxWidth; *height = ItemAt(count - 1)->Bottom(); } else { @@ -1228,7 +1228,7 @@ BRect bounds = Bounds(); int32 count = CountItems(); - + float itemHeight = 0.0; if (CountItems() > 0) @@ -1277,10 +1277,10 @@ { BFont font; GetFont(&font); - for (int32 i = 0; i < CountItems(); i++) + for (int32 i = 0; i < CountItems(); i++) ItemAt(i)->Update(this, &font); _RecalcItemTops(0); -} +} /*! @@ -1527,14 +1527,14 @@ fAnchorIndex = b; else if (fAnchorIndex == b) fAnchorIndex = a; - + // track selection // NOTE: this is only important if the selection status // of both items is not the same int32 first = min_c(a, b); int32 last = max_c(a, b); if (ItemAt(a)->IsSelected() != ItemAt(b)->IsSelected()) { - if (first < fFirstSelected || last > fLastSelected) + if (first < fFirstSelected || last > fLastSelected) _RescanSelection(min_c(first, fFirstSelected), min_c(last, fLastSelected)); // though the actually selected items stayed the // same, the selection has still changed @@ -1543,7 +1543,7 @@ ItemAt(a)->SetTop(bFrame.top); ItemAt(b)->SetTop(aFrame.top); - + // take care of invalidation if (Window()) { // NOTE: window looper is assumed to be locked! @@ -1582,9 +1582,9 @@ // same, the selection has still changed SelectionChanged(); } - + _RecalcItemTops((to > from) ? from : to); - + // take care of invalidation if (Window()) { // NOTE: window looper is assumed to be locked! From julun at mail.berlios.de Sun Jul 6 12:26:14 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 6 Jul 2008 12:26:14 +0200 Subject: [Haiku-commits] r26275 - haiku/trunk/src/kits/interface Message-ID: <200807061026.m66AQE8a012340@sheep.berlios.de> Author: julun Date: 2008-07-06 12:26:14 +0200 (Sun, 06 Jul 2008) New Revision: 26275 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26275&view=rev Modified: haiku/trunk/src/kits/interface/ListView.cpp Log: * don't leak fTrack * fixed broken while loop * call _InitObject also from the archive constructor * just noticed while trying to load the R5 epson printer driver, still not working... Modified: haiku/trunk/src/kits/interface/ListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/ListView.cpp 2008-07-06 10:21:41 UTC (rev 26274) +++ haiku/trunk/src/kits/interface/ListView.cpp 2008-07-06 10:26:14 UTC (rev 26275) @@ -91,31 +91,19 @@ : BView(archive) { int32 listType; - archive->FindInt32("_lv_type", &listType); - fListType = (list_view_type)listType; + _InitObject((list_view_type)listType); - fFirstSelected = -1; - fLastSelected = -1; - fAnchorIndex = -1; - - fSelectMessage = NULL; - fScrollView = NULL; - fTrack = NULL; - int32 i = 0; BMessage subData; - - while (archive->FindMessage("_l_items", i++, &subData)) { + while (archive->FindMessage("_l_items", i++, &subData) == B_OK) { BArchivable *object = instantiate_object(&subData); if (!object) continue; BListItem *item = dynamic_cast(object); - if (!item) - continue; - - AddItem(item); + if (item) + AddItem(item); } if (archive->HasMessage("_msg")) { @@ -136,6 +124,7 @@ BListView::~BListView() { + delete fTrack; SetSelectionMessage(NULL); } @@ -1459,7 +1448,7 @@ if (dragDistance > 5.0) { fTrack->try_drag = false; - return InitiateDrag(fTrack->drag_start, fTrack->item_index, fTrack->was_selected);; + return InitiateDrag(fTrack->drag_start, fTrack->item_index, fTrack->was_selected); } return false; } From julun at mail.berlios.de Sun Jul 6 12:34:58 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 6 Jul 2008 12:34:58 +0200 Subject: [Haiku-commits] r26276 - haiku/trunk/src/kits/app Message-ID: <200807061034.m66AYwnA019764@sheep.berlios.de> Author: julun Date: 2008-07-06 12:34:47 +0200 (Sun, 06 Jul 2008) New Revision: 26276 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26276&view=rev Modified: haiku/trunk/src/kits/app/Looper.cpp Log: * Archive the thread priority as well, it can be found in an R5 archive if Run() was called. Modified: haiku/trunk/src/kits/app/Looper.cpp =================================================================== --- haiku/trunk/src/kits/app/Looper.cpp 2008-07-06 10:26:14 UTC (rev 26275) +++ haiku/trunk/src/kits/app/Looper.cpp 2008-07-06 10:34:47 UTC (rev 26276) @@ -173,7 +173,11 @@ if (data->FindInt32("_port_cap", &portCapacity) != B_OK || portCapacity < 0) portCapacity = B_LOOPER_PORT_DEFAULT_CAPACITY; - _InitData(Name(), B_NORMAL_PRIORITY, portCapacity); + int32 priority; + if (data->FindInt32("_prio", &priority) != B_OK) + priority = B_NORMAL_PRIORITY; + + _InitData(Name(), priority, portCapacity); } @@ -199,7 +203,9 @@ if (status == B_OK) status = data->AddInt32("_port_cap", info.capacity); - // TODO: what about the thread priority? + thread_info threadInfo; + if (get_thread_info(Thread(), &threadInfo) == B_OK) + status = data->AddInt32("_prio", threadInfo.priority); return status; } @@ -522,7 +528,7 @@ // and release if it's the case if (atomicCount > 1) #endif - release_sem(fLockSem); + release_sem(fLockSem); } PRINT(("BLooper::Unlock() done\n")); } @@ -898,7 +904,7 @@ { status_t err = B_OK; -#if DEBUG < 1 +#if DEBUG < 1 if (oldCount > 0) { #endif do { From ingo_weinhold at gmx.de Sun Jul 6 15:44:34 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sun, 06 Jul 2008 15:44:34 +0200 Subject: [Haiku-commits] r26241 - haiku/trunk/src/add-ons/kernel/file_systems/ext2 In-Reply-To: <49283267548-BeMail@zon> References: <49283267548-BeMail@zon> Message-ID: <20080706154434.460.1@knochen-vm.nameserver> On 2008-07-03 at 23:12:19 [+0200], Axel D?rfler wrote: > Ingo Weinhold wrote: > > On 2008-07-03 at 22:41:32 [+0200], axeld at BerliOS < > > axeld at mail.berlios.de> > > wrote: > > > * Now prints the disk size as part of the default name so that > > > different > > > volumes are easier to differentiate. > > BTW, I intended to introduce a generic DDM service call constructing > > a name > > for an unnamed partition, since there are no volume names in ReiserFS > > and > > probably other FSs either. I'm not sure how nice it is to include the > > That's a nice idea! :-) > > > position in the device and partition tree as well -- I guess the FS > > size is > > sufficient in most cases, though not very helpful if one has several > > partitions with the same size. > > We could add the size in a first pass, and if there are still > partitions with the same name, we could add more information (like the > partition number or USB vs. SCSI/IDE/...), as well. Mmh, I actually only thought of a simple function file systems could invoke in their scan_partition() hook. That would make it kind of impossible to adapt the information encoded in the name depending on other partitions/devices, since at that time it isn't known what names would clash. Computing better names would certainly be possible in the DDM or maybe even via the userland API. The latter might even be the best option, since it would allow the application in question to display the most appropriate amount of information. E.g. DriveSetup displays partitions in the context of their disk device anyway, so it doesn't make sense to add those information to the name. Tracker on the other hand might want to do that. Well, I guess in the end it might be best to just go with " ()" and let the applications in question deal with further disambiguation themselves (like showing a the device/partition location in Tracker's "Get Info" dialog or, when we manage to add those, in a tool tip). > BTW I thought that it might be nice to have a (possibly userland > situated) service that recognizes partition types/file systems (with > volume name if possible) that are otherwise not supported. > At least that would look much better in apps like DriveSetup. Why another service? Adding a file system module that only implements {identify,scan}_partition() seems the obvious way to go to me. We might want to add another partition flag to indicate that mounting isn't supported, so that Tracker wouldn't display them in the mount menu, though. CU, Ingo From zooey at mail.berlios.de Sun Jul 6 15:50:28 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Sun, 6 Jul 2008 15:50:28 +0200 Subject: [Haiku-commits] r26277 - haiku/trunk/src/kits/network Message-ID: <200807061350.m66DoSUm019190@sheep.berlios.de> Author: zooey Date: 2008-07-06 15:50:28 +0200 (Sun, 06 Jul 2008) New Revision: 26277 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26277&view=rev Modified: haiku/trunk/src/kits/network/init.cpp Log: * when finding out whether or not R5 compatibility mode is required, we may have to scan loaded libraries, too, as the dependency on network libraries may not be present in the executable image, but may be "hidden" in one of those library images (as is the case with Beam). Modified: haiku/trunk/src/kits/network/init.cpp =================================================================== --- haiku/trunk/src/kits/network/init.cpp 2008-07-06 10:34:47 UTC (rev 26276) +++ haiku/trunk/src/kits/network/init.cpp 2008-07-06 13:50:28 UTC (rev 26277) @@ -4,6 +4,7 @@ * * Authors: * Axel D?rfler, axeld at pinc-software.de + * Oliver Tappe, zooey at hirschkaefer.de */ @@ -59,25 +60,31 @@ // We're using the BeOS startup code, check if BONE libraries are in // use, and if not, enable the R5 compatibility layer. - + // As dependencies to network libraries may be "hidden" in libraries, we + // may have to scan not only the executable, but every loaded image. + int enable = 0; + uint32 crumble; const char *name; - cookie = 0; - int enable = 0; + do { + crumble = 0; + while (__get_next_image_dependency(info.id, &crumble, &name) == B_OK) { + if (!strcmp(name, "libbind.so") + || !strcmp(name, "libsocket.so") + || !strcmp(name, "libbnetapi.so") + || !strcmp(name, "libnetwork.so")) + enable -= 2; + else if (!strcmp(name, "libnet.so") + || !strcmp(name, "libnetapi.so")) + enable++; + } - while (__get_next_image_dependency(info.id, &cookie, &name) == B_OK) { - if (!strcmp(name, "libbind.so") - || !strcmp(name, "libsocket.so") - || !strcmp(name, "libbnetapi.so") - || !strcmp(name, "libnetwork.so")) - enable -= 2; - else if (!strcmp(name, "libnet.so") - || !strcmp(name, "libnetapi.so")) - enable++; - } - - if (enable > 0) { - __gR5Compatibility = true; - find_own_image(); - debug_printf("libnetwork.so running in R5 compatibility mode.\n"); - } + if (enable > 0) { + __gR5Compatibility = true; + find_own_image(); + debug_printf("libnetwork.so running in R5 compatibility mode.\n"); + return; + } + } while(enable == 0 + && get_next_image_info(B_CURRENT_TEAM, (int32 *)&cookie, &info) + == B_OK); } From julun at mail.berlios.de Sun Jul 6 16:46:06 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 6 Jul 2008 16:46:06 +0200 Subject: [Haiku-commits] r26278 - haiku/trunk/src/kits/interface Message-ID: <200807061446.m66Ek6Pr023617@sheep.berlios.de> Author: julun Date: 2008-07-06 16:46:06 +0200 (Sun, 06 Jul 2008) New Revision: 26278 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26278&view=rev Modified: haiku/trunk/src/kits/interface/OutlineListView.cpp Log: * Fixed broken archive functionality, before we would not archive subitems and store the archived items in the wrong message field. Verified on R5. Modified: haiku/trunk/src/kits/interface/OutlineListView.cpp =================================================================== --- haiku/trunk/src/kits/interface/OutlineListView.cpp 2008-07-06 13:50:28 UTC (rev 26277) +++ haiku/trunk/src/kits/interface/OutlineListView.cpp 2008-07-06 14:46:06 UTC (rev 26278) @@ -32,7 +32,7 @@ private: int (*fCompareFunc)(const BListItem *, const BListItem *); }; - + // #pragma mark - @@ -46,6 +46,17 @@ BOutlineListView::BOutlineListView(BMessage* archive) : BListView(archive) { + int32 i = 0; + BMessage subData; + while (archive->FindMessage("_l_full_items", i++, &subData) == B_OK) { + BArchivable *object = instantiate_object(&subData); + if (!object) + continue; + + BListItem *item = dynamic_cast(object); + if (item) + AddItem(item); + } } @@ -68,7 +79,36 @@ status_t BOutlineListView::Archive(BMessage* archive, bool deep) const { - return BListView::Archive(archive, deep); + // Note: We can't call the BListView Archive function here, as we are also + // interested in subitems BOutlineListView can have. They are even stored + // with a different field name (_l_full_items vs. _l_items). + + status_t status = BView::Archive(archive, deep); + if (status != B_OK) + return status; + + status = archive->AddInt32("_lv_type", fListType); + if (status == B_OK && deep) { + int32 i = 0; + BListItem *item = NULL; + while ((item = static_cast(fFullList.ItemAt(i++)))) { + BMessage subData; + status = item->Archive(&subData, true); + if (status >= B_OK) + status = archive->AddMessage("_l_full_items", &subData); + + if (status < B_OK) + break; + } + } + + if (status >= B_OK && InvocationMessage() != NULL) + status = archive->AddMessage("_msg", InvocationMessage()); + + if (status == B_OK && fSelectMessage != NULL) + status = archive->AddMessage("_2nd_msg", fSelectMessage); + + return status; } @@ -147,7 +187,7 @@ { if (superitem == NULL) return AddItem(item); - + fFullList.AddItem(item, FullListIndexOf(superitem) + 1); item->fLevel = superitem->OutlineLevel() + 1; @@ -279,7 +319,7 @@ BOutlineListView::FullListIndexOf(BPoint point) const { int32 index = BListView::IndexOf(point); - + if (index > 0) index = FullListIndex(index); @@ -458,7 +498,7 @@ items++; } - + _RecalcItemTops(startIndex); // fix selection hints // TODO: revise for multi selection lists @@ -473,7 +513,7 @@ Select(index); } } - + _FixupScrollBar(); Invalidate(); } @@ -484,7 +524,7 @@ { BListItem *item = FullListItemAt(fullListIndex); if (!item) - return false; + return false; return item->IsExpanded(); } @@ -625,7 +665,7 @@ int (*compareFunc)(const BListItem* a, const BListItem* b)) { BListItem **items = (BListItem **)tree->Items(); - std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc)); + std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc)); if (oneLevelOnly) return; @@ -691,7 +731,7 @@ int32 i = FullListIndexOf(underItem); if (i == -1) return 0; - + ++i; int32 count = 0; uint32 baseLevel = underItem->OutlineLevel(); @@ -777,7 +817,7 @@ BListItem *item = (BListItem *)sourceList.ItemAt(i); if (item->OutlineLevel() <= parent->OutlineLevel()) break; - destList.AddItem(item); + destList.AddItem(item); } } @@ -829,7 +869,7 @@ BListItem *firstItem = ItemAt(firstIndex); BListItem *secondItem = ItemAt(secondIndex); BList firstSubItems, secondSubItems; - + if (Superitem(firstItem) != Superitem(secondItem)) return false; if (!firstItem->IsItemVisible() || !secondItem->IsItemVisible()) @@ -844,12 +884,12 @@ _CullInvisibleItems(firstSubItems); _CullInvisibleItems(secondSubItems); - _DoSwap(fList, firstIndex, secondIndex, &firstSubItems, + _DoSwap(fList, firstIndex, secondIndex, &firstSubItems, &secondSubItems); _RecalcItemTops(firstIndex); _RescanSelection(firstIndex, secondIndex + secondSubItems.CountItems()); - Invalidate(Bounds()); + Invalidate(Bounds()); return true; } @@ -858,7 +898,7 @@ { if (code == B_SWAP_OP) return _SwapItems(data->swap.a, data->swap.b); - + return BListView::DoMiscellaneous(code, data); } @@ -976,24 +1016,24 @@ uint32 level = item->OutlineLevel(); int32 superIndex; BListItem* super = _SuperitemForIndex(fullIndex, level, &superIndex); - + if (item->IsItemVisible()) { // remove children, too while (fullIndex + 1 < CountItems()) { BListItem *subItem = ItemAt(fullIndex + 1); - + if (subItem->OutlineLevel() <= level) break; if (subItem->IsItemVisible()) BListView::RemoveItem(subItem); - + fFullList.RemoveItem(fullIndex + 1); delete subItem; } BListView::RemoveItem(item); } - + fFullList.RemoveItem(fullIndex); if (super != NULL) { From bonefish at mail.berlios.de Sun Jul 6 17:32:41 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Sun, 6 Jul 2008 17:32:41 +0200 Subject: [Haiku-commits] r26279 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200807061532.m66FWf85028152@sheep.berlios.de> Author: bonefish Date: 2008-07-06 17:32:40 +0200 (Sun, 06 Jul 2008) New Revision: 26279 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26279&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp Log: Also print the indices of stack frames. This makes the "call" command more convenient to use. Modified: haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-07-06 14:46:06 UTC (rev 26278) +++ haiku/trunk/src/system/kernel/arch/x86/arch_debug.cpp 2008-07-06 15:32:40 UTC (rev 26279) @@ -103,7 +103,8 @@ static void -print_stack_frame(struct thread *thread, addr_t eip, addr_t ebp, addr_t nextEbp) +print_stack_frame(struct thread *thread, addr_t eip, addr_t ebp, addr_t nextEbp, + int32 callIndex) { const char *symbol, *image; addr_t baseAddress; @@ -120,7 +121,7 @@ status = lookup_symbol(thread, eip, &baseAddress, &symbol, &image, &exactMatch); - kprintf("%08lx (+%4ld) %08lx", ebp, diff, eip); + kprintf("%2ld %08lx (+%4ld) %08lx", callIndex, ebp, diff, eip); if (status == B_OK) { if (symbol != NULL) { @@ -293,7 +294,7 @@ bool onKernelStack = true; - for (;;) { + for (int32 callIndex = 0;; callIndex++) { onKernelStack = onKernelStack && is_kernel_stack_address(thread, ebp); @@ -301,7 +302,7 @@ struct iframe *frame = (struct iframe *)ebp; print_iframe(frame); - print_stack_frame(thread, frame->eip, ebp, frame->ebp); + print_stack_frame(thread, frame->eip, ebp, frame->ebp, callIndex); ebp = frame->ebp; } else { @@ -315,7 +316,7 @@ if (eip == 0 || ebp == 0) break; - print_stack_frame(thread, eip, ebp, nextEbp); + print_stack_frame(thread, eip, ebp, nextEbp, callIndex); ebp = nextEbp; } From stippi at mail.berlios.de Sun Jul 6 20:29:53 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 6 Jul 2008 20:29:53 +0200 Subject: [Haiku-commits] r26280 - in haiku/trunk/src/apps/mediaplayer: . interface media_node_framework media_node_framework/audio support Message-ID: <200807061829.m66ITrFE016555@sheep.berlios.de> Author: stippi Date: 2008-07-06 20:29:42 +0200 (Sun, 06 Jul 2008) New Revision: 26280 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26280&view=rev Added: haiku/trunk/src/apps/mediaplayer/interface/PeakView.cpp haiku/trunk/src/apps/mediaplayer/interface/PeakView.h Modified: haiku/trunk/src/apps/mediaplayer/ControllerView.cpp haiku/trunk/src/apps/mediaplayer/Jamfile haiku/trunk/src/apps/mediaplayer/MainWin.cpp haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.h haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.h haiku/trunk/src/apps/mediaplayer/support/MessageEvent.cpp haiku/trunk/src/apps/mediaplayer/support/MessageEvent.h Log: * The SeekSlider did not update the knob when it was resized. * Subtile visual improvements to the SeekSlider. * Added a PeakView for displaying the audio peaks that are produced by the AudioProducer. * A MessageEvent can now directly take a custom BMessage for delivery. * The peak notification mechanism is a bit separate from the rest of the Controller notification design, since the notification delivery should be delayed until the audio is actually audible. I may change this quick and dirty design though, since it is not so nice. The target time could also be part of the message and be handled at a different stage, but that would make it less efficient. * Layout improvements to the playback controls. * Code cleanup here and there, changed some license statements. Modified: haiku/trunk/src/apps/mediaplayer/ControllerView.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/ControllerView.cpp 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/ControllerView.cpp 2008-07-06 18:29:42 UTC (rev 26280) @@ -32,7 +32,7 @@ ControllerView::ControllerView(BRect frame, Controller* controller, Playlist* playlist) - : TransportControlGroup(frame) + : TransportControlGroup(frame, true, true, false) , fController(controller) , fPlaylist(playlist) , fPlaylistObserver(new PlaylistObserver(this)) Modified: haiku/trunk/src/apps/mediaplayer/Jamfile =================================================================== --- haiku/trunk/src/apps/mediaplayer/Jamfile 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/Jamfile 2008-07-06 18:29:42 UTC (rev 26280) @@ -26,6 +26,7 @@ Application MediaPlayer : # interface DrawingTidbits.cpp + PeakView.cpp SeekSlider.cpp TransportButton.cpp VolumeSlider.cpp Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-06 18:29:42 UTC (rev 26280) @@ -41,8 +41,10 @@ #include #include +#include "AudioProducer.h" #include "ControllerObserver.h" #include "MainApp.h" +#include "PeakView.h" #include "PlaylistObserver.h" #include "PlaylistWindow.h" #include "SettingsWindow.h" @@ -170,6 +172,9 @@ fPlaylist->AddListener(fPlaylistObserver); fController->SetVideoView(fVideoView); fController->AddListener(fControllerObserver); + PeakView* peakView = fControls->GetPeakView(); + peakView->SetPeakNotificationWhat(MSG_PEAK_NOTIFICATION); + fController->SetPeakListener(peakView); // printf("fMenuBarHeight %d\n", fMenuBarHeight); // printf("fControlsHeight %d\n", fControlsHeight); @@ -201,6 +206,7 @@ fPlaylist->RemoveListener(fPlaylistObserver); fController->RemoveListener(fControllerObserver); + fController->SetPeakListener(NULL); // give the views a chance to detach from any notifiers // before we delete them Modified: haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/TransportControlGroup.cpp 2008-07-06 18:29:42 UTC (rev 26280) @@ -1,13 +1,10 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan A?mus + * Copyright ? 2006-2008 Stephan A?mus + * All rights reserved. Distributed under the terms of the MIT License. */ // NOTE: Based on my code in the BeOS interface for the VLC media player -// that I did during the VLC 0.4.3 - 0.4.6 times. Code not done by me +// that I did during the VLC 0.4.3 - 0.4.6 times. Code not written by me // removed. -Stephan A?mus #include "TransportControlGroup.h" @@ -18,6 +15,7 @@ #include #include "ButtonBitmaps.h" +#include "PeakView.h" #include "PlaybackState.h" #include "SeekSlider.h" #include "TransportButton.h" @@ -53,63 +51,55 @@ // constructor TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons, - bool useWindButtons) + bool usePeakView, bool useWindButtons) : BView(frame, "transport control group", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS) , fBottomControlHeight(0.0) + , fPeakViewMinWidth(0.0) { SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); frame.Set(0.0, 0.0, 10.0, 10.0); // Seek Slider - fSeekSlider = new SeekSlider(frame, "seek slider", - new BMessage(MSG_SEEK), - 0, kPositionFactor); + fSeekSlider = new SeekSlider(frame, "seek slider", new BMessage(MSG_SEEK), + 0, kPositionFactor); fSeekSlider->ResizeToPreferred(); AddChild(fSeekSlider); // Buttons - if (useSkipButtons) { - // Skip Back - frame.right = kRewindBitmapWidth - 1; - frame.bottom = kRewindBitmapHeight - 1; + if (useSkipButtons) { + // Skip Back + frame.right = kRewindBitmapWidth - 1; + frame.bottom = kRewindBitmapHeight - 1; fBottomControlHeight = kRewindBitmapHeight - 1.0; - fSkipBack = new TransportButton(frame, B_EMPTY_STRING, - kSkipBackBitmapBits, - kPressedSkipBackBitmapBits, - kDisabledSkipBackBitmapBits, - new BMessage(MSG_SKIP_BACKWARDS)); - AddChild(fSkipBack); - - // Skip Foward - fSkipForward = new TransportButton(frame, B_EMPTY_STRING, - kSkipForwardBitmapBits, - kPressedSkipForwardBitmapBits, - kDisabledSkipForwardBitmapBits, - new BMessage(MSG_SKIP_FORWARD)); - AddChild(fSkipForward); - } else { - fSkipBack = NULL; - fSkipForward = NULL; + fSkipBack = new TransportButton(frame, B_EMPTY_STRING, + kSkipBackBitmapBits, kPressedSkipBackBitmapBits, + kDisabledSkipBackBitmapBits, new BMessage(MSG_SKIP_BACKWARDS)); + AddChild(fSkipBack); + + // Skip Foward + fSkipForward = new TransportButton(frame, B_EMPTY_STRING, + kSkipForwardBitmapBits, kPressedSkipForwardBitmapBits, + kDisabledSkipForwardBitmapBits, new BMessage(MSG_SKIP_FORWARD)); + AddChild(fSkipForward); + } else { + fSkipBack = NULL; + fSkipForward = NULL; } if (useWindButtons) { // Forward fForward = new TransportButton(frame, B_EMPTY_STRING, - kForwardBitmapBits, - kPressedForwardBitmapBits, - kDisabledForwardBitmapBits, - new BMessage(MSG_FORWARD)); + kForwardBitmapBits, kPressedForwardBitmapBits, + kDisabledForwardBitmapBits, new BMessage(MSG_FORWARD)); AddChild(fForward); - + // Rewind fRewind = new TransportButton(frame, B_EMPTY_STRING, - kRewindBitmapBits, - kPressedRewindBitmapBits, - kDisabledRewindBitmapBits, - new BMessage(MSG_REWIND)); + kRewindBitmapBits, kPressedRewindBitmapBits, + kDisabledRewindBitmapBits, new BMessage(MSG_REWIND)); AddChild(fRewind); } else { fForward = NULL; @@ -117,56 +107,56 @@ } // Play Pause - frame.right = kPlayPauseBitmapWidth - 1; - frame.bottom = kPlayPauseBitmapHeight - 1; + frame.right = kPlayPauseBitmapWidth - 1; + frame.bottom = kPlayPauseBitmapHeight - 1; if (fBottomControlHeight < kPlayPauseBitmapHeight - 1.0) fBottomControlHeight = kPlayPauseBitmapHeight - 1.0; - fPlayPause = new PlayPauseButton(frame, B_EMPTY_STRING, - kPlayButtonBitmapBits, - kPressedPlayButtonBitmapBits, - kDisabledPlayButtonBitmapBits, - kPlayingPlayButtonBitmapBits, - kPressedPlayingPlayButtonBitmapBits, - kPausedPlayButtonBitmapBits, - kPressedPausedPlayButtonBitmapBits, - new BMessage(MSG_PLAY)); + fPlayPause = new PlayPauseButton(frame, B_EMPTY_STRING, + kPlayButtonBitmapBits, kPressedPlayButtonBitmapBits, + kDisabledPlayButtonBitmapBits, kPlayingPlayButtonBitmapBits, + kPressedPlayingPlayButtonBitmapBits, kPausedPlayButtonBitmapBits, + kPressedPausedPlayButtonBitmapBits, new BMessage(MSG_PLAY)); - AddChild(fPlayPause); + AddChild(fPlayPause); - // Stop - frame.right = kStopBitmapWidth - 1; - frame.bottom = kStopBitmapHeight - 1; + // Stop + frame.right = kStopBitmapWidth - 1; + frame.bottom = kStopBitmapHeight - 1; if (fBottomControlHeight < kStopBitmapHeight - 1.0) fBottomControlHeight = kStopBitmapHeight - 1.0; - fStop = new TransportButton(frame, B_EMPTY_STRING, - kStopButtonBitmapBits, - kPressedStopButtonBitmapBits, - kDisabledStopButtonBitmapBits, - new BMessage(MSG_STOP)); + fStop = new TransportButton(frame, B_EMPTY_STRING, kStopButtonBitmapBits, + kPressedStopButtonBitmapBits, kDisabledStopButtonBitmapBits, + new BMessage(MSG_STOP)); AddChild(fStop); // Mute - frame.right = kSpeakerIconBitmapWidth - 1; - frame.bottom = kSpeakerIconBitmapHeight - 1; + frame.right = kSpeakerIconBitmapWidth - 1; + frame.bottom = kSpeakerIconBitmapHeight - 1; if (fBottomControlHeight < kSpeakerIconBitmapHeight - 1.0) fBottomControlHeight = kSpeakerIconBitmapHeight - 1.0; - fMute = new TransportButton(frame, B_EMPTY_STRING, - kSpeakerIconBits, - kPressedSpeakerIconBits, - kSpeakerIconBits, - new BMessage(MSG_SET_MUTE)); + fMute = new TransportButton(frame, B_EMPTY_STRING, kSpeakerIconBits, + kPressedSpeakerIconBits, kSpeakerIconBits, new BMessage(MSG_SET_MUTE)); AddChild(fMute); - // Volume Slider + // Volume Slider fVolumeSlider = new VolumeSlider(BRect(0.0, 0.0, VOLUME_MIN_WIDTH, - kVolumeSliderBitmapHeight - 1.0), - "volume slider", - _DbToGain(_ExponentialToLinear(kVolumeDbMin)) * kVolumeFactor, - _DbToGain(_ExponentialToLinear(kVolumeDbMax)) * kVolumeFactor, - new BMessage(MSG_SET_VOLUME)); - fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(0.0)) * kVolumeFactor); + kVolumeSliderBitmapHeight - 1.0), "volume slider", + _DbToGain(_ExponentialToLinear(kVolumeDbMin)) * kVolumeFactor, + _DbToGain(_ExponentialToLinear(kVolumeDbMax)) * kVolumeFactor, + new BMessage(MSG_SET_VOLUME)); + fVolumeSlider->SetValue(_DbToGain(_ExponentialToLinear(0.0)) + * kVolumeFactor); AddChild(fVolumeSlider); + + // Peak view + if (usePeakView) { + fPeakView = new PeakView("peak view", false, false); + AddChild(fPeakView); + fPeakView->GetPreferredSize(&fPeakViewMinWidth, NULL); + } else { + fPeakView = NULL; + } } // destructor @@ -469,6 +459,8 @@ minWidth += fSkipForward->Bounds().Width(); minWidth += fMute->Bounds().Width(); minWidth += VOLUME_MIN_WIDTH; + if (fPeakView) + minWidth += fPeakViewMinWidth; // layout seek slider r.bottom = r.top + fSeekSlider->Bounds().Height(); @@ -481,7 +473,8 @@ float currentWidth = frame.Width(); float space = (currentWidth - minWidth) / 6.0; // apply weighting - space = MIN_SPACE + (space - MIN_SPACE) / VOLUME_SLIDER_LAYOUT_WEIGHT; + space = min_c(MIN_SPACE + (space - MIN_SPACE) / VOLUME_SLIDER_LAYOUT_WEIGHT, + MIN_SPACE * 2.0); // layout controls with "space" inbetween r.left = frame.left; r.top = r.bottom + MIN_SPACE + 1.0; @@ -522,11 +515,24 @@ r.left = r.right + space + space; r.right = r.left + fMute->Bounds().Width(); _LayoutControl(fMute, r); + // volume slider r.left = r.right + SPEAKER_SLIDER_DIST; // keep speaker icon and volume slider attached - r.right = frame.right; + // layout volume slider + float peakViewWidth = 0.0; + if (fPeakView) + peakViewWidth = (frame.right - r.left) / 2 + space; + + r.right = frame.right - peakViewWidth; _LayoutControl(fVolumeSlider, r, true); + + if (fPeakView) { + peakViewWidth -= space; + r.left = r.right + space; + r.right = r.left + peakViewWidth; + _LayoutControl(fPeakView, r, true, true); + } } // _MinFrame @@ -547,6 +553,8 @@ minWidth += fSkipForward->Bounds().Width() + MIN_SPACE + MIN_SPACE; minWidth += fMute->Bounds().Width() + SPEAKER_SLIDER_DIST; minWidth += VOLUME_MIN_WIDTH; + if (fPeakView) + minWidth += fPeakViewMinWidth; // add up height of seek slider and heighest control on bottom float minHeight = 2 * BORDER_INSET; Modified: haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/TransportControlGroup.h 2008-07-06 18:29:42 UTC (rev 26280) @@ -1,9 +1,6 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan A?mus + * Copyright ? 2006-2008 Stephan A?mus + * All rights reserved. Distributed under the terms of the MIT License. */ // NOTE: Based on my code in the BeOS interface for the VLC media player @@ -15,6 +12,7 @@ #include +class PeakView; class PlayPauseButton; class TransportButton; class SeekSlider; @@ -33,8 +31,9 @@ class TransportControlGroup : public BView { public: TransportControlGroup(BRect frame, - bool useSkipButtons = true, - bool useWindButtons = false); + bool useSkipButtons, + bool usePeakView, + bool useWindButtons); virtual ~TransportControlGroup(); // BView interface @@ -67,6 +66,9 @@ void SetVolume(float value); void SetPosition(float value); + PeakView* GetPeakView() const + { return fPeakView; } + private: void _LayoutControls(BRect frame) const; BRect _MinFrame() const; @@ -91,7 +93,7 @@ float _GainToDb(float gain); SeekSlider* fSeekSlider; - + PeakView* fPeakView; VolumeSlider* fVolumeSlider; TransportButton* fSkipBack; @@ -103,6 +105,7 @@ TransportButton* fMute; float fBottomControlHeight; + float fPeakViewMinWidth; }; #endif // TRANSPORT_CONTROL_GROUP_H Added: haiku/trunk/src/apps/mediaplayer/interface/PeakView.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/interface/PeakView.cpp 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/interface/PeakView.cpp 2008-07-06 18:29:42 UTC (rev 26280) @@ -0,0 +1,429 @@ +/* + * Copyright (C) 1998-1999 Be Incorporated. All rights reseved. + * Distributed under the terms of the Be Sample Code license. + * + * Copyright (C) 2001-2008 Stephan A?mus. All rights reserved. + * Distributed under the terms of the MIT license. + */ +#include "PeakView.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +using std::nothrow; + +enum { + MSG_PULSE = 'puls', + MSG_LOCK_PEAKS = 'lpks' +}; + +// constructor +PeakView::PeakView(const char* name, bool useGlobalPulse, bool displayLabels) + : BView(BRect(0.0, 0.0, 155.0 + 4.0, 10.0 + 4.0), + name, B_FOLLOW_LEFT | B_FOLLOW_TOP, + useGlobalPulse ? B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS + : B_WILL_DRAW | B_FRAME_EVENTS), + fUseGlobalPulse(useGlobalPulse), + fDisplayLabels(displayLabels), + fPeakLocked(false), + + fRefreshDelay(20000), + fPulse(NULL), + + fCurrentMaxL(0.0), + fLastMaxL(0.0), + fOvershotL(false), + + fCurrentMaxR(0.0), + fLastMaxR(0.0), + fOvershotR(false), + + fBackBitmap(new BBitmap(BRect(0.0, 0.0, 256.0, 18.0), B_CMAP8)), + fPeakNotificationWhat(0) +{ + GetFontHeight(&fFontHeight); + + SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + SetViewColor(B_TRANSPARENT_COLOR); + + FrameResized(Bounds().Width(), Bounds().Height()); + + if (fDisplayLabels) + ResizeBy(0, ceilf(fFontHeight.ascent + fFontHeight.descent)); +} + +// destructor +PeakView::~PeakView() +{ + delete fPulse; + delete fBackBitmap; +} + +// MessageReceived +void +PeakView::MessageReceived(BMessage* message) +{ + if (message->what == fPeakNotificationWhat) { + float maxL; + if (message->FindFloat("max", 0, &maxL) < B_OK) + maxL = 0.0; + float maxR; + if (message->FindFloat("max", 1, &maxR) < B_OK) + maxR = 0.0; + SetMax(maxL, maxR); + return; + } + + switch (message->what) { + case MSG_PULSE: + Pulse(); + break; + + case MSG_LOCK_PEAKS: + fPeakLocked = !fPeakLocked; + break; + + default: + BView::MessageReceived(message); + break; + } +} + +// AttachedToWindow +void +PeakView::AttachedToWindow() +{ + if (!fUseGlobalPulse) { + delete fPulse; + BMessage message(MSG_PULSE); + fPulse = new BMessageRunner(BMessenger(this), &message, + fRefreshDelay); + } +} + +// DetachedFromWindow +void +PeakView::DetachedFromWindow() +{ + delete fPulse; + fPulse = NULL; +} + +// MouseDown +void +PeakView::MouseDown(BPoint where) +{ + int32 buttons; + if (Window()->CurrentMessage()->FindInt32("buttons", &buttons) < B_OK) + buttons = B_PRIMARY_MOUSE_BUTTON; + + if (buttons & B_PRIMARY_MOUSE_BUTTON) { + fOvershotL = false; + fOvershotR = false; + fLastMaxL = fCurrentMaxL; + fLastMaxR = fCurrentMaxR; + } else if (buttons & B_TERTIARY_MOUSE_BUTTON) { + fPeakLocked = !fPeakLocked; + } else { + BPopUpMenu* menu = new BPopUpMenu("peak context menu"); + BMenuItem* item = new BMenuItem("Lock Peaks", + new BMessage(MSG_LOCK_PEAKS)); + item->SetMarked(fPeakLocked); + menu->AddItem(item); + menu->SetTargetForItems(this); + + menu->SetAsyncAutoDestruct(true); + menu->SetFont(be_plain_font); + + where = ConvertToScreen(where); + bool keepOpen = false; // ? + if (keepOpen) { + BRect mouseRect(where, where); + mouseRect.InsetBy(-3.0, -3.0); + where += BPoint(3.0, 3.0); + menu->Go(where, true, false, mouseRect, true); + } else { + where += BPoint(3.0, 3.0); + menu->Go(where, true, false, true); + } + } +} + +// Draw +void +PeakView::Draw(BRect area) +{ + rgb_color background = LowColor(); + rgb_color lightShadow = tint_color(background, B_DARKEN_1_TINT); + rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT); + rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT); + rgb_color black = tint_color(background, B_DARKEN_MAX_TINT); + BRect r(_BackBitmapFrame()); + float width = r.Width(); + r.InsetBy(-2.0, -2.0); + // frame + BeginLineArray(9); + AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), lightShadow); + AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), + lightShadow); + AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), + light); + AddLine(BPoint(r.right - 1.0, r.bottom), + BPoint(r.left + 1.0, r.bottom), light); + r.InsetBy(1.0, 1.0); + AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), darkShadow); + AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), + darkShadow); + AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), + lightShadow); + AddLine(BPoint(r.right - 1.0, r.bottom), + BPoint(r.left + 1.0, r.bottom), lightShadow); + r.InsetBy(1.0, 1.0); + AddLine(BPoint(r.left, (r.top + r.bottom) / 2.0), + BPoint(r.right, (r.top + r.bottom) / 2.0), black); + EndLineArray(); + + // peak bitmap + if (fBackBitmap) + _DrawBitmap(); + + // dB + if (fDisplayLabels) { + font_height fh; + GetFontHeight(&fh); + float y = Bounds().bottom; + y -= fh.descent; + DrawString("0", BPoint(4.0 + width - StringWidth("0"), y)); + DrawString("-6", BPoint(0.477 * width, y)); + DrawString("-12", BPoint(0.227 * width, y)); + } +} + +// FrameResized +void +PeakView::FrameResized(float width, float height) +{ + BRect bitmapFrame = _BackBitmapFrame(); + _ResizeBackBitmap(bitmapFrame.IntegerWidth() + 1); + _UpdateBackBitmap(); +} + +// Pulse +void +PeakView::Pulse() +{ + if (!fBackBitmap) + return; + + if (!fPeakLocked) { + if (fCurrentMaxL > fLastMaxL) + fLastMaxL = fCurrentMaxL; + if (fCurrentMaxR > fLastMaxR) + fLastMaxR = fCurrentMaxR; + } + _UpdateBackBitmap(); + fCurrentMaxL = 0.0; + fCurrentMaxR = 0.0; + + _DrawBitmap(); + Flush(); +} + +// GetPreferredSize +void +PeakView::GetPreferredSize(float* _width, float* _height) +{ + float minWidth = 0; + float minHeight = 0; + if (fBackBitmap) { + minWidth = 20 + 4; + minHeight = 3 + 4; + } + if (fDisplayLabels) { + font_height fh; + GetFontHeight(&fh); + minWidth = max_c(60.0, minWidth); + minHeight += ceilf(fh.ascent + fh.descent); + } + if (_width) + *_width = minWidth; + if (_height) + *_height = minHeight; +} + +// IsValid +bool +PeakView::IsValid() const +{ + return fBackBitmap && fBackBitmap->IsValid(); +} + +// SetPeakRefreshDelay +void +PeakView::SetPeakRefreshDelay(bigtime_t delay) +{ + if (fRefreshDelay == delay) + return; + fRefreshDelay = delay; + if (fPulse) + fPulse->SetInterval(fRefreshDelay); +} + +// SetPeakNotificationWhat +void +PeakView::SetPeakNotificationWhat(uint32 what) +{ + fPeakNotificationWhat = what; +} + +// SetMax +void +PeakView::SetMax(float maxL, float maxR) +{ + if (fCurrentMaxL < maxL) + fCurrentMaxL = maxL; + if (fCurrentMaxR < maxR) + fCurrentMaxR = maxR; + + if (fCurrentMaxL > 1.0) + fOvershotL = true; + if (fCurrentMaxR > 1.0) + fOvershotR = true; +} + +// #pragma mark - + +// _BackBitmapFrame +BRect +PeakView::_BackBitmapFrame() const +{ + BRect frame = Bounds(); + frame.InsetBy(2, 2); + if (fDisplayLabels) + frame.bottom -= ceilf(fFontHeight.ascent + fFontHeight.descent); + return frame; +} + +// _ResizeBackBitmap +void +PeakView::_ResizeBackBitmap(int32 width) +{ + if (fBackBitmap) { + if (fBackBitmap->Bounds().IntegerWidth() + 1 == width) + return; + } + delete fBackBitmap; + fBackBitmap = new (nothrow) BBitmap(BRect(0, 0, width - 1, 1), 0, B_RGB32); + if (!fBackBitmap || !fBackBitmap->IsValid()) { + delete fBackBitmap; + fBackBitmap = NULL; + return; + } + memset(fBackBitmap->Bits(), 0, fBackBitmap->BitsLength()); +} + +// _UpdateBackBitmap +void +PeakView::_UpdateBackBitmap() +{ + if (!fBackBitmap) + return; + + uint8* l = (uint8*)fBackBitmap->Bits(); + uint8* r = l + fBackBitmap->BytesPerRow(); + uint32 width = fBackBitmap->Bounds().IntegerWidth() + 1; + _RenderSpan(l, width, fCurrentMaxL, fLastMaxL, fOvershotL); + _RenderSpan(r, width, fCurrentMaxR, fLastMaxR ,fOvershotR); +} + +// _RenderSpan +void +PeakView:: _RenderSpan(uint8* span, uint32 width, float current, float peak, + bool overshot) +{ + uint8 emptyR = 15; + uint8 emptyG = 36; + uint8 emptyB = 16; + + uint8 fillR = 41; + uint8 fillG = 120; + uint8 fillB = 45; + + uint8 currentR = 45; + uint8 currentG = 255; + uint8 currentB = 45; + + uint8 lastR = 255; + uint8 lastG = 229; + uint8 lastB = 87; + + uint8 overR = 255; + uint8 overG = 89; + uint8 overB = 7; + + uint8 kFadeFactor = 180; + + uint32 split = (uint32)(current * (width - 2) + 0.5); + split += split & 1; + uint32 last = (uint32)(peak * (width - 2) + 0.5); + last += last & 1; + uint32 over = overshot ? width - 1 : width; + over += over & 1; + + for (uint32 x = 0; x < width - 1; x += 2) { + uint8 fadedB = (uint8)(((int)span[0] * kFadeFactor) >> 8); + uint8 fadedG = (uint8)(((int)span[1] * kFadeFactor) >> 8); + uint8 fadedR = (uint8)(((int)span[2] * kFadeFactor) >> 8); + if (x < split) { + span[0] = max_c(fillB, fadedB); + span[1] = max_c(fillG, fadedG); + span[2] = max_c(fillR, fadedR); + } else if (x == split) { + span[0] = currentB; + span[1] = currentG; + span[2] = currentR; + } else if (x > split) { + span[0] = max_c(emptyB, fadedB); + span[1] = max_c(emptyG, fadedG); + span[2] = max_c(emptyR, fadedR); + } + if (x == last) { + span[0] = lastB; + span[1] = lastG; + span[2] = lastR; + } + if (x == over) { + span[0] = overB; + span[1] = overG; + span[2] = overR; + } + span += 8; + } +} + +// _DrawBitmap +void +PeakView::_DrawBitmap() +{ + BRect r = _BackBitmapFrame(); + BRect topHalf = r; + topHalf.bottom = (r.top + r.bottom) / 2.0 - 1; + BRect bottomHalf = r; + bottomHalf.top = topHalf.bottom + 2; + BRect bitmapRect = fBackBitmap->Bounds(); + bitmapRect.bottom = bitmapRect.top; + DrawBitmapAsync(fBackBitmap, bitmapRect, topHalf); + bitmapRect.OffsetBy(0, 1); + DrawBitmapAsync(fBackBitmap, bitmapRect, bottomHalf); +} + + Added: haiku/trunk/src/apps/mediaplayer/interface/PeakView.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/interface/PeakView.h 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/interface/PeakView.h 2008-07-06 18:29:42 UTC (rev 26280) @@ -0,0 +1,92 @@ +/* + * Copyright (C) 1998-1999 Be Incorporated. All rights reseved. + * Distributed under the terms of the Be Sample Code license. + * + * Copyright (C) 2001-2008 Stephan A?mus. All rights reserved. + * Distributed under the terms of the MIT license. + */ + +/*---------------------------------------------------------- +PURPOSE: +gui class for displaying stereo audio peak level info + +FEATURES: +- uses a bitmap, but not a view accepting one, to redraw +without flickering. +- can be configured to use it's own message runner instead +of the windows current pulse (in case you have text views in +the window as well, which use a slow pulse for cursor blinking) +- if used with own message runner, refresh delay is configurable +- can be used in a dynamic liblayout gui + +USAGE: +To display the peak level of your streaming audio, just +calculate the local maximum of both channels within your +audio buffer and call SetMax() once for every buffer. The +PeakView will take care of the rest. +min = 0.0 +max = 1.0 +----------------------------------------------------------*/ +#ifndef PEAK_VIEW_H +#define PEAL_VIEW_H + + +#include + +class BBitmap; +class BMessageRunner; + +class PeakView : public BView { +public: + PeakView(const char* name, + bool useGlobalPulse = true, + bool displayLabels = true); + virtual ~PeakView(); + + // BView interface + virtual void MessageReceived(BMessage* message); + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void MouseDown(BPoint where); + virtual void Draw(BRect area); + virtual void FrameResized(float width, float height); + virtual void Pulse(); + virtual void GetPreferredSize(float* _width, + float* _height); + + // PeakView + bool IsValid() const; + void SetPeakRefreshDelay(bigtime_t delay); + void SetPeakNotificationWhat(uint32 what); + void SetMax(float maxL, float maxR); + + private: + BRect _BackBitmapFrame() const; + void _ResizeBackBitmap(int32 width); + void _UpdateBackBitmap(); + void _RenderSpan(uint8* span, uint32 width, + float current, float peak, bool overshot); + void _DrawBitmap(); + + bool fUseGlobalPulse; + bool fDisplayLabels; + bool fPeakLocked; + + bigtime_t fRefreshDelay; + BMessageRunner* fPulse; + + float fCurrentMaxL; + float fLastMaxL; + bool fOvershotL; + + float fCurrentMaxR; + float fLastMaxR; + bool fOvershotR; + + BBitmap* fBackBitmap; + font_height fFontHeight; + + uint32 fPeakNotificationWhat; +}; + +#endif // PEAK_VIEW_H Modified: haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.cpp 2008-07-06 18:29:42 UTC (rev 26280) @@ -1,13 +1,10 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan A?mus + * Copyright ? 2006-2008 Stephan A?mus + * All rights reserved. Distributed under the terms of the MIT License. */ // NOTE: Based on my code in the BeOS interface for the VLC media player -// that I did during the VLC 0.4.3 - 0.4.6 times. Code not done by me +// that I did during the VLC 0.4.3 - 0.4.6 times. Code not written by me // removed. -Stephan A?mus #include "SeekSlider.h" @@ -32,7 +29,7 @@ SeekSlider::SeekSlider(BRect frame, const char* name, BMessage* message, int32 minValue, int32 maxValue) : BControl(frame, name, NULL, message, B_FOLLOW_LEFT | B_FOLLOW_TOP, - B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE) + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) , fTracking(false) , fLastTrackTime(0) , fKnobPos(_KnobPosFor(Bounds(), Value())) @@ -101,9 +98,9 @@ rgb_color dotGrey = midShadow; rgb_color dotGreen = greenShadow; // draw frame - _StrokeFrame(r, softShadow, softShadow, softLight, softLight); + _StrokeFrame(r, softShadow, softShadow, light, light); r.InsetBy(1.0, 1.0); - _StrokeFrame(r, black, black, light, light); + _StrokeFrame(r, black, black, softShadow, softShadow); if (IsEnabled()) { // *** enabled look *** r.InsetBy(1.0, 1.0); @@ -281,6 +278,13 @@ void +SeekSlider::FrameResized(float width, float height) +{ + _SetKnobPosition(_KnobPosFor(Bounds(), Value())); +} + + +void SeekSlider::SetPosition(float position) { int32 value = fMinValue + (int32)floorf((fMaxValue - fMinValue) * position + 0.5); Modified: haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h 2008-07-06 15:32:40 UTC (rev 26279) +++ haiku/trunk/src/apps/mediaplayer/interface/SeekSlider.h 2008-07-06 18:29:42 UTC (rev 26280) @@ -1,9 +1,6 @@ /* - * Copyright 2006, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stephan A?mus + * Copyright ? 2006-2008 Stephan A?mus + * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef SEEK_SLIDER_H @@ -15,10 +12,8 @@ class SeekSlider : public BControl { public: SeekSlider(BRect frame, [... truncated: 299 lines follow ...] From stippi at mail.berlios.de Sun Jul 6 20:32:30 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sun, 6 Jul 2008 20:32:30 +0200 Subject: [Haiku-commits] r26281 - haiku/trunk/src/apps/mediaplayer/media_node_framework/audio Message-ID: <200807061832.m66IWUe6016881@sheep.berlios.de> Author: stippi Date: 2008-07-06 20:32:28 +0200 (Sun, 06 Jul 2008) New Revision: 26281 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26281&view=rev Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp Log: That is more likely to give the right realtime... Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-06 18:29:42 UTC (rev 26280) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-06 18:32:28 UTC (rev 26281) @@ -776,7 +776,8 @@ float maxAbs = max_c(fabs(min[i]), fabs(max[i])); message.AddFloat("max", maxAbs); } - bigtime_t realTime = TimeSource()->RealTimeFor(performanceTime, 0); + bigtime_t realTime = TimeSource()->RealTimeFor( + fStartTime + performanceTime, 0); realTime -= 2000; // deliver event about one video frame earlier to account // for latency between app_server and client From korli at mail.berlios.de Sun Jul 6 21:20:03 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Sun, 6 Jul 2008 21:20:03 +0200 Subject: [Haiku-commits] r26282 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200807061920.m66JK313023105@sheep.berlios.de> Author: korli Date: 2008-07-06 21:20:03 +0200 (Sun, 06 Jul 2008) New Revision: 26282 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26282&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp Log: moved stateStatus read/write out of the interrupt handler added some error verbose Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-06 18:32:28 UTC (rev 26281) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-06 19:20:03 UTC (rev 26282) @@ -110,16 +110,9 @@ /* Controller or stream related? */ if (intrStatus & INTR_STATUS_CONTROLLER) { - uint32 stateStatus = controller->Read16(HDAC_STATE_STATUS); uint8 rirbStatus = controller->Read8(HDAC_RIRB_STATUS); uint8 corbStatus = controller->Read8(HDAC_CORB_STATUS); - if (stateStatus) { - /* Detected Codec state change */ - controller->Write16(HDAC_STATE_STATUS, stateStatus); - controller->codec_status = stateStatus; - } - /* Check for incoming responses */ if (rirbStatus) { controller->Write8(HDAC_RIRB_STATUS, rirbStatus); @@ -672,7 +665,7 @@ status_t hda_hw_init(hda_controller* controller) { - uint16 capabilities; + uint16 capabilities, stateStatus; status_t status; /* Map MMIO registers */ @@ -708,13 +701,17 @@ /* Get controller into valid state */ status = reset_controller(controller); - if (status != B_OK) + if (status != B_OK) { + dprintf("hda: reset_controller failed\n"); goto reset_failed; + } /* Setup CORB/RIRB/DMA POS */ status = init_corb_rirb_pos(controller); - if (status != B_OK) + if (status != B_OK) { + dprintf("hda: init_corb_rirb_pos failed\n"); goto corb_rirb_failed; + } controller->Write16(HDAC_WAKE_ENABLE, 0x7fff); @@ -722,14 +719,19 @@ controller->Write32(HDAC_INTR_CONTROL, INTR_CONTROL_GLOBAL_ENABLE | INTR_CONTROL_CONTROLLER_ENABLE); - if (!controller->codec_status) { + snooze(1000); + + stateStatus = controller->Read16(HDAC_STATE_STATUS); + if (!stateStatus) { + dprintf("hda: bad codec status\n"); status = ENODEV; goto corb_rirb_failed; } + controller->Write16(HDAC_STATE_STATUS, stateStatus); // Create codecs for (uint32 index = 0; index < HDA_MAX_CODECS; index++) { - if ((controller->codec_status & (1 << index)) != 0) + if ((stateStatus & (1 << index)) != 0) hda_codec_new(controller, index); } for (uint32 index = 0; index < HDA_MAX_CODECS; index++) { @@ -743,6 +745,7 @@ if (controller->active_codec != NULL) return B_OK; + dprintf("hda: no active codec\n"); status = ENODEV; corb_rirb_failed: From mmu_man at mail.berlios.de Sun Jul 6 22:23:26 2008 From: mmu_man at mail.berlios.de (mmu_man at mail.berlios.de) Date: Sun, 6 Jul 2008 22:23:26 +0200 Subject: [Haiku-commits] r26283 - haiku/trunk/src/apps/mediaplayer/media_node_framework/audio Message-ID: <200807062023.m66KNQvV028758@sheep.berlios.de> Author: mmu_man Date: 2008-07-06 22:23:25 +0200 (Sun, 06 Jul 2008) New Revision: 26283 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26283&view=rev Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp Log: Fix scope for gcc4. Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-06 19:20:03 UTC (rev 26282) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-06 20:23:25 UTC (rev 26283) @@ -781,7 +781,7 @@ realTime -= 2000; // deliver event about one video frame earlier to account // for latency between app_server and client - MessageEvent* event = new (nothrow) MessageEvent(realTime, + MessageEvent* event = new (std::nothrow) MessageEvent(realTime, fPeakListener, message); if (event != NULL) EventQueue::Default().AddEvent(event); From ingo_weinhold at gmx.de Mon Jul 7 00:38:28 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Mon, 07 Jul 2008 00:38:28 +0200 Subject: [Haiku-commits] r26244 - haiku/trunk/src/system/kernel In-Reply-To: <12295930101-BeMail@primary> References: <12295930101-BeMail@primary> Message-ID: <20080707003828.522.6@knochen-vm.nameserver> On 2008-07-05 at 15:06:53 [+0200], Michael Lotz wrote: > > I don't think there's any difference in this respect. The current > > implementation uses bins for different allocation sizes, a slab > > allocator > > based implementation uses a set of object caches with different > > object > > sizes. > > Yes, but that's quite a big difference in fact. One heap_allocator can > have multiple bins of different sizes. It employs a address -> > heap_page -> bin translation to directly look up in what page and bin > an allocation resides. With a set of object caches this is more > involved, as you have to search through those to find in which one an > allocation resides, as with a bog standard free() you don't know the > allocation size. That's in fact the single most problematic thing - not > knowing the allocation size. There are ways around that by employing a > boundary tag to store the allocation size, but that is neither safe nor > space efficient. Why would that not be safe? Or do you mean when code overwrites the tags? > Especially when doing aligned allocations of > B_PAGE_SIZE this can get pretty wasteful. Unless I'm much mistaken that's actually the only memalign() in the kernel (in the VM translation map code), and we might want to use a specialized allocator for those anyway. > > implementation performs pretty well. In fact I think it's a bit > > similar to > > a slab allocator. The latter has a few optimizations (like per-CPU > > magazines and slab coloring), though, that will probably give it an > > edge. > > In fact it has become (unintentionally even ;-) mostly the same as a > slab. It has a cache (heap_allocator), slabs (heap_pages), objects (the > actual allocations) and depots (heap_area). It does a few optimizations > by removing the full lists for example (as they are not really needed > as you can't do anything with a full page/area) and through bins it has > the above mentioned advantage over a set of individual object_caches. > This makes it just more fit to the task at hand. > > And really adding per-CPU allocators is just a matter of adding a [< > cpuCount>] dimension to sHeaps and taking the current CPU into account > when choosing the heap to allocate from. Coloring can be done by simply > rotating the start offset of a bin per page. So I'd rather add those > two things to the heap than changing the heap to a not exactly fitting > mechanism. > > > I haven't looked closely at our slab allocator implementation, but > > IIRC it > > still needs some work (e.g. object depots are disabled). Just in case > > you're looking for a task... :-P > > I have taken a closer look at our slab and the block_allocator it > provides, and it just isn't as efficient (space wise, it uses said > boundary tag). In fact since the heap is so similar to a slab now, you > could just as well suggest replacing the slab with the heap. By simply > removing the bins from the heap (making the element size global per > allocator) and adding constructors/destructors, you'd get a perfectly > capable slab... > > But really in the sense of "the best tool for the job" I think we just > shouldn't mix both approaches. Each has it's own set of problems and > mechanism to solve them. Using one for the other would undoubtatly > work, but why would you use a slab for something that isn't really the > task of a slab by wrapping around glue code and using extra memory when > you have a perfectly capable heap that is specifically designed for the > task and doesn't need either workaround? Regarding boundary tags, that could be solved differently, e.g. by maintaining a page -> object cache map. > It's not even like you could > remove a lot of code, as the heap is pretty compact and self contained. It's still a few KB of frequently-used code. The same goes for the slab allocator. Cutting down the code size should be friendlier to the CPU caches at least. CU, Ingo From mmlr at mail.berlios.de Mon Jul 7 03:09:43 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Mon, 7 Jul 2008 03:09:43 +0200 Subject: [Haiku-commits] r26284 - haiku/trunk/src/system/kernel Message-ID: <200807070109.m6719hce014188@sheep.berlios.de> Author: mmlr Date: 2008-07-07 03:09:41 +0200 (Mon, 07 Jul 2008) New Revision: 26284 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26284&view=rev Modified: haiku/trunk/src/system/kernel/heap.cpp Log: * Change the fixed bin list to a generated one based on a few constraining factors per heap class. The previous bin sizes would in many cases just have wasted memory by not fully using up the available space while not providing any more elements than a bigger size. The computed bins ensure that the best sizes are used based on a min count, min size, alignment and max waste per page. Also changed the heap sizes to more reasonable values and renamed them to small, medium and large. * Remove the shouldGrow parameter from heap_memalign() and just check it using heap_should_grow() where appropriate. * Fix readding a nun-full area to the area list, the added page count can be bigger than one, therefore the check must be free_page_count == pageCount. * Simplify ensuring correct alignment, just aligning the size instead of checking each candidate bin for alignment is enough. Modified: haiku/trunk/src/system/kernel/heap.cpp =================================================================== --- haiku/trunk/src/system/kernel/heap.cpp 2008-07-06 20:23:25 UTC (rev 26283) +++ haiku/trunk/src/system/kernel/heap.cpp 2008-07-07 01:09:41 UTC (rev 26284) @@ -122,7 +122,10 @@ uint32 initial_percentage; size_t max_allocation_size; size_t page_size; - size_t bin_sizes[20]; + size_t min_bin_size; + size_t bin_alignment; + uint32 min_count_per_page; + size_t max_waste_per_page; } heap_class; static const uint32 kAreaAllocationMagic = 'AAMG'; @@ -143,16 +146,35 @@ // Heap class configuration #define HEAP_CLASS_COUNT 3 static heap_class sHeapClasses[HEAP_CLASS_COUNT] = { - { "small", 50, B_PAGE_SIZE, B_PAGE_SIZE, - { 8, 12, 16, 24, 32, 48, 64, 96, 128, 160, 192, 256, 384, 512, 1024, - 2048, 4096, 0 } + { + "small", /* name */ + 50, /* initial percentage */ + B_PAGE_SIZE / 8, /* max allocation size */ + B_PAGE_SIZE, /* page size */ + 8, /* min bin size */ + 4, /* bin alignment */ + 8, /* min count per page */ + 16 /* max waste per page */ }, - { "large", 30, B_PAGE_SIZE * 32, B_PAGE_SIZE * 32, - { 4096, 5120, 6144, 7168, 8192, 12288, 16384, 24576, 32768, 65536, - 131072, 0 } + { + "medium", /* name */ + 30, /* initial percentage */ + B_PAGE_SIZE * 2, /* max allocation size */ + B_PAGE_SIZE * 8, /* page size */ + B_PAGE_SIZE / 8, /* min bin size */ + 32, /* bin alignment */ + 4, /* min count per page */ + 64 /* max waste per page */ }, - { "huge", 20, HEAP_AREA_USE_THRESHOLD, B_PAGE_SIZE * 64, - { 131072, 262144, 0 } + { + "large", /* name */ + 20, /* initial percentage */ + HEAP_AREA_USE_THRESHOLD, /* max allocation size */ + B_PAGE_SIZE * 16, /* page size */ + B_PAGE_SIZE * 2, /* min bin size */ + 128, /* bin alignment */ + 1, /* min count per page */ + 256 /* max waste per page */ } }; @@ -938,30 +960,38 @@ static heap_allocator * heap_create_allocator(const char *name, addr_t base, size_t size, - uint32 heapClass) + uint32 heapClassIndex) { + heap_class *heapClass = &sHeapClasses[heapClassIndex]; heap_allocator *heap = (heap_allocator *)base; base += sizeof(heap_allocator); size -= sizeof(heap_allocator); heap->name = name; - heap->heap_class = heapClass; - heap->page_size = sHeapClasses[heapClass].page_size; + heap->heap_class = heapClassIndex; + heap->page_size = heapClass->page_size; heap->total_pages = heap->total_free_pages = heap->empty_areas = 0; heap->areas = heap->all_areas = NULL; heap->bins = (heap_bin *)base; heap->bin_count = 0; - while (true) { - size_t binSize = sHeapClasses[heapClass].bin_sizes[heap->bin_count]; - if (binSize == 0) - break; + size_t binSize = 0, lastSize = 0; + uint32 count = heap->page_size / heapClass->min_bin_size; + for (; count >= heapClass->min_count_per_page; count--, lastSize = binSize) { + binSize = (heap->page_size / count) & ~(heapClass->bin_alignment - 1); + if (binSize == lastSize) + continue; + if (heap->page_size - count * binSize > heapClass->max_waste_per_page) + continue; heap_bin *bin = &heap->bins[heap->bin_count]; bin->element_size = binSize; bin->max_free_count = heap->page_size / binSize; bin->page_list = NULL; heap->bin_count++; + + if (heap->bin_count >= 32) + panic("heap configuration invalid - max bin count reached\n"); }; base += heap->bin_count * sizeof(heap_bin); @@ -980,7 +1010,7 @@ area->free_page_count += pageCount; heap->total_free_pages += pageCount; - if (area->free_page_count == 1) { + if (area->free_page_count == pageCount) { // we need to add ourselfs to the area list of the heap area->prev = NULL; area->next = heap->areas; @@ -1000,11 +1030,8 @@ area->prev->next = area->next; if (area->next) area->next->prev = area->prev; - if (heap->areas == area) { + if (heap->areas == area) heap->areas = area->next; - if (area->next) - area->next->prev = NULL; - } area->prev = insert; area->next = insert->next; @@ -1231,8 +1258,7 @@ static void * -heap_memalign(heap_allocator *heap, size_t alignment, size_t size, - bool *shouldGrow) +heap_memalign(heap_allocator *heap, size_t alignment, size_t size) { TRACE(("memalign(alignment = %lu, size = %lu)\n", alignment, size)); @@ -1247,29 +1273,26 @@ size += sizeof(heap_leak_check_info); #endif - uint32 binIndex; - for (binIndex = 0; binIndex < heap->bin_count; binIndex++) { + if (alignment != 0) { // TODO: The alignment is done by ensuring that the element size // of the target bin is aligned with the requested alignment. This // has the problem that it wastes space because a better (smaller) bin // could possibly be selected. We should pick the best bin and check // if there is an aligned block in the free list or if a new (page // aligned) page has to be allocated anyway. - size_t elementSize = heap->bins[binIndex].element_size; - if (size <= elementSize && (alignment == 0 - || (elementSize & (alignment - 1)) == 0)) + size = ROUNDUP(size, alignment); + } + + uint32 binIndex; + for (binIndex = 0; binIndex < heap->bin_count; binIndex++) { + if (size <= heap->bins[binIndex].element_size) break; } void *address = heap_raw_alloc(heap, size, binIndex); - if (alignment != 0 && ((addr_t)address & (alignment - 1))) - panic("alignment not met at %p with 0x%08lx\n", address, alignment); TRACE(("memalign(): asked to allocate %lu bytes, returning pointer %p\n", size, address)); - if (shouldGrow) - *shouldGrow = heap_should_grow(heap); - #if KERNEL_HEAP_LEAK_CHECK size -= sizeof(heap_leak_check_info); #endif @@ -1547,12 +1570,13 @@ size += sizeof(heap_leak_check_info_s); #endif - for (uint32 i = 0; i < HEAP_CLASS_COUNT; i++) { - if (size <= sHeapClasses[i].max_allocation_size) - return i; + uint32 index = 0; + for (; index < HEAP_CLASS_COUNT - 1; index++) { + if (size <= sHeapClasses[index].max_allocation_size) + return index; } - return HEAP_CLASS_COUNT - 1; + return index; } @@ -1781,16 +1805,18 @@ uint32 heapClass = heap_class_for(size); heap_allocator *heap = sHeaps[heapClass]; - bool shouldGrow = false; - void *result = heap_memalign(heap, alignment, size, &shouldGrow); + void *result = heap_memalign(heap, alignment, size); if (result == NULL) { - // request an urgent grow and wait + // request an urgent grow and wait - we don't do it ourselfs here to + // serialize growing through the grow thread, as otherwise multiple + // threads hitting this situation (likely when memory ran out) would + // all add areas sLastGrowRequest[heapClass]++; switch_sem(sHeapGrowSem, sHeapGrownNotify); // and then try again - result = heap_memalign(heap, alignment, size, NULL); - } else if (shouldGrow) { + result = heap_memalign(heap, alignment, size); + } else if (heap_should_grow(heap)) { // should grow sometime soon, notify the grower release_sem_etc(sHeapGrowSem, 1, B_DO_NOT_RESCHEDULE); } @@ -1810,10 +1836,8 @@ { // use dedicated memory in the grow thread by default if (thread_get_current_thread_id() == sHeapGrowThread) { - bool shouldGrow = false; - heap_allocator *heap = sGrowHeap; - void *result = heap_memalign(heap, 0, size, &shouldGrow); - if (shouldGrow && !sAddGrowHeap) { + void *result = heap_memalign(sGrowHeap, 0, size); + if (!sAddGrowHeap && heap_should_grow(sGrowHeap)) { // hopefully the heap grower will manage to create a new heap // before running out of private memory... dprintf("heap: requesting new grow heap\n"); @@ -1827,7 +1851,7 @@ // try public memory, there might be something available heap_allocator *heap = sHeaps[heap_class_for(size)]; - void *result = heap_memalign(heap, 0, size, NULL); + void *result = heap_memalign(heap, 0, size); if (result != NULL) return result; From stippi at mail.berlios.de Mon Jul 7 10:32:18 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 7 Jul 2008 10:32:18 +0200 Subject: [Haiku-commits] r26285 - haiku/trunk/src/apps/mediaplayer/media_node_framework/audio Message-ID: <200807070832.m678WICv032177@sheep.berlios.de> Author: stippi Date: 2008-07-07 10:32:17 +0200 (Mon, 07 Jul 2008) New Revision: 26285 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26285&view=rev Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp Log: Remove the negative delay that was supposed to account for client->app_server delay. The audio is later than the calculated realtime anyways, I suspect the OSS Node does not advertise it's latency 100% correctly yet. Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-07 01:09:41 UTC (rev 26284) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp 2008-07-07 08:32:17 UTC (rev 26285) @@ -778,9 +778,6 @@ } bigtime_t realTime = TimeSource()->RealTimeFor( fStartTime + performanceTime, 0); - realTime -= 2000; - // deliver event about one video frame earlier to account - // for latency between app_server and client MessageEvent* event = new (std::nothrow) MessageEvent(realTime, fPeakListener, message); if (event != NULL) From stippi at mail.berlios.de Mon Jul 7 10:33:03 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 7 Jul 2008 10:33:03 +0200 Subject: [Haiku-commits] r26286 - haiku/trunk/src/apps/mediaplayer Message-ID: <200807070833.m678X3vM032270@sheep.berlios.de> Author: stippi Date: 2008-07-07 10:33:03 +0200 (Mon, 07 Jul 2008) New Revision: 26286 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26286&view=rev Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp Log: Don't reset the window size when playing a new file if it isn't necessary. Modified: haiku/trunk/src/apps/mediaplayer/MainWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-07 08:32:17 UTC (rev 26285) +++ haiku/trunk/src/apps/mediaplayer/MainWin.cpp 2008-07-07 08:33:03 UTC (rev 26286) @@ -122,8 +122,8 @@ , fNoMenu(false) , fNoBorder(false) , fNoControls(false) - , fSourceWidth(0) - , fSourceHeight(0) + , fSourceWidth(-1) + , fSourceHeight(-1) , fWidthScale(1.0) , fHeightScale(1.0) , fMouseDownTracking(false) @@ -849,10 +849,13 @@ fVideoMenu->SetEnabled(fHasVideo); fAudioMenu->SetEnabled(fHasAudio); // fDebugMenu->SetEnabled(fHasVideo); + int previousSourceWidth = fSourceWidth; + int previousSourceHeight = fSourceHeight; if (fHasVideo) { fController->GetSize(&fSourceWidth, &fSourceHeight); fWidthScale = 1.0; fHeightScale = 1.0; + // TODO: implement aspect ratio } else { fSourceWidth = 0; fSourceHeight = 0; @@ -861,9 +864,11 @@ } _UpdateControlsEnabledStatus(); - // TODO: Don't if the video size did not change! Also don't - // exit full screen mode. - _ResizeWindow(100); + // adopt the size and window layout if necessary + if (!fIsFullscreen && (previousSourceWidth != fSourceWidth + || previousSourceHeight != fSourceHeight)) { + _ResizeWindow(100); + } fVideoView->MakeFocus(); } @@ -1024,12 +1029,9 @@ void MainWin::_ResizeWindow(int percent) { - int video_width; - int video_height; - // Get required window size - video_width = lround(fSourceWidth * fWidthScale); - video_height = lround(fSourceHeight * fHeightScale); + int video_width = lround(fSourceWidth * fWidthScale); + int video_height = lround(fSourceHeight * fHeightScale); video_width = (video_width * percent) / 100; video_height = (video_height * percent) / 100; From revol at free.fr Mon Jul 7 11:32:57 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Mon, 07 Jul 2008 11:32:57 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r26285_-_haiku/trunk/src/apps/me?= =?windows-1252?q?diaplayer/media=5Fnode=5Fframework/audio?= In-Reply-To: <200807070832.m678WICv032177@sheep.berlios.de> Message-ID: <940594695-BeMail@laptop> > Author: stippi > Date: 2008-07-07 10:32:17 +0200 (Mon, 07 Jul 2008) > New Revision: 26285 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26285&view=rev > > Modified: > haiku/trunk/src/apps/mediaplayer/media_node_framework/audio/ > AudioProducer.cpp > Log: > Remove the negative delay that was supposed to account for client-> > app_server you mean media_addon_server, right ? Actually, for video, when using BBitmap, you might want to try and measure the time it takes to DrawBitmap() for latency. Probably negligible though. > delay. The audio is later than the calculated realtime anyways, I > suspect > the OSS Node does not advertise it's latency 100% correctly yet. Quite certainly, you'll probably fix it faster than me :) Fran?ois. From superstippi at gmx.de Mon Jul 7 11:46:39 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Mon, 07 Jul 2008 11:46:39 +0200 Subject: [Haiku-commits] r26285 - haiku/trunk/src/apps/mediaplayer/media_node_framework/audio In-Reply-To: <940594695-BeMail@laptop> References: <940594695-BeMail@laptop> Message-ID: <20080707094639.114150@gmx.net> Hi, > > Log: > > Remove the negative delay that was supposed to account for client-> > > app_server > > you mean media_addon_server, right ? > Actually, for video, when using BBitmap, you might want to try and > measure the time it takes to DrawBitmap() for latency. Probably > negligible though. What you say is exactly what delay I meant. I only guestimated it though. > > delay. The audio is later than the calculated realtime anyways, I > > suspect > > the OSS Node does not advertise it's latency 100% correctly yet. > > Quite certainly, you'll probably fix it faster than me :) We'll see... :-) Best regards, -Stephan From axeld at pinc-software.de Mon Jul 7 12:40:09 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 12:40:09 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26250_-_in_haiku/branches/developer/bo?= =?utf-8?q?nefish/vm=3A_headers/private/kernel_src/system/kernel/cache_src?= =?utf-8?q?/system/kernel/fs_src/system/kernel/vm?= In-Reply-To: <200807041636.m64GaJdR004595@sheep.berlios.de> Message-ID: <5500476969-BeMail@zon> bonefish at mail.berlios.de wrote: > - off_t fileSize = cache->virtual_size; > + off_t fileSize = cache->virtual_end; I actually find this more confusing than before; "end" somehow implies that (virtual_end - virtual_base) == size. But it's just the "size", so maybe we should instead just remove the "virtual_" part of it? Bye, Axel. From axeld at mail.berlios.de Mon Jul 7 13:16:51 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 13:16:51 +0200 Subject: [Haiku-commits] r26287 - haiku/trunk/src/system/kernel/cache Message-ID: <200807071116.m67BGptn017930@sheep.berlios.de> Author: axeld Date: 2008-07-07 13:16:50 +0200 (Mon, 07 Jul 2008) New Revision: 26287 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26287&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp Log: * Made a class FileMap from struct file_map. * Added two TODO comments to the start of the file. Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 08:33:03 UTC (rev 26286) +++ haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 11:16:50 UTC (rev 26287) @@ -30,9 +30,14 @@ # define TRACE(x) ; #endif +// TODO: use a sparse array - eventually, the unused BlockMap would be something +// to reuse for this. We could also have an upperbound of memory consumption +// for the whole map. +// TODO: it would be nice if we could free a file map in low memory situations. + #define CACHED_FILE_EXTENTS 2 // must be smaller than MAX_FILE_IO_VECS - // ToDo: find out how much of these are typically used + // TODO: find out how much of these are typically used struct file_extent { off_t offset; @@ -40,76 +45,79 @@ }; struct file_extent_array { - file_extent *array; + file_extent* array; size_t max_count; }; -struct file_map { - file_map(off_t size); - ~file_map(); +class FileMap { +public: + FileMap(struct vnode* vnode, off_t size); + ~FileMap(); - file_extent *operator[](uint32 index); - file_extent *ExtentAt(uint32 index); - file_extent *FindExtent(off_t offset, uint32 *_index); - status_t Add(file_io_vec *vecs, size_t vecCount, off_t &lastOffset); - void Invalidate(off_t offset, off_t size); - void Free(); + void Invalidate(off_t offset, off_t size); + void SetSize(off_t size); + void Free(); - status_t _MakeSpace(size_t amount); + status_t Translate(off_t offset, size_t size, + file_io_vec* vecs, size_t* _count); + size_t Count() const { return fCount; } + struct vnode* Vnode() const { return fVnode; } + off_t Size() const { return fSize; } + +private: + file_extent* _ExtentAt(uint32 index); + file_extent* _FindExtent(off_t offset, uint32* _index); + status_t _MakeSpace(size_t count); + status_t _Add(file_io_vec* vecs, size_t vecCount, + off_t& lastOffset); + union { - file_extent direct[CACHED_FILE_EXTENTS]; - file_extent_array indirect; + file_extent fDirect[CACHED_FILE_EXTENTS]; + file_extent_array fIndirect; }; - size_t count; - struct vnode *vnode; - off_t size; + size_t fCount; + struct vnode* fVnode; + off_t fSize; }; -file_map::file_map(off_t _size) +FileMap::FileMap(struct vnode* vnode, off_t size) { - indirect.array = NULL; - count = 0; - size = _size; + fCount = 0; + fVnode = vnode; + fSize = size; } -file_map::~file_map() +FileMap::~FileMap() { Free(); } -file_extent * -file_map::operator[](uint32 index) +file_extent* +FileMap::_ExtentAt(uint32 index) { - return ExtentAt(index); -} - - -file_extent * -file_map::ExtentAt(uint32 index) -{ - if (index >= count) + if (index >= fCount) return NULL; - if (count > CACHED_FILE_EXTENTS) - return &indirect.array[index]; + if (fCount > CACHED_FILE_EXTENTS) + return &fIndirect.array[index]; - return &direct[index]; + return &fDirect[index]; } -file_extent * -file_map::FindExtent(off_t offset, uint32 *_index) +file_extent* +FileMap::_FindExtent(off_t offset, uint32 *_index) { int32 left = 0; - int32 right = count - 1; + int32 right = fCount - 1; while (left <= right) { int32 index = (left + right) / 2; - file_extent *extent = ExtentAt(index); + file_extent* extent = _ExtentAt(index); if (extent->offset > offset) { // search in left part @@ -131,67 +139,67 @@ status_t -file_map::_MakeSpace(size_t amount) +FileMap::_MakeSpace(size_t count) { - if (amount <= CACHED_FILE_EXTENTS) { + if (count <= CACHED_FILE_EXTENTS) { // just use the reserved area in the file_cache_ref structure - if (amount <= CACHED_FILE_EXTENTS && count > CACHED_FILE_EXTENTS) { + if (count <= CACHED_FILE_EXTENTS && fCount > CACHED_FILE_EXTENTS) { // the new size is smaller than the minimal array size - file_extent *array = indirect.array; - memcpy(direct, array, sizeof(file_extent) * amount); + file_extent *array = fIndirect.array; + memcpy(fDirect, array, sizeof(file_extent) * count); free(array); } } else { // resize array if needed - file_extent *oldArray = NULL; + file_extent* oldArray = NULL; size_t maxCount = CACHED_FILE_EXTENTS; - if (count > CACHED_FILE_EXTENTS) { - oldArray = indirect.array; - maxCount = indirect.max_count; + if (fCount > CACHED_FILE_EXTENTS) { + oldArray = fIndirect.array; + maxCount = fIndirect.max_count; } - if (amount > maxCount) { + if (count > maxCount) { // allocate new array - while (maxCount < amount) { + while (maxCount < count) { if (maxCount < 32768) maxCount <<= 1; else maxCount += 32768; } - file_extent *newArray = (file_extent *)realloc(oldArray, + file_extent* newArray = (file_extent *)realloc(oldArray, maxCount * sizeof(file_extent)); if (newArray == NULL) return B_NO_MEMORY; - if (count > 0 && count <= CACHED_FILE_EXTENTS) - memcpy(newArray, direct, sizeof(file_extent) * count); + if (fCount > 0 && fCount <= CACHED_FILE_EXTENTS) + memcpy(newArray, fDirect, sizeof(file_extent) * fCount); - indirect.array = newArray; - indirect.max_count = maxCount; + fIndirect.array = newArray; + fIndirect.max_count = maxCount; } } - count = amount; + fCount = count; return B_OK; } status_t -file_map::Add(file_io_vec *vecs, size_t vecCount, off_t &lastOffset) +FileMap::_Add(file_io_vec* vecs, size_t vecCount, off_t& lastOffset) { - TRACE(("file_map@%p::Add(vecCount = %ld)\n", this, vecCount)); + TRACE(("FileMap@%p::Add(vecCount = %ld)\n", this, vecCount)); - uint32 start = count; + uint32 start = fCount; off_t offset = 0; - status_t status = _MakeSpace(count + vecCount); + status_t status = _MakeSpace(fCount + vecCount); if (status != B_OK) return status; - file_extent *lastExtent = NULL; + file_extent* lastExtent = NULL; if (start != 0) { - lastExtent = ExtentAt(start - 1); + lastExtent = _ExtentAt(start - 1); offset = lastExtent->offset + lastExtent->disk.length; } @@ -202,12 +210,12 @@ lastExtent->disk.length += vecs[i].length; offset += vecs[i].length; start--; - _MakeSpace(count - 1); + _MakeSpace(fCount - 1); continue; } } - file_extent *extent = ExtentAt(start + i); + file_extent* extent = _ExtentAt(start + i); extent->offset = offset; extent->disk = vecs[i]; @@ -216,8 +224,8 @@ } #ifdef TRACE_FILE_MAP - for (uint32 i = 0; i < count; i++) { - file_extent *extent = ExtentAt(i); + for (uint32 i = 0; i < fCount; i++) { + file_extent* extent = _ExtentAt(i); dprintf("[%ld] extent offset %Ld, disk offset %Ld, length %Ld\n", i, extent->offset, extent->disk.offset, extent->disk.length); } @@ -231,7 +239,7 @@ /*! Invalidates or removes the specified part of the file map. */ void -file_map::Invalidate(off_t offset, off_t size) +FileMap::Invalidate(off_t offset, off_t size) { // TODO: honour size, we currently always remove everything after "offset" if (offset == 0) { @@ -240,7 +248,7 @@ } uint32 index; - file_extent *extent = FindExtent(offset, &index); + file_extent* extent = _FindExtent(offset, &index); if (extent != NULL) { _MakeSpace(index); @@ -251,104 +259,44 @@ void -file_map::Free() +FileMap::SetSize(off_t size) { - if (count > CACHED_FILE_EXTENTS) - free(indirect.array); + if (size < fSize) + Invalidate(size, fSize - size); - count = 0; + fSize = size; } -// #pragma mark - public FS API - - -extern "C" void * -file_map_create(dev_t mountID, ino_t vnodeID, off_t size) +void +FileMap::Free() { - TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld, size = %Ld)\n", - mountID, vnodeID, size)); + if (fCount > CACHED_FILE_EXTENTS) + free(fIndirect.array); - file_map *map = new file_map(size); - if (map == NULL) - return NULL; - - // Get the vnode for the object - // (note, this does not grab a reference to the node) - if (vfs_lookup_vnode(mountID, vnodeID, &map->vnode) != B_OK) { - delete map; - return NULL; - } - - return map; + fCount = 0; } -extern "C" void -file_map_delete(void *_map) +status_t +FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count) { - file_map *map = (file_map *)_map; - if (map == NULL) - return; - - TRACE(("file_map_delete(map = %p)\n", map)); - delete map; -} - - -extern "C" void -file_map_set_size(void *_map, off_t size) -{ - if (_map == NULL) - return; - - file_map *map = (file_map *)_map; - - if (size < map->size) - map->Invalidate(size, map->size - size); - - map->size = size; -} - - -extern "C" void -file_map_invalidate(void *_map, off_t offset, off_t size) -{ - if (_map == NULL) - return; - - file_map *map = (file_map *)_map; - map->Invalidate(offset, size); -} - - -extern "C" status_t -file_map_translate(void *_map, off_t offset, size_t size, file_io_vec *vecs, - size_t *_count) -{ - if (_map == NULL) - return B_BAD_VALUE; - - TRACE(("file_map_translate(map %p, offset %Ld, size %ld)\n", - _map, offset, size)); - - file_map &map = *(file_map *)_map; size_t maxVecs = *_count; status_t status = B_OK; - if (offset >= map.size) { + if (offset >= Size()) { *_count = 0; return B_OK; } - if (offset + size > map.size) - size = map.size - offset; + if (offset + size > fSize) + size = fSize - offset; // First, we need to make sure that we have already cached all file // extents needed for this request. - file_extent *lastExtent = NULL; - if (map.count > 0) - lastExtent = map.ExtentAt(map.count - 1); + file_extent* lastExtent = NULL; + if (fCount > 0) + lastExtent = _ExtentAt(fCount - 1); off_t mapOffset = 0; if (lastExtent != NULL) @@ -359,12 +307,11 @@ while (mapOffset < end) { // We don't have the requested extents yet, retrieve them size_t vecCount = maxVecs; - status = vfs_get_file_map(map.vnode, mapOffset, ~0UL, vecs, - &vecCount); + status = vfs_get_file_map(Vnode(), mapOffset, ~0UL, vecs, &vecCount); if (status < B_OK && status != B_BUFFER_OVERFLOW) return status; - status_t addStatus = map.Add(vecs, vecCount, mapOffset); + status_t addStatus = _Add(vecs, vecCount, mapOffset); if (addStatus != B_OK) { // only clobber the status in case of failure status = addStatus; @@ -381,13 +328,13 @@ // we need to translate it for the requested access. uint32 index; - file_extent *fileExtent = map.FindExtent(offset, &index); + file_extent* fileExtent = _FindExtent(offset, &index); offset -= fileExtent->offset; vecs[0].offset = fileExtent->disk.offset + offset; vecs[0].length = fileExtent->disk.length - offset; - if (vecs[0].length >= size || index >= map.count - 1) { + if (vecs[0].length >= size || index >= fCount - 1) { *_count = 1; return B_OK; } @@ -396,7 +343,7 @@ size -= vecs[0].length; - for (index = 1; index < map.count;) { + for (index = 1; index < fCount;) { fileExtent++; vecs[index] = fileExtent->disk; @@ -417,3 +364,71 @@ return B_OK; } + +// #pragma mark - public FS API + + +extern "C" void* +file_map_create(dev_t mountID, ino_t vnodeID, off_t size) +{ + TRACE(("file_map_create(mountID = %ld, vnodeID = %Ld, size = %Ld)\n", + mountID, vnodeID, size)); + + // Get the vnode for the object + // (note, this does not grab a reference to the node) + struct vnode* vnode; + if (vfs_lookup_vnode(mountID, vnodeID, &vnode) != B_OK) + return NULL; + + return new(std::nothrow) FileMap(vnode, size); +} + + +extern "C" void +file_map_delete(void* _map) +{ + FileMap* map = (FileMap*)_map; + if (map == NULL) + return; + + TRACE(("file_map_delete(map = %p)\n", map)); + delete map; +} + + +extern "C" void +file_map_set_size(void* _map, off_t size) +{ + FileMap* map = (FileMap*)_map; + if (map == NULL) + return; + + map->SetSize(size); +} + + +extern "C" void +file_map_invalidate(void* _map, off_t offset, off_t size) +{ + FileMap* map = (FileMap*)_map; + if (map == NULL) + return; + + map->Invalidate(offset, size); +} + + +extern "C" status_t +file_map_translate(void* _map, off_t offset, size_t size, file_io_vec* vecs, + size_t* _count) +{ + TRACE(("file_map_translate(map %p, offset %Ld, size %ld)\n", + _map, offset, size)); + + FileMap* map = (FileMap*)_map; + if (map == NULL) + return B_BAD_VALUE; + + return map->Translate(offset, size, vecs, _count); +} + From mmu_man at mail.berlios.de Mon Jul 7 13:22:29 2008 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Mon, 7 Jul 2008 13:22:29 +0200 Subject: [Haiku-commits] r26288 - haiku/trunk/src/system/kernel/arch/m68k Message-ID: <200807071122.m67BMTCL026399@sheep.berlios.de> Author: mmu_man Date: 2008-07-07 13:22:26 +0200 (Mon, 07 Jul 2008) New Revision: 26288 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26288&view=rev Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S haiku/trunk/src/system/kernel/arch/m68k/arch_system_info.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c haiku/trunk/src/system/kernel/arch/m68k/arch_user_debugger.cpp haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp Log: - handle the supervisor bit from SR correctly on iframes - various notes on 060 vs others: - 060 has 040 compatible mmu, except pgtables must *not* be on copyback memory - 060 has a processor control reg which has a revision number to use in system_info - notes on ctx switch: - must be kept in sync with asm code - fsave generate variable size frames, so reserve space and use non-predecrementing EA. Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S 2008-07-07 11:16:50 UTC (rev 26287) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_asm.S 2008-07-07 11:22:26 UTC (rev 26288) @@ -79,6 +79,7 @@ #warning M68K: FIX m68k_context_switch +// XXX:sync with arch_thread.c:arch_thread_init_kthread_stack // void m68k_context_switch(addr_t *old_sp, addr_t new_sp); FUNCTION(m68k_context_switch): // save fp ? @@ -86,6 +87,7 @@ movem.l %d0-%d7/%a0-%a7,-(%sp) fmovem %fp0-%fp7,-(%sp) fsave -(%sp) +#warning M68K: use fixed size for fsave // XXX Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_system_info.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_system_info.cpp 2008-07-07 11:16:50 UTC (rev 26287) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_system_info.cpp 2008-07-07 11:22:26 UTC (rev 26288) @@ -46,6 +46,7 @@ sBusClockFrequency = args->arch_args.bus_frequency; sCPURevision = args->arch_args.cpu_type; //XXX +#warning M68K: use 060 PCR[15:8] sCPUType = B_CPU_M68K; return B_OK; Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c 2008-07-07 11:16:50 UTC (rev 26287) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c 2008-07-07 11:22:26 UTC (rev 26288) @@ -84,8 +84,8 @@ for (i = thread->arch_info.iframes.index - 1; i >= 0; i--) { struct iframe *frame = thread->arch_info.iframes.frames[i]; -// if (frame->srr1 & MSR_PRIVILEGE_LEVEL) -// return frame; + if (frame->sr & (1 << M68K_SR_S) == 0) + return frame; } return NULL; Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_user_debugger.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_user_debugger.cpp 2008-07-07 11:16:50 UTC (rev 26287) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_user_debugger.cpp 2008-07-07 11:22:26 UTC (rev 26288) @@ -52,6 +52,8 @@ // 0 1 trace on flow // 1 0 single step // 1 1 undef + // note 060 and 020(?) only have T1 bit, + // but this should be compatible as well. if (thread->debug_info.flags & B_THREAD_DEBUG_SINGLE_STEP) { frame->cpu.sr &= ~(M68K_SR_T_MASK); frame->cpu.sr |= (1 << M68K_SR_T1); Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp 2008-07-07 11:16:50 UTC (rev 26287) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp 2008-07-07 11:22:26 UTC (rev 26288) @@ -28,10 +28,13 @@ * so we use a function array to switch to the one we want. */ +#warning M68K: 060: must *not* have pgtables in copyback cachable mem!!! + //extern struct m68k_vm_ops m68851_vm_ops; extern struct m68k_vm_ops m68030_vm_ops; -//extern struct m68k_vm_ops m68030_vm_ops; -//extern struct m68k_vm_ops m68030_vm_ops; +//extern struct m68k_vm_ops m68040_vm_ops; +// 060 should be identical to 040 except for copyback issue +//extern struct m68k_vm_ops m68060_vm_ops; #warning M68K: use a static! m68k_vm_ops *get_vm_ops() From mmu_man at mail.berlios.de Mon Jul 7 13:30:14 2008 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Mon, 7 Jul 2008 13:30:14 +0200 Subject: [Haiku-commits] r26289 - haiku/trunk/headers/private/kernel/arch/m68k Message-ID: <200807071130.m67BUEVp006797@sheep.berlios.de> Author: mmu_man Date: 2008-07-07 13:30:12 +0200 (Mon, 07 Jul 2008) New Revision: 26289 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26289&view=rev Modified: haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h Log: Would work better with the definition... Modified: haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h =================================================================== --- haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h 2008-07-07 11:22:26 UTC (rev 26288) +++ haiku/trunk/headers/private/kernel/arch/m68k/arch_cpu.h 2008-07-07 11:30:12 UTC (rev 26289) @@ -15,6 +15,7 @@ #define SR_IP_MASK 0x0700 #define SR_S 0x2000 +#define M68K_SR_S 13 #define M68K_SR_T_MASK 0xC000 #define M68K_SR_T0 14 #define M68K_SR_T1 15 @@ -365,6 +366,7 @@ double f0;*/ } _PACKED; +#if 0 /* ppc */ enum machine_state { MSR_EXCEPTIONS_ENABLED = 1L << 15, // EE MSR_PRIVILEGE_LEVEL = 1L << 14, // PR @@ -376,6 +378,7 @@ }; //struct block_address_translation; +#endif typedef struct arch_cpu_info { int null; From mmu_man at mail.berlios.de Mon Jul 7 13:31:45 2008 From: mmu_man at mail.berlios.de (mmu_man at mail.berlios.de) Date: Mon, 7 Jul 2008 13:31:45 +0200 Subject: [Haiku-commits] r26290 - haiku/trunk/src/system/kernel/arch/m68k Message-ID: <200807071131.m67BVj3D008758@sheep.berlios.de> Author: mmu_man Date: 2008-07-07 13:31:40 +0200 (Mon, 07 Jul 2008) New Revision: 26290 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26290&view=rev Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c Log: ..and the correct struct name. Modified: haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c =================================================================== --- haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c 2008-07-07 11:30:12 UTC (rev 26289) +++ haiku/trunk/src/system/kernel/arch/m68k/arch_thread.c 2008-07-07 11:31:40 UTC (rev 26290) @@ -84,7 +84,7 @@ for (i = thread->arch_info.iframes.index - 1; i >= 0; i--) { struct iframe *frame = thread->arch_info.iframes.frames[i]; - if (frame->sr & (1 << M68K_SR_S) == 0) + if (frame->cpu.sr & (1 << M68K_SR_S) == 0) return frame; } From axeld at mail.berlios.de Mon Jul 7 14:02:26 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 14:02:26 +0200 Subject: [Haiku-commits] r26291 - in haiku/trunk: headers/private/kernel src/system/kernel/cache src/system/kernel/fs Message-ID: <200807071202.m67C2Qgc000069@sheep.berlios.de> Author: axeld Date: 2008-07-07 14:02:24 +0200 (Mon, 07 Jul 2008) New Revision: 26291 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26291&view=rev Modified: haiku/trunk/headers/private/kernel/file_cache.h haiku/trunk/src/system/kernel/cache/file_map.cpp haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Added some optional KDL command and statistics to the file map implementation. * Turned them on for now. Modified: haiku/trunk/headers/private/kernel/file_cache.h =================================================================== --- haiku/trunk/headers/private/kernel/file_cache.h 2008-07-07 11:31:40 UTC (rev 26290) +++ haiku/trunk/headers/private/kernel/file_cache.h 2008-07-07 12:02:24 UTC (rev 26291) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef _KERNEL_FILE_CACHE_H @@ -44,6 +44,8 @@ extern void cache_node_launched(size_t argCount, char * const *args); extern void cache_prefetch_vnode(struct vnode *vnode, off_t offset, size_t size); extern void cache_prefetch(dev_t mountID, ino_t vnodeID, off_t offset, size_t size); + +extern status_t file_map_init(void); extern status_t file_cache_init_post_boot_device(void); extern status_t file_cache_init(void); Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 11:31:40 UTC (rev 26290) +++ haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 12:02:24 UTC (rev 26291) @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -35,6 +35,8 @@ // for the whole map. // TODO: it would be nice if we could free a file map in low memory situations. +#define DEBUG_FILE_MAP + #define CACHED_FILE_EXTENTS 2 // must be smaller than MAX_FILE_IO_VECS // TODO: find out how much of these are typically used @@ -49,7 +51,11 @@ size_t max_count; }; -class FileMap { +class FileMap +#ifdef DEBUG_FILE_MAP + : public DoublyLinkedListLinkImpl +#endif +{ public: FileMap(struct vnode* vnode, off_t size); ~FileMap(); @@ -61,12 +67,13 @@ status_t Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count); + file_extent* ExtentAt(uint32 index); + size_t Count() const { return fCount; } struct vnode* Vnode() const { return fVnode; } off_t Size() const { return fSize; } private: - file_extent* _ExtentAt(uint32 index); file_extent* _FindExtent(off_t offset, uint32* _index); status_t _MakeSpace(size_t count); status_t _Add(file_io_vec* vecs, size_t vecCount, @@ -81,23 +88,40 @@ off_t fSize; }; +#ifdef DEBUG_FILE_MAP +typedef DoublyLinkedList FileMapList; +static FileMapList sList; +static mutex sLock; +#endif + + FileMap::FileMap(struct vnode* vnode, off_t size) { fCount = 0; fVnode = vnode; fSize = size; + +#ifdef DEBUG_FILE_MAP + MutexLocker _(sLock); + sList.Add(this); +#endif } FileMap::~FileMap() { Free(); + +#ifdef DEBUG_FILE_MAP + MutexLocker _(sLock); + sList.Remove(this); +#endif } file_extent* -FileMap::_ExtentAt(uint32 index) +FileMap::ExtentAt(uint32 index) { if (index >= fCount) return NULL; @@ -117,7 +141,7 @@ while (left <= right) { int32 index = (left + right) / 2; - file_extent* extent = _ExtentAt(index); + file_extent* extent = ExtentAt(index); if (extent->offset > offset) { // search in left part @@ -199,7 +223,7 @@ file_extent* lastExtent = NULL; if (start != 0) { - lastExtent = _ExtentAt(start - 1); + lastExtent = ExtentAt(start - 1); offset = lastExtent->offset + lastExtent->disk.length; } @@ -215,7 +239,7 @@ } } - file_extent* extent = _ExtentAt(start + i); + file_extent* extent = ExtentAt(start + i); extent->offset = offset; extent->disk = vecs[i]; @@ -225,7 +249,7 @@ #ifdef TRACE_FILE_MAP for (uint32 i = 0; i < fCount; i++) { - file_extent* extent = _ExtentAt(i); + file_extent* extent = ExtentAt(i); dprintf("[%ld] extent offset %Ld, disk offset %Ld, length %Ld\n", i, extent->offset, extent->disk.offset, extent->disk.length); } @@ -296,7 +320,7 @@ file_extent* lastExtent = NULL; if (fCount > 0) - lastExtent = _ExtentAt(fCount - 1); + lastExtent = ExtentAt(fCount - 1); off_t mapOffset = 0; if (lastExtent != NULL) @@ -365,6 +389,118 @@ } +// #pragma mark - + + +#ifdef DEBUG_FILE_MAP + +static int +dump_file_map(int argc, char** argv) +{ + if (argc < 2) { + print_debugger_command_usage(argv[0]); + return 0; + } + + bool printExtents = false; + if (argc > 2 && !strcmp(argv[1], "-p")) + printExtents = true; + + FileMap* map = (FileMap*)parse_expression(argv[argc - 1]); + if (map == NULL) { + kprintf("invalid file map!\n"); + return 0; + } + + kprintf("FileMap %p\n", map); + kprintf(" size %Ld\n", map->Size()); + kprintf(" count %lu\n", map->Count()); + + if (!printExtents) + return 0; + + for (uint32 i = 0; i < map->Count(); i++) { + file_extent* extent = map->ExtentAt(i); + + kprintf(" [%lu] offset %Ld, disk offset %Ld, length %Ld\n", + i, extent->offset, extent->disk.offset, extent->disk.length); + } + + return 0; +} + + +static int +dump_file_map_stats(int argc, char** argv) +{ + off_t minSize = 0; + off_t maxSize = -1; + + if (argc == 2) { + maxSize = parse_expression(argv[1]); + } else if (argc > 2) { + minSize = parse_expression(argv[1]); + maxSize = parse_expression(argv[2]); + } + + FileMapList::Iterator iterator = sList.GetIterator(); + off_t size = 0; + off_t mapSize = 0; + uint32 extents = 0; + uint32 count = 0; + uint32 emptyCount = 0; + + while (iterator.HasNext()) { + FileMap* map = iterator.Next(); + + if (minSize > map->Size() || (maxSize != -1 && maxSize < map->Size())) + continue; + + if (map->Count() != 0) { + file_extent* extent = map->ExtentAt(map->Count() - 1); + if (extent != NULL) + mapSize += extent->offset + extent->disk.length; + + extents += map->Count(); + } else + emptyCount++; + + size += map->Size(); + count++; + } + + kprintf("%ld file maps (%ld empty), %Ld file bytes in total, %Ld bytes " + "cached, %lu extents\n", count, emptyCount, size, mapSize, extents); + kprintf("average %lu extents per map for %Ld bytes.\n", + extents / (count - emptyCount), mapSize / (count - emptyCount)); + + return 0; +} + +#endif // DEBUG_FILE_MAP + + +// #pragma mark - private kernel API + + +extern "C" status_t +file_map_init(void) +{ +#ifdef DEBUG_FILE_MAP + add_debugger_command_etc("file_map", &dump_file_map, + "Dumps the specified file map.", + "[-p] \n" + " -p - causes the file extents to be printed as well.\n" + " - pointer to the file map.\n", 0); + add_debugger_command("file_map_stats", &dump_file_map_stats, + "Dumps some file map statistics."); + + mutex_init(&sLock, "file map list"); +#endif + return B_OK; +} + + // #pragma mark - public FS API Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 11:31:40 UTC (rev 26290) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:02:24 UTC (rev 26291) @@ -4394,6 +4394,8 @@ register_low_memory_handler(&vnode_low_memory_handler, NULL, 0); + file_map_init(); + return file_cache_init(); } From axeld at pinc-software.de Mon Jul 7 14:09:14 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 14:09:14 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26282_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/audio/hda?= In-Reply-To: <200807061920.m66JK313023105@sheep.berlios.de> Message-ID: <10845814160-BeMail@zon> korli at BerliOS wrote: > Log: > moved stateStatus read/write out of the interrupt handler Was there a specific reason for this? Or just because it doesn't need to be in there? Where does HDA initialization fail for you? If moving the state out of the interrupt, it looks like your audio hardware didn't get an interrupt assigned in the first place, though. Bye, Axel. From axeld at mail.berlios.de Mon Jul 7 14:24:27 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 14:24:27 +0200 Subject: [Haiku-commits] r26292 - haiku/trunk/src/system/kernel/fs Message-ID: <200807071224.m67CORRt003193@sheep.berlios.de> Author: axeld Date: 2008-07-07 14:24:24 +0200 (Mon, 07 Jul 2008) New Revision: 26292 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26292&view=rev Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Since we now have a vnode::type field, several calls of read_stat() were no longer necessary. * Optimized file_seek() using this field, too; reading the stat is now only done when necessary. * file_read() and file_write() will now return B_IS_A_DIRECTORY so that not every file system has to care about that particular error code. Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:02:24 UTC (rev 26291) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:24:24 UTC (rev 26292) @@ -4716,21 +4716,29 @@ static status_t -file_read(struct file_descriptor *descriptor, off_t pos, void *buffer, size_t *length) +file_read(struct file_descriptor *descriptor, off_t pos, void *buffer, + size_t *length) { struct vnode *vnode = descriptor->u.vnode; - FUNCTION(("file_read: buf %p, pos %Ld, len %p = %ld\n", buffer, pos, length, *length)); + + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; + return FS_CALL(vnode, read, descriptor->cookie, pos, buffer, length); } static status_t -file_write(struct file_descriptor *descriptor, off_t pos, const void *buffer, size_t *length) +file_write(struct file_descriptor *descriptor, off_t pos, const void *buffer, + size_t *length) { struct vnode *vnode = descriptor->u.vnode; - FUNCTION(("file_write: buf %p, pos %Ld, len %p\n", buffer, pos, length)); + + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; + return FS_CALL(vnode, write, descriptor->cookie, pos, buffer, length); } @@ -4738,22 +4746,13 @@ static off_t file_seek(struct file_descriptor *descriptor, off_t pos, int seekType) { + struct vnode *vnode = descriptor->u.vnode; off_t offset; FUNCTION(("file_seek(pos = %Ld, seekType = %d)\n", pos, seekType)); - // stat() the node - struct vnode *vnode = descriptor->u.vnode; - if (!HAS_FS_CALL(vnode, read_stat)) - return EOPNOTSUPP; - - struct stat stat; - status_t status = FS_CALL(vnode, read_stat, &stat); - if (status < B_OK) - return status; - // some kinds of files are not seekable - switch (stat.st_mode & S_IFMT) { + switch (vnode->type & S_IFMT) { case S_IFIFO: case S_IFSOCK: return ESPIPE; @@ -4776,8 +4775,19 @@ offset = descriptor->pos; break; case SEEK_END: + { + // stat() the node + if (!HAS_FS_CALL(vnode, read_stat)) + return EOPNOTSUPP; + + struct stat stat; + status_t status = FS_CALL(vnode, read_stat, &stat); + if (status < B_OK) + return status; + offset = stat.st_size; break; + } default: return B_BAD_VALUE; } @@ -5784,13 +5794,12 @@ case SEEK_END: { struct vnode *vnode = descriptor->u.vnode; - struct stat stat; - status_t status; - if (!HAS_FS_CALL(vnode, read_stat)) return EOPNOTSUPP; - status = FS_CALL(vnode, read_attr_stat, descriptor->cookie, &stat); + struct stat stat; + status_t status = FS_CALL(vnode, read_attr_stat, descriptor->cookie, + &stat); if (status < B_OK) return status; @@ -6388,13 +6397,8 @@ if (status < B_OK) goto err5; - // make sure covered_vnode is a DIR - struct stat coveredNodeStat; - status = FS_CALL(coveredVnode, read_stat, &coveredNodeStat); - if (status < B_OK) - goto err5; - - if (!S_ISDIR(coveredNodeStat.st_mode)) { + // make sure covered_vnode is a directory + if (!S_ISDIR(coveredVnode->type)) { status = B_NOT_A_DIRECTORY; goto err5; } @@ -6838,7 +6842,6 @@ struct io_context *context; struct vnode *vnode = NULL; struct vnode *oldDirectory; - struct stat stat; status_t status; FUNCTION(("set_cwd: path = \'%s\'\n", path)); @@ -6848,11 +6851,7 @@ if (status < 0) return status; - status = FS_CALL(vnode, read_stat, &stat); - if (status < 0) - goto err; - - if (!S_ISDIR(stat.st_mode)) { + if (!S_ISDIR(vnode->type)) { // nope, can't cwd to here status = B_NOT_A_DIRECTORY; goto err; From axeld at pinc-software.de Mon Jul 7 14:24:24 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 14:24:24 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26267_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/reiserfs?= In-Reply-To: <200807052226.m65MQLEQ032542@sheep.berlios.de> Message-ID: <11755341135-BeMail@zon> korli at BerliOS wrote: > Modified: > haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/ > kernel_interface.cpp > Log: > reads now returns B_IS_A_DIRECTORY instead of B_BAD_VALUE for > directories I put that logic into the VFS in r26292, it's no longer needed in all file systems. We might check for symlinks as well there, though. Bye, Axel. From axeld at mail.berlios.de Mon Jul 7 14:27:41 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 14:27:41 +0200 Subject: [Haiku-commits] r26293 - haiku/trunk/src/system/kernel/fs Message-ID: <200807071227.m67CRfWk003659@sheep.berlios.de> Author: axeld Date: 2008-07-07 14:27:37 +0200 (Mon, 07 Jul 2008) New Revision: 26293 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26293&view=rev Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * file_{read|write}() now only accept regular files, and will return either B_BAD_VALUE or B_IS_A_DIRECTORY depending on the vnode type. Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:24:24 UTC (rev 26292) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:27:37 UTC (rev 26293) @@ -4722,9 +4722,13 @@ struct vnode *vnode = descriptor->u.vnode; FUNCTION(("file_read: buf %p, pos %Ld, len %p = %ld\n", buffer, pos, length, *length)); - if (S_ISDIR(vnode->type)) - return B_IS_A_DIRECTORY; + if (!S_ISREG(vnode->type)) { + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; + return B_BAD_VALUE; + } + return FS_CALL(vnode, read, descriptor->cookie, pos, buffer, length); } @@ -4736,9 +4740,13 @@ struct vnode *vnode = descriptor->u.vnode; FUNCTION(("file_write: buf %p, pos %Ld, len %p\n", buffer, pos, length)); - if (S_ISDIR(vnode->type)) - return B_IS_A_DIRECTORY; + if (!S_ISREG(vnode->type)) { + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; + return B_BAD_VALUE; + } + return FS_CALL(vnode, write, descriptor->cookie, pos, buffer, length); } From korli at users.berlios.de Mon Jul 7 14:38:52 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 7 Jul 2008 14:38:52 +0200 Subject: [Haiku-commits] r26282 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: <10845814160-BeMail@zon> References: <200807061920.m66JK313023105@sheep.berlios.de> <10845814160-BeMail@zon> Message-ID: Hi Axel, 2008/7/7 Axel D?rfler : > korli at BerliOS wrote: >> Log: >> moved stateStatus read/write out of the interrupt handler > > Was there a specific reason for this? Or just because it doesn't need > to be in there? > Where does HDA initialization fail for you? > If moving the state out of the interrupt, it looks like your audio > hardware didn't get an interrupt assigned in the first place, though. On my machine, the interrupt happened after the codec scan, hence no codec was found. BTW there is no good reason to read the codec states register in the interrupt handler, I didn't see any hda implementations doing this. Does the hda driver work on your hardware ? Here, the playback engine seems to be working, but no sound is output. Is 24bits/96khz a normal playback format ? Thanks. Bye, J?r?me From korli at users.berlios.de Mon Jul 7 14:42:23 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 7 Jul 2008 14:42:23 +0200 Subject: [Haiku-commits] r26292 - haiku/trunk/src/system/kernel/fs In-Reply-To: <200807071224.m67CORRt003193@sheep.berlios.de> References: <200807071224.m67CORRt003193@sheep.berlios.de> Message-ID: Hi Axel, 2008/7/7 axeld at BerliOS : > * file_read() and file_write() will now return B_IS_A_DIRECTORY so that not > every file system has to care about that particular error code. From axeld at mail.berlios.de Mon Jul 7 14:45:39 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 14:45:39 +0200 Subject: [Haiku-commits] r26294 - haiku/trunk/src/system/kernel/fs Message-ID: <200807071245.m67CjdH1005776@sheep.berlios.de> Author: axeld Date: 2008-07-07 14:45:38 +0200 (Mon, 07 Jul 2008) New Revision: 26294 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26294&view=rev Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Reverted r26293 again, as that "subtle" change also prevented any device I/O from happening... Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:27:37 UTC (rev 26293) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-07 12:45:38 UTC (rev 26294) @@ -4722,13 +4722,9 @@ struct vnode *vnode = descriptor->u.vnode; FUNCTION(("file_read: buf %p, pos %Ld, len %p = %ld\n", buffer, pos, length, *length)); - if (!S_ISREG(vnode->type)) { - if (S_ISDIR(vnode->type)) - return B_IS_A_DIRECTORY; + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; - return B_BAD_VALUE; - } - return FS_CALL(vnode, read, descriptor->cookie, pos, buffer, length); } @@ -4740,13 +4736,9 @@ struct vnode *vnode = descriptor->u.vnode; FUNCTION(("file_write: buf %p, pos %Ld, len %p\n", buffer, pos, length)); - if (!S_ISREG(vnode->type)) { - if (S_ISDIR(vnode->type)) - return B_IS_A_DIRECTORY; + if (S_ISDIR(vnode->type)) + return B_IS_A_DIRECTORY; - return B_BAD_VALUE; - } - return FS_CALL(vnode, write, descriptor->cookie, pos, buffer, length); } From axeld at mail.berlios.de Mon Jul 7 14:53:53 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 14:53:53 +0200 Subject: [Haiku-commits] r26295 - haiku/trunk/src/system/kernel/cache Message-ID: <200807071253.m67Crrup006407@sheep.berlios.de> Author: axeld Date: 2008-07-07 14:53:53 +0200 (Mon, 07 Jul 2008) New Revision: 26295 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26295&view=rev Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp Log: * Added a lock to FileMap - since the map is retrieved lazily, and file systems like BFS only hold a read lock when reading the map, accessing the file map wasn't safe. * Made FileMap::Free() private, and renamed it to _Free(). Modified: haiku/trunk/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 12:45:38 UTC (rev 26294) +++ haiku/trunk/src/system/kernel/cache/file_map.cpp 2008-07-07 12:53:53 UTC (rev 26295) @@ -62,7 +62,6 @@ void Invalidate(off_t offset, off_t size); void SetSize(off_t size); - void Free(); status_t Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count); @@ -78,11 +77,14 @@ status_t _MakeSpace(size_t count); status_t _Add(file_io_vec* vecs, size_t vecCount, off_t& lastOffset); + void _InvalidateAfter(off_t offset); + void _Free(); union { file_extent fDirect[CACHED_FILE_EXTENTS]; file_extent_array fIndirect; }; + mutex fLock; size_t fCount; struct vnode* fVnode; off_t fSize; @@ -98,6 +100,7 @@ FileMap::FileMap(struct vnode* vnode, off_t size) { + mutex_init(&fLock, "file map"); fCount = 0; fVnode = vnode; fSize = size; @@ -111,7 +114,8 @@ FileMap::~FileMap() { - Free(); + _Free(); + mutex_destroy(&fLock); #ifdef DEBUG_FILE_MAP MutexLocker _(sLock); @@ -260,17 +264,9 @@ } -/*! Invalidates or removes the specified part of the file map. -*/ void -FileMap::Invalidate(off_t offset, off_t size) +FileMap::_InvalidateAfter(off_t offset) { - // TODO: honour size, we currently always remove everything after "offset" - if (offset == 0) { - Free(); - return; - } - uint32 index; file_extent* extent = _FindExtent(offset, &index); if (extent != NULL) { @@ -282,18 +278,37 @@ } +/*! Invalidates or removes the specified part of the file map. +*/ void +FileMap::Invalidate(off_t offset, off_t size) +{ + MutexLocker _(fLock); + + // TODO: honour size, we currently always remove everything after "offset" + if (offset == 0) { + _Free(); + return; + } + + _InvalidateAfter(offset); +} + + +void FileMap::SetSize(off_t size) { + MutexLocker _(fLock); + if (size < fSize) - Invalidate(size, fSize - size); + _InvalidateAfter(size); fSize = size; } void -FileMap::Free() +FileMap::_Free() { if (fCount > CACHED_FILE_EXTENTS) free(fIndirect.array); @@ -305,6 +320,8 @@ status_t FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count) { + MutexLocker _(fLock); + size_t maxVecs = *_count; status_t status = B_OK; From axeld at pinc-software.de Mon Jul 7 17:10:48 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 17:10:48 +0200 CEST Subject: [Haiku-commits] r26292 - haiku/trunk/src/system/kernel/fs In-Reply-To: Message-ID: <21739172355-BeMail@zon> "J?r?me Duval" wrote: > 2008/7/7 axeld at BerliOS : > > * file_read() and file_write() will now return B_IS_A_DIRECTORY so > > that not > > every file system has to care about that particular error code. > From the spec, read() and write() for directories could actually be > supported by a file system. What do you think ? > > [...] > [EISDIR] > The fildes argument refers to a directory and the implementation > does not allow the directory to be read using read(), pread() or > readv(). I don't think there is a useful purpose for this, but if we someday stumble upon it, we can still change the VFS back. Bye, Axel. From ingo_weinhold at gmx.de Mon Jul 7 17:16:04 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Mon, 07 Jul 2008 17:16:04 +0200 Subject: [Haiku-commits] r26250 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm In-Reply-To: <5500476969-BeMail@zon> References: <5500476969-BeMail@zon> Message-ID: <20080707171604.547.1@knochen-vm.nameserver> On 2008-07-07 at 12:40:09 [+0200], Axel D?rfler wrote: > bonefish at mail.berlios.de wrote: > > - off_t fileSize = cache->virtual_size; > > + off_t fileSize = cache->virtual_end; > > I actually find this more confusing than before; "end" somehow implies > that (virtual_end - virtual_base) == size. But it's just the "size", so > maybe we should instead just remove the "virtual_" part of it? As I see it (virtual_end - virtual_base) is indeed the size of the cache, i.e. it implies the number of pages the cache will maximally hold. I understand that for vnode caches virtual_base is always 0 and virtual_end is always the file size, but for anonymous caches that's not the case. CU, Ingo From axeld at pinc-software.de Mon Jul 7 17:15:01 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 17:15:01 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26282_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/audio/hda?= In-Reply-To: Message-ID: <21992894440-BeMail@zon> Hi J?r?me, "J?r?me Duval" wrote: > > Was there a specific reason for this? Or just because it doesn't > > need > > to be in there? > > Where does HDA initialization fail for you? > > If moving the state out of the interrupt, it looks like your audio > > hardware didn't get an interrupt assigned in the first place, > > though. > On my machine, the interrupt happened after the codec scan, hence no > codec was found. So the wait time was too short? > BTW there is no good reason to read the codec states register in the > interrupt handler, I didn't see any hda implementations doing this. True enough, I just took that part over from Ithamar, and it's not wrong either (as an interrupt is generated when the codec state changes). > Does the hda driver work on your hardware ? Here, the playback engine > seems to be working, but no sound is output. You might want to try the multi_audio_test application - using that, I could get sound out of the driver when I tried the last time (some months ago). > Is 24bits/96khz a normal playback format ? Sounds like it is, I don't know if the hmulti_audio-Add-on supports this, though. Bye, Axel. From axeld at mail.berlios.de Mon Jul 7 17:19:21 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 17:19:21 +0200 Subject: [Haiku-commits] r26296 - in haiku/trunk: headers/private/fs_shell src/system/kernel/fs src/tools/fs_shell Message-ID: <200807071519.m67FJLPo026645@sheep.berlios.de> Author: axeld Date: 2008-07-07 17:19:19 +0200 (Mon, 07 Jul 2008) New Revision: 26296 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26296&view=rev Added: haiku/trunk/headers/private/fs_shell/fssh_lock.h Removed: haiku/trunk/src/tools/fs_shell/block_cache_priv.h haiku/trunk/src/tools/fs_shell/lock.h Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/src/system/kernel/fs/rootfs.cpp haiku/trunk/src/tools/fs_shell/block_cache.cpp haiku/trunk/src/tools/fs_shell/driver_settings.cpp haiku/trunk/src/tools/fs_shell/fd.cpp haiku/trunk/src/tools/fs_shell/file_cache.cpp haiku/trunk/src/tools/fs_shell/lock.cpp haiku/trunk/src/tools/fs_shell/module.cpp haiku/trunk/src/tools/fs_shell/vfs.cpp haiku/trunk/src/tools/fs_shell/vfs.h Log: * Made the private kernel locking primitives available to file systems as well. * Applied Korli's mutex_unlock() fix to block_cache.cpp. * Removed block_cache_priv.h, as it's no longer needed (moved its definitions into block_cache.cpp, as in the kernel file). Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-07 15:19:19 UTC (rev 26296) @@ -33,6 +33,7 @@ #include "fssh_fs_query.h" #include "fssh_fs_volume.h" #include "fssh_kernel_export.h" +#include "fssh_lock.h" #include "fssh_module.h" #include "fssh_node_monitor.h" #include "fssh_os.h" @@ -954,6 +955,46 @@ //////////////////////////////////////////////////////////////////////////////// +// #pragma mark - fssh_lock.h + +#define mutex fssh_mutex +#define rw_lock fssh_rw_lock +#define recursive_lock fssh_recursive_lock + +#define MUTEX_FLAG_CLONE_NAME FSSH_MUTEX_FLAG_CLONE_NAME +#define RW_LOCK_FLAG_CLONE_NAME FSSH_RW_LOCK_FLAG_CLONE_NAME + +#define ASSERT_LOCKED_RECURSIVE(r) FSSH_ASSERT_LOCKED_RECURSIVE(r) +#define ASSERT_LOCKED_MUTEX(m) FSSH_ASSERT_LOCKED_MUTEX(m) + +#define MUTEX_INITIALIZER(name) FSSH_MUTEX_INITIALIZER(name) +#define RECURSIVE_LOCK_INITIALIZER(name) FSSH_RECURSIVE_LOCK_INITIALIZER(name) +#define RW_LOCK_INITIALIZER(name) FSSH_RW_LOCK_INITIALIZER(name) + +#define recursive_lock_init fssh_recursive_lock_init +#define recursive_lock_init_etc fssh_recursive_lock_init_etc +#define recursive_lock_destroy fssh_recursive_lock_destroy +#define recursive_lock_lock fssh_recursive_lock_lock +#define recursive_lock_unlock fssh_recursive_lock_unlock +#define recursive_lock_get_recursion fssh_recursive_lock_get_recursion + +#define rw_lock_init fssh_rw_lock_init +#define rw_lock_init_etc fssh_rw_lock_init_etc +#define rw_lock_destroy fssh_rw_lock_destroy +#define rw_lock_read_lock fssh_rw_lock_read_lock +#define rw_lock_read_unlock fssh_rw_lock_read_unlock +#define rw_lock_write_lock fssh_rw_lock_write_lock +#define rw_lock_write_unlock fssh_rw_lock_write_unlock + +#define mutex_init fssh_mutex_init +#define mutex_init_etc fssh_mutex_init_etc +#define mutex_destroy fssh_mutex_destroy +#define mutex_lock fssh_mutex_lock +#define mutex_trylock fssh_mutex_trylock +#define mutex_unlock fssh_mutex_unlock + + +//////////////////////////////////////////////////////////////////////////////// // #pragma mark - fssh_module.h #define module_info fssh_module_info Added: haiku/trunk/headers/private/fs_shell/fssh_lock.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 15:19:19 UTC (rev 26296) @@ -0,0 +1,125 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _FSSH_KERNEL_LOCK_H +#define _FSSH_KERNEL_LOCK_H + + +#include +#include +#include + + +typedef struct fssh_mutex { + fssh_sem_id sem; + fssh_thread_id holder; +} fssh_mutex; + +#define FSSH_MUTEX_FLAG_CLONE_NAME 0x1 + + +typedef struct fssh_recursive_lock { + fssh_sem_id sem; + fssh_thread_id holder; + int recursion; +} fssh_recursive_lock; + + +typedef struct fssh_rw_lock { + fssh_sem_id sem; + int32_t count; +} fssh_rw_lock; + +#define FSSH_RW_LOCK_FLAG_CLONE_NAME 0x1 + +#define FSSH_ASSERT_LOCKED_RECURSIVE(r) +#define FSSH_ASSERT_LOCKED_MUTEX(m) + +// static initializers +#define FSSH_MUTEX_INITIALIZER(name) { name, NULL, 0, 0 } +#define FSSH_RECURSIVE_LOCK_INITIALIZER(name) { FSSH_MUTEX_INITIALIZER(name), -1, 0 } +#define FSSH_RW_LOCK_INITIALIZER(name) { name, NULL, -1, 0, 0, 0 } + +#ifdef __cplusplus +extern "C" { +#endif + +extern void fssh_recursive_lock_init(fssh_recursive_lock *lock, const char *name); + // name is *not* cloned nor freed in recursive_lock_destroy() +extern void fssh_recursive_lock_init_etc(fssh_recursive_lock *lock, const char *name, + uint32_t flags); +extern void fssh_recursive_lock_destroy(fssh_recursive_lock *lock); +extern fssh_status_t fssh_recursive_lock_lock(fssh_recursive_lock *lock); +extern void fssh_recursive_lock_unlock(fssh_recursive_lock *lock); +extern int32_t fssh_recursive_lock_get_recursion(fssh_recursive_lock *lock); + +extern void fssh_rw_lock_init(fssh_rw_lock* lock, const char* name); + // name is *not* cloned nor freed in rw_lock_destroy() +extern void fssh_rw_lock_init_etc(fssh_rw_lock* lock, const char* name, uint32_t flags); +extern void fssh_rw_lock_destroy(fssh_rw_lock* lock); +extern fssh_status_t fssh_rw_lock_read_lock(fssh_rw_lock* lock); +extern fssh_status_t fssh_rw_lock_read_unlock(fssh_rw_lock* lock); +extern fssh_status_t fssh_rw_lock_write_lock(fssh_rw_lock* lock); +extern fssh_status_t fssh_rw_lock_write_unlock(fssh_rw_lock* lock); + +extern void fssh_mutex_init(fssh_mutex* lock, const char* name); + // name is *not* cloned nor freed in mutex_destroy() +extern void fssh_mutex_init_etc(fssh_mutex* lock, const char* name, uint32_t flags); +extern void fssh_mutex_destroy(fssh_mutex* lock); +extern fssh_status_t fssh_mutex_lock(fssh_mutex* lock); +extern fssh_status_t fssh_mutex_trylock(fssh_mutex* lock); +extern void fssh_mutex_unlock(fssh_mutex* lock); + +#ifdef __cplusplus +} + +namespace FSShell { + +// MutexLocking +class MutexLocking { +public: + inline bool Lock(fssh_mutex *lockable) + { + return fssh_mutex_lock(lockable) == FSSH_B_OK; + } + + inline void Unlock(fssh_mutex *lockable) + { + fssh_mutex_unlock(lockable); + } +}; + +// MutexLocker +typedef AutoLocker MutexLocker; + +// RecursiveLockLocking +class RecursiveLockLocking { +public: + inline bool Lock(fssh_recursive_lock *lockable) + { + return fssh_recursive_lock_lock(lockable) == FSSH_B_OK; + } + + inline void Unlock(fssh_recursive_lock *lockable) + { + fssh_recursive_lock_unlock(lockable); + } +}; + +// RecursiveLocker +typedef AutoLocker RecursiveLocker; + +} // namespace FSShell + +using FSShell::AutoLocker; +using FSShell::MutexLocker; +using FSShell::RecursiveLocker; + +#endif // __cplusplus + +#endif /* _FSSH_KERNEL_LOCK_H */ Modified: haiku/trunk/src/system/kernel/fs/rootfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/rootfs.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/system/kernel/fs/rootfs.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -12,7 +12,6 @@ # include "hash.h" # include "list.h" -# include "lock.h" #else # include # include Modified: haiku/trunk/src/tools/fs_shell/block_cache.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/block_cache.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/tools/fs_shell/block_cache.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -3,16 +3,15 @@ * Distributed under the terms of the MIT License. */ -#include "block_cache_priv.h" - #include - #include +#include "DoublyLinkedList.h" #include "fssh_atomic.h" #include "fssh_errno.h" #include "fssh_fs_cache.h" #include "fssh_kernel_export.h" +#include "fssh_lock.h" #include "fssh_string.h" #include "fssh_unistd.h" #include "hash.h" @@ -43,6 +42,78 @@ namespace FSShell { +struct hash_table; +struct vm_page; + + +//#define DEBUG_CHANGED +#undef DEBUG_CHANGED + + +struct cache_transaction; +struct cached_block; +struct block_cache; +typedef DoublyLinkedListLink block_link; + + +struct cached_block { + cached_block *next; // next in hash + cached_block *transaction_next; + block_link link; + fssh_off_t block_number; + void *current_data; + void *original_data; + void *parent_data; +#ifdef DEBUG_CHANGED + void *compare; +#endif + int32_t ref_count; + int32_t accessed; + bool busy : 1; + bool is_writing : 1; + bool is_dirty : 1; + bool unused : 1; + bool unmapped : 1; + cache_transaction *transaction; + cache_transaction *previous_transaction; + + static int Compare(void *_cacheEntry, const void *_block); + static uint32_t Hash(void *_cacheEntry, const void *_block, uint32_t range); +}; + +typedef DoublyLinkedList > block_list; + +struct block_cache { + hash_table *hash; + fssh_mutex lock; + int fd; + fssh_off_t max_blocks; + fssh_size_t block_size; + int32_t allocated_block_count; + int32_t next_transaction_id; + cache_transaction *last_transaction; + hash_table *transaction_hash; + + block_list unused_blocks; + + bool read_only; + + block_cache(int fd, fssh_off_t numBlocks, fssh_size_t blockSize, bool readOnly); + ~block_cache(); + + fssh_status_t InitCheck(); + + void RemoveUnusedBlocks(int32_t maxAccessed = LONG_MAX, int32_t count = LONG_MAX); + void FreeBlock(cached_block *block); + cached_block *NewBlock(fssh_off_t blockNumber); + void Free(void *address); + void *Allocate(); + + static void LowMemoryHandler(void *data, int32_t level); +}; + static const int32_t kMaxBlockCount = 1024; struct cache_hook : DoublyLinkedListLinkImpl { @@ -200,14 +271,13 @@ if (transaction_hash == NULL) return; - if (benaphore_init(&lock, "block cache") < FSSH_B_OK) - return; + fssh_mutex_init(&lock, "block cache"); } block_cache::~block_cache() { - benaphore_destroy(&lock); + fssh_mutex_destroy(&lock); hash_uninit(transaction_hash); hash_uninit(hash); @@ -627,7 +697,7 @@ fssh_cache_start_transaction(void *_cache) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); if (cache->last_transaction && cache->last_transaction->open) { fssh_panic("last transaction (%d) still open!\n", @@ -653,7 +723,7 @@ fssh_cache_sync_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); fssh_status_t status = FSSH_B_ENTRY_NOT_FOUND; TRACE(("cache_sync_transaction(id %d)\n", id)); @@ -690,7 +760,7 @@ fssh_transaction_notification_hook hook, void *data) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("cache_end_transaction(id = %d)\n", id)); @@ -744,7 +814,7 @@ fssh_cache_abort_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("cache_abort_transaction(id = %ld)\n", id)); @@ -794,7 +864,7 @@ fssh_transaction_notification_hook hook, void *data) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("cache_detach_sub_transaction(id = %d)\n", id)); @@ -878,7 +948,7 @@ fssh_cache_abort_sub_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("cache_abort_sub_transaction(id = %ld)\n", id)); @@ -929,7 +999,7 @@ fssh_cache_start_sub_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("cache_start_sub_transaction(id = %d)\n", id)); @@ -985,7 +1055,7 @@ if (hook == NULL) return FSSH_B_NO_MEMORY; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL) { @@ -1008,7 +1078,7 @@ { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL) @@ -1036,7 +1106,7 @@ cached_block *block = (cached_block *)*_cookie; block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL || !transaction->open) @@ -1072,7 +1142,7 @@ fssh_cache_blocks_in_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL) @@ -1086,7 +1156,7 @@ fssh_cache_blocks_in_main_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL) @@ -1100,7 +1170,7 @@ fssh_cache_blocks_in_sub_transaction(void *_cache, int32_t id) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); cache_transaction *transaction = lookup_transaction(cache, id); if (transaction == NULL) @@ -1122,7 +1192,7 @@ if (allowWrites) fssh_block_cache_sync(cache); - BenaphoreLocker locker(&cache->lock); + fssh_mutex_lock(&cache->lock); // free all blocks @@ -1171,7 +1241,7 @@ // we will sync all dirty blocks to disk that have a completed // transaction or no transaction only - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); hash_iterator iterator; hash_open(cache->hash, &iterator); @@ -1205,7 +1275,7 @@ return FSSH_B_BAD_VALUE; } - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); for (; numBlocks > 0; numBlocks--, blockNumber++) { cached_block *block = (cached_block *)hash_lookup(cache->hash, @@ -1228,7 +1298,7 @@ fssh_block_cache_make_writable(void *_cache, fssh_off_t blockNumber, int32_t transaction) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); if (cache->read_only) fssh_panic("tried to make block writable on a read-only cache!"); @@ -1250,7 +1320,7 @@ fssh_off_t length, int32_t transaction) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("block_cache_get_writable_etc(block = %Ld, transaction = %ld)\n", blockNumber, transaction)); @@ -1276,7 +1346,7 @@ int32_t transaction) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); TRACE(("block_cache_get_empty(block = %Ld, transaction = %ld)\n", blockNumber, transaction)); @@ -1293,7 +1363,7 @@ fssh_off_t length) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); bool allocated; cached_block *block = get_cached_block(cache, blockNumber, &allocated); @@ -1341,7 +1411,7 @@ fssh_block_cache_put(void *_cache, fssh_off_t blockNumber) { block_cache *cache = (block_cache *)_cache; - BenaphoreLocker locker(&cache->lock); + MutexLocker locker(&cache->lock); put_cached_block(cache, blockNumber); } Deleted: haiku/trunk/src/tools/fs_shell/block_cache_priv.h Modified: haiku/trunk/src/tools/fs_shell/driver_settings.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/driver_settings.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/tools/fs_shell/driver_settings.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -28,20 +28,17 @@ #include #include "fssh_fcntl.h" +#include "fssh_lock.h" #include "fssh_os.h" #include "fssh_stat.h" #include "fssh_string.h" #include "fssh_unistd.h" #include "list.h" -#include "lock.h" using namespace FSShell; -#define ASSERT_LOCKED_MUTEX(lock) - - #define SETTINGS_DIRECTORY "/kernel/drivers/" #define SETTINGS_MAGIC 'DrvS' @@ -72,7 +69,7 @@ static struct list sHandles; -static mutex sLock; +static fssh_mutex sLock; // #pragma mark - private functions @@ -587,7 +584,7 @@ { settings_handle *handle = NULL; - ASSERT_LOCKED_MUTEX(&sLock); + FSSH_ASSERT_LOCKED_MUTEX(&sLock); while ((handle = (settings_handle*)list_get_next_item(&sHandles, handle)) != NULL) { if (!fssh_strcmp(handle->name, name)) @@ -603,10 +600,11 @@ fssh_status_t driver_settings_init() { - return mutex_init(&sLock, "driver settings"); + fssh_mutex_init(&sLock, "driver settings"); + return FSSH_B_OK; } -} +} // namespace FSShell // #pragma mark - public API @@ -619,13 +617,13 @@ return FSSH_B_BAD_VALUE; #if 0 - mutex_lock(&sLock); + fssh_mutex_lock(&sLock); // ToDo: as soon as "/boot" is accessible, we should start throwing away settings if (--handle->ref_count == 0) { list_remove_link(&handle->link); } else handle = NULL; - mutex_unlock(&sLock); + fssh_mutex_unlock(&sLock); #endif if (handle != NULL) @@ -645,7 +643,7 @@ return NULL; // see if we already have these settings loaded - mutex_lock(&sLock); + fssh_mutex_lock(&sLock); handle = find_driver_settings(driverName); if (handle != NULL) { handle->ref_count++; @@ -661,7 +659,7 @@ handle = NULL; } } - mutex_unlock(&sLock); + fssh_mutex_unlock(&sLock); return handle; } @@ -683,7 +681,7 @@ file = fssh_open(driverName, FSSH_O_RDONLY); if (file < FSSH_B_OK) { - mutex_unlock(&sLock); + fssh_mutex_unlock(&sLock); return NULL; } @@ -691,7 +689,7 @@ if (handle != NULL) list_add_item(&sHandles, handle); - mutex_unlock(&sLock); + fssh_mutex_unlock(&sLock); fssh_close(file); return (void *)handle; Modified: haiku/trunk/src/tools/fs_shell/fd.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/fd.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/tools/fs_shell/fd.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -1,13 +1,15 @@ -/* Operations on file descriptors - * - * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. +/* + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ +//! Operations on file descriptors + #include "fd.h" #include +#include "fssh_atomic.h" #include "fssh_fcntl.h" #include "fssh_kernel_export.h" #include "fssh_kernel_priv.h" @@ -96,7 +98,7 @@ int fd = -1; uint32_t i; - mutex_lock(&context->io_mutex); + fssh_mutex_lock(&context->io_mutex); for (i = firstIndex; i < context->table_size; i++) { if (!context->fds[i]) { @@ -114,7 +116,7 @@ fssh_atomic_add(&descriptor->open_count, 1); err: - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); return fd; } @@ -215,7 +217,7 @@ if (fd < 0) return NULL; - mutex_lock(&context->io_mutex); + fssh_mutex_lock(&context->io_mutex); if ((uint32_t)fd < context->table_size) descriptor = context->fds[fd]; @@ -228,7 +230,7 @@ inc_fd_ref_count(descriptor); } - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); return descriptor; } @@ -245,7 +247,7 @@ if (fd < 0) return NULL; - mutex_lock(&context->io_mutex); + fssh_mutex_lock(&context->io_mutex); if ((uint32_t)fd < context->table_size) descriptor = context->fds[fd]; @@ -260,7 +262,7 @@ descriptor = NULL; } - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); return descriptor; } @@ -285,9 +287,9 @@ if (status < 0) put_fd(descriptor); else { - mutex_lock(&context->io_mutex); + fssh_mutex_lock(&context->io_mutex); fd_set_close_on_exec(context, status, false); - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); } return status; @@ -315,14 +317,14 @@ // Get current I/O context and lock it context = get_current_io_context(kernel); - mutex_lock(&context->io_mutex); + fssh_mutex_lock(&context->io_mutex); // Check if the fds are valid (mutex must be locked because // the table size could be changed) if ((uint32_t)oldfd >= context->table_size || (uint32_t)newfd >= context->table_size || context->fds[oldfd] == NULL) { - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); return FSSH_B_FILE_ERROR; } @@ -342,7 +344,7 @@ fd_set_close_on_exec(context, newfd, false); - mutex_unlock(&context->io_mutex); + fssh_mutex_unlock(&context->io_mutex); // Say bye bye to the evicted fd if (evicted) { Modified: haiku/trunk/src/tools/fs_shell/file_cache.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/file_cache.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/tools/fs_shell/file_cache.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Haiku Inc. All rights reserved. + * Copyright 2004-2008, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -15,12 +15,12 @@ #include "DoublyLinkedList.h" #include "fssh_kernel_export.h" +#include "fssh_lock.h" #include "fssh_stdio.h" #include "fssh_string.h" #include "fssh_uio.h" #include "fssh_unistd.h" #include "hash.h" -#include "lock.h" #include "vfs.h" @@ -61,7 +61,7 @@ fssh_size_t bufferSize); struct file_cache_ref { - mutex lock; + fssh_mutex lock; fssh_mount_id mountID; fssh_vnode_id nodeID; void* node; @@ -87,12 +87,12 @@ vec.iov_base = (void *)buffer; vec.iov_len = bufferSize; - mutex_unlock(&ref->lock); + fssh_mutex_unlock(&ref->lock); fssh_status_t status = vfs_read_pages(ref->node, cookie, offset + pageOffset, &vec, 1, &bufferSize, false); - mutex_lock(&ref->lock); + fssh_mutex_lock(&ref->lock); return status; } @@ -106,12 +106,12 @@ vec.iov_base = (void *)buffer; vec.iov_len = bufferSize; - mutex_unlock(&ref->lock); + fssh_mutex_unlock(&ref->lock); fssh_status_t status = vfs_write_pages(ref->node, cookie, offset + pageOffset, &vec, 1, &bufferSize, false); - mutex_lock(&ref->lock); + fssh_mutex_lock(&ref->lock); return status; } @@ -258,13 +258,7 @@ // create lock char buffer[32]; fssh_snprintf(buffer, sizeof(buffer), "file cache %d:%lld", (int)mountID, vnodeID); - error = mutex_init(&ref->lock, buffer); - if (error != FSSH_B_OK) { - fssh_dprintf("file_cache_create(): Failed to init mutex: %s\n", - fssh_strerror(error)); - delete ref; - return NULL; - } + fssh_mutex_init(&ref->lock, buffer); return ref; } @@ -280,8 +274,8 @@ TRACE(("file_cache_delete(ref = %p)\n", ref)); - mutex_lock(&ref->lock); - mutex_destroy(&ref->lock); + fssh_mutex_lock(&ref->lock); + fssh_mutex_destroy(&ref->lock); delete ref; } @@ -297,9 +291,9 @@ if (ref == NULL) return FSSH_B_OK; - mutex_lock(&ref->lock); + fssh_mutex_lock(&ref->lock); ref->virtual_size = size; - mutex_unlock(&ref->lock); + fssh_mutex_unlock(&ref->lock); return FSSH_B_OK; } Modified: haiku/trunk/src/tools/fs_shell/lock.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 12:53:53 UTC (rev 26295) +++ haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 15:19:19 UTC (rev 26296) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -8,16 +8,16 @@ /* Mutex and recursive_lock code */ -#include "lock.h" +#include "fssh_lock.h" #include "fssh_kernel_export.h" -namespace FSShell { +#define FSSH_RW_MAX_READERS 100000 -int32_t -recursive_lock_get_recursion(recursive_lock *lock) +extern "C" int32_t +fssh_recursive_lock_get_recursion(fssh_recursive_lock *lock) { if (lock->holder == fssh_find_thread(NULL)) return lock->recursion; @@ -26,11 +26,11 @@ } -fssh_status_t -recursive_lock_init(recursive_lock *lock, const char *name) +extern "C" void +fssh_recursive_lock_init(fssh_recursive_lock *lock, const char *name) { if (lock == NULL) - return FSSH_B_BAD_VALUE; + return; if (name == NULL) name = "recursive lock"; @@ -38,16 +38,13 @@ lock->holder = -1; lock->recursion = 0; lock->sem = fssh_create_sem(1, name); - - if (lock->sem >= FSSH_B_OK) - return FSSH_B_OK; - - return lock->sem; + if (lock->sem < FSSH_B_OK) + fssh_panic("could not create recursive lock"); } -void -recursive_lock_destroy(recursive_lock *lock) +extern "C" void +fssh_recursive_lock_destroy(fssh_recursive_lock *lock) { if (lock == NULL) return; @@ -57,8 +54,8 @@ } -fssh_status_t -recursive_lock_lock(recursive_lock *lock) +extern "C" fssh_status_t +fssh_recursive_lock_lock(fssh_recursive_lock *lock) { fssh_thread_id thread = fssh_find_thread(NULL); @@ -74,8 +71,8 @@ } -void -recursive_lock_unlock(recursive_lock *lock) +extern "C" void +fssh_recursive_lock_unlock(fssh_recursive_lock *lock) { if (fssh_find_thread(NULL) != lock->holder) fssh_panic("recursive_lock %p unlocked by non-holder thread!\n", lock); @@ -90,11 +87,11 @@ // #pragma mark - -fssh_status_t -mutex_init(mutex *m, const char *name) +extern "C" void +fssh_mutex_init(fssh_mutex *m, const char *name) { if (m == NULL) - return FSSH_EINVAL; + return; if (name == NULL) name = "mutex_sem"; @@ -102,15 +99,13 @@ m->holder = -1; m->sem = fssh_create_sem(1, name); - if (m->sem >= FSSH_B_OK) - return FSSH_B_OK; - - return m->sem; + if (m->sem < FSSH_B_OK) + fssh_panic("could not create mutex"); } -void -mutex_destroy(mutex *mutex) +extern "C" void +fssh_mutex_destroy(fssh_mutex *mutex) { if (mutex == NULL) return; @@ -123,8 +118,8 @@ } -fssh_status_t -mutex_lock(mutex *mutex) +extern "C" fssh_status_t +fssh_mutex_lock(fssh_mutex *mutex) { fssh_thread_id me = fssh_find_thread(NULL); fssh_status_t status; @@ -141,8 +136,8 @@ } -void -mutex_unlock(mutex *mutex) +extern "C" void +fssh_mutex_unlock(fssh_mutex *mutex) { fssh_thread_id me = fssh_find_thread(NULL); @@ -159,51 +154,23 @@ // #pragma mark - -fssh_status_t -benaphore_init(benaphore *ben, const char *name) +extern "C" void +fssh_rw_lock_init(fssh_rw_lock *lock, const char *name) [... truncated: 1026 lines follow ...] From korli at users.berlios.de Mon Jul 7 17:34:35 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Mon, 7 Jul 2008 17:34:35 +0200 Subject: [Haiku-commits] r26292 - haiku/trunk/src/system/kernel/fs In-Reply-To: <21739172355-BeMail@zon> References: <21739172355-BeMail@zon> Message-ID: 2008/7/7 Axel D?rfler : > "J?r?me Duval" wrote: >> 2008/7/7 axeld at BerliOS : >> > * file_read() and file_write() will now return B_IS_A_DIRECTORY so >> > that not >> > every file system has to care about that particular error code. >> From the spec, read() and write() for directories could actually be >> supported by a file system. What do you think ? >> >> [...] >> [EISDIR] >> The fildes argument refers to a directory and the implementation >> does not allow the directory to be read using read(), pread() or >> readv(). > > I don't think there is a useful purpose for this, but if we someday > stumble upon it, we can still change the VFS back. Agreed :) Bye, J?r?me From axeld at mail.berlios.de Mon Jul 7 18:17:35 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 18:17:35 +0200 Subject: [Haiku-commits] r26297 - in haiku/trunk: headers/private/fs_shell headers/private/kernel src/system/kernel src/tools/fs_shell Message-ID: <200807071617.m67GHZiS001670@sheep.berlios.de> Author: axeld Date: 2008-07-07 18:17:34 +0200 (Mon, 07 Jul 2008) New Revision: 26297 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26297&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/headers/private/fs_shell/fssh_lock.h haiku/trunk/headers/private/kernel/lock.h haiku/trunk/src/system/kernel/lock.cpp haiku/trunk/src/tools/fs_shell/lock.cpp Log: * Added a recursive_lock_trylock() function. Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-07 15:19:19 UTC (rev 26296) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-07 16:17:34 UTC (rev 26297) @@ -975,6 +975,7 @@ #define recursive_lock_init_etc fssh_recursive_lock_init_etc #define recursive_lock_destroy fssh_recursive_lock_destroy #define recursive_lock_lock fssh_recursive_lock_lock +#define recursive_lock_trylock fssh_recursive_lock_trylock #define recursive_lock_unlock fssh_recursive_lock_unlock #define recursive_lock_get_recursion fssh_recursive_lock_get_recursion Modified: haiku/trunk/headers/private/fs_shell/fssh_lock.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 15:19:19 UTC (rev 26296) +++ haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 16:17:34 UTC (rev 26297) @@ -55,6 +55,7 @@ uint32_t flags); extern void fssh_recursive_lock_destroy(fssh_recursive_lock *lock); extern fssh_status_t fssh_recursive_lock_lock(fssh_recursive_lock *lock); +extern fssh_status_t fssh_recursive_lock_trylock(fssh_recursive_lock *lock); extern void fssh_recursive_lock_unlock(fssh_recursive_lock *lock); extern int32_t fssh_recursive_lock_get_recursion(fssh_recursive_lock *lock); Modified: haiku/trunk/headers/private/kernel/lock.h =================================================================== --- haiku/trunk/headers/private/kernel/lock.h 2008-07-07 15:19:19 UTC (rev 26296) +++ haiku/trunk/headers/private/kernel/lock.h 2008-07-07 16:17:34 UTC (rev 26297) @@ -84,6 +84,7 @@ uint32 flags); extern void recursive_lock_destroy(recursive_lock *lock); extern status_t recursive_lock_lock(recursive_lock *lock); +extern status_t recursive_lock_trylock(recursive_lock *lock); extern void recursive_lock_unlock(recursive_lock *lock); extern int32 recursive_lock_get_recursion(recursive_lock *lock); Modified: haiku/trunk/src/system/kernel/lock.cpp =================================================================== --- haiku/trunk/src/system/kernel/lock.cpp 2008-07-07 15:19:19 UTC (rev 26296) +++ haiku/trunk/src/system/kernel/lock.cpp 2008-07-07 16:17:34 UTC (rev 26297) @@ -92,9 +92,10 @@ { thread_id thread = thread_get_current_thread_id(); - if (!kernel_startup && !are_interrupts_enabled()) + if (!kernel_startup && !are_interrupts_enabled()) { panic("recursive_lock_lock: called with interrupts disabled for lock " "%p (\"%s\")\n", lock, lock->lock.name); + } if (thread != RECURSIVE_LOCK_HOLDER(lock)) { mutex_lock(&lock->lock); @@ -108,6 +109,30 @@ } +status_t +recursive_lock_trylock(recursive_lock *lock) +{ + thread_id thread = thread_get_current_thread_id(); + + if (!kernel_startup && !are_interrupts_enabled()) + panic("recursive_lock_lock: called with interrupts disabled for lock " + "%p (\"%s\")\n", lock, lock->lock.name); + + if (thread != RECURSIVE_LOCK_HOLDER(lock)) { + status_t status = mutex_trylock(&lock->lock); + if (status != B_OK) + return status; + +#ifndef KDEBUG + lock->holder = thread; +#endif + } + + lock->recursion++; + return B_OK; +} + + void recursive_lock_unlock(recursive_lock *lock) { Modified: haiku/trunk/src/tools/fs_shell/lock.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 15:19:19 UTC (rev 26296) +++ haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 16:17:34 UTC (rev 26297) @@ -71,6 +71,24 @@ } +extern "C" fssh_status_t +fssh_recursive_lock_trylock(fssh_recursive_lock *lock) +{ + fssh_thread_id thread = fssh_find_thread(NULL); + + if (thread != lock->holder) { + fssh_status_t status = fssh_acquire_sem_etc(lock->sem, 1, + FSSH_B_RELATIVE_TIMEOUT, 0); + if (status < FSSH_B_OK) + return status; + + lock->holder = thread; + } + lock->recursion++; + return FSSH_B_OK; +} + + extern "C" void fssh_recursive_lock_unlock(fssh_recursive_lock *lock) { From umccullough at gmail.com Mon Jul 7 18:11:33 2008 From: umccullough at gmail.com (Urias McCullough) Date: Mon, 7 Jul 2008 09:11:33 -0700 Subject: [Haiku-commits] r26296 - in haiku/trunk: headers/private/fs_shell src/system/kernel/fs src/tools/fs_shell In-Reply-To: <200807071519.m67FJLPo026645@sheep.berlios.de> References: <200807071519.m67FJLPo026645@sheep.berlios.de> Message-ID: <1e80d8750807070911g44de1a73v8566a3b86a07b8c2@mail.gmail.com> 2008/7/7 axeld at BerliOS : > Author: axeld > Date: 2008-07-07 17:19:19 +0200 (Mon, 07 Jul 2008) > New Revision: 26296 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26296&view=rev > > Added: > haiku/trunk/headers/private/fs_shell/fssh_lock.h > Removed: > haiku/trunk/src/tools/fs_shell/block_cache_priv.h > haiku/trunk/src/tools/fs_shell/lock.h > Modified: > haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h > haiku/trunk/src/system/kernel/fs/rootfs.cpp > haiku/trunk/src/tools/fs_shell/block_cache.cpp > haiku/trunk/src/tools/fs_shell/driver_settings.cpp > haiku/trunk/src/tools/fs_shell/fd.cpp > haiku/trunk/src/tools/fs_shell/file_cache.cpp > haiku/trunk/src/tools/fs_shell/lock.cpp > haiku/trunk/src/tools/fs_shell/module.cpp > haiku/trunk/src/tools/fs_shell/vfs.cpp > haiku/trunk/src/tools/fs_shell/vfs.h > Log: > * Made the private kernel locking primitives available to file systems as well. > * Applied Korli's mutex_unlock() fix to block_cache.cpp. > * Removed block_cache_priv.h, as it's no longer needed (moved its definitions > into block_cache.cpp, as in the kernel file). I'm guessing this is the change that is causing the following build problem: C++ generated/objects/linux/x86/release/tools/bfs_shell/bfs_disk_system.o In file included from src/add-ons/kernel/file_systems/bfs/BlockAllocator.h:9, from src/add-ons/kernel/file_systems/bfs/Volume.h:12, from src/add-ons/kernel/file_systems/bfs/bfs_disk_system.cpp:9: src/add-ons/kernel/file_systems/bfs/Lock.h:197: error: using typedef-name 'FSShell::RecursiveLocker' after 'class' headers/private/fs_shell/fssh_lock.h:115: error: 'FSShell::RecursiveLocker' has a previous declaration here cc -c "src/add-ons/kernel/file_systems/bfs/bfs_disk_system.cpp" -O1 -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare -Wno-multichar -DBFS_SHELL -Wall -Wno-multichar -fno-rtti -D_ZETA_USING_DEPRECATED_API_=1 -D_ZETA_TS_FIND_DIR_=1 -DARCH_x86 -D_NO_INLINE_ASM -D__INTEL__ -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DHAIKU_HOST_PLATFORM_LINUX -iquote build/user_config_headers -iquote build/config_headers -iquote src/tools/bfs_shell -iquote generated/objects/common/tools/bfs_shell -iquote generated/objects/linux/x86/common/tools/bfs_shell -iquote generated/objects/haiku/x86/common/tools/bfs_shell -iquote src/add-ons/kernel/file_systems/bfs -I headers/private/fs_shell -I headers/build/host/linux -o "generated/objects/linux/x86/release/tools/bfs_shell/bfs_disk_system.o" ; ...failed C++ generated/objects/linux/x86/release/tools/bfs_shell/bfs_disk_system.o ... From axeld at mail.berlios.de Mon Jul 7 18:21:03 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 18:21:03 +0200 Subject: [Haiku-commits] r26298 - in haiku/trunk/src: add-ons/disk_systems/bfs add-ons/kernel/file_systems/bfs system/boot/loader/file_systems/bfs Message-ID: <200807071621.m67GL3aJ002212@sheep.berlios.de> Author: axeld Date: 2008-07-07 18:21:00 +0200 (Mon, 07 Jul 2008) New Revision: 26298 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26298&view=rev Modified: haiku/trunk/src/add-ons/disk_systems/bfs/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Jamfile haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Query.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/system_dependencies.h haiku/trunk/src/system/boot/loader/file_systems/bfs/Jamfile Log: * Removed the home-brewn locking classes in BFS besides the read/write lock (for now). * Inode::fSmallDataLock is now a recursive_lock, Journal::fLock is now a recursive_lock, too, Journal::fEntriesLock is now a mutex, as is BPlusTree::fIteratorLock. Modified: haiku/trunk/src/add-ons/disk_systems/bfs/Jamfile =================================================================== --- haiku/trunk/src/add-ons/disk_systems/bfs/Jamfile 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/disk_systems/bfs/Jamfile 2008-07-07 16:21:00 UTC (rev 26298) @@ -1,8 +1,7 @@ SubDir HAIKU_TOP src add-ons disk_systems bfs ; -UsePrivateHeaders kernel ; -UsePrivateHeaders shared ; -UsePrivateHeaders storage ; +UsePrivateKernelHeaders ; +UsePrivateHeaders shared storage ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems bfs ] ; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp 2008-07-07 16:21:00 UTC (rev 26298) @@ -79,13 +79,13 @@ fName = name; // try to find it in the small data region - if (fInode->SmallDataLock().Lock() == B_OK) { + if (recursive_lock_lock(&fInode->SmallDataLock()) == B_OK) { fNodeGetter.SetToNode(fInode); fSmall = fInode->FindSmallData(fNodeGetter.Node(), (const char *)name); if (fSmall != NULL) return B_OK; - fInode->SmallDataLock().Unlock(); + recursive_lock_unlock(&fInode->SmallDataLock()); fNodeGetter.Unset(); } @@ -98,7 +98,7 @@ Attribute::Put() { if (fSmall != NULL) { - fInode->SmallDataLock().Unlock(); + recursive_lock_unlock(&fInode->SmallDataLock()); fNodeGetter.Unset(); fSmall = NULL; } @@ -195,7 +195,7 @@ if (fSmall == NULL && fAttribute == NULL) return B_NO_INIT; - // ToDo: move small_data logic from Inode::ReadAttribute() over to here! + // TODO: move small_data logic from Inode::ReadAttribute() over to here! return fInode->ReadAttribute(cookie->name, 0, pos, buffer, _length); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2008-07-07 16:21:00 UTC (rev 26298) @@ -341,6 +341,7 @@ fHeader(NULL), fCachedHeader(this) { + mutex_init(&fIteratorLock, "bfs b+tree iterator"); SetTo(transaction, stream); } @@ -351,6 +352,7 @@ fHeader(NULL), fCachedHeader(this) { + mutex_init(&fIteratorLock, "bfs b+tree iterator"); SetTo(stream); } @@ -364,6 +366,7 @@ fAllowDuplicates(true), fStatus(B_NO_INIT) { + mutex_init(&fIteratorLock, "bfs b+tree iterator"); } @@ -372,14 +375,13 @@ // if there are any TreeIterators left, we need to stop them // (can happen when the tree's inode gets deleted while // traversing the tree - a TreeIterator doesn't lock the inode) - if (fIteratorLock.Lock() < B_OK) - return; + mutex_lock(&fIteratorLock); TreeIterator *iterator = NULL; while ((iterator = fIterators.Next(iterator)) != NULL) iterator->Stop(); - fIteratorLock.Unlock(); + mutex_destroy(&fIteratorLock); } @@ -565,38 +567,27 @@ // Although every iterator which is affected by this update currently // waits on a semaphore, other iterators could be added/removed at // any time, so we need to protect this loop - if (fIteratorLock.Lock() < B_OK) - return; + MutexLocker _(fIteratorLock); TreeIterator *iterator = NULL; while ((iterator = fIterators.Next(iterator)) != NULL) iterator->Update(offset, nextOffset, keyIndex, splitAt, change); - - fIteratorLock.Unlock(); } void BPlusTree::_AddIterator(TreeIterator *iterator) { - if (fIteratorLock.Lock() < B_OK) - return; - + MutexLocker _(fIteratorLock); fIterators.Add(iterator); - - fIteratorLock.Unlock(); } void BPlusTree::_RemoveIterator(TreeIterator *iterator) { - if (fIteratorLock.Lock() < B_OK) - return; - + MutexLocker _(fIteratorLock); fIterators.Remove(iterator); - - fIteratorLock.Unlock(); } @@ -2139,7 +2130,8 @@ void -TreeIterator::Update(off_t offset, off_t nextOffset, uint16 keyIndex, uint16 splitAt, int8 change) +TreeIterator::Update(off_t offset, off_t nextOffset, uint16 keyIndex, + uint16 splitAt, int8 change) { if (offset != fCurrentNodeOffset) return; @@ -2158,7 +2150,7 @@ if (keyIndex <= fCurrentKey) fCurrentKey += change; - // ToDo: duplicate handling! + // TODO: duplicate handling! } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.h 2008-07-07 16:21:00 UTC (rev 26298) @@ -273,7 +273,7 @@ int32 fNodeSize; bool fAllowDuplicates; status_t fStatus; - SimpleLock fIteratorLock; + mutex fIteratorLock; Chain fIterators; }; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-07 16:21:00 UTC (rev 26298) @@ -441,15 +441,16 @@ BlockAllocator::BlockAllocator(Volume *volume) : fVolume(volume), - fLock("bfs allocator"), fGroups(NULL), fCheckBitmap(NULL) { + mutex_init(&fLock, "bfs allocator"); } BlockAllocator::~BlockAllocator() { + mutex_destroy(&fLock); delete[] fGroups; } @@ -457,9 +458,6 @@ status_t BlockAllocator::Initialize(bool full) { - if (fLock.InitCheck() < B_OK) - return B_ERROR; - fNumGroups = fVolume->AllocationGroups(); fBlocksPerGroup = fVolume->SuperBlock().BlocksPerAllocationGroup(); fGroups = new AllocationGroup[fNumGroups]; @@ -469,8 +467,8 @@ if (!full) return B_OK; - fLock.Lock(); - // the lock will be released by the initialize() function + mutex_lock(&fLock); + // the lock will be released by the _Initialize() method thread_id id = spawn_kernel_thread((thread_func)BlockAllocator::_Initialize, "bfs block allocator", B_LOW_PRIORITY, (void *)this); @@ -547,7 +545,7 @@ uint32 *buffer = (uint32 *)malloc(blocks << blockShift); if (buffer == NULL) { - allocator->fLock.Unlock(); + mutex_unlock(&allocator->fLock); RETURN_ERROR(B_NO_MEMORY); } @@ -621,7 +619,7 @@ volume->SuperBlock().used_blocks = HOST_ENDIAN_TO_BFS_INT64(usedBlocks); } - allocator->fLock.Unlock(); + mutex_unlock(&allocator->fLock); return B_OK; } @@ -636,7 +634,7 @@ FUNCTION_START(("group = %ld, start = %u, maximum = %u, minimum = %u\n", group, start, maximum, minimum)); AllocationBlock cached(fVolume); - Locker lock(fLock); + MutexLocker lock(fLock); // The first scan through all allocation groups will look for the // wanted maximum of blocks, the second scan will just look to @@ -821,7 +819,7 @@ status_t BlockAllocator::Free(Transaction &transaction, block_run run) { - Locker lock(fLock); + MutexLocker lock(fLock); int32 group = run.AllocationGroup(); uint16 start = run.Start(); @@ -896,14 +894,14 @@ if (!_IsValidCheckControl(control)) return B_BAD_VALUE; - status_t status = fLock.Lock(); + status_t status = mutex_lock(&fLock); if (status < B_OK) return status; size_t size = BitmapSize(); fCheckBitmap = (uint32 *)malloc(size); if (fCheckBitmap == NULL) { - fLock.Unlock(); + mutex_unlock(&fLock); return B_NO_MEMORY; } @@ -911,7 +909,7 @@ if (cookie == NULL) { free(fCheckBitmap); fCheckBitmap = NULL; - fLock.Unlock(); + mutex_unlock(&fLock); return B_NO_MEMORY; } @@ -1013,7 +1011,7 @@ fCheckBitmap = NULL; fCheckCookie = NULL; delete cookie; - fLock.Unlock(); + mutex_unlock(&fLock); return B_OK; } @@ -1113,7 +1111,7 @@ // check if the inode's name is the same as in the b+tree if (inode->IsRegularNode()) { - SimpleLocker locker(inode->SmallDataLock()); + RecursiveLocker locker(inode->SmallDataLock()); NodeGetter node(fVolume, inode); const char *localName = inode->Name(node.Node()); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h 2008-07-07 16:21:00 UTC (rev 26298) @@ -6,7 +6,7 @@ #define BLOCK_ALLOCATOR_H -#include "Lock.h" +#include "system_dependencies.h" class AllocationGroup; @@ -57,7 +57,7 @@ static status_t _Initialize(BlockAllocator *); Volume *fVolume; - Semaphore fLock; + mutex fLock; AllocationGroup *fGroups; int32 fNumGroups; uint32 fBlocksPerGroup; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-07-07 16:21:00 UTC (rev 26298) @@ -330,6 +330,8 @@ (int)BlockRun().AllocationGroup(), BlockRun().Start()); fLock.Initialize(lockName); + recursive_lock_init(&fSmallDataLock, "bfs inode small data"); + // these two will help to maintain the indices fOldSize = Size(); fOldLastModified = LastModified(); @@ -361,6 +363,8 @@ (int)run.AllocationGroup(), run.Start()); fLock.Initialize(lockName); + recursive_lock_init(&fSmallDataLock, "bfs inode small data"); + NodeGetter node(volume, transaction, this, true); memset(&fNode, 0, sizeof(bfs_inode)); @@ -482,24 +486,16 @@ void Inode::_AddIterator(AttributeIterator *iterator) { - if (fSmallDataLock.Lock() < B_OK) - return; - + RecursiveLocker _(fSmallDataLock); fIterators.Add(iterator); - - fSmallDataLock.Unlock(); } void Inode::_RemoveIterator(AttributeIterator *iterator) { - if (fSmallDataLock.Lock() < B_OK) - return; - + RecursiveLocker _(fSmallDataLock); fIterators.Remove(iterator); - - fSmallDataLock.Unlock(); } @@ -511,7 +507,7 @@ Inode::_MakeSpaceForSmallData(Transaction &transaction, bfs_inode *node, const char *name, int32 bytes) { - ASSERT(fSmallDataLock.IsLocked()); + ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); while (bytes > 0) { small_data *item = node->SmallDataStart(), *max = NULL; @@ -575,7 +571,7 @@ status_t Inode::_RemoveSmallData(bfs_inode *node, small_data *item, int32 index) { - ASSERT(fSmallDataLock.IsLocked()); + ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); small_data *next = item->Next(); if (!next->IsLast(node)) { @@ -617,7 +613,7 @@ return B_BAD_VALUE; bfs_inode *node = nodeGetter.WritableNode(); - SimpleLocker locker(fSmallDataLock); + RecursiveLocker locker(fSmallDataLock); // search for the small_data item @@ -668,7 +664,7 @@ return B_DEVICE_FULL; nodeGetter.MakeWritable(transaction); - SimpleLocker locker(fSmallDataLock); + RecursiveLocker locker(fSmallDataLock); // Find the last item or one with the same name we have to add small_data *item = node->SmallDataStart(); @@ -809,7 +805,7 @@ if (node == NULL) RETURN_ERROR(B_BAD_VALUE); - ASSERT(fSmallDataLock.IsLocked()); + ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); small_data *data = *_smallData; @@ -836,7 +832,7 @@ small_data * Inode::FindSmallData(const bfs_inode *node, const char *name) const { - ASSERT(fSmallDataLock.IsLocked()); + ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); small_data *smallData = NULL; while (_GetNextSmallData(const_cast(node), &smallData) @@ -855,7 +851,7 @@ const char * Inode::Name(const bfs_inode *node) const { - ASSERT(fSmallDataLock.IsLocked()); + ASSERT_LOCKED_RECURSIVE(&fSmallDataLock); small_data *smallData = NULL; while (_GetNextSmallData((bfs_inode *)node, &smallData) == B_OK) { @@ -874,7 +870,7 @@ Inode::GetName(char *buffer, size_t size) const { NodeGetter node(fVolume, this); - SimpleLocker locker(fSmallDataLock); + RecursiveLocker locker(fSmallDataLock); const char *name = Name(node.Node()); if (name == NULL) @@ -966,7 +962,7 @@ // search in the small_data section (which has to be locked first) { NodeGetter node(fVolume, this); - SimpleLocker locker(fSmallDataLock); + RecursiveLocker locker(fSmallDataLock); small_data *smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { @@ -1025,7 +1021,7 @@ if (GetAttribute(name, &attribute) < B_OK) { // save the old attribute data NodeGetter node(fVolume, transaction, this); - fSmallDataLock.Lock(); + recursive_lock_lock(&fSmallDataLock); small_data *smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { @@ -1036,7 +1032,7 @@ memcpy(oldData = oldBuffer, smallData->Data(), oldLength); } } - fSmallDataLock.Unlock(); + recursive_lock_unlock(&fSmallDataLock); // if the attribute doesn't exist yet (as a file), try to put it in the // small_data section first - if that fails (due to insufficent space), @@ -1128,7 +1124,7 @@ // update index for attributes in the small_data section { - fSmallDataLock.Lock(); + RecursiveLocker _(fSmallDataLock); small_data *smallData = FindSmallData(node.Node(), name); if (smallData != NULL) { @@ -1138,7 +1134,6 @@ index.Update(transaction, name, smallData->Type(), smallData->Data(), length, NULL, 0, this); } - fSmallDataLock.Unlock(); } status_t status = _RemoveSmallData(transaction, node, name); @@ -2561,7 +2556,7 @@ const bfs_inode *node = nodeGetter.Node(); const small_data *item = ((bfs_inode *)node)->SmallDataStart(); - fInode->SmallDataLock().Lock(); + RecursiveLocker _(&fInode->SmallDataLock()); int32 i = 0; for (;;item = item->Next()) { @@ -2589,8 +2584,6 @@ fCurrentSmallData = -1; } - fInode->SmallDataLock().Unlock(); - if (fCurrentSmallData != -1) return B_OK; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-07-07 16:21:00 UTC (rev 26298) @@ -46,7 +46,7 @@ off_t BlockNumber() const { return fVolume->VnodeToBlock(fID); } ReadWriteLock &Lock() { return fLock; } - SimpleLock &SmallDataLock() { return fSmallDataLock; } + recursive_lock &SmallDataLock() { return fSmallDataLock; } status_t WriteBack(Transaction &transaction); bool IsContainer() const @@ -207,7 +207,7 @@ // we need those values to ensure we will remove // the correct keys from the indices - mutable SimpleLock fSmallDataLock; + mutable recursive_lock fSmallDataLock; Chain fIterators; }; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Jamfile 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Jamfile 2008-07-07 16:21:00 UTC (rev 26298) @@ -24,10 +24,9 @@ SubDirC++Flags $(defines) -Wall -Wno-multichar ; } -UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateKernelHeaders ; UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; -UsePrivateHeaders [ FDirName shared ] ; -UsePrivateHeaders [ FDirName storage ] ; +UsePrivateHeaders shared storage ; KernelAddon bfs : bfs_disk_system.cpp Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.cpp 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.cpp 2008-07-07 16:21:00 UTC (rev 26298) @@ -395,7 +395,6 @@ Journal::Journal(Volume *volume) : fVolume(volume), - fLock("bfs journal"), fOwner(NULL), fLogSize(volume->Log().Length()), fMaxTransactionSize(fLogSize / 2 - 5), @@ -403,19 +402,24 @@ fUnwrittenTransactions(0), fHasSubtransaction(false) { + recursive_lock_init(&fLock, "bfs journal"); + mutex_init(&fEntriesLock, "bfs journal entries"); } Journal::~Journal() { FlushLogAndBlocks(); + + recursive_lock_destroy(&fLock); + mutex_destroy(&fEntriesLock); } status_t Journal::InitCheck() { - return fLock.InitCheck(); + return B_OK; } @@ -605,7 +609,7 @@ // Set log_start pointer if possible... - journal->fEntriesLock.Lock(); + mutex_lock(&journal->fEntriesLock); if (logEntry == journal->fEntries.First()) { LogEntry *next = journal->fEntries.GetNext(logEntry); @@ -624,7 +628,7 @@ journal->fUsed -= logEntry->Length(); journal->fEntries.Remove(logEntry); - journal->fEntriesLock.Unlock(); + mutex_unlock(&journal->fEntriesLock); delete logEntry; @@ -839,10 +843,10 @@ // at this point, we can finally end the transaction - we're in // a guaranteed valid state - fEntriesLock.Lock(); + mutex_lock(&fEntriesLock); fEntries.Add(logEntry); fUsed += logEntry->Length(); - fEntriesLock.Unlock(); + mutex_unlock(&fEntriesLock); if (detached) { fTransactionID = cache_detach_sub_transaction(fVolume->BlockCache(), @@ -864,13 +868,14 @@ status_t Journal::_FlushLog(bool canWait, bool flushBlocks) { - status_t status = canWait ? fLock.Lock() : fLock.LockWithTimeout(0); + status_t status = canWait ? recursive_lock_lock(&fLock) + : recursive_lock_trylock(&fLock); if (status != B_OK) return status; - if (fLock.OwnerCount() > 1) { + if (recursive_lock_get_recursion(&fLock) > 1) { // whoa, FlushLogAndBlocks() was called from inside a transaction - fLock.Unlock(); + recursive_lock_unlock(&fLock); return B_OK; } @@ -885,7 +890,7 @@ if (flushBlocks) status = fVolume->FlushDevice(); - fLock.Unlock(); + recursive_lock_unlock(&fLock); return status; } @@ -903,11 +908,11 @@ status_t Journal::Lock(Transaction *owner) { - status_t status = fLock.Lock(); + status_t status = recursive_lock_lock(&fLock); if (status != B_OK) return status; - if (fLock.OwnerCount() > 1) { + if (recursive_lock_get_recursion(&fLock) > 1) { // we'll just use the current transaction again return B_OK; } @@ -929,7 +934,7 @@ fTransactionID = cache_start_transaction(fVolume->BlockCache()); if (fTransactionID < B_OK) { - fLock.Unlock(); + recursive_lock_unlock(&fLock); return fTransactionID; } @@ -943,7 +948,7 @@ void Journal::Unlock(Transaction *owner, bool success) { - if (fLock.OwnerCount() == 1) { + if (recursive_lock_get_recursion(&fLock) == 1) { // we only end the transaction if we would really unlock it // ToDo: what about failing transactions that do not unlock? _TransactionDone(success); @@ -952,7 +957,7 @@ fOwner = NULL; } - fLock.Unlock(); + recursive_lock_unlock(&fLock); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h 2008-07-07 16:21:00 UTC (rev 26298) @@ -14,6 +14,7 @@ #include "Volume.h" #include "Chain.h" +#include "Lock.h" #include "Utility.h" @@ -69,11 +70,11 @@ void *_journal); Volume *fVolume; - RecursiveLock fLock; + recursive_lock fLock; Transaction *fOwner; uint32 fLogSize, fMaxTransactionSize, fUsed; int32 fUnwrittenTransactions; - SimpleLock fEntriesLock; + mutex fEntriesLock; LogEntryList fEntries; bigtime_t fTimestamp; int32 fTransactionID; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h 2008-07-07 16:17:34 UTC (rev 26297) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h 2008-07-07 16:21:00 UTC (rev 26298) @@ -26,202 +26,8 @@ # error implement recursive write locking first #endif -class Semaphore { - public: - Semaphore(const char *name) - : -#ifdef USE_BENAPHORE - fSemaphore(create_sem(0, name)), - fCount(1) -#else - fSemaphore(create_sem(1, name)) -#endif - { - } +// #pragma mark - Many Reader/Single Writer Lock - ~Semaphore() - { - delete_sem(fSemaphore); - } - - status_t InitCheck() - { - if (fSemaphore < B_OK) - return fSemaphore; - - return B_OK; - } - - status_t Lock() - { -#ifdef USE_BENAPHORE - if (atomic_add(&fCount, -1) <= 0) -#endif - return acquire_sem(fSemaphore); -#ifdef USE_BENAPHORE - return B_OK; -#endif - } - - status_t Unlock() - { -#ifdef USE_BENAPHORE - if (atomic_add(&fCount, 1) < 0) -#endif - return release_sem(fSemaphore); -#ifdef USE_BENAPHORE - return B_OK; -#endif - } - - private: - sem_id fSemaphore; -#ifdef USE_BENAPHORE - vint32 fCount; -#endif -}; - -// a convenience class to lock a Semaphore object - -class Locker { - public: - Locker(Semaphore &lock) - : fLock(lock) - { - fStatus = lock.Lock(); - ASSERT(fStatus == B_OK); - } - - ~Locker() - { - if (fStatus == B_OK) - fLock.Unlock(); - } - - status_t Status() const - { - return fStatus; - } - - private: - Semaphore &fLock; - status_t fStatus; -}; - - -// #pragma mark - Recursive Lock - -class RecursiveLock { - public: - RecursiveLock(const char *name) - : -#ifdef USE_BENAPHORE - fSemaphore(create_sem(0, name)), - fCount(1), -#else - fSemaphore(create_sem(1, name)), -#endif - fOwner(-1) - { - } - - status_t InitCheck() const - { - if (fSemaphore < B_OK) - return fSemaphore; - - return B_OK; - } - - status_t LockWithTimeout(bigtime_t timeout) - { - thread_id thread = find_thread(NULL); - if (thread == fOwner) { - fOwnerCount++; - return B_OK; - } - - status_t status; -#ifdef USE_BENAPHORE - if (atomic_add(&fCount, -1) > 0) - status = B_OK; - else -#endif - status = acquire_sem_etc(fSemaphore, 1, B_RELATIVE_TIMEOUT, timeout); - - if (status == B_OK) { - fOwner = thread; - fOwnerCount = 1; - } - - return status; - } - - status_t Lock() - { - return LockWithTimeout(B_INFINITE_TIMEOUT); - } - - status_t Unlock() - { - thread_id thread = find_thread(NULL); - if (thread != fOwner) { - panic("RecursiveLock unlocked by %d, owned by %d\n", (int)thread, (int)fOwner); - } - - if (--fOwnerCount == 0) { - fOwner = -1; -#ifdef USE_BENAPHORE - if (atomic_add(&fCount, 1) < 0) -#endif - return release_sem(fSemaphore); - } - - return B_OK; - } - - thread_id Owner() const { return fOwner; } - int32 OwnerCount() const { return fOwnerCount; } - - private: - sem_id fSemaphore; -#ifdef USE_BENAPHORE - vint32 fCount; -#endif - thread_id fOwner; - int32 fOwnerCount; -}; - -// a convenience class to lock an RecursiveLock object - -class RecursiveLocker { - public: - RecursiveLocker(RecursiveLock &lock) - : fLock(lock) - { - fStatus = lock.Lock(); - ASSERT(fStatus == B_OK); - } - - ~RecursiveLocker() - { - if (fStatus == B_OK) - fLock.Unlock(); - } - - status_t Status() const - { - return fStatus; - } - - private: - RecursiveLock &fLock; - status_t fStatus; -}; - - -//**** Many Reader/Single Writer Lock - // This is a "fast" implementation of a single writer/many reader // locking scheme. It's fast because it uses the benaphore idea // to do lazy semaphore locking - in most cases it will only have @@ -523,78 +329,4 @@ status_t fStatus; }; - -// A simple locking structure that doesn't use a semaphore - it's useful -// if you have to protect critical parts with a short runtime. -// It also allows to nest several locks for the same thread. - -class SimpleLock { - public: - SimpleLock() - : - fHolder(-1), - fCount(0) - { - } - - status_t Lock(bigtime_t time = 500) - { - int32 thisThread = find_thread(NULL); - int32 current; - while (1) { - /*if (fHolder == -1) { - current = fHolder; - fHolder = thisThread; - }*/ - current = atomic_test_and_set(&fHolder, thisThread, -1); - if (current == -1) - break; - if (current == thisThread) - break; - - snooze(time); - } - - // ToDo: the lock cannot fail currently! We may want - // to change this - atomic_add(&fCount, 1); - return B_OK; - } - - void Unlock() - { - if (atomic_add(&fCount, -1) == 1) - atomic_set(&fHolder, -1); - } - - bool IsLocked() const - { - return fHolder == find_thread(NULL); - } - - private: - vint32 fHolder; - vint32 fCount; -}; - -// A convenience class to lock the SimpleLock, note the -// different timing compared to the direct call - -class SimpleLocker { - public: - SimpleLocker(SimpleLock &lock,bigtime_t time = 1000) - : fLock(lock) - { - lock.Lock(time); - } - - ~SimpleLocker() - { - fLock.Unlock(); - } - - private: - SimpleLock &fLock; -}; - #endif /* LOCK_H */ [... truncated: 221 lines follow ...] From axeld at mail.berlios.de Mon Jul 7 18:26:58 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 18:26:58 +0200 Subject: [Haiku-commits] r26299 - haiku/trunk/headers/private/fs_shell Message-ID: <200807071626.m67GQwJD002905@sheep.berlios.de> Author: axeld Date: 2008-07-07 18:26:57 +0200 (Mon, 07 Jul 2008) New Revision: 26299 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26299&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h Log: * The fssh_auto_locker.h header was not self-contained. Modified: haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h 2008-07-07 16:21:00 UTC (rev 26298) +++ haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h 2008-07-07 16:26:57 UTC (rev 26299) @@ -6,6 +6,9 @@ #define _FSSH_AUTO_LOCKER_H +#include + + namespace FSShell { // AutoLockerStandardLocking From axeld at mail.berlios.de Mon Jul 7 18:34:40 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 18:34:40 +0200 Subject: [Haiku-commits] r26300 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200807071634.m67GYe5K009241@sheep.berlios.de> Author: axeld Date: 2008-07-07 18:34:38 +0200 (Mon, 07 Jul 2008) New Revision: 26300 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26300&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp Log: * Work-around for the KDEBUG "holder" mechanism; we actually want to lock the mutex in another thread here than we will unlock it. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-07 16:26:57 UTC (rev 26299) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-07 16:34:38 UTC (rev 26300) @@ -474,6 +474,10 @@ "bfs block allocator", B_LOW_PRIORITY, (void *)this); if (id < B_OK) return _Initialize(this); +#ifdef KDEBUG + else + fLock.holder = id; +#endif return resume_thread(id); } From axeld at mail.berlios.de Mon Jul 7 20:10:22 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 20:10:22 +0200 Subject: [Haiku-commits] r26301 - haiku/trunk/headers/private/fs_shell Message-ID: <200807071810.m67IAMHL003910@sheep.berlios.de> Author: axeld Date: 2008-07-07 20:10:21 +0200 (Mon, 07 Jul 2008) New Revision: 26301 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26301&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h haiku/trunk/headers/private/fs_shell/fssh_errors.h Log: * Replaced most of the error enums with #defines. * fssh_auto_locker.h should probably better use an FS-Shell header instead of stddef.h. Modified: haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h 2008-07-07 16:34:38 UTC (rev 26300) +++ haiku/trunk/headers/private/fs_shell/fssh_auto_locker.h 2008-07-07 18:10:21 UTC (rev 26301) @@ -6,7 +6,7 @@ #define _FSSH_AUTO_LOCKER_H -#include +#include namespace FSShell { Modified: haiku/trunk/headers/private/fs_shell/fssh_errors.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_errors.h 2008-07-07 16:34:38 UTC (rev 26300) +++ haiku/trunk/headers/private/fs_shell/fssh_errors.h 2008-07-07 18:10:21 UTC (rev 26301) @@ -24,56 +24,52 @@ #define FSSH_B_DEVICE_ERROR_BASE FSSH_B_GENERAL_ERROR_BASE + 0xa000 /* Developer-defined errors start at (B_ERRORS_END+1) */ -#define FSSH_B_ERRORS_END (FSSH_B_GENERAL_ERROR_BASE + 0xffff) +#define FSSH_B_ERRORS_END (FSSH_B_GENERAL_ERROR_BASE + 0xffff) /* General Errors */ -enum { - FSSH_B_NO_MEMORY = FSSH_B_GENERAL_ERROR_BASE, - FSSH_B_IO_ERROR, - FSSH_B_PERMISSION_DENIED, - FSSH_B_BAD_INDEX, - FSSH_B_BAD_TYPE, - FSSH_B_BAD_VALUE, - FSSH_B_MISMATCHED_VALUES, - FSSH_B_NAME_NOT_FOUND, - FSSH_B_NAME_IN_USE, - FSSH_B_TIMED_OUT, - FSSH_B_INTERRUPTED, - FSSH_B_WOULD_BLOCK, - FSSH_B_CANCELED, - FSSH_B_NO_INIT, - FSSH_B_BUSY, - FSSH_B_NOT_ALLOWED, - FSSH_B_BAD_DATA, - FSSH_B_DONT_DO_THAT, +#define FSSH_B_NO_MEMORY (FSSH_B_GENERAL_ERROR_BASE + 0) +#define FSSH_B_IO_ERROR (FSSH_B_GENERAL_ERROR_BASE + 1) +#define FSSH_B_PERMISSION_DENIED (FSSH_B_GENERAL_ERROR_BASE + 2) +#define FSSH_B_BAD_INDEX (FSSH_B_GENERAL_ERROR_BASE + 3) +#define FSSH_B_BAD_TYPE (FSSH_B_GENERAL_ERROR_BASE + 4) +#define FSSH_B_BAD_VALUE (FSSH_B_GENERAL_ERROR_BASE + 5) +#define FSSH_B_MISMATCHED_VALUES (FSSH_B_GENERAL_ERROR_BASE + 6) +#define FSSH_B_NAME_NOT_FOUND (FSSH_B_GENERAL_ERROR_BASE + 7) +#define FSSH_B_NAME_IN_USE (FSSH_B_GENERAL_ERROR_BASE + 8) +#define FSSH_B_TIMED_OUT (FSSH_B_GENERAL_ERROR_BASE + 9) +#define FSSH_B_INTERRUPTED (FSSH_B_GENERAL_ERROR_BASE + 10) +#define FSSH_B_WOULD_BLOCK (FSSH_B_GENERAL_ERROR_BASE + 11) +#define FSSH_B_CANCELED (FSSH_B_GENERAL_ERROR_BASE + 12) +#define FSSH_B_NO_INIT (FSSH_B_GENERAL_ERROR_BASE + 13) +#define FSSH_B_BUSY (FSSH_B_GENERAL_ERROR_BASE + 14) +#define FSSH_B_NOT_ALLOWED (FSSH_B_GENERAL_ERROR_BASE + 15) +#define FSSH_B_BAD_DATA (FSSH_B_GENERAL_ERROR_BASE + 16) +#define FSSH_B_DONT_DO_THAT (FSSH_B_GENERAL_ERROR_BASE + 17) - FSSH_B_ERROR = -1, - FSSH_B_OK = 0, - FSSH_B_NO_ERROR = 0 -}; +#define FSSH_B_ERROR (-1) +#define FSSH_B_OK ((int)0) +#define FSSH_B_NO_ERROR ((int)0) /* Kernel Kit Errors */ -enum { - FSSH_B_BAD_SEM_ID = FSSH_B_OS_ERROR_BASE, - FSSH_B_NO_MORE_SEMS, +#define FSSH_B_BAD_SEM_ID (FSSH_B_OS_ERROR_BASE + 0) +#define FSSH_B_NO_MORE_SEMS (FSSH_B_OS_ERROR_BASE + 1) - FSSH_B_BAD_THREAD_ID = FSSH_B_OS_ERROR_BASE + 0x100, - FSSH_B_NO_MORE_THREADS, - FSSH_B_BAD_THREAD_STATE, - FSSH_B_BAD_TEAM_ID, - FSSH_B_NO_MORE_TEAMS, +#define FSSH_B_BAD_THREAD_ID (FSSH_B_OS_ERROR_BASE + 0x100) +#define FSSH_B_NO_MORE_THREADS (FSSH_B_OS_ERROR_BASE + 0x101) +#define FSSH_B_BAD_THREAD_STATE (FSSH_B_OS_ERROR_BASE + 0x102) +#define FSSH_B_BAD_TEAM_ID (FSSH_B_OS_ERROR_BASE + 0x103) +#define FSSH_B_NO_MORE_TEAMS (FSSH_B_OS_ERROR_BASE + 0x104) - FSSH_B_BAD_PORT_ID = FSSH_B_OS_ERROR_BASE + 0x200, - FSSH_B_NO_MORE_PORTS, +#define FSSH_B_BAD_PORT_ID (FSSH_B_OS_ERROR_BASE + 0x200) +#define FSSH_B_NO_MORE_PORTS (FSSH_B_OS_ERROR_BASE + 0x201) - FSSH_B_BAD_IMAGE_ID = FSSH_B_OS_ERROR_BASE + 0x300, - FSSH_B_BAD_ADDRESS, - FSSH_B_NOT_AN_EXECUTABLE, - FSSH_B_MISSING_LIBRARY, - FSSH_B_MISSING_SYMBOL, +#define FSSH_B_BAD_IMAGE_ID (FSSH_B_OS_ERROR_BASE + 0x300) +#define FSSH_B_BAD_ADDRESS (FSSH_B_OS_ERROR_BASE + 0x301) +#define FSSH_B_NOT_AN_EXECUTABLE (FSSH_B_OS_ERROR_BASE + 0x302) +#define FSSH_B_MISSING_LIBRARY (FSSH_B_OS_ERROR_BASE + 0x303) +#define FSSH_B_MISSING_SYMBOL (FSSH_B_OS_ERROR_BASE + 0x304) - FSSH_B_DEBUGGER_ALREADY_INSTALLED = FSSH_B_OS_ERROR_BASE + 0x400 -}; +#define FSSH_B_DEBUGGER_ALREADY_INSTALLED (FSSH_B_OS_ERROR_BASE + 0x400) /* Application Kit Errors */ enum { @@ -99,24 +95,22 @@ }; /* Storage Kit/File System Errors */ -enum { - FSSH_B_FILE_ERROR = FSSH_B_STORAGE_ERROR_BASE, - FSSH_B_FILE_NOT_FOUND, /* deprecated: use FSSH_B_ENTRY_NOT_FOUND instead */ - FSSH_B_FILE_EXISTS, - FSSH_B_ENTRY_NOT_FOUND, - FSSH_B_NAME_TOO_LONG, - FSSH_B_NOT_A_DIRECTORY, - FSSH_B_DIRECTORY_NOT_EMPTY, - FSSH_B_DEVICE_FULL, - FSSH_B_READ_ONLY_DEVICE, - FSSH_B_IS_A_DIRECTORY, - FSSH_B_NO_MORE_FDS, - FSSH_B_CROSS_DEVICE_LINK, - FSSH_B_LINK_LIMIT, - FSSH_B_BUSTED_PIPE, - FSSH_B_UNSUPPORTED, - FSSH_B_PARTITION_TOO_SMALL -}; +#define FSSH_B_FILE_ERROR (FSSH_B_STORAGE_ERROR_BASE + 0) +#define FSSH_B_FILE_NOT_FOUND (FSSH_B_STORAGE_ERROR_BASE + 1) +#define FSSH_B_FILE_EXISTS (FSSH_B_STORAGE_ERROR_BASE + 2) +#define FSSH_B_ENTRY_NOT_FOUND (FSSH_B_STORAGE_ERROR_BASE + 3) +#define FSSH_B_NAME_TOO_LONG (FSSH_B_STORAGE_ERROR_BASE + 4) +#define FSSH_B_NOT_A_DIRECTORY (FSSH_B_STORAGE_ERROR_BASE + 5) +#define FSSH_B_DIRECTORY_NOT_EMPTY (FSSH_B_STORAGE_ERROR_BASE + 6) +#define FSSH_B_DEVICE_FULL (FSSH_B_STORAGE_ERROR_BASE + 7) +#define FSSH_B_READ_ONLY_DEVICE (FSSH_B_STORAGE_ERROR_BASE + 8) +#define FSSH_B_IS_A_DIRECTORY (FSSH_B_STORAGE_ERROR_BASE + 9) +#define FSSH_B_NO_MORE_FDS (FSSH_B_STORAGE_ERROR_BASE + 10) +#define FSSH_B_CROSS_DEVICE_LINK (FSSH_B_STORAGE_ERROR_BASE + 11) +#define FSSH_B_LINK_LIMIT (FSSH_B_STORAGE_ERROR_BASE + 12) +#define FSSH_B_BUSTED_PIPE (FSSH_B_STORAGE_ERROR_BASE + 13) +#define FSSH_B_UNSUPPORTED (FSSH_B_STORAGE_ERROR_BASE + 14) +#define FSSH_B_PARTITION_TOO_SMALL (FSSH_B_STORAGE_ERROR_BASE + 15) /* POSIX Errors */ #define FSSH_E2BIG (FSSH_B_POSIX_ERROR_BASE + 1) @@ -161,7 +155,7 @@ #define FSSH_ESTALE (FSSH_B_POSIX_ERROR_BASE + 40) #define FSSH_EOVERFLOW (FSSH_B_POSIX_ERROR_BASE + 41) #define FSSH_EMSGSIZE (FSSH_B_POSIX_ERROR_BASE + 42) -#define FSSH_EOPNOTSUPP (FSSH_B_POSIX_ERROR_BASE + 43) +#define FSSH_EOPNOTSUPP (FSSH_B_POSIX_ERROR_BASE + 43) #define FSSH_ENOTSOCK (FSSH_B_POSIX_ERROR_BASE + 44) #define FSSH_EHOSTDOWN (FSSH_B_POSIX_ERROR_BASE + 45) #define FSSH_EBADMSG (FSSH_B_POSIX_ERROR_BASE + 46) From axeld at mail.berlios.de Mon Jul 7 20:12:34 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 7 Jul 2008 20:12:34 +0200 Subject: [Haiku-commits] r26302 - in haiku/trunk: headers/private/fs_shell headers/private/kernel/util src/tools/fs_shell Message-ID: <200807071812.m67ICY2J004330@sheep.berlios.de> Author: axeld Date: 2008-07-07 20:12:33 +0200 (Mon, 07 Jul 2008) New Revision: 26302 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26302&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_lock.h haiku/trunk/headers/private/kernel/util/AutoLock.h haiku/trunk/src/tools/fs_shell/lock.cpp Log: * Added ReadLocker/WriteLocker classes to auto lock an rw_lock. * Added *_init_etc() functions to the fs_shell. Modified: haiku/trunk/headers/private/fs_shell/fssh_lock.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 18:10:21 UTC (rev 26301) +++ haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 18:12:33 UTC (rev 26302) @@ -115,11 +115,42 @@ // RecursiveLocker typedef AutoLocker RecursiveLocker; +class ReadWriteLockReadLocking { +public: + inline bool Lock(fssh_rw_lock *lockable) + { + return fssh_rw_lock_read_lock(lockable) == FSSH_B_OK; + } + + inline void Unlock(fssh_rw_lock *lockable) + { + fssh_rw_lock_read_unlock(lockable); + } +}; + +class ReadWriteLockWriteLocking { +public: + inline bool Lock(fssh_rw_lock *lockable) + { + return fssh_rw_lock_write_lock(lockable) == FSSH_B_OK; + } + + inline void Unlock(fssh_rw_lock *lockable) + { + fssh_rw_lock_write_unlock(lockable); + } +}; + +typedef AutoLocker ReadLocker; +typedef AutoLocker WriteLocker; + } // namespace FSShell using FSShell::AutoLocker; using FSShell::MutexLocker; using FSShell::RecursiveLocker; +using FSShell::ReadLocker; +using FSShell::WriteLocker; #endif // __cplusplus Modified: haiku/trunk/headers/private/kernel/util/AutoLock.h =================================================================== --- haiku/trunk/headers/private/kernel/util/AutoLock.h 2008-07-07 18:10:21 UTC (rev 26301) +++ haiku/trunk/headers/private/kernel/util/AutoLock.h 2008-07-07 18:12:33 UTC (rev 26302) @@ -1,5 +1,7 @@ /* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. * Copyright 2005-2007, Ingo Weinhold, bonefish at users.sf.net. All rights reserved. + * * Distributed under the terms of the MIT License. */ #ifndef KERNEL_UTIL_AUTO_LOCKER_H @@ -50,6 +52,35 @@ // RecursiveLocker typedef AutoLocker RecursiveLocker; +class ReadWriteLockReadLocking { +public: + inline bool Lock(rw_lock *lockable) + { + return rw_lock_read_lock(lockable) == B_OK; + } + + inline void Unlock(rw_lock *lockable) + { + rw_lock_read_unlock(lockable); + } +}; + +class ReadWriteLockWriteLocking { +public: + inline bool Lock(rw_lock *lockable) + { + return rw_lock_write_lock(lockable) == B_OK; + } + + inline void Unlock(rw_lock *lockable) + { + rw_lock_write_unlock(lockable); + } +}; + +typedef AutoLocker ReadLocker; +typedef AutoLocker WriteLocker; + // InterruptsLocking class InterruptsLocking { public: @@ -135,6 +166,8 @@ using BPrivate::AutoLocker; using BPrivate::MutexLocker; using BPrivate::RecursiveLocker; +using BPrivate::ReadLocker; +using BPrivate::WriteLocker; using BPrivate::InterruptsLocker; using BPrivate::SpinLocker; using BPrivate::InterruptsSpinLocker; Modified: haiku/trunk/src/tools/fs_shell/lock.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 18:10:21 UTC (rev 26301) +++ haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 18:12:33 UTC (rev 26302) @@ -123,6 +123,13 @@ extern "C" void +fssh_mutex_init_etc(fssh_mutex *m, const char *name, uint32_t flags) +{ + fssh_mutex_init(m, name); +} + + +extern "C" void fssh_mutex_destroy(fssh_mutex *mutex) { if (mutex == NULL) @@ -188,6 +195,13 @@ extern "C" void +fssh_rw_lock_init_etc(fssh_rw_lock *lock, const char *name, uint32_t flags) +{ + fssh_rw_lock_init(lock, name); +} + + +extern "C" void fssh_rw_lock_destroy(fssh_rw_lock *lock) { if (lock == NULL) From axeld at pinc-software.de Mon Jul 7 20:19:32 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 20:19:32 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26296_-_in_haiku/trunk=3A_headers/priv?= =?utf-8?q?ate/fs=5Fshell_src/system/kernel/fs_src/tools/fs=5Fshell?= In-Reply-To: <1e80d8750807070911g44de1a73v8566a3b86a07b8c2@mail.gmail.com> Message-ID: <33063678704-BeMail@zon> "Urias McCullough" wrote: > I'm guessing this is the change that is causing the following build > problem: > > C++ generated/objects/linux/x86/release/tools/bfs_shell/ > bfs_disk_system.o > In file included from src/add-ons/kernel/file_systems/bfs/ > BlockAllocator.h:9, > from src/add-ons/kernel/file_systems/bfs/ > Volume.h:12, > from src/add-ons/kernel/file_systems/bfs/ > bfs_disk_system.cpp:9: > src/add-ons/kernel/file_systems/bfs/Lock.h:197: error: using > typedef-name 'FSShell::RecursiveLocker' after 'class' > headers/private/fs_shell/fssh_lock.h:115: error: > 'FSShell::RecursiveLocker' has a previous declaration here Yes, it was. I didn't notice it because I had some other pending changes that removed that error. Sorry! Bye, Axel. From axeld at pinc-software.de Mon Jul 7 20:22:12 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 20:22:12 +0200 CEST Subject: [Haiku-commits] r26250 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/vm In-Reply-To: <20080707171604.547.1@knochen-vm.nameserver> Message-ID: <33223371899-BeMail@zon> Ingo Weinhold wrote: > On 2008-07-07 at 12:40:09 [+0200], Axel D?rfler > > wrote: > > bonefish at mail.berlios.de wrote: > > > - off_t fileSize = cache->virtual_size; > > > + off_t fileSize = cache->virtual_end; > > I actually find this more confusing than before; "end" somehow > > implies > > that (virtual_end - virtual_base) == size. But it's just the > > "size", so > > maybe we should instead just remove the "virtual_" part of it? > As I see it (virtual_end - virtual_base) is indeed the size of the > cache, > i.e. it implies the number of pages the cache will maximally hold. I > understand that for vnode caches virtual_base is always 0 and > virtual_end > is always the file size, but for anonymous caches that's not the > case. Ah, well, you're right of course, somehow I was confused 8-) Bye, Axel. From zooey at mail.berlios.de Mon Jul 7 20:53:02 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Mon, 7 Jul 2008 20:53:02 +0200 Subject: [Haiku-commits] r26303 - haiku/trunk/src/kits/network Message-ID: <200807071853.m67Ir2Mm010513@sheep.berlios.de> Author: zooey Date: 2008-07-07 20:53:01 +0200 (Mon, 07 Jul 2008) New Revision: 26303 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26303&view=rev Modified: haiku/trunk/src/kits/network/socket.cpp Log: Fixed R5 compatibility "layer" in libnetwork: * instead of always converting from the expected r5_sockaddr_in to haiku's own, we now explicitly check whether or not the given sockaddr is an r5_sockaddr_in or not, naturally doing the conversion only if it is. This is necessary since even R5 applications may not always pass in r5_sockaddr_in structs (as for instance gethostbyname() will return a native [haiku-]sockaddr_in) * cleaned up the confusion between the name r5addr and it's actual meaning (holding a haiku sockaddr_in) - renaming it to haikuAddr instead * undid the part of Ingo's r25489 described as: "Extended R5 compatibility check to also consider calls from libbnetapi" - as I fail to see why this would be desirable and in fact it stops at least Beam from working. Ingo: if you can remember, please enlighten me what was the reason behind this change. This finally makes Beam "work" (well: connect to servers and download mails ;-) Vision, NetworkTime and NetPositive are still working, too, so hopefully there are no regressions. Modified: haiku/trunk/src/kits/network/socket.cpp =================================================================== --- haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:12:33 UTC (rev 26302) +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:53:01 UTC (rev 26303) @@ -22,6 +22,7 @@ #include +#include static inline bool check_r5_compatibility() { @@ -39,9 +40,7 @@ stack_frame* frame = (stack_frame*)get_stack_frame(); if (frame->return_address >= __gNetworkStart - && frame->return_address < __gNetworkEnd - || frame->return_address >= __gNetAPIStart - && frame->return_address < __gNetAPIEnd) { + && frame->return_address < __gNetworkEnd) { return false; } @@ -50,6 +49,27 @@ } +static bool +is_r5_sockaddr(const struct sockaddr *_addr) +{ + /* r5_sockaddr_in structs do not contain sin_len, but have a larger + * sin_family instead (two bytes), so in a r5_sockaddr_in, the first two + * bytes will always be equal to R5_AF_INET, while for haiku's own + * sockaddr_in, that will never be the case, since the first byte contains + * the length which should never be zero. + * The only other case where this check could fail is when the address does + * not belong to the internet family at all. But even in that case we would + * not want to try to convert the addresses, as the conversion itself + * blindly casts the address to sockaddr_in, which would yield unpredictable + * results for other address families. + */ + const r5_sockaddr_in *addr = (r5_sockaddr_in *)_addr; + if (addr == NULL || addr->sin_family != R5_AF_INET) + return false; + + return true; +} + static void convert_from_r5_sockaddr(struct sockaddr *_to, const struct sockaddr *_from) { @@ -174,11 +194,11 @@ extern "C" int bind(int socket, const struct sockaddr *address, socklen_t addressLength) { - struct sockaddr r5addr; + struct sockaddr haikuAddr; - if (check_r5_compatibility()) { - convert_from_r5_sockaddr(&r5addr, address); - address = &r5addr; + if (check_r5_compatibility() && is_r5_sockaddr(address)) { + convert_from_r5_sockaddr(&haikuAddr, address); + address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); } @@ -196,11 +216,11 @@ extern "C" int connect(int socket, const struct sockaddr *address, socklen_t addressLength) { - struct sockaddr r5addr; + struct sockaddr haikuAddr; - if (check_r5_compatibility()) { - convert_from_r5_sockaddr(&r5addr, address); - address = &r5addr; + if (check_r5_compatibility() && is_r5_sockaddr(address)) { + convert_from_r5_sockaddr(&haikuAddr, address); + address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); } @@ -219,14 +239,14 @@ accept(int socket, struct sockaddr *_address, socklen_t *_addressLength) { bool r5compatible = check_r5_compatibility(); - struct sockaddr r5addr; + struct sockaddr haikuAddr; sockaddr* address; socklen_t addressLength; if (r5compatible && _address != NULL) { - address = &r5addr; - addressLength = sizeof(r5addr); + address = &haikuAddr; + addressLength = sizeof(haikuAddr); } else { address = _address; addressLength = _addressLength ? *_addressLength : 0; @@ -239,7 +259,7 @@ } if (r5compatible && _address != NULL) { - convert_to_r5_sockaddr(_address, &r5addr); + convert_to_r5_sockaddr(_address, &haikuAddr); if (_addressLength != NULL) *_addressLength = sizeof(struct r5_sockaddr_in); } else if (_addressLength != NULL) @@ -261,14 +281,14 @@ struct sockaddr *_address, socklen_t *_addressLength) { bool r5compatible = check_r5_compatibility(); - struct sockaddr r5addr; + struct sockaddr haikuAddr; sockaddr* address; socklen_t addressLength; if (r5compatible && _address != NULL) { - address = &r5addr; - addressLength = sizeof(r5addr); + address = &haikuAddr; + addressLength = sizeof(haikuAddr); } else { address = _address; addressLength = _addressLength ? *_addressLength : 0; @@ -282,7 +302,7 @@ } if (r5compatible) { - convert_to_r5_sockaddr(_address, &r5addr); + convert_to_r5_sockaddr(_address, &haikuAddr); if (_addressLength != NULL) *_addressLength = sizeof(struct r5_sockaddr_in); } else if (_addressLength != NULL) @@ -310,11 +330,11 @@ sendto(int socket, const void *data, size_t length, int flags, const struct sockaddr *address, socklen_t addressLength) { - struct sockaddr r5addr; + struct sockaddr haikuAddr; - if (check_r5_compatibility()) { - convert_from_r5_sockaddr(&r5addr, address); - address = &r5addr; + if (check_r5_compatibility() && is_r5_sockaddr(address)) { + convert_from_r5_sockaddr(&haikuAddr, address); + address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); } @@ -364,14 +384,14 @@ getpeername(int socket, struct sockaddr *_address, socklen_t *_addressLength) { bool r5compatible = check_r5_compatibility(); - struct sockaddr r5addr; + struct sockaddr haikuAddr; sockaddr* address; socklen_t addressLength; if (r5compatible && _address != NULL) { - address = &r5addr; - addressLength = sizeof(r5addr); + address = &haikuAddr; + addressLength = sizeof(haikuAddr); } else { address = _address; addressLength = _addressLength ? *_addressLength : 0; @@ -384,7 +404,7 @@ } if (r5compatible) { - convert_to_r5_sockaddr(_address, &r5addr); + convert_to_r5_sockaddr(_address, &haikuAddr); if (_addressLength != NULL) *_addressLength = sizeof(struct r5_sockaddr_in); } else if (_addressLength != NULL) @@ -398,14 +418,14 @@ getsockname(int socket, struct sockaddr *_address, socklen_t *_addressLength) { bool r5compatible = check_r5_compatibility(); - struct sockaddr r5addr; + struct sockaddr haikuAddr; sockaddr* address; socklen_t addressLength; if (r5compatible && _address != NULL) { - address = &r5addr; - addressLength = sizeof(r5addr); + address = &haikuAddr; + addressLength = sizeof(haikuAddr); } else { address = _address; addressLength = _addressLength ? *_addressLength : 0; @@ -418,7 +438,7 @@ } if (r5compatible) { - convert_to_r5_sockaddr(_address, &r5addr); + convert_to_r5_sockaddr(_address, &haikuAddr); if (_addressLength != NULL) *_addressLength = sizeof(struct r5_sockaddr_in); } else if (_addressLength != NULL) From julun at mail.berlios.de Mon Jul 7 21:10:41 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 21:10:41 +0200 Subject: [Haiku-commits] r26304 - in haiku/trunk: headers/private/interface src/kits/interface Message-ID: <200807071910.m67JAfQD014095@sheep.berlios.de> Author: julun Date: 2008-07-07 21:10:39 +0200 (Mon, 07 Jul 2008) New Revision: 26304 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26304&view=rev Modified: haiku/trunk/headers/private/interface/ViewPrivate.h haiku/trunk/src/kits/interface/PrintJob.cpp haiku/trunk/src/kits/interface/View.cpp Log: * maintain our own rect while printing, this makes it possible to print all pages e.g. syslog from StyledEdit Modified: haiku/trunk/headers/private/interface/ViewPrivate.h =================================================================== --- haiku/trunk/headers/private/interface/ViewPrivate.h 2008-07-07 18:53:01 UTC (rev 26303) +++ haiku/trunk/headers/private/interface/ViewPrivate.h 2008-07-07 19:10:39 UTC (rev 26304) @@ -30,8 +30,8 @@ B_VIEW_BLENDING_BIT = 0x00000020, B_VIEW_SCALE_BIT = 0x00000040, B_VIEW_FONT_ALIASING_BIT = 0x00000080, - B_VIEW_FRAME_BIT = 0x00000100, - B_VIEW_ORIGIN_BIT = 0x00000200, + B_VIEW_FRAME_BIT = 0x00000100, + B_VIEW_ORIGIN_BIT = 0x00000200, B_VIEW_PEN_SIZE_BIT = 0x00000400, B_VIEW_PEN_LOCATION_BIT = 0x00000800, B_VIEW_LOW_COLOR_BIT = 0x00008000, @@ -101,6 +101,9 @@ uint32 valid_flags; // flags used for archiving uint32 archiving_flags; + + // maintain our own rect as seen from the app while printing + BRect print_rect; }; inline bool @@ -120,7 +123,7 @@ struct _array_hdr_{ float startX; - float startY; + float startY; float endX; float endY; rgb_color color; @@ -129,7 +132,7 @@ struct _array_data_{ // the max number of points in the array uint32 maxCount; - // the current number of points in the array + // the current number of points in the array uint32 count; // the array of points _array_hdr_* array; Modified: haiku/trunk/src/kits/interface/PrintJob.cpp =================================================================== --- haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 18:53:01 UTC (rev 26303) +++ haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 19:10:39 UTC (rev 26304) @@ -27,6 +27,7 @@ #include +#include #include @@ -506,9 +507,9 @@ BRegion region; region.Set(BRect(rect.left, rect.top, rect.right, rect.bottom)); + view->fState->print_rect = rect; view->AppendToPicture(picture); - view->fIsPrinting = true; view->PushState(); view->SetOrigin(origin); view->ConstrainClippingRegion(®ion); @@ -520,9 +521,11 @@ view->SetHighColor(highColor); } + view->fIsPrinting = true; view->Draw(rect); + view->fIsPrinting = false; + view->PopState(); - view->fIsPrinting = false; view->EndPicture(); BView *child = view->ChildAt(0); @@ -538,13 +541,13 @@ if (view->Flags() & B_DRAW_ON_CHILDREN) { view->AppendToPicture(picture); - view->fIsPrinting = true; view->PushState(); view->SetOrigin(origin); view->ConstrainClippingRegion(®ion); + view->fIsPrinting = true; view->DrawAfterChildren(rect); + view->fIsPrinting = false; view->PopState(); - view->fIsPrinting = false; view->EndPicture(); } } Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-07 18:53:01 UTC (rev 26303) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-07 19:10:39 UTC (rev 26304) @@ -639,6 +639,9 @@ } } */ + if (fIsPrinting) + return fState->print_rect; + return fBounds; } @@ -1506,7 +1509,7 @@ // no reason to process this further if no scroll is intended. if (where.x == fBounds.left && where.y == fBounds.top) return; - + // make sure scrolling is within valid bounds if (fHorScroller) { float min, max; @@ -2286,7 +2289,13 @@ // changed, so it is always read from the server region->MakeEmpty(); + if (fOwner) { + if (fIsPrinting && _CheckOwnerLock()) { + region->Set(fState->print_rect); + return; + } + _CheckLockAndSwitchCurrent(); fOwner->fLink->StartMessage(AS_VIEW_GET_CLIP_REGION); From julun at mail.berlios.de Mon Jul 7 21:14:09 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 21:14:09 +0200 Subject: [Haiku-commits] r26305 - haiku/trunk/src/kits/interface Message-ID: <200807071914.m67JE9EH014607@sheep.berlios.de> Author: julun Date: 2008-07-07 21:14:08 +0200 (Mon, 07 Jul 2008) New Revision: 26305 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26305&view=rev Modified: haiku/trunk/src/kits/interface/PrintJob.cpp Log: * check against baad as e.g. the epson addon does not return okok on success Modified: haiku/trunk/src/kits/interface/PrintJob.cpp =================================================================== --- haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 19:10:39 UTC (rev 26304) +++ haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 19:14:08 UTC (rev 26305) @@ -846,7 +846,7 @@ BMessage reply; if (printServer.SendMessage(request, &reply) != B_OK - || reply.what != 'okok') { + || reply.what == 'baad') { messenger->SetResult(NULL); return B_ERROR; } From julun at mail.berlios.de Mon Jul 7 21:23:44 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 21:23:44 +0200 Subject: [Haiku-commits] r26306 - haiku/trunk/src/kits/interface Message-ID: <200807071923.m67JNi8p015579@sheep.berlios.de> Author: julun Date: 2008-07-07 21:23:40 +0200 (Mon, 07 Jul 2008) New Revision: 26306 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26306&view=rev Modified: haiku/trunk/src/kits/interface/PrintJob.cpp Log: * revert the last change as we can get stop etc. also Modified: haiku/trunk/src/kits/interface/PrintJob.cpp =================================================================== --- haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 19:14:08 UTC (rev 26305) +++ haiku/trunk/src/kits/interface/PrintJob.cpp 2008-07-07 19:23:40 UTC (rev 26306) @@ -846,7 +846,7 @@ BMessage reply; if (printServer.SendMessage(request, &reply) != B_OK - || reply.what == 'baad') { + || reply.what != 'okok' ) { messenger->SetResult(NULL); return B_ERROR; } From julun at mail.berlios.de Mon Jul 7 21:39:11 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 21:39:11 +0200 Subject: [Haiku-commits] r26307 - haiku/trunk/src/servers/print Message-ID: <200807071939.m67JdB80017062@sheep.berlios.de> Author: julun Date: 2008-07-07 21:39:10 +0200 (Mon, 07 Jul 2008) New Revision: 26307 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26307&view=rev Modified: haiku/trunk/src/servers/print/Printer.cpp Log: * cleanup, no functional change Modified: haiku/trunk/src/servers/print/Printer.cpp =================================================================== --- haiku/trunk/src/servers/print/Printer.cpp 2008-07-07 19:23:40 UTC (rev 26306) +++ haiku/trunk/src/servers/print/Printer.cpp 2008-07-07 19:39:10 UTC (rev 26307) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku. All rights reserved. + * Copyright 2001-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -29,7 +29,7 @@ SpoolFolder::SpoolFolder(BLocker*locker, BLooper* looper, const BDirectory& spoolDir) - : Folder(locker, looper, spoolDir) + : Folder(locker, looper, spoolDir) { } @@ -40,7 +40,7 @@ if ((kind == kJobAdded || kind == kJobAttrChanged) && job->IsValid() && job->IsWaiting()) { be_app_messenger.SendMessage(PSRV_PRINT_SPOOLED_JOB); - } + } } @@ -74,11 +74,12 @@ return sPrinters.ItemAt(idx); } } - + // None found, so return NULL return NULL; } + Printer* Printer::Find(node_ref* node) { node_ref n; @@ -86,19 +87,23 @@ for (int32 idx=0; idx < sPrinters.CountItems(); idx++) { Printer* printer = sPrinters.ItemAt(idx); printer->SpoolDir()->GetNodeRef(&n); - if (n == *node) return printer; + if (n == *node) + return printer; } - + // None found, so return NULL return NULL; } + Printer* Printer::At(int32 idx) { return sPrinters.ItemAt(idx); } -void Printer::Remove(Printer* printer) { + +void Printer::Remove(Printer* printer) +{ sPrinters.RemoveItem(printer); } @@ -107,6 +112,7 @@ return sPrinters.CountItems(); } + // --------------------------------------------------------------- // Printer [constructor] // @@ -133,14 +139,16 @@ if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) == B_OK) SetName(name.String()); - if (name == "Preview") fSinglePrintThread = false; - + if (name == "Preview") + fSinglePrintThread = false; + // Add us to the global list of known printer definitions sPrinters.AddItem(this); - + ResetJobStatus(); } + Printer::~Printer() { ((PrintServerApp*)be_app)->NotifyPrinterDeletion(this); @@ -157,10 +165,11 @@ path.Append(Name()); rc = rmdir(path.Path()); } - + return rc; } + // --------------------------------------------------------------- // ConfigurePrinter // @@ -174,24 +183,24 @@ // --------------------------------------------------------------- status_t Printer::ConfigurePrinter() { + status_t rc; image_id id; - status_t rc; - - if ((rc=LoadPrinterAddon(id)) == B_OK) { + if ((rc = LoadPrinterAddon(id)) == B_OK) { // Addon was loaded, so try and get the add_printer symbol add_printer_func_t func; - - if (get_image_symbol(id, "add_printer", B_SYMBOL_TYPE_TEXT, (void**)&func) == B_OK) { - // call the function and check its result + if (get_image_symbol(id, "add_printer", B_SYMBOL_TYPE_TEXT, + (void**)&func) == B_OK) { + // call the function and check its result rc = ((*func)(Name()) == NULL) ? B_ERROR : B_OK; } - + ::unload_add_on(id); } - + return rc; } + // --------------------------------------------------------------- // ConfigurePage // @@ -207,30 +216,31 @@ // --------------------------------------------------------------- status_t Printer::ConfigurePage(BMessage& settings) { + status_t rc; image_id id; - status_t rc; - - if ((rc=LoadPrinterAddon(id)) == B_OK) { + if ((rc = LoadPrinterAddon(id)) == B_OK) { // Addon was loaded, so try and get the config_page symbol config_func_t func; - - if ((rc=get_image_symbol(id, "config_page", B_SYMBOL_TYPE_TEXT, (void**)&func)) == B_OK) { - // call the function and check its result + if ((rc=get_image_symbol(id, "config_page", B_SYMBOL_TYPE_TEXT, + (void**)&func)) == B_OK) { + // call the function and check its result BMessage* new_settings = (*func)(SpoolDir(), &settings); if (new_settings != NULL && new_settings->what != 'baad') { settings = *new_settings; AddCurrentPrinter(&settings); - } else + } else { rc = B_ERROR; + } delete new_settings; } - + ::unload_add_on(id); } - + return rc; } + // --------------------------------------------------------------- // ConfigureJob // @@ -246,27 +256,27 @@ // --------------------------------------------------------------- status_t Printer::ConfigureJob(BMessage& settings) { + status_t rc; image_id id; - status_t rc; - - if ((rc=LoadPrinterAddon(id)) == B_OK) { + if ((rc = LoadPrinterAddon(id)) == B_OK) { // Addon was loaded, so try and get the config_job symbol config_func_t func; - - if ((rc=get_image_symbol(id, "config_job", B_SYMBOL_TYPE_TEXT, (void**)&func)) == B_OK) { - // call the function and check its result + if ((rc = get_image_symbol(id, "config_job", B_SYMBOL_TYPE_TEXT, + (void**)&func)) == B_OK) { + // call the function and check its result BMessage* new_settings = (*func)(SpoolDir(), &settings); if ((new_settings != NULL) && (new_settings->what != 'baad')) { settings = *new_settings; AddCurrentPrinter(&settings); - } else + } else { rc = B_ERROR; + } delete new_settings; } - + ::unload_add_on(id); } - + return rc; } @@ -276,14 +286,16 @@ // // Print spooled jobs in a new thread. // --------------------------------------------------------------- -void Printer::HandleSpooledJob() { +void Printer::HandleSpooledJob() +{ BAutolock lock(gLock); - if (lock.IsLocked() && (!fSinglePrintThread || fProcessing == 0) && FindSpooledJob()) { + if (lock.IsLocked() + && (!fSinglePrintThread || fProcessing == 0) && FindSpooledJob()) { StartPrintThread(); } } - + // --------------------------------------------------------------- // GetDefaultSettings // @@ -295,37 +307,38 @@ // Returns: // B_OK if successful or errorcode otherwise. // --------------------------------------------------------------- -status_t Printer::GetDefaultSettings(BMessage& settings) { +status_t Printer::GetDefaultSettings(BMessage& settings) +{ + status_t rc; image_id id; - status_t rc; - - if ((rc=LoadPrinterAddon(id)) == B_OK) { + if ((rc = LoadPrinterAddon(id)) == B_OK) { // Addon was loaded, so try and get the default_settings symbol default_settings_t func; - - if ((rc=get_image_symbol(id, "default_settings", B_SYMBOL_TYPE_TEXT, (void**)&func)) == B_OK) { + if ((rc = get_image_symbol(id, "default_settings", B_SYMBOL_TYPE_TEXT, + (void**)&func)) == B_OK) { // call the function and check its result BMessage* new_settings = (*func)(SpoolDir()); if (new_settings) { - settings = *new_settings; + settings = *new_settings; AddCurrentPrinter(&settings); } else { rc = B_ERROR; } delete new_settings; } - + ::unload_add_on(id); } - return rc; } - - -void Printer::AbortPrintThread() { + + +void Printer::AbortPrintThread() +{ fAbort = true; } - + + // --------------------------------------------------------------- // LoadPrinterAddon // @@ -339,25 +352,27 @@ // --------------------------------------------------------------- status_t Printer::LoadPrinterAddon(image_id& id) { + status_t rc; BString drName; - status_t rc; - BPath path; - - if ((rc=SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &drName)) == B_OK) { - // try to locate the driver - if ((rc=::TestForAddonExistence(drName.String(), B_USER_ADDONS_DIRECTORY, "Print", path)) != B_OK) { - if ((rc=::TestForAddonExistence(drName.String(), B_COMMON_ADDONS_DIRECTORY, "Print", path)) != B_OK) { - rc = ::TestForAddonExistence(drName.String(), B_BEOS_ADDONS_DIRECTORY, "Print", path); + if ((rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &drName)) == B_OK) { + // try to locate the driver + BPath path; + if ((rc= ::TestForAddonExistence(drName.String(), B_USER_ADDONS_DIRECTORY, + "Print", path)) != B_OK) { + if ((rc = ::TestForAddonExistence(drName.String(), B_COMMON_ADDONS_DIRECTORY, + "Print", path)) != B_OK) { + rc = ::TestForAddonExistence(drName.String(), B_BEOS_ADDONS_DIRECTORY, + "Print", path); } } - - // If the driver was found + + // If the driver was found if (rc == B_OK) { - // If we cannot load the addon + // If we cannot load the addon if ((id=::load_add_on(path.Path())) < 0) rc = id; } - } + } return rc; } @@ -401,12 +416,13 @@ case B_EXECUTE_PROPERTY: HandleScriptingCommand(msg); break; - + default: Inherited::MessageReceived(msg); } } + // --------------------------------------------------------------- // GetName // @@ -415,27 +431,32 @@ // Parameters: // name - the name of the printer. // --------------------------------------------------------------- -void Printer::GetName(BString& name) { +void Printer::GetName(BString& name) +{ if (B_OK != SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name)) name = "Unknown Printer"; } + // --------------------------------------------------------------- // ResetJobStatus // // Reset status of "processing" jobs to "waiting" at print_server start. // --------------------------------------------------------------- -void Printer::ResetJobStatus() { +void Printer::ResetJobStatus() +{ if (fPrinter.Lock()) { const int32 n = fPrinter.CountJobs(); for (int32 i = 0; i < n; i ++) { Job* job = fPrinter.JobAt(i); - if (job->Status() == kProcessing) job->SetStatus(kWaiting); + if (job->Status() == kProcessing) + job->SetStatus(kWaiting); } fPrinter.Unlock(); } } + // --------------------------------------------------------------- // HasCurrentPrinter // @@ -447,16 +468,18 @@ // Returns: // true if successful. // --------------------------------------------------------------- -bool Printer::HasCurrentPrinter(BString& name) { +bool Printer::HasCurrentPrinter(BString& name) +{ BMessage settings; // read settings from spool file and get printer name BFile jobFile(&fJob->EntryRef(), B_READ_WRITE); - return jobFile.InitCheck() == B_OK && - jobFile.Seek(sizeof(print_file_header), SEEK_SET) == sizeof(print_file_header) && - settings.Unflatten(&jobFile) == B_OK && - settings.FindString(PSRV_FIELD_CURRENT_PRINTER, &name) == B_OK; + return jobFile.InitCheck() == B_OK + && jobFile.Seek(sizeof(print_file_header), SEEK_SET) == sizeof(print_file_header) + && settings.Unflatten(&jobFile) == B_OK + && settings.FindString(PSRV_FIELD_CURRENT_PRINTER, &name) == B_OK; } + // --------------------------------------------------------------- // MoveJob // @@ -468,32 +491,36 @@ // Returns: // true if successful. // --------------------------------------------------------------- -bool Printer::MoveJob(const BString& name) { +bool Printer::MoveJob(const BString& name) +{ BPath file(&fJob->EntryRef()); BPath path; file.GetParent(&path); - path.Append(".."); path.Append(name.String()); + path.Append(".."); + path.Append(name.String()); BDirectory dir(path.Path()); BEntry entry(&fJob->EntryRef()); // try to move job file to proper directory return entry.MoveTo(&dir) == B_OK; } + // --------------------------------------------------------------- // FindSpooledJob // // Looks if there is a job waiting to be processed and moves // jobs to the proper printer folder. // -// Note: +// Note: // Our implementation of BPrintJob moves jobs to the // proper printer folder. -// // +// // Returns: // true if there is a job present in fJob. // --------------------------------------------------------------- -bool Printer::FindSpooledJob() { +bool Printer::FindSpooledJob() +{ BString name2; GetName(name2); do { @@ -514,6 +541,7 @@ return false; } + // --------------------------------------------------------------- // PrintSpooledJob // @@ -528,30 +556,28 @@ // --------------------------------------------------------------- status_t Printer::PrintSpooledJob(BFile* spoolFile) { - take_job_func_t func; + status_t rc; image_id id; - status_t rc; - - if ((rc=LoadPrinterAddon(id)) == B_OK) { - // Addon was loaded, so try and get the take_job symbol - if ((rc=get_image_symbol(id, "take_job", B_SYMBOL_TYPE_TEXT, (void**)&func)) == B_OK) { - // This seems to be required for legacy? - // HP PCL3 add-on crashes without it! + if ((rc = LoadPrinterAddon(id)) == B_OK) { + take_job_func_t func; + // Addon was loaded, so try and get the take_job symbol + if ((rc = get_image_symbol(id, "take_job", B_SYMBOL_TYPE_TEXT, + (void**)&func)) == B_OK) { + // This seems to be required for legacy? + // HP PCL3 add-on crashes without it! BMessage params(B_REFS_RECEIVED); params.AddInt32("file", (int32)spoolFile); params.AddInt32("printer", (int32)SpoolDir()); // call the function and check its result BMessage* result = (*func)(spoolFile, SpoolDir(), ¶ms); - + if (result == NULL || result->what != 'okok') rc = B_ERROR; - delete result; } - + ::unload_add_on(id); } - return rc; } @@ -565,12 +591,13 @@ // Parameters: // job - the spool job. // --------------------------------------------------------------- -void Printer::PrintThread(Job* job) { - // Wait until resource is available +void Printer::PrintThread(Job* job) +{ + // Wait until resource is available fResource->Lock(); bool failed = true; // Can we continue? - if (!fAbort) { + if (!fAbort) { BFile jobFile(&job->EntryRef(), B_READ_WRITE); // Tell the printer to print the spooled job if (jobFile.InitCheck() == B_OK && PrintSpooledJob(&jobFile) == B_OK) { @@ -579,15 +606,17 @@ } } // Set status of spooled job on error - if (failed) job->SetStatus(kFailed); + if (failed) + job->SetStatus(kFailed); fResource->Unlock(); job->Release(); atomic_add(&fProcessing, -1); Release(); // Notify print_server to process next spooled job - be_app_messenger.SendMessage(PSRV_PRINT_SPOOLED_JOB); + be_app_messenger.SendMessage(PSRV_PRINT_SPOOLED_JOB); } + // --------------------------------------------------------------- // print_thread // @@ -599,27 +628,31 @@ // Returns: // 0 always. // --------------------------------------------------------------- -status_t Printer::print_thread(void* data) { +status_t Printer::print_thread(void* data) +{ Job* job = static_cast(data); job->GetPrinter()->PrintThread(job); return 0; } + // --------------------------------------------------------------- // StartPrintThread // // Sets the status of the current spool job to "processing" and // starts the print_thread. // --------------------------------------------------------------- -void Printer::StartPrintThread() { +void Printer::StartPrintThread() +{ Acquire(); thread_id tid = spawn_thread(print_thread, "print", B_NORMAL_PRIORITY, (void*)fJob); if (tid > 0) { fJob->SetStatus(kProcessing); atomic_add(&fProcessing, 1); - resume_thread(tid); + resume_thread(tid); } else { - fJob->Release(); Release(); + fJob->Release(); + Release(); } } From julun at mail.berlios.de Mon Jul 7 22:01:46 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 22:01:46 +0200 Subject: [Haiku-commits] r26308 - haiku/trunk/src/servers/print Message-ID: <200807072001.m67K1kHv022353@sheep.berlios.de> Author: julun Date: 2008-07-07 22:01:46 +0200 (Mon, 07 Jul 2008) New Revision: 26308 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26308&view=rev Modified: haiku/trunk/src/servers/print/Printer.h Log: * rearranged header a bit Modified: haiku/trunk/src/servers/print/Printer.h =================================================================== --- haiku/trunk/src/servers/print/Printer.h 2008-07-07 19:39:10 UTC (rev 26307) +++ haiku/trunk/src/servers/print/Printer.h 2008-07-07 20:01:46 UTC (rev 26308) @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006, Haiku. All rights reserved. + * Copyright 2001-2008, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -26,14 +26,16 @@ // OpenTracker shared sources #include "ObjectList.h" + class SpoolFolder : public Folder { protected: void Notify(Job* job, int kind); - + public: SpoolFolder(BLocker* locker, BLooper* looper, const BDirectory& spoolDir); }; + /*****************************************************************************/ // Printer // @@ -43,65 +45,73 @@ class Printer : public BHandler, public Object { typedef BHandler Inherited; - public: - Printer(const BDirectory* node, Resource* res); - ~Printer(); + Printer(const BDirectory* node, Resource* res); + virtual ~Printer(); - // Static helper functions - static Printer* Find(const BString& name); - static Printer* Find(node_ref* node); - static Printer* At(int32 idx); - static void Remove(Printer* printer); - static int32 CountPrinters(); + virtual void MessageReceived(BMessage* message); + virtual status_t GetSupportedSuites(BMessage* msg); + virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index, + BMessage* spec, int32 form, const char* prop); - status_t Remove(); - status_t ConfigurePrinter(); - status_t ConfigureJob(BMessage& ioSettings); - status_t ConfigurePage(BMessage& ioSettings); - status_t GetDefaultSettings(BMessage& configuration); + // Static helper functions + static Printer* Find(const BString& name); + static Printer* Find(node_ref* node); + static Printer* At(int32 idx); + static void Remove(Printer* printer); + static int32 CountPrinters(); - // Try to start processing of next spooled job - void HandleSpooledJob(); - // Abort print_thread without processing spooled job - void AbortPrintThread(); + status_t Remove(); + status_t ConfigurePrinter(); + status_t ConfigureJob(BMessage& ioSettings); + status_t ConfigurePage(BMessage& ioSettings); + status_t GetDefaultSettings(BMessage& configuration); - void MessageReceived(BMessage* msg); + // Try to start processing of next spooled job + void HandleSpooledJob(); - // Scripting support, see Printer.Scripting.cpp - status_t GetSupportedSuites(BMessage* msg); - void HandleScriptingCommand(BMessage* msg); - BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, - int32 form, const char* prop); - - void GetName(BString& name); - Resource* GetResource() { return fResource; } - + // Abort print_thread without processing spooled job + void AbortPrintThread(); + + // Scripting support, see Printer.Scripting.cpp + void HandleScriptingCommand(BMessage* msg); + + void GetName(BString& name); + Resource* GetResource() { return fResource; } + private: - status_t LoadPrinterAddon(image_id& id); - void AddCurrentPrinter(BMessage* m); + status_t LoadPrinterAddon(image_id& id); + void AddCurrentPrinter(BMessage* m); - SpoolFolder fPrinter; // the printer spooling directory - Resource* fResource; // the resource required for processing a print job - bool fSinglePrintThread; // is printer add-on allowed to process multiple print job at once - Job* fJob; // the next job to process - vint32 fProcessing; // the current nmber of processing threads - bool fAbort; // stop processing - - static BObjectList sPrinters; + // Accessor + BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); } - // Accessor - BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); } + void ResetJobStatus(); + bool HasCurrentPrinter(BString& name); + bool MoveJob(const BString& name); - void ResetJobStatus(); - bool HasCurrentPrinter(BString& name); - bool MoveJob(const BString& name); - // Get next spooled job if any - bool FindSpooledJob(); - status_t PrintSpooledJob(BFile* spoolFile); - void PrintThread(Job* job); - static status_t print_thread(void* data); - void StartPrintThread(); + // Get next spooled job if any + bool FindSpooledJob(); + status_t PrintSpooledJob(BFile* spoolFile); + void PrintThread(Job* job); + + static status_t print_thread(void* data); + void StartPrintThread(); + +private: + // the printer spooling directory + SpoolFolder fPrinter; + // the resource required for processing a print job + Resource* fResource; + // is printer add-on allowed to process multiple print job at once + bool fSinglePrintThread; + // the next job to process + Job* fJob; + // the current nmber of processing threads + vint32 fProcessing; + // stop processing + bool fAbort; + static BObjectList sPrinters; }; #endif From julun at mail.berlios.de Mon Jul 7 22:04:03 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Mon, 7 Jul 2008 22:04:03 +0200 Subject: [Haiku-commits] r26309 - haiku/trunk/src/servers/print Message-ID: <200807072004.m67K43eq022462@sheep.berlios.de> Author: julun Date: 2008-07-07 22:04:03 +0200 (Mon, 07 Jul 2008) New Revision: 26309 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26309&view=rev Modified: haiku/trunk/src/servers/print/Printer.cpp haiku/trunk/src/servers/print/Printer.h Log: * set the what field to okok on success, as the epson returns 'Good' for some reason Modified: haiku/trunk/src/servers/print/Printer.cpp =================================================================== --- haiku/trunk/src/servers/print/Printer.cpp 2008-07-07 20:01:46 UTC (rev 26308) +++ haiku/trunk/src/servers/print/Printer.cpp 2008-07-07 20:04:03 UTC (rev 26309) @@ -37,8 +37,8 @@ // Notify print_server that there is a job file waiting for printing void SpoolFolder::Notify(Job* job, int kind) { - if ((kind == kJobAdded || kind == kJobAttrChanged) && - job->IsValid() && job->IsWaiting()) { + if ((kind == kJobAdded || kind == kJobAttrChanged) + && job->IsValid() && job->IsWaiting()) { be_app_messenger.SendMessage(PSRV_PRINT_SPOOLED_JOB); } } @@ -70,12 +70,9 @@ { // Look in list to find printer definition for (int32 idx=0; idx < sPrinters.CountItems(); idx++) { - if (name == sPrinters.ItemAt(idx)->Name()) { + if (name == sPrinters.ItemAt(idx)->Name()) return sPrinters.ItemAt(idx); - } } - - // None found, so return NULL return NULL; } @@ -84,7 +81,7 @@ { node_ref n; // Look in list to find printer definition - for (int32 idx=0; idx < sPrinters.CountItems(); idx++) { + for (int32 idx = 0; idx < sPrinters.CountItems(); idx++) { Printer* printer = sPrinters.ItemAt(idx); printer->SpoolDir()->GetNodeRef(&n); if (n == *node) @@ -155,6 +152,24 @@ } +void Printer::MessageReceived(BMessage* msg) +{ + switch(msg->what) { + case B_GET_PROPERTY: + case B_SET_PROPERTY: + case B_CREATE_PROPERTY: + case B_DELETE_PROPERTY: + case B_COUNT_PROPERTIES: + case B_EXECUTE_PROPERTY: + HandleScriptingCommand(msg); + break; + + default: + Inherited::MessageReceived(msg); + } +} + + // Remove printer spooler directory status_t Printer::Remove() { @@ -227,7 +242,8 @@ BMessage* new_settings = (*func)(SpoolDir(), &settings); if (new_settings != NULL && new_settings->what != 'baad') { settings = *new_settings; - AddCurrentPrinter(&settings); + settings.what = 'okok'; + AddCurrentPrinter(settings); } else { rc = B_ERROR; } @@ -267,7 +283,8 @@ BMessage* new_settings = (*func)(SpoolDir(), &settings); if ((new_settings != NULL) && (new_settings->what != 'baad')) { settings = *new_settings; - AddCurrentPrinter(&settings); + settings.what = 'okok'; + AddCurrentPrinter(settings); } else { rc = B_ERROR; } @@ -320,7 +337,8 @@ BMessage* new_settings = (*func)(SpoolDir()); if (new_settings) { settings = *new_settings; - AddCurrentPrinter(&settings); + settings.what = 'okok'; + AddCurrentPrinter(settings); } else { rc = B_ERROR; } @@ -385,41 +403,13 @@ // Parameters: // msg - message. // --------------------------------------------------------------- -void Printer::AddCurrentPrinter(BMessage* msg) +void Printer::AddCurrentPrinter(BMessage& message) { BString name; GetName(name); - if (msg->HasString(PSRV_FIELD_CURRENT_PRINTER)) { - msg->ReplaceString(PSRV_FIELD_CURRENT_PRINTER, name.String()); - } else { - msg->AddString(PSRV_FIELD_CURRENT_PRINTER, name.String()); - } -} - -// --------------------------------------------------------------- -// MessageReceived -// -// Handle scripting messages. -// -// Parameters: -// msg - message. -// --------------------------------------------------------------- -void Printer::MessageReceived(BMessage* msg) -{ - switch(msg->what) { - case B_GET_PROPERTY: - case B_SET_PROPERTY: - case B_CREATE_PROPERTY: - case B_DELETE_PROPERTY: - case B_COUNT_PROPERTIES: - case B_EXECUTE_PROPERTY: - HandleScriptingCommand(msg); - break; - - default: - Inherited::MessageReceived(msg); - } + message.RemoveName(PSRV_FIELD_CURRENT_PRINTER); + message.AddString(PSRV_FIELD_CURRENT_PRINTER, name.String()); } @@ -433,7 +423,7 @@ // --------------------------------------------------------------- void Printer::GetName(BString& name) { - if (B_OK != SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name)) + if (SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_PRT_NAME, &name) != B_OK) name = "Unknown Printer"; } Modified: haiku/trunk/src/servers/print/Printer.h =================================================================== --- haiku/trunk/src/servers/print/Printer.h 2008-07-07 20:01:46 UTC (rev 26308) +++ haiku/trunk/src/servers/print/Printer.h 2008-07-07 20:04:03 UTC (rev 26309) @@ -81,7 +81,7 @@ private: status_t LoadPrinterAddon(image_id& id); - void AddCurrentPrinter(BMessage* m); + void AddCurrentPrinter(BMessage& message); // Accessor BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); } From korli at mail.berlios.de Mon Jul 7 22:45:54 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Mon, 7 Jul 2008 22:45:54 +0200 Subject: [Haiku-commits] r26310 - haiku/trunk/src/add-ons/kernel/drivers/audio/echo Message-ID: <200807072045.m67Kjs7Q026693@sheep.berlios.de> Author: korli Date: 2008-07-07 22:45:54 +0200 (Mon, 07 Jul 2008) New Revision: 26310 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26310&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp Log: forgot to close the stream before deletion Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-07 20:04:03 UTC (rev 26309) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-07 20:45:54 UTC (rev 26310) @@ -385,9 +385,19 @@ echo_stream_delete(echo_stream *stream) { cpu_status status; + ECHOGALS_CLOSEAUDIOPARAMETERS close_params; LOG(("echo_stream_delete\n")); echo_stream_halt(stream); + + if (stream->pipe >= 0) { + close_params.wPipeIndex = stream->pipe; + status = stream->card->pEG->CloseAudio(&close_params); + if (status != ECHOSTATUS_OK && status != ECHOSTATUS_CHANNEL_NOT_OPEN) { + PRINT(("echo_stream_set_audioparms : CloseAudio failed\n")); + PRINT((" status: %s \n", pStatusStrs[status])); + } + } if(stream->buffer) echo_mem_free(stream->card, stream->buffer->log_base); From axeld at pinc-software.de Mon Jul 7 22:48:58 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 07 Jul 2008 22:48:58 +0200 CEST Subject: [Haiku-commits] r26303 - haiku/trunk/src/kits/network In-Reply-To: <200807071853.m67Ir2Mm010513@sheep.berlios.de> Message-ID: <41985224795-BeMail@zon> zooey at BerliOS wrote: > * instead of always converting from the expected r5_sockaddr_in to > haiku's own, > we now explicitly check whether or not the given sockaddr is an > r5_sockaddr_in > or not, naturally doing the conversion only if it is. This is > necessary since > even R5 applications may not always pass in r5_sockaddr_in structs > (as for > instance gethostbyname() will return a native [haiku-]sockaddr_in) Doesn't that mean instead that we have to fix gethostbyname()? If an R5 app looks at an address is got from there, it should see an R5 compatible address, too, IMO. > * cleaned up the confusion between the name r5addr and it's actual > meaning > (holding a haiku sockaddr_in) - renaming it to haikuAddr instead It was only needed for R5... :-) > * undid the part of Ingo's r25489 described as: "Extended R5 > compatibility > check to also consider calls from libbnetapi" - as I fail to see > why this > would be desirable and in fact it stops at least Beam from working. > Ingo: if you can remember, please enlighten me what was the reason > behind > this change. I remember that I actually did understand it back then, but I don't anymore :-)) > Modified: haiku/trunk/src/kits/network/socket.cpp > =================================================================== > --- haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:12:33 UTC > (rev 26302) > +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:53:01 UTC > (rev 26303) > @@ -22,6 +22,7 @@ > #include > > > +#include > static inline bool Looks like a debug leftover. Bye, Axel. From zooey at mail.berlios.de Mon Jul 7 23:06:05 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Mon, 7 Jul 2008 23:06:05 +0200 Subject: [Haiku-commits] r26311 - haiku/trunk/src/kits/network Message-ID: <200807072106.m67L6556029610@sheep.berlios.de> Author: zooey Date: 2008-07-07 23:06:04 +0200 (Mon, 07 Jul 2008) New Revision: 26311 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26311&view=rev Modified: haiku/trunk/src/kits/network/socket.cpp Log: * removed debuggin leftover Modified: haiku/trunk/src/kits/network/socket.cpp =================================================================== --- haiku/trunk/src/kits/network/socket.cpp 2008-07-07 20:45:54 UTC (rev 26310) +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-07 21:06:04 UTC (rev 26311) @@ -22,7 +22,6 @@ #include -#include static inline bool check_r5_compatibility() { From ingo_weinhold at gmx.de Mon Jul 7 23:11:22 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Mon, 07 Jul 2008 23:11:22 +0200 Subject: [Haiku-commits] r26300 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: <200807071634.m67GYe5K009241@sheep.berlios.de> References: <200807071634.m67GYe5K009241@sheep.berlios.de> Message-ID: <20080707231122.543.2@knochen-vm.nameserver> On 2008-07-07 at 18:34:40 [+0200], axeld at BerliOS wrote: > Author: axeld > Date: 2008-07-07 18:34:38 +0200 (Mon, 07 Jul 2008) > New Revision: 26300 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26300&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp > Log: > * Work-around for the KDEBUG "holder" mechanism; we actually want to lock > the > mutex in another thread here than we will unlock it. > > > Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp > =================================================================== > --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp > 2008-07-07 16:26:57 UTC (rev 26299) > +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp > 2008-07-07 16:34:38 UTC (rev 26300) > @@ -474,6 +474,10 @@ > "bfs block allocator", B_LOW_PRIORITY, (void *)this); > if (id < B_OK) > return _Initialize(this); > +#ifdef KDEBUG > + else > + fLock.holder = id; > +#endif That's a bit ugly IMHO. How about a mutex_transfer_lock(mutex*, thread_id)? Could be inline and a no-op with KDEBUG disabled. CU, Ingo From ingo_weinhold at gmx.de Mon Jul 7 23:34:42 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Mon, 07 Jul 2008 23:34:42 +0200 Subject: [Haiku-commits] r26303 - haiku/trunk/src/kits/network In-Reply-To: <200807071853.m67Ir2Mm010513@sheep.berlios.de> References: <200807071853.m67Ir2Mm010513@sheep.berlios.de> Message-ID: <20080707233442.573.3@knochen-vm.nameserver> On 2008-07-07 at 20:53:02 [+0200], zooey at BerliOS wrote: > Author: zooey > Date: 2008-07-07 20:53:01 +0200 (Mon, 07 Jul 2008) > New Revision: 26303 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26303&view=rev > > Modified: > haiku/trunk/src/kits/network/socket.cpp > Log: > Fixed R5 compatibility "layer" in libnetwork: > * instead of always converting from the expected r5_sockaddr_in to haiku's > own, > we now explicitly check whether or not the given sockaddr is an > r5_sockaddr_in > or not, naturally doing the conversion only if it is. This is necessary > since > even R5 applications may not always pass in r5_sockaddr_in structs (as for > instance gethostbyname() will return a native [haiku-]sockaddr_in) > * cleaned up the confusion between the name r5addr and it's actual meaning > (holding a haiku sockaddr_in) - renaming it to haikuAddr instead > * undid the part of Ingo's r25489 described as: "Extended R5 compatibility > check to also consider calls from libbnetapi" - as I fail to see why this > would be desirable and in fact it stops at least Beam from working. > Ingo: if you can remember, please enlighten me what was the reason behind > this change. IIRC, I just restored the status quo after moving the libbnetapi code out of libnetwork into its own library. > This finally makes Beam "work" (well: connect to servers and download mails > ;-) Cool! Time to switch to Haiku, eh? :-P CU, Ingo From zooey at hirschkaefer.de Mon Jul 7 23:17:49 2008 From: zooey at hirschkaefer.de (Oliver Tappe) Date: Mon, 07 Jul 2008 23:17:49 +0200 Subject: [Haiku-commits] r26303 - haiku/trunk/src/kits/network In-Reply-To: <41985224795-BeMail@zon> References: <41985224795-BeMail@zon> Message-ID: <20080707231749.2054.3@bee.hirschkaefer.site> On 2008-07-07 at 22:48:58 [+0200], Axel D?rfler wrote: > zooey at BerliOS wrote: > > * instead of always converting from the expected r5_sockaddr_in to > > haiku's own, > > we now explicitly check whether or not the given sockaddr is an > > r5_sockaddr_in > > or not, naturally doing the conversion only if it is. This is > > necessary since > > even R5 applications may not always pass in r5_sockaddr_in structs > > (as for > > instance gethostbyname() will return a native [haiku-]sockaddr_in) > > Doesn't that mean instead that we have to fix gethostbyname()? > If an R5 app looks at an address is got from there, it should see an R5 > compatible address, too, IMO. Yeah, you're right, I suppose. I thought about it, but then refrained from hacking away at the ISC stuff. I will do that tomorrow. Once gethostbyname() is fixed, do you think I should revert the actual checking for r5_sockaddr_in again, such that we will be able to spot other problematic functions more easily? [ ... ] > > Modified: haiku/trunk/src/kits/network/socket.cpp > > =================================================================== > > --- haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:12:33 UTC > > (rev 26302) > > +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-07 18:53:01 UTC > > (rev 26303) > > @@ -22,6 +22,7 @@ > > #include > > > > > > +#include > > static inline bool > > Looks like a debug leftover. Ah, yes, fixed in r26311 - thanks for proofreading :-) cheers, Oliver From mmlr at mail.berlios.de Mon Jul 7 23:52:42 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Mon, 7 Jul 2008 23:52:42 +0200 Subject: [Haiku-commits] r26312 - haiku/trunk/src/libs/compat/freebsd_network/compat/sys Message-ID: <200807072152.m67LqgW7001650@sheep.berlios.de> Author: mmlr Date: 2008-07-07 23:52:40 +0200 (Mon, 07 Jul 2008) New Revision: 26312 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26312&view=rev Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h Log: Adding bus_barrier macro to compatibility layer. Modified: haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h =================================================================== --- haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2008-07-07 21:06:04 UTC (rev 26311) +++ haiku/trunk/src/libs/compat/freebsd_network/compat/sys/bus.h 2008-07-07 21:52:40 UTC (rev 26312) @@ -70,6 +70,9 @@ __asm__ __volatile__ ("" : : : "memory"); } +#define bus_barrier(r, o, l, f) \ + bus_space_barrier((r)->r_bustag, (r)->r_bushandle, (o), (l), (f)) + struct resource; struct resource_spec { From bonefish at mail.berlios.de Tue Jul 8 00:52:08 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 8 Jul 2008 00:52:08 +0200 Subject: [Haiku-commits] r26313 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807072252.m67Mq8n4000646@sheep.berlios.de> Author: bonefish Date: 2008-07-08 00:51:46 +0200 (Tue, 08 Jul 2008) New Revision: 26313 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26313&view=rev Added: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMDeviceCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMDeviceCache.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMNullCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMNullCache.h Removed: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp Log: * Renamed the backing store files according to the classes they implement. * Copied VMAnonymousCache to VMAnonymousNoSwapCache. The latter is used ATM. The former will implement swap support. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile 2008-07-07 21:52:40 UTC (rev 26312) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile 2008-07-07 22:51:46 UTC (rev 26313) @@ -9,9 +9,10 @@ vm_daemons.cpp vm_low_memory.cpp vm_page.cpp - vm_store_anonymous_noswap.cpp - vm_store_device.cpp - vm_store_null.cpp + VMAnonymousCache.cpp + VMAnonymousNoSwapCache.cpp + VMDeviceCache.cpp + VMNullCache.cpp #vm_tests.c : $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp (from rev 26270, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-07 22:51:46 UTC (rev 26313) @@ -0,0 +1,170 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include "VMAnonymousCache.h" + +#include +#include +#include +#include + +#include + + +//#define TRACE_STORE +#ifdef TRACE_STORE +# define TRACE(x) dprintf x +#else +# define TRACE(x) ; +#endif + +// The stack functionality looks like a good candidate to put into its own +// store. I have not done this because once we have a swap file backing up +// the memory, it would probably not be a good idea to separate this +// anymore. + + +VMAnonymousCache::~VMAnonymousCache() +{ + vm_unreserve_memory(committed_size); +} + + +status_t +VMAnonymousCache::Init(bool canOvercommit, int32 numPrecommittedPages, + int32 numGuardPages) +{ + TRACE(("VMAnonymousCache::Init(canOvercommit = %s, numGuardPages = %ld) " + "at %p\n", canOvercommit ? "yes" : "no", numGuardPages, store)); + + status_t error = VMCache::Init(CACHE_TYPE_RAM); + if (error != B_OK) + return error; + + fCanOvercommit = canOvercommit; + fHasPrecommitted = false; + fPrecommittedPages = min_c(numPrecommittedPages, 255); + fGuardedSize = numGuardPages * B_PAGE_SIZE; + + return B_OK; +} + + +status_t +VMAnonymousCache::Commit(off_t size) +{ + // if we can overcommit, we don't commit here, but in anonymous_fault() + if (fCanOvercommit) { + if (fHasPrecommitted) + return B_OK; + + // pre-commit some pages to make a later failure less probable + fHasPrecommitted = true; + uint32 precommitted = fPrecommittedPages * B_PAGE_SIZE; + if (size > precommitted) + size = precommitted; + } + + // Check to see how much we could commit - we need real memory + + if (size > committed_size) { + // try to commit + if (vm_try_reserve_memory(size - committed_size) != B_OK) + return B_NO_MEMORY; + } else { + // we can release some + vm_unreserve_memory(committed_size - size); + } + + committed_size = size; + return B_OK; +} + + +bool +VMAnonymousCache::HasPage(off_t offset) +{ + return false; +} + + +status_t +VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + panic("anonymous_store: read called. Invalid!\n"); + return B_ERROR; +} + + +status_t +VMAnonymousCache::Write(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + // no place to write, this will cause the page daemon to skip this store + return B_ERROR; +} + + +status_t +VMAnonymousCache::Fault(struct vm_address_space *aspace, off_t offset) +{ + if (fCanOvercommit) { + if (fGuardedSize > 0) { + uint32 guardOffset; + +#ifdef STACK_GROWS_DOWNWARDS + guardOffset = 0; +#elif defined(STACK_GROWS_UPWARDS) + guardOffset = virtual_size - fGuardedSize; +#else +# error Stack direction has not been defined in arch_config.h +#endif + + // report stack fault, guard page hit! + if (offset >= guardOffset && offset < guardOffset + fGuardedSize) { + TRACE(("stack overflow!\n")); + return B_BAD_ADDRESS; + } + } + + if (fPrecommittedPages == 0) { + // try to commit additional memory + if (vm_try_reserve_memory(B_PAGE_SIZE) != B_OK) + return B_NO_MEMORY; + + committed_size += B_PAGE_SIZE; + } else + fPrecommittedPages--; + } + + // This will cause vm_soft_fault() to handle the fault + return B_BAD_HANDLER; +} + + +void +VMAnonymousCache::MergeStore(VMCache* source) +{ + if (source->type != CACHE_TYPE_RAM) { + panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache %p " + "requested", source); + return; + } + + // take over the source' committed size + committed_size += source->committed_size; + source->committed_size = 0; + + off_t actualSize = virtual_end - virtual_base; + if (committed_size > actualSize) { + vm_unreserve_memory(committed_size - actualSize); + committed_size = actualSize; + } +} Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h (from rev 26250, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h) Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp (from rev 26270, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp 2008-07-06 00:44:17 UTC (rev 26270) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-07 22:51:46 UTC (rev 26313) @@ -0,0 +1,170 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include "VMAnonymousNoSwapCache.h" + +#include +#include +#include +#include + +#include + + +//#define TRACE_STORE +#ifdef TRACE_STORE +# define TRACE(x) dprintf x +#else +# define TRACE(x) ; +#endif + +// The stack functionality looks like a good candidate to put into its own +// store. I have not done this because once we have a swap file backing up +// the memory, it would probably not be a good idea to separate this +// anymore. + + +VMAnonymousNoSwapCache::~VMAnonymousNoSwapCache() +{ + vm_unreserve_memory(committed_size); +} + + +status_t +VMAnonymousNoSwapCache::Init(bool canOvercommit, int32 numPrecommittedPages, + int32 numGuardPages) +{ + TRACE(("VMAnonymousNoSwapCache::Init(canOvercommit = %s, numGuardPages = %ld) " + "at %p\n", canOvercommit ? "yes" : "no", numGuardPages, store)); + + status_t error = VMCache::Init(CACHE_TYPE_RAM); + if (error != B_OK) + return error; + + fCanOvercommit = canOvercommit; + fHasPrecommitted = false; + fPrecommittedPages = min_c(numPrecommittedPages, 255); + fGuardedSize = numGuardPages * B_PAGE_SIZE; + + return B_OK; +} + + +status_t +VMAnonymousNoSwapCache::Commit(off_t size) +{ + // if we can overcommit, we don't commit here, but in anonymous_fault() + if (fCanOvercommit) { + if (fHasPrecommitted) + return B_OK; + + // pre-commit some pages to make a later failure less probable + fHasPrecommitted = true; + uint32 precommitted = fPrecommittedPages * B_PAGE_SIZE; + if (size > precommitted) + size = precommitted; + } + + // Check to see how much we could commit - we need real memory + + if (size > committed_size) { + // try to commit + if (vm_try_reserve_memory(size - committed_size) != B_OK) + return B_NO_MEMORY; + } else { + // we can release some + vm_unreserve_memory(committed_size - size); + } + + committed_size = size; + return B_OK; +} + + +bool +VMAnonymousNoSwapCache::HasPage(off_t offset) +{ + return false; +} + + +status_t +VMAnonymousNoSwapCache::Read(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + panic("anonymous_store: read called. Invalid!\n"); + return B_ERROR; +} + + +status_t +VMAnonymousNoSwapCache::Write(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + // no place to write, this will cause the page daemon to skip this store + return B_ERROR; +} + + +status_t +VMAnonymousNoSwapCache::Fault(struct vm_address_space *aspace, off_t offset) +{ + if (fCanOvercommit) { + if (fGuardedSize > 0) { + uint32 guardOffset; + +#ifdef STACK_GROWS_DOWNWARDS + guardOffset = 0; +#elif defined(STACK_GROWS_UPWARDS) + guardOffset = virtual_size - fGuardedSize; +#else +# error Stack direction has not been defined in arch_config.h +#endif + + // report stack fault, guard page hit! + if (offset >= guardOffset && offset < guardOffset + fGuardedSize) { + TRACE(("stack overflow!\n")); + return B_BAD_ADDRESS; + } + } + + if (fPrecommittedPages == 0) { + // try to commit additional memory + if (vm_try_reserve_memory(B_PAGE_SIZE) != B_OK) + return B_NO_MEMORY; + + committed_size += B_PAGE_SIZE; + } else + fPrecommittedPages--; + } + + // This will cause vm_soft_fault() to handle the fault + return B_BAD_HANDLER; +} + + +void +VMAnonymousNoSwapCache::MergeStore(VMCache* source) +{ + if (source->type != CACHE_TYPE_RAM) { + panic("VMAnonymousNoSwapCache::MergeStore(): merge with non-RAM cache %p " + "requested", source); + return; + } + + // take over the source' committed size + committed_size += source->committed_size; + source->committed_size = 0; + + off_t actualSize = virtual_end - virtual_base; + if (committed_size > actualSize) { + vm_unreserve_memory(committed_size - actualSize); + committed_size = actualSize; + } +} Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.h (from rev 26250, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h 2008-07-04 16:35:50 UTC (rev 26250) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.h 2008-07-07 22:51:46 UTC (rev 26313) @@ -0,0 +1,42 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ +#ifndef _KERNEL_VM_STORE_ANONYMOUS_H +#define _KERNEL_VM_STORE_ANONYMOUS_H + +#include + + +class VMAnonymousNoSwapCache : public VMCache { +public: + virtual ~VMAnonymousNoSwapCache(); + + status_t Init(bool canOvercommit, int32 numPrecommittedPages, + int32 numGuardPages); + + virtual status_t Commit(off_t size); + virtual bool HasPage(off_t offset); + + virtual status_t Read(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter); + virtual status_t Write(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter); + + virtual status_t Fault(struct vm_address_space *aspace, off_t offset); + + virtual void MergeStore(VMCache* source); + +private: + bool fCanOvercommit; + bool fHasPrecommitted; + uint8 fPrecommittedPages; + int32 fGuardedSize; +}; + + +#endif /* _KERNEL_VM_STORE_ANONYMOUS_H */ Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMDeviceCache.cpp (from rev 26250, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp 2008-07-04 16:35:50 UTC (rev 26250) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMDeviceCache.cpp 2008-07-07 22:51:46 UTC (rev 26313) @@ -0,0 +1,43 @@ +/* + * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + * + * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. + * Distributed under the terms of the NewOS License. + */ + +#include "VMDeviceCache.h" + + +status_t +VMDeviceCache::Init(addr_t baseAddress) +{ + fBaseAddress = baseAddress; + return VMCache::Init(CACHE_TYPE_DEVICE); +} + + +bool +VMDeviceCache::HasPage(off_t offset) +{ + // this should never be called + return false; +} + + +status_t +VMDeviceCache::Read(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + panic("device_store: read called. Invalid!\n"); + return B_ERROR; +} + + +status_t +VMDeviceCache::Write(off_t offset, const iovec *vecs, size_t count, + size_t *_numBytes, bool fsReenter) +{ + // no place to write, this will cause the page daemon to skip this store + return B_OK; +} Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMDeviceCache.h (from rev 26248, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.h) Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMNullCache.cpp (from rev 26250, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp 2008-07-04 16:35:50 UTC (rev 26250) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMNullCache.cpp 2008-07-07 22:51:46 UTC (rev 26313) @@ -0,0 +1,13 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include "VMNullCache.h" + + +status_t +VMNullCache::Init() +{ + return VMCache::Init(CACHE_TYPE_NULL); +} Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMNullCache.h (from rev 26250, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h) Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-07 21:52:40 UTC (rev 26312) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_cache.cpp 2008-07-07 22:51:46 UTC (rev 26313) @@ -968,9 +968,9 @@ #include -#include "vm_store_anonymous_noswap.h" -#include "vm_store_device.h" -#include "vm_store_null.h" +#include "VMAnonymousNoSwapCache.h" +#include "VMDeviceCache.h" +#include "VMNullCache.h" #include "../cache/vnode_store.h" @@ -978,7 +978,7 @@ VMCacheFactory::CreateAnonymousCache(VMCache*& _cache, bool canOvercommit, int32 numPrecommittedPages, int32 numGuardPages) { - VMAnonymousCache* cache = new(nogrow) VMAnonymousCache; + VMAnonymousNoSwapCache* cache = new(nogrow) VMAnonymousNoSwapCache; if (cache == NULL) return B_NO_MEMORY; Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.cpp Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_anonymous_noswap.h Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.cpp Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_device.h Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.cpp Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_store_null.h From bonefish at mail.berlios.de Tue Jul 8 01:15:43 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 8 Jul 2008 01:15:43 +0200 Subject: [Haiku-commits] r26314 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807072315.m67NFhW0026157@sheep.berlios.de> Author: bonefish Date: 2008-07-08 01:15:39 +0200 (Tue, 08 Jul 2008) New Revision: 26314 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26314&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp Log: Reordered headers. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-07 22:51:46 UTC (rev 26313) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-07 23:15:39 UTC (rev 26314) @@ -9,14 +9,14 @@ #include "VMAnonymousNoSwapCache.h" +#include + +#include #include #include #include -#include -#include - //#define TRACE_STORE #ifdef TRACE_STORE # define TRACE(x) dprintf x From bonefish at mail.berlios.de Tue Jul 8 01:18:30 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 8 Jul 2008 01:18:30 +0200 Subject: [Haiku-commits] r26315 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807072318.m67NIUbF029937@sheep.berlios.de> Author: bonefish Date: 2008-07-08 01:18:28 +0200 (Tue, 08 Jul 2008) New Revision: 26315 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26315&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h Log: Work in progress by Zhao Shuai: Beginnings of swap file support. Not complete, working, or integrated yet. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-07 23:15:39 UTC (rev 26314) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-07 23:18:28 UTC (rev 26315) @@ -1,4 +1,5 @@ /* + * Copyright 2008, Zhao Shuai, upczhsh at 163.com. * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. @@ -9,14 +10,17 @@ #include "VMAnonymousCache.h" +#include + +#include #include #include +#include +#include +#include #include -#include -#include - //#define TRACE_STORE #ifdef TRACE_STORE # define TRACE(x) dprintf x @@ -24,12 +28,74 @@ # define TRACE(x) ; #endif + +#define SWAP_HASH_SIZE 128 +#define SWAP_HASH_MASK (SWAP_HASH_SIZE - 1) + +#define SWAP_BLOCK_SHIFT 5 +#define SWAP_BLOCK_PAGES (1 << SWAP_BLOCK_SHIFT) + +#define SWAP_BLOCK_NONE -1 + + // The stack functionality looks like a good candidate to put into its own // store. I have not done this because once we have a swap file backing up // the memory, it would probably not be a good idea to separate this // anymore. +struct swap_file { + mutex lock; + struct vnode *vnode; + dev_t device; + ino_t inode; + int page_count; + int used; // # of pages used + struct swap_file *next; + int *maps; // bitmap for the pages + int hint; // next free page +}; + + +struct swap_file_address { + struct swap_file *swapfile; + int page_index; +}; + + +// Each swap block contains SWAP_BLOCK_PAGES pages +struct swap_block { + struct swap_block *hash_next; + VMAnonymousCache *store; + addr_t cache_offset; +// int used; + struct swap_file_address swap_pages[SWAP_BLOCK_PAGES]; +}; + + +static status_t swap_space_alloc(int, struct swap_file_address *); +static void swap_space_dealloc(struct swap_file_address, int); + +static object_cache * sSwapBlockCache; + +static struct swap_block **sSwapHash; +static int sSwapHashMask; +static mutex sSwapHashLock; + +static struct swap_file *sSwapFileList = NULL; +static mutex sSwapFileListLock; +static int sSwapFileCount = 0; +static struct swap_file *sSwapFileAlloc = NULL; //allocate from here + + +// bitmap allocation macros +#define MAP_SHIFT 5 +#define NUM_BITS_PER_WORD 32 // number of bits per word +#define TESTBIT(map, i) (((map)[(i) >> MAP_SHIFT] & (1 << (i) % NUM_BITS_PER_WORD))) +#define SETBIT(map, i) (((map)[(i) >> MAP_SHIFT] |= (1 << (i) % NUM_BITS_PER_WORD))) +#define CLEARBIT(map, i) (((map)[(i) >> MAP_SHIFT] &= ~(1 << (i) % NUM_BITS_PER_WORD))) + + VMAnonymousCache::~VMAnonymousCache() { vm_unreserve_memory(committed_size); @@ -98,8 +164,42 @@ VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - panic("anonymous_store: read called. Invalid!\n"); - return B_ERROR; + status_t status = B_OK; + off_t cache_offset; + iovec iov; + off_t pos; + struct swap_file_address start_address, address; + int i, j; + + cache_offset = offset >> PAGE_SHIFT; + + start_address.swapfile = NULL; + start_address.page_index = SWAP_BLOCK_NONE; + address.swapfile = NULL; + address.page_index = SWAP_BLOCK_NONE; + + for (i = 0; i < count; i = j) { + _SwapBlockGetAddress(cache_offset + i, &start_address); + for (j = i+1; j < count; j++) { + _SwapBlockGetAddress(cache_offset + j, &address); + if (address.swapfile != start_address.swapfile || + address.page_index != start_address.page_index + j - i) + break; + } + + pos = start_address.page_index * PAGE_SIZE; + iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); + iov.iov_len = (j-i) * PAGE_SIZE; + + status = vfs_read_pages(start_address.swapfile->vnode, NULL, pos, &iov, j-i, + _numBytes, fsReenter); + if(status != B_OK) + return status; + + swap_space_dealloc(start_address, j-i); + } + + return B_OK; } @@ -107,8 +207,39 @@ VMAnonymousCache::Write(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - // no place to write, this will cause the page daemon to skip this store - return B_ERROR; + status_t status = B_OK; + off_t pos; + iovec iov; + int i, j, n; + struct swap_file_address address; + int page_index; + + offset >>= PAGE_SHIFT; + iov.iov_base = vecs->iov_base; + iov.iov_len = vecs->iov_len; + + n = count; + for (i = 0; i < count; i += n) { + //try to allocate n pages, if fail, try to allocate n/2 + while ((status = swap_space_alloc(n, &address)) == B_ERROR + && n >= 2) + n >>= 1; + if (status == B_ERROR) + return B_ERROR; + + for (j = 0; j < n; j++) + _SwapBlockBuild(offset + i + j, address); + + pos = address.page_index * PAGE_SIZE; + iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); + iov.iov_len = n * PAGE_SIZE; + + if ((status = vfs_write_pages(address.swapfile->vnode, NULL, pos, + &iov, n, _numBytes, fsReenter)) != B_OK) + return B_ERROR; + } + + return status; } @@ -168,3 +299,226 @@ committed_size = actualSize; } } + + +swap_block** +VMAnonymousCache::_SwapHash(off_t cache_offset) +{ + struct swap_block **pswap; + struct swap_block *swap; + + cache_offset &= ~(off_t)(SWAP_HASH_MASK); + pswap = &sSwapHash[(cache_offset ^ (int)(int *)this) & sSwapHashMask]; + while ((swap = *pswap) != NULL) { + if (swap->store == this && swap->cache_offset == cache_offset) + break; + pswap = &swap->hash_next; + } + + return pswap; +} + + +void +VMAnonymousCache::_SwapBlockBuild(off_t cache_offset, + swap_file_address& address) +{ + struct swap_block *swap; + struct swap_block **pswap; + int index, i; + + mutex_lock(&sSwapHashLock); + pswap = _SwapHash(cache_offset); + + if ((swap = *pswap) == NULL) { + swap = *pswap = (struct swap_block *)object_cache_alloc(sSwapBlockCache, CACHE_DONT_SLEEP); + if (swap == NULL) { + mutex_unlock(&sSwapHashLock); + panic("swap block cache allocation error\n"); + } + + swap->hash_next = NULL; + swap->store = this; + swap->cache_offset = cache_offset & ~(off_t)(SWAP_BLOCK_PAGES - 1); +// swap->used = 0; + + for (i = 0; i < SWAP_BLOCK_PAGES; i++) + swap->swap_pages[i].swapfile = NULL; + swap->swap_pages[i].page_index = SWAP_BLOCK_NONE; + } + + index = cache_offset & (SWAP_BLOCK_PAGES - 1); + swap->swap_pages[index].swapfile = address.swapfile; + swap->swap_pages[index].page_index = address.page_index; + +// swap->used++; + + mutex_unlock(&sSwapHashLock); +} + + +void +VMAnonymousCache::_SwapBlockGetAddress(off_t cache_offset, + swap_file_address *address) +{ + struct swap_block *swap; + struct swap_block **pswap; + int index; + + mutex_lock(&sSwapHashLock); + pswap = _SwapHash(cache_offset); + + if ((swap = *pswap) != NULL) { + index = cache_offset & (off_t)SWAP_HASH_MASK; + address->swapfile = swap->swap_pages[index].swapfile; + address->page_index = swap->swap_pages[index].page_index; + } + + mutex_unlock(&sSwapHashLock); +} + + +static status_t +swap_space_alloc(int npages, struct swap_file_address *address) +{ + int hint, i, j; + + for (j = 0; j < sSwapFileCount; j++) { + if (sSwapFileAlloc == NULL) { + sSwapFileAlloc = sSwapFileList->next; + if (sSwapFileAlloc == NULL) // there is no swap_file + return B_ERROR; + } + + mutex_lock(&sSwapFileAlloc->lock); + hint = sSwapFileAlloc->hint; + + i = 0; + while (i < npages && (hint + npages) < sSwapFileAlloc->page_count) { + if (TESTBIT(sSwapFileAlloc->maps, hint+i)) + { + hint++; + i = 0; + } else + i++; + } + + if (i == npages) + break; + else { // this swap_file is full, find another + mutex_unlock(&sSwapFileAlloc->lock); + sSwapFileAlloc = sSwapFileAlloc->next; + } + } + + if (j == sSwapFileCount) { + panic("swap space exhausted\n"); + return B_ERROR; + } + + address->swapfile = sSwapFileAlloc; + address->page_index = hint; + + for (i = 0; i < npages; i++) + SETBIT(sSwapFileAlloc->maps, hint + i); + if (hint == sSwapFileAlloc->hint) + sSwapFileAlloc->hint += i; + + sSwapFileAlloc->used += npages; + if (sSwapFileAlloc->used > 9 * sSwapFileAlloc->page_count / 10) + sSwapFileAlloc = sSwapFileAlloc->next; + + mutex_unlock(&sSwapFileAlloc->lock); + + return B_OK; +} + + +static void +swap_space_dealloc(struct swap_file_address address, int npages) +{ + mutex_lock(&address.swapfile->lock); + + for (int i = 0; i < npages; i++) + CLEARBIT(address.swapfile->maps, address.page_index + i); + if (address.swapfile->hint > address.page_index) + address.swapfile->hint = address.page_index; + + address.swapfile->used -= npages; + + mutex_unlock(&address.swapfile->lock); +} + + +static status_t +swap_file_add(char *path) +{ + vnode *vp = NULL; + status_t status = B_OK; + struct swap_file *swap, *sw; + struct stat st; + + if ((status = vfs_get_vnode_from_path(path, true, &vp)) != B_OK) + return status; + + swap = (struct swap_file *)malloc(sizeof(struct swap_file)); + if (swap == NULL) + return B_NO_MEMORY; + + mutex_init(&swap->lock, "swap_file"); + + if ((status = vfs_stat_vnode(vp, &st)) != B_OK) { + free(swap); + return status; + } + swap->vnode = vp; + swap->device = st.st_dev; + swap->inode = st.st_ino; + + swap->page_count = st.st_size >> PAGE_SHIFT; + swap->used = 0; + + swap->maps = (int *)malloc(swap->page_count / NUM_BITS_PER_WORD + 1); + if (swap->maps == NULL) { + free(swap); + return B_NO_MEMORY; + } + memset(swap->maps, 0, swap->page_count % 8 + 1); + swap->hint = 0; + + // add this file to swap file list + mutex_lock(&sSwapFileListLock); + sw = sSwapFileList; + while (sw != NULL) + sw = sw->next; + sw->next = swap; + swap->next = NULL; + mutex_unlock(&sSwapFileListLock); + + sSwapFileCount++; + + return status; +} + + +static void +swap_init(void) +{ + // create swap block cache + sSwapBlockCache = create_object_cache("swapblock", + sizeof(struct swap_block), sizeof(void*), NULL, NULL, NULL); + if (sSwapBlockCache == NULL) + panic("can't create object cache for swap blocks\n"); + + // init swap hash table + sSwapHash = (struct swap_block **)malloc(sizeof(struct swap_block *) * SWAP_HASH_SIZE); + if (sSwapHash == NULL) + panic("swap hash table allocation error\n"); + sSwapHashMask = SWAP_HASH_SIZE - 1; + mutex_init(&sSwapHashLock, "swaphash"); + + // init swap file list + mutex_init(&sSwapFileListLock, "swaplist"); + sSwapFileAlloc = sSwapFileList; + sSwapFileCount = 0; +} Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-07 23:15:39 UTC (rev 26314) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-07 23:18:28 UTC (rev 26315) @@ -12,6 +12,10 @@ #include +struct swap_block; +struct swap_file_address; + + class VMAnonymousCache : public VMCache { public: virtual ~VMAnonymousCache(); @@ -32,6 +36,13 @@ virtual void MergeStore(VMCache* source); private: + swap_block** _SwapHash(off_t cache_offset); + void _SwapBlockBuild(off_t cache_offset, + swap_file_address& address); + void _SwapBlockGetAddress(off_t cache_offset, + swap_file_address *address); + +private: bool fCanOvercommit; bool fHasPrecommitted; uint8 fPrecommittedPages; From axeld at pinc-software.de Tue Jul 8 09:15:41 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 08 Jul 2008 09:15:41 +0200 CEST Subject: [Haiku-commits] r26300 - haiku/trunk/src/add-ons/kernel/file_systems/bfs In-Reply-To: <20080707231122.543.2@knochen-vm.nameserver> Message-ID: <635937440-BeMail@zon> Ingo Weinhold wrote: > > +#ifdef KDEBUG > > + else > > + fLock.holder = id; > > +#endif > That's a bit ugly IMHO. How about a mutex_transfer_lock(mutex*, > thread_id)? > Could be inline and a no-op with KDEBUG disabled. You got me there! :-) Sounds like a nice solution - I will do that. Bye, Axel. From axeld at mail.berlios.de Tue Jul 8 09:56:51 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 8 Jul 2008 09:56:51 +0200 Subject: [Haiku-commits] r26316 - in haiku/trunk: headers/private/fs_shell headers/private/kernel src/system/kernel src/tools/fs_shell Message-ID: <200807080756.m687upiP016552@sheep.berlios.de> Author: axeld Date: 2008-07-08 09:56:49 +0200 (Tue, 08 Jul 2008) New Revision: 26316 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26316&view=rev Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h haiku/trunk/headers/private/fs_shell/fssh_lock.h haiku/trunk/headers/private/kernel/lock.h haiku/trunk/src/system/kernel/lock.cpp haiku/trunk/src/tools/fs_shell/lock.cpp Log: * The rw_lock is now able to nest read/write locks when you have a write lock. It follows the semantics of the BFS R/W lock, though, that is, if you unlock your write lock before the read locks, the read locks effectively become write locks, too. * Added a mutex_transfer_lock() function that will allow you to unlock a mutex in a different thread than the one which locked it (only matters if KDEBUG is enabled, though). Modified: haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-07 23:18:28 UTC (rev 26315) +++ haiku/trunk/headers/private/fs_shell/fssh_api_wrapper.h 2008-07-08 07:56:49 UTC (rev 26316) @@ -993,6 +993,7 @@ #define mutex_lock fssh_mutex_lock #define mutex_trylock fssh_mutex_trylock #define mutex_unlock fssh_mutex_unlock +#define mutex_transfer_lock fssh_mutex_transfer_lock //////////////////////////////////////////////////////////////////////////////// Modified: haiku/trunk/headers/private/fs_shell/fssh_lock.h =================================================================== --- haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-07 23:18:28 UTC (rev 26315) +++ haiku/trunk/headers/private/fs_shell/fssh_lock.h 2008-07-08 07:56:49 UTC (rev 26316) @@ -32,6 +32,7 @@ typedef struct fssh_rw_lock { fssh_sem_id sem; + fssh_thread_id holder; int32_t count; } fssh_rw_lock; @@ -75,6 +76,7 @@ extern fssh_status_t fssh_mutex_lock(fssh_mutex* lock); extern fssh_status_t fssh_mutex_trylock(fssh_mutex* lock); extern void fssh_mutex_unlock(fssh_mutex* lock); +extern void fssh_mutex_transfer_lock(fssh_mutex* lock, fssh_thread_id thread); #ifdef __cplusplus } Modified: haiku/trunk/headers/private/kernel/lock.h =================================================================== --- haiku/trunk/headers/private/kernel/lock.h 2008-07-07 23:18:28 UTC (rev 26315) +++ haiku/trunk/headers/private/kernel/lock.h 2008-07-08 07:56:49 UTC (rev 26316) @@ -46,6 +46,7 @@ thread_id holder; int32 reader_count; int32 writer_count; + int32 owner_count; uint32 flags; } rw_lock; @@ -159,6 +160,15 @@ } +static inline void +mutex_transfer_lock(mutex* lock, thread_id thread) +{ +#ifdef KDEBUG + lock->holder = thread; +#endif +} + + extern void lock_debug_init(); #ifdef __cplusplus Modified: haiku/trunk/src/system/kernel/lock.cpp =================================================================== --- haiku/trunk/src/system/kernel/lock.cpp 2008-07-07 23:18:28 UTC (rev 26315) +++ haiku/trunk/src/system/kernel/lock.cpp 2008-07-08 07:56:49 UTC (rev 26316) @@ -191,7 +191,7 @@ lock->waiters->last = waiter->last; lock->holder = waiter->thread->id; - + // unblock thread thread_unblock_locked(waiter->thread, B_OK); } @@ -221,6 +221,7 @@ lock->holder = -1; lock->reader_count = 0; lock->writer_count = 0; + lock->owner_count = 0; lock->flags = 0; } @@ -233,6 +234,7 @@ lock->holder = -1; lock->reader_count = 0; lock->writer_count = 0; + lock->owner_count = 0; lock->flags = flags & RW_LOCK_FLAG_CLONE_NAME; } @@ -284,6 +286,10 @@ lock->reader_count++; return B_OK; } + if (lock->holder == thread_get_current_thread_id()) { + lock->owner_count++; + return B_OK; + } return rw_lock_wait(lock, false); } @@ -294,6 +300,18 @@ { InterruptsSpinLocker locker(thread_spinlock); + if (lock->holder == thread_get_current_thread_id()) { + if (--lock->owner_count > 0) + return B_OK; + + // this originally has been a write lock + lock->writer_count--; + lock->holder = -1; + + rw_lock_unblock(lock); + return B_OK; + } + if (lock->reader_count <= 0) { panic("rw_lock_read_unlock(): lock %p not read-locked", lock); return B_BAD_VALUE; @@ -302,7 +320,6 @@ lock->reader_count--; rw_lock_unblock(lock); - return B_OK; } @@ -315,11 +332,22 @@ if (lock->reader_count == 0 && lock->writer_count == 0) { lock->writer_count++; lock->holder = thread_get_current_thread_id(); + lock->owner_count = 1; return B_OK; } + if (lock->holder == thread_get_current_thread_id()) { + lock->owner_count++; + return B_OK; + } lock->writer_count++; - return rw_lock_wait(lock, true); + + status_t status = rw_lock_wait(lock, true); + if (status == B_OK) { + lock->holder = thread_get_current_thread_id(); + lock->owner_count = 1; + } + return status; } @@ -333,6 +361,8 @@ lock); return B_BAD_VALUE; } + if (--lock->owner_count > 0) + return B_OK; lock->writer_count--; lock->holder = -1; Modified: haiku/trunk/src/tools/fs_shell/lock.cpp =================================================================== --- haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-07 23:18:28 UTC (rev 26315) +++ haiku/trunk/src/tools/fs_shell/lock.cpp 2008-07-08 07:56:49 UTC (rev 26316) @@ -176,6 +176,13 @@ } +extern "C" void +fssh_mutex_transfer_lock(fssh_mutex *mutex, fssh_thread_id thread) +{ + mutex->holder = thread; +} + + // #pragma mark - @@ -188,6 +195,9 @@ if (name == NULL) name = "r/w lock"; + lock->count = 0; + lock->holder = -1; + lock->sem = fssh_create_sem(FSSH_RW_MAX_READERS, name); if (lock->sem < FSSH_B_OK) fssh_panic("could not create r/w lock"); @@ -214,6 +224,11 @@ extern "C" fssh_status_t fssh_rw_lock_read_lock(fssh_rw_lock *lock) { + if (lock->holder == fssh_find_thread(NULL)) { + lock->count++; + return FSSH_B_OK; + } + return fssh_acquire_sem(lock->sem); } @@ -221,6 +236,9 @@ extern "C" fssh_status_t fssh_rw_lock_read_unlock(fssh_rw_lock *lock) { + if (lock->holder == fssh_find_thread(NULL) && --lock->count > 0) + return FSSH_B_OK; + return fssh_release_sem(lock->sem); } @@ -228,13 +246,29 @@ extern "C" fssh_status_t fssh_rw_lock_write_lock(fssh_rw_lock *lock) { - return fssh_acquire_sem_etc(lock->sem, FSSH_RW_MAX_READERS, 0, 0); + if (lock->holder == fssh_find_thread(NULL)) { + lock->count++; + return FSSH_B_OK; + } + + fssh_status_t status = fssh_acquire_sem_etc(lock->sem, FSSH_RW_MAX_READERS, + 0, 0); + if (status == FSSH_B_OK) { + lock->holder = fssh_find_thread(NULL); + lock->count = 1; + } + return status; } extern "C" fssh_status_t fssh_rw_lock_write_unlock(fssh_rw_lock *lock) { + if (--lock->count > 0) + return FSSH_B_OK; + + lock->holder = -1; + return fssh_release_sem_etc(lock->sem, FSSH_RW_MAX_READERS, 0); } From axeld at mail.berlios.de Tue Jul 8 10:04:39 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 8 Jul 2008 10:04:39 +0200 Subject: [Haiku-commits] r26317 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200807080804.m6884dOV017673@sheep.berlios.de> Author: axeld Date: 2008-07-08 10:04:37 +0200 (Tue, 08 Jul 2008) New Revision: 26317 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26317&view=rev Removed: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/CachedBlock.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Replaced BFS's ReadWriteLock implementation with the kernel's rw_lock. * The BlockAllocator now uses the new mutex_transfer_lock() function instead of clobbering the mutex directly. * Removed Lock.h - it's no longer needed. * Minor white space cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Attribute.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Axel D?rfler, axeld at pinc-software.de. + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. * This file may be used under the terms of the MIT License. */ @@ -71,7 +71,7 @@ } -status_t +status_t Attribute::Get(const char *name) { Put(); @@ -119,7 +119,7 @@ attr_cookie *cookie = (attr_cookie *)malloc(sizeof(attr_cookie)); if (cookie == NULL) - RETURN_ERROR(B_NO_MEMORY); + RETURN_ERROR(B_NO_MEMORY); fName = name; @@ -152,7 +152,7 @@ attr_cookie *cookie = (attr_cookie *)malloc(sizeof(attr_cookie)); if (cookie == NULL) - RETURN_ERROR(B_NO_MEMORY); + RETURN_ERROR(B_NO_MEMORY); // initialize the cookie strlcpy(cookie->name, fName, B_ATTR_NAME_LENGTH); @@ -222,7 +222,7 @@ } if (fAttribute != NULL) { - WriteLocked locked(fAttribute->Lock()); + WriteLocker locker(fAttribute->Lock()); Transaction transaction(fAttribute->GetVolume(), fAttribute->BlockNumber()); status_t status = fAttribute->SetFileSize(transaction, 0); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -1259,7 +1259,7 @@ #endif // lock access to stream - WriteLocked locked(fStream->Lock()); + WriteLocker locker(fStream->Lock()); Stack stack; if (_SeekDown(stack, key, keyLength) != B_OK) @@ -1653,7 +1653,7 @@ RETURN_ERROR(B_BAD_VALUE); // lock access to stream - WriteLocked locked(fStream->Lock()); + WriteLocker locker(fStream->Lock()); Stack stack; if (_SeekDown(stack, key, keyLength) != B_OK) @@ -1771,7 +1771,7 @@ RETURN_ERROR(B_BAD_TYPE); // lock access to stream (a read lock is okay for this purpose) - ReadLocked locked(fStream->Lock()); + ReadLocker locker(fStream->Lock()); off_t nodeOffset = fHeader->RootNode(); CachedNode cached(this); @@ -1825,7 +1825,7 @@ RETURN_ERROR(B_BAD_TYPE); // lock access to stream - ReadLocked locked(fStream->Lock()); + ReadLocker locker(fStream->Lock()); off_t nodeOffset = fHeader->RootNode(); CachedNode cached(this); @@ -1889,7 +1889,7 @@ RETURN_ERROR(B_BAD_VALUE); // lock access to stream - ReadLocked locked(fTree->fStream->Lock()); + ReadLocker locker(fTree->fStream->Lock()); off_t nodeOffset = fTree->fHeader->RootNode(); CachedNode cached(fTree); @@ -1959,7 +1959,7 @@ return B_ENTRY_NOT_FOUND; // lock access to stream - ReadLocked locked(fTree->fStream->Lock()); + ReadLocker locker(fTree->fStream->Lock()); CachedNode cached(fTree); const bplustree_node *node; @@ -2095,7 +2095,7 @@ RETURN_ERROR(B_BAD_VALUE); // lock access to stream - ReadLocked locked(fTree->fStream->Lock()); + ReadLocker locker(fTree->fStream->Lock()); off_t nodeOffset = fTree->fHeader->RootNode(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -474,10 +474,8 @@ "bfs block allocator", B_LOW_PRIORITY, (void *)this); if (id < B_OK) return _Initialize(this); -#ifdef KDEBUG else - fLock.holder = id; -#endif + mutex_transfer_lock(&fLock, id); return resume_thread(id); } Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/CachedBlock.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/CachedBlock.h 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/CachedBlock.h 2008-07-08 08:04:37 UTC (rev 26317) @@ -12,7 +12,6 @@ #include "Volume.h" #include "Journal.h" -#include "Lock.h" #include "Chain.h" #include "Debug.h" @@ -96,7 +95,7 @@ } -inline +inline CachedBlock::CachedBlock(CachedBlock *cached) : fVolume(cached->fVolume), @@ -161,7 +160,7 @@ { Unset(); fBlockNumber = block; - + if (empty) { fBlock = (uint8 *)block_cache_get_empty(fVolume->BlockCache(), block, transaction.ID()); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Index.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -1,5 +1,5 @@ -/* - * Copyright 2001-2007, Axel D?rfler, axeld at pinc-software.de. +/* + * Copyright 2001-2008, Axel D?rfler, axeld at pinc-software.de. * This file may be used under the terms of the MIT License. */ @@ -63,7 +63,7 @@ { // remove the old node, if the index is set for the second time Unset(); - + fName = name; // only stores the pointer, so it assumes that it will stay constant // in further comparisons (currently only used in Index::Update()) @@ -138,7 +138,7 @@ { if (fNode == NULL) return 0; - + int32 mode = fNode->Mode() & (S_STR_INDEX | S_INT_INDEX | S_UINT_INDEX | S_LONG_LONG_INDEX | S_ULONG_LONG_INDEX | S_FLOAT_INDEX | S_DOUBLE_INDEX); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -328,7 +328,7 @@ char lockName[B_OS_NAME_LENGTH]; snprintf(lockName, sizeof(lockName), "bfs inode %d.%d", (int)BlockRun().AllocationGroup(), BlockRun().Start()); - fLock.Initialize(lockName); + rw_lock_init_etc(&fLock, lockName, RW_LOCK_FLAG_CLONE_NAME); recursive_lock_init(&fSmallDataLock, "bfs inode small data"); @@ -361,7 +361,7 @@ char lockName[B_OS_NAME_LENGTH]; snprintf(lockName, sizeof(lockName), "bfs inode+%d.%d", (int)run.AllocationGroup(), run.Start()); - fLock.Initialize(lockName); + rw_lock_init_etc(&fLock, lockName, RW_LOCK_FLAG_CLONE_NAME); recursive_lock_init(&fSmallDataLock, "bfs inode small data"); @@ -399,6 +399,8 @@ file_cache_delete(FileCache()); file_map_delete(Map()); delete fTree; + + rw_lock_destroy(&fLock); } @@ -429,9 +431,7 @@ } } - // it's more important to know that the inode is corrupt - // so we check for the lock not until here - return fLock.InitCheck(); + return B_OK; } @@ -1055,7 +1055,7 @@ } if (attribute != NULL) { - if (attribute->Lock().LockWrite() == B_OK) { + if (rw_lock_write_lock(&attribute->Lock()) == B_OK) { // Save the old attribute data (if this fails, oldLength will // reflect it) if (fVolume->CheckForLiveQuery(name) && attribute->Size() > 0) { @@ -1071,14 +1071,14 @@ if (status == B_OK) { // it does - remove its file - attribute->Lock().UnlockWrite(); + rw_lock_write_unlock(&attribute->Lock()); status = _RemoveAttribute(transaction, name, false, NULL); } else { // The attribute type might have been changed - we need to // adopt the new one attribute->Node().type = HOST_ENDIAN_TO_BFS_INT32(type); status = attribute->WriteBack(transaction); - attribute->Lock().UnlockWrite(); + rw_lock_write_unlock(&attribute->Lock()); if (status == B_OK) { status = attribute->WriteAt(transaction, pos, buffer, @@ -1376,7 +1376,7 @@ if (pos < 0) return B_BAD_VALUE; - ReadLocked locker(Lock()); + ReadLocker locker(Lock()); if (pos >= Size() || length == 0) { *_length = 0; @@ -1393,8 +1393,8 @@ Inode::WriteAt(Transaction &transaction, off_t pos, const uint8 *buffer, size_t *_length) { - WriteLocked locker(Lock()); - if (locker.IsLocked() < B_OK) + WriteLocker locker(Lock()); + if (!locker.IsLocked()) RETURN_ERROR(B_ERROR); // update the last modification time in memory, it will be written @@ -2310,7 +2310,7 @@ RETURN_ERROR(B_BAD_VALUE); } - WriteLocked locker(parent != NULL ? &parent->Lock() : NULL); + WriteLocker locker(parent != NULL ? &parent->Lock() : NULL); // the parent directory is locked during the whole inode creation if (parent != NULL && parent->IsDirectory()) { @@ -2354,7 +2354,7 @@ return status; // truncate the existing file - WriteLocked locked(inode->Lock()); + WriteLocker _(inode->Lock()); status_t status = inode->SetFileSize(transaction, 0); if (status >= B_OK) Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Inode.h 2008-07-08 08:04:37 UTC (rev 26317) @@ -10,7 +10,6 @@ #include "Volume.h" #include "Journal.h" -#include "Lock.h" #include "Chain.h" #include "Debug.h" #include "CachedBlock.h" @@ -45,7 +44,7 @@ ino_t ID() const { return fID; } off_t BlockNumber() const { return fVolume->VnodeToBlock(fID); } - ReadWriteLock &Lock() { return fLock; } + rw_lock &Lock() { return fLock; } recursive_lock &SmallDataLock() { return fSmallDataLock; } status_t WriteBack(Transaction &transaction); @@ -193,7 +192,7 @@ status_t _ShrinkStream(Transaction &transaction, off_t size); private: - ReadWriteLock fLock; + rw_lock fLock; Volume *fVolume; ino_t fID; BPlusTree *fTree; Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Journal.h 2008-07-08 08:04:37 UTC (rev 26317) @@ -14,7 +14,6 @@ #include "Volume.h" #include "Chain.h" -#include "Lock.h" #include "Utility.h" Deleted: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Lock.h Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-08 07:56:49 UTC (rev 26316) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-08 08:04:37 UTC (rev 26317) @@ -339,7 +339,7 @@ RETURN_ERROR(B_BAD_VALUE); if (!reenter) - inode->Lock().Lock(); + rw_lock_read_lock(&inode->Lock()); uint32 vecIndex = 0; size_t vecOffset = 0; @@ -368,7 +368,7 @@ } if (!reenter) - inode->Lock().Unlock(); + rw_lock_read_unlock(&inode->Lock()); return status; } @@ -388,7 +388,7 @@ RETURN_ERROR(B_BAD_VALUE); if (!reenter) - inode->Lock().Lock(); + rw_lock_read_lock(&inode->Lock()); uint32 vecIndex = 0; size_t vecOffset = 0; @@ -417,7 +417,7 @@ } if (!reenter) - inode->Lock().Unlock(); + rw_lock_read_unlock(&inode->Lock()); return status; } @@ -646,11 +646,10 @@ return B_BAD_VALUE; Inode *inode = (Inode *)_node->private_node; - ReadLocked locked(inode->Lock()); + ReadLocker locker(inode->Lock()); - status_t status = locked.IsLocked(); - if (status < B_OK) - RETURN_ERROR(status); + if (!locker.IsLocked()) + RETURN_ERROR(B_ERROR); return inode->Sync(); } @@ -689,8 +688,8 @@ Transaction transaction(volume, inode->BlockNumber()); - WriteLocked locked(inode->Lock()); - if (locked.IsLocked() < B_OK) + WriteLocker locker(inode->Lock()); + if (!locker.IsLocked()) RETURN_ERROR(B_ERROR); bfs_inode &node = inode->Node(); @@ -1150,7 +1149,7 @@ // Should we truncate the file? if (openMode & O_TRUNC) { Transaction transaction(volume, inode->BlockNumber()); - WriteLocked locked(inode->Lock()); + WriteLocker locker(inode->Lock()); status_t status = inode->SetFileSize(transaction, 0); if (status >= B_OK) @@ -1219,7 +1218,7 @@ transaction.Done(); if (status == B_OK) { - ReadLocked locker(inode->Lock()); + ReadLocker locker(inode->Lock()); // periodically notify if the file size has changed // TODO: should we better test for a change in the last_modified time only? @@ -1258,7 +1257,7 @@ bool needsTrimming = false; if (!volume->IsReadOnly()) { - ReadLocked locker(inode->Lock()); + ReadLocker locker(inode->Lock()); needsTrimming = inode->NeedsTrimming(); if ((cookie->open_mode & O_RWMASK) != 0 @@ -1274,7 +1273,7 @@ status_t status = transaction.IsStarted() ? B_OK : B_ERROR; if (status == B_OK) { - WriteLocked locker(inode->Lock()); + WriteLocker locker(inode->Lock()); // trim the preallocated blocks and update the size, // and last_modified indices if needed From bonefish at mail.berlios.de Tue Jul 8 16:34:17 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 8 Jul 2008 16:34:17 +0200 Subject: [Haiku-commits] r26318 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807081434.m68EYH0j012602@sheep.berlios.de> Author: bonefish Date: 2008-07-08 16:34:15 +0200 (Tue, 08 Jul 2008) New Revision: 26318 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26318&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp Log: When resizing a cache we need to offset by its virtual_base. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-08 08:04:37 UTC (rev 26317) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-08 14:34:15 UTC (rev 26318) @@ -1239,7 +1239,7 @@ // If no one else uses the area's cache, we can resize it, too. if (cache->areas == area && area->cache_next == NULL && list_is_empty(&cache->consumers)) { - status_t error = cache->Resize(newSize); + status_t error = cache->Resize(cache->virtual_base + newSize); if (error != B_OK) return error; } @@ -4782,7 +4782,7 @@ if (oldSize < newSize) { // Growing the cache can fail, so we do it first. - status = cache->Resize(newSize); + status = cache->Resize(cache->virtual_base + newSize); if (status != B_OK) return status; } @@ -4822,7 +4822,7 @@ // shrinking the cache can't fail, so we do it now if (status == B_OK && newSize < oldSize) - status = cache->Resize(newSize); + status = cache->Resize(cache->virtual_base + newSize); if (status < B_OK) { // This shouldn't really be possible, but hey, who knows @@ -4831,7 +4831,7 @@ current->size = oldSize; } - cache->Resize(oldSize); + cache->Resize(cache->virtual_base + oldSize); } // TODO: we must honour the lock restrictions of this area From axeld at pinc-software.de Tue Jul 8 16:52:20 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 08 Jul 2008 16:52:20 +0200 CEST Subject: [Haiku-commits] r26303 - haiku/trunk/src/kits/network In-Reply-To: <20080707231749.2054.3@bee.hirschkaefer.site> Message-ID: <28034726181-BeMail@zon> Oliver Tappe wrote: > On 2008-07-07 at 22:48:58 [+0200], Axel D?rfler > > wrote: > > Doesn't that mean instead that we have to fix gethostbyname()? > > If an R5 app looks at an address is got from there, it should see > > an R5 > > compatible address, too, IMO. > Yeah, you're right, I suppose. I thought about it, but then refrained > from > hacking away at the ISC stuff. I will do that tomorrow. Thanks! :-) > Once gethostbyname() is fixed, do you think I should revert the > actual > checking for r5_sockaddr_in again, such that we will be able to spot > other > problematic functions more easily? At least it shouldn't be needed afterwards, anymore - maybe disabling it would be a good idea. [...] Bye, Axel. From bonefish at mail.berlios.de Tue Jul 8 17:02:22 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 8 Jul 2008 17:02:22 +0200 Subject: [Haiku-commits] r26319 - in haiku/branches/developer/bonefish/vm: build/jam headers/os/bluetooth headers/os/bluetooth/HCI headers/os/bluetooth/L2CAP headers/os/net headers/posix headers/private/bluetooth headers/private/fs_shell headers/private/interface headers/private/kernel headers/private/kernel/arch/m68k headers/private/kernel/arch/x86 headers/private/kernel/disk_device_manager headers/private/kernel/util src/add-ons/disk_systems/bfs src/add-ons/kernel/bus_managers/acpi src/add-ons/kernel/bus_managers/acpi/common src/add-ons/kernel/bus_managers/acpi/compiler src/add-ons/kernel/bus_managers/acpi/debugger src/add-ons/kernel/bus_managers/acpi/disassembler src/add-ons/kernel/bus_managers/acpi/dispatcher src/add-ons/kernel/bus_managers/acpi/events src/add-ons/kernel/bus_managers/acpi/executer src/add-ons/kernel/bus_managers/acpi/hardware src/add-ons/kernel/bus_managers/acpi/include src/add-ons/kernel/bus_managers/acpi/include/platform src/add-ons/kernel/bus_managers/acpi/namespace ! src/add-ons/kernel/bus_managers/acpi/parser src/add-ons/kernel/bus_managers/acpi/resources src/add-ons/kernel/bus_managers/acpi/tables src/add-ons/kernel/bus_managers/acpi/utilities src/add-ons/kernel/bus_managers/firewire src/add-ons/kernel/busses/scsi/ahci src/add-ons/kernel/drivers/audio/echo src/add-ons/kernel/drivers/audio/echo/generic src/add-ons/kernel/drivers/audio/hda src/add-ons/kernel/drivers/bluetooth src/add-ons/kernel/drivers/bluetooth/h2 src/add-ons/kernel/drivers/bluetooth/h2/h2generic src/add-ons/kernel/drivers/disk/usb/usb_disk src/add-ons/kernel/file_systems src/add-ons/kernel/file_systems/bfs src/add-ons/kernel/file_systems/ext2 src/add-ons/kernel/file_systems/reiserfs src/add-ons/kernel/network/devices src/add-ons/kernel/network/devices/bluetooth src/add-ons/kernel/network/protocols/l2cap src/add-ons/kernel/partitioning_systems/intel src/apps/deskbar src/apps/mediaplayer src/apps/mediaplayer/interface src/apps/mediaplayer/media_node_framework src/apps/m! ediaplayer/media_node_framework/audio src/apps/mediaplayer/pla! ylist sr Message-ID: <200807081502.m68F2MB0017389@sheep.berlios.de> Author: bonefish Date: 2008-07-08 16:58:39 +0200 (Tue, 08 Jul 2008) New Revision: 26319 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26319&view=rev Added: haiku/branches/developer/bonefish/vm/headers/private/fs_shell/fssh_lock.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsfield.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsinit.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsmethod.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsmthdat.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsobject.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsopcode.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswexec.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswload.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswscope.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswstate.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exconfig.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exconvrt.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/excreate.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exdump.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exfield.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exfldio.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exmisc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exmutex.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exnames.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg1.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg2.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg3.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg6.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exprep.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exregion.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresnte.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresolv.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresop.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstore.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstoren.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstorob.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exsystem.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psargs.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psloop.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psopcode.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psparse.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psscope.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/pstree.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/pswalk.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psxface.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/CachedBlock.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Inode.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/devices/bluetooth/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/devices/bluetooth/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/interface/PeakView.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/interface/PeakView.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/RandomizePLItemsCommand.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/ haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/apic.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/hpet.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/pit.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_apic.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_hpet.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_pit.c haiku/branches/developer/bonefish/vm/src/system/libroot/posix/string/strlwr.c haiku/branches/developer/bonefish/vm/src/system/libroot/posix/string/strupr.c haiku/branches/developer/bonefish/vm/src/tests/kits/net/NetAddressTest.cpp haiku/branches/developer/bonefish/vm/src/tests/system/kernel/page_fault_cache_merge_test.cpp Removed: haiku/branches/developer/bonefish/vm/headers/private/kernel/arch/x86/arch_hpet.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsfield.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsinit.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsmethod.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsmthdat.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsobject.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsopcode.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dsutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswexec.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswload.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswscope.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/dispatcher/dswstate.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exconfig.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exconvrt.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/excreate.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exdump.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exfield.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exfldio.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exmisc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exmutex.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exnames.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg1.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg2.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg3.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exoparg6.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exprep.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exregion.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresnte.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresolv.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exresop.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstore.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstoren.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exstorob.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exsystem.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/executer/exutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/platform/acdos16.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/interpreter/ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psargs.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psloop.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psopcode.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psparse.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psscope.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/pstree.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/pswalk.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/parser/psxface.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Lock.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/CachedBlock.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/DirectoryIterator.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Inode.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Inode.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/ext2.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/ext2/kernel_interface.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/devices/bluetooth/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/devices/bluetooth/bluetooth.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/apic.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/hpet.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/pit.h haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_apic.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_hpet.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/timers/x86_pit.c haiku/branches/developer/bonefish/vm/src/tools/fs_shell/block_cache_priv.h haiku/branches/developer/bonefish/vm/src/tools/fs_shell/lock.h Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage haiku/branches/developer/bonefish/vm/headers/os/bluetooth/BluetoothDevice.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DeviceClass.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryAgent.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryListener.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_acl.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_command.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_event.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_module.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_transport.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/L2CAP/btL2CAP.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/LocalDevice.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/RemoteDevice.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/bdaddrUtils.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/bluetooth.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/bluetooth_error.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/bluetooth_util.h haiku/branches/developer/bonefish/vm/headers/os/net/NetAddress.h haiku/branches/developer/bonefish/vm/headers/posix/string.h haiku/branches/developer/bonefish/vm/headers/private/bluetooth/CommandManager.h haiku/branches/developer/bonefish/vm/headers/private/bluetooth/ConnectionIncoming.h haiku/branches/developer/bonefish/vm/headers/private/bluetooth/PincodeWindow.h haiku/branches/developer/bonefish/vm/headers/private/bluetooth/bluetoothserver_p.h haiku/branches/developer/bonefish/vm/headers/private/bluetooth/btDebug.h haiku/branches/developer/bonefish/vm/headers/private/fs_shell/fssh_api_wrapper.h haiku/branches/developer/bonefish/vm/headers/private/fs_shell/fssh_auto_locker.h haiku/branches/developer/bonefish/vm/headers/private/fs_shell/fssh_errors.h haiku/branches/developer/bonefish/vm/headers/private/interface/ViewPrivate.h haiku/branches/developer/bonefish/vm/headers/private/kernel/arch/m68k/arch_cpu.h haiku/branches/developer/bonefish/vm/headers/private/kernel/arch/x86/timer.h haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KPartition.h haiku/branches/developer/bonefish/vm/headers/private/kernel/file_cache.h haiku/branches/developer/bonefish/vm/headers/private/kernel/heap.h haiku/branches/developer/bonefish/vm/headers/private/kernel/kmodule.h haiku/branches/developer/bonefish/vm/headers/private/kernel/lock.h haiku/branches/developer/bonefish/vm/headers/private/kernel/timer.h haiku/branches/developer/bonefish/vm/headers/private/kernel/util/AutoLock.h haiku/branches/developer/bonefish/vm/src/add-ons/disk_systems/bfs/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/a16find.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/adfile.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/adisasm.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/dmtable.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/dmtbdump.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/common/dmtbinfo.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/Makefile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/aslmain.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/aslopcodes.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/asloperands.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/aslopt.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/aslstubs.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/compiler/aslutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbcmds.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbdisply.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbexec.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbfileio.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbhistry.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/debugger/dbutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmbuffer.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmnames.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmopcode.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmresrc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmresrcl.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/disassembler/dmwalk.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evevent.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evgpe.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evgpeblk.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evmisc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evregion.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/events/evrgnini.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/hardware/hwregs.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/hardware/hwsleep.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acconfig.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acdisasm.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acdispat.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acexcep.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/achware.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acinterp.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/aclocal.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acmacros.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acnamesp.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acpiosxf.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acpixf.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acstruct.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/actables.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/actbl1.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/actypes.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/acutils.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/include/platform/achaiku.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsdump.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nseval.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsinit.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsload.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsparse.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nssearch.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/namespace/nsxfeval.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/oshaiku.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/resources/rscalc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/resources/rscreate.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/resources/rsmisc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/resources/rsutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbfadt.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbfind.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbinstal.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbutils.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbxface.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/tables/tbxfroot.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utalloc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utclib.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utcopy.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utdebug.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utdelete.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/uteval.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utglobal.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utmisc.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utmutex.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utobject.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/uttrack.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/acpi/utilities/utxface.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/bus_managers/firewire/firewire.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/ahci_defs.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/echo.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/generic/OsSupportBeOS.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2cfg.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2transactions.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2upper.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/snet_buffer.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/snet_buffer.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Attribute.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/BPlusTree.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/BPlusTree.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/CachedBlock.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Index.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Inode.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Inode.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Jamfile haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Journal.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Journal.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Query.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/system_dependencies.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Key.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/network/protocols/l2cap/l2cap_address.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/partitioning_systems/intel/intel.cpp haiku/branches/developer/bonefish/vm/src/apps/deskbar/BeMenu.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/Controller.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/Controller.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/ControllerView.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/Jamfile haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/MainApp.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/MainWin.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/TransportControlGroup.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/TransportControlGroup.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/interface/SeekSlider.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/interface/SeekSlider.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/media_node_framework/NodeManager.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/media_node_framework/NodeManager.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/media_node_framework/audio/AudioProducer.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/ListViews.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/MovePLItemsCommand.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/Playlist.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/PlaylistListView.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/PlaylistListView.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/playlist/PlaylistWindow.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/AudioTrackSupplier.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/MediaTrackAudioSupplier.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/MediaTrackVideoSupplier.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/supplier/VideoTrackSupplier.h haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/support/MessageEvent.cpp haiku/branches/developer/bonefish/vm/src/apps/mediaplayer/support/MessageEvent.h haiku/branches/developer/bonefish/vm/src/data/beos_mime/text/html haiku/branches/developer/bonefish/vm/src/data/beos_mime/text/x-source-code haiku/branches/developer/bonefish/vm/src/data/beos_mime/text/x-vnd.be.resourcedef haiku/branches/developer/bonefish/vm/src/data/beos_mime/text/xml haiku/branches/developer/bonefish/vm/src/kits/app/Looper.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/CommandManager.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/DiscoveryAgent.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/DiscoveryListener.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/Jamfile haiku/branches/developer/bonefish/vm/src/kits/bluetooth/KitSupport.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/KitSupport.h haiku/branches/developer/bonefish/vm/src/kits/bluetooth/LocalDevice.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/RemoteDevice.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/UI/ConnectionIncoming.cpp haiku/branches/developer/bonefish/vm/src/kits/bluetooth/UI/PincodeWindow.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/ListView.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/OutlineListView.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/PrintJob.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp haiku/branches/developer/bonefish/vm/src/kits/network/init.cpp haiku/branches/developer/bonefish/vm/src/kits/network/libnetapi/NetAddress.cpp haiku/branches/developer/bonefish/vm/src/kits/network/socket.cpp haiku/branches/developer/bonefish/vm/src/kits/tracker/MountMenu.cpp haiku/branches/developer/bonefish/vm/src/libs/compat/freebsd_network/compat/sys/bus.h haiku/branches/developer/bonefish/vm/src/preferences/media/MediaViews.cpp haiku/branches/developer/bonefish/vm/src/servers/app/ServerApp.cpp haiku/branches/developer/bonefish/vm/src/servers/app/ServerApp.h haiku/branches/developer/bonefish/vm/src/servers/app/ServerWindow.cpp haiku/branches/developer/bonefish/vm/src/servers/app/ServerWindow.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/BPortNot.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/BPortNot.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/BluetoothServer.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/BluetoothServer.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/DeviceManager.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/DeviceManager.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIDelegate.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/Jamfile haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceHandler.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceImpl.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceImpl.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/Output.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/Output.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/server-bluetooth.rdef haiku/branches/developer/bonefish/vm/src/servers/print/Printer.cpp haiku/branches/developer/bonefish/vm/src/servers/print/Printer.h haiku/branches/developer/bonefish/vm/src/system/boot/loader/file_systems/bfs/Jamfile haiku/branches/developer/bonefish/vm/src/system/boot/loader/menu.cpp haiku/branches/developer/bonefish/vm/src/system/boot/platform/bios_ia32/menu.cpp haiku/branches/developer/bonefish/vm/src/system/boot/platform/bios_ia32/smp.cpp haiku/branches/developer/bonefish/vm/src/system/boot/platform/bios_ia32/video.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/m68k/arch_asm.S haiku/branches/developer/bonefish/vm/src/system/kernel/arch/m68k/arch_system_info.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/m68k/arch_thread.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/m68k/arch_user_debugger.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/m68k/arch_vm_translation_map.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_cpu.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_debug.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_debug_console.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_hpet.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_interrupts.S haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_smp.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_thread.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_timer.c haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/arch_user_debugger.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/cache/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_map.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/debug/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/debug/debug.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/debug/debug_commands.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/debug/debug_variables.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/debug/user_debugger.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/device_manager.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/legacy_drivers.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/disk_device_manager/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/disk_device_manager/KPartition.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/fs/fd.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/rootfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/socket.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs_net_boot.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/heap.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/lib/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/lock.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/messaging/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/messaging/MessagingService.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/module.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/posix/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/slab/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/thread.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/util/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/util/cbuf.c haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp haiku/branches/developer/bonefish/vm/src/system/libroot/posix/string/Jamfile haiku/branches/developer/bonefish/vm/src/tests/kits/net/Jamfile haiku/branches/developer/bonefish/vm/src/tests/system/kernel/Jamfile haiku/branches/developer/bonefish/vm/src/tools/fs_shell/block_cache.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/driver_settings.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/fd.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/file_cache.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/lock.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/module.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/vfs.cpp haiku/branches/developer/bonefish/vm/src/tools/fs_shell/vfs.h Log: Synchronized with trunk r26317. Modified: haiku/branches/developer/bonefish/vm/build/jam/HaikuImage =================================================================== --- haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/build/jam/HaikuImage 2008-07-08 14:58:39 UTC (rev 26319) @@ -30,7 +30,7 @@ csplit ctags cut date dc dd desklink df diff diff3 dircolors dirname draggers driveinfo dstcheck du echo eject env error expand expr expr factor false fdinfo ffm find finddir fmt fold fortune frcode ftp ftpd - funzip #fwcontrol + funzip fwcontrol gawk $(X86_ONLY)gdb grep groups gzip gzexe hd head hey hostname id ident ideinfo idestatus ifconfig install installsound iroster isvolume join keymap kill less lessecho lesskey link listarea listattr listimage listdev @@ -133,9 +133,9 @@ ; #BEOS_ADD_ONS_DRIVERS_ACPI = $(X86_ONLY)acpi_button ; BEOS_ADD_ONS_BUS_MANAGERS = pci $(X86_ONLY)ps2 $(X86_ONLY)isa ide scsi - config_manager agp_gart usb #firewire + config_manager agp_gart usb firewire ; -BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda fat iso9660 ; +BEOS_ADD_ONS_FILE_SYSTEMS = bfs cdda ext2 fat iso9660 $(GPL_ONLY)reiserfs ; #googlefs nfs $(GPL_ONLY)ntfs ; @@ -171,7 +171,7 @@ random tty zero ; AddDriversToHaikuImage audio hmulti : $(BEOS_ADD_ONS_DRIVERS_AUDIO) ; AddDriversToHaikuImage midi : $(BEOS_ADD_ONS_DRIVERS_MIDI) ; -AddDriversToHaikuImage bus : usb_raw ; # fw_raw +AddDriversToHaikuImage bus : usb_raw fw_raw ; AddDriversToHaikuImage disk floppy : $(X86_ONLY)pc_floppy ; AddDriversToHaikuImage disk scsi : scsi_cd scsi_disk ; AddDriversToHaikuImage disk usb : usb_disk ; Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/BluetoothDevice.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/BluetoothDevice.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/BluetoothDevice.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,46 +1,46 @@ -/* - * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BLUETOOTH_DEVICE_H -#define _BLUETOOTH_DEVICE_H - -#include -#include - - -#include -#include - -#include - - -namespace Bluetooth { - -class BluetoothDevice { - - public: - - virtual BString GetFriendlyName()=0; - virtual DeviceClass GetDeviceClass()=0; - - virtual BString GetProperty(const char* property)=0; - virtual void GetProperty(const char* property, uint32* value)=0; - - virtual bdaddr_t GetBluetoothAddress()=0; - - protected: - bdaddr_t fBdaddr; - DeviceClass fDeviceClass; -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::BluetoothDevice; -#endif - -#endif +/* + * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BLUETOOTH_DEVICE_H +#define _BLUETOOTH_DEVICE_H + +#include +#include + + +#include +#include + +#include + + +namespace Bluetooth { + +class BluetoothDevice { + + public: + + virtual BString GetFriendlyName()=0; + virtual DeviceClass GetDeviceClass()=0; + + virtual BString GetProperty(const char* property)=0; + virtual void GetProperty(const char* property, uint32* value)=0; + + virtual bdaddr_t GetBluetoothAddress()=0; + + protected: + bdaddr_t fBdaddr; + DeviceClass fDeviceClass; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::BluetoothDevice; +#endif + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/BluetoothDevice.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DeviceClass.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DeviceClass.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DeviceClass.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,69 +1,69 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DEVICE_CLASS_H -#define _DEVICE_CLASS_H - -#include - -namespace Bluetooth { - -class DeviceClass { - - public: - - DeviceClass(int record) - { - this->record = record; - } - - DeviceClass() - { - this->record = 0; - } - - - int GetServiceClasses() - { - return (record & 0x00FFE000) >> 13; - } - - - int GetMajorDeviceClass() - { - return (record & 0x00001F00) >> 8; - } - - - void GetMajorDeviceClass(BString* str) - { - - } - - - int GetMinorDeviceClass() - { - return (record & 0x000000FF) >> 2; - } - - - void GetMinorDeviceClass(BString* str) - { - - } - - private: - int record; -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DeviceClass; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DEVICE_CLASS_H +#define _DEVICE_CLASS_H + +#include + +namespace Bluetooth { + +class DeviceClass { + + public: + + DeviceClass(int record) + { + this->record = record; + } + + DeviceClass() + { + this->record = 0; + } + + + int GetServiceClasses() + { + return (record & 0x00FFE000) >> 13; + } + + + int GetMajorDeviceClass() + { + return (record & 0x00001F00) >> 8; + } + + + void GetMajorDeviceClass(BString* str) + { + + } + + + int GetMinorDeviceClass() + { + return (record & 0x000000FF) >> 2; + } + + + void GetMinorDeviceClass(BString* str) + { + + } + + private: + int record; +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DeviceClass; +#endif + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DeviceClass.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryAgent.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryAgent.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryAgent.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,74 +1,74 @@ -/* - * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DISCOVERY_AGENT_H -#define _DISCOVERY_AGENT_H - -#include -#include - - -#define BT_CACHED 0x00 -#define BT_PREKNOWN 0x01 -#define BT_NOT_DISCOVERABLE 0x01 - -#define BT_GIAC 0x9E8B33 -#define BT_LIAC 0x9E8B00 - -#define BT_MAX_RESPONSES (32) -#define BT_BASE_INQUIRY_TIME (1.28) -#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */ - -namespace Bluetooth { - -class DiscoveryListener; -class RemoteDevice; - -class DiscoveryAgent { - - public: - - static const int GIAC = BT_GIAC; - static const int LIAC = BT_LIAC; - - static const int PREKNOWN = BT_PREKNOWN; - static const int CACHED = BT_CACHED; - static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; - - RemoteDevicesList RetrieveDevices(int option); /* TODO */ - status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ - status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); - status_t CancelInquiry(DiscoveryListener* listener); - - /* - int searchServices(int[] attrSet, - UUID[] uuidSet, - RemoteDevice btDev, - DiscoveryListener discListener); - - bool cancelServiceSearch(int transID); - BString selectService(UUID uuid, int security, boolean master); - */ - - private: - DiscoveryAgent(LocalDevice* ld); - void SetLocalDeviceOwner(LocalDevice* ld); - - DiscoveryListener* fLastUsedListener; - LocalDevice* fLocalDevice; - - friend class LocalDevice; - -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DiscoveryAgent; -#endif - -#endif +/* + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DISCOVERY_AGENT_H +#define _DISCOVERY_AGENT_H + +#include +#include + + +#define BT_CACHED 0x00 +#define BT_PREKNOWN 0x01 +#define BT_NOT_DISCOVERABLE 0x01 + +#define BT_GIAC 0x9E8B33 +#define BT_LIAC 0x9E8B00 + +#define BT_MAX_RESPONSES (32) +#define BT_BASE_INQUIRY_TIME (1.28) +#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */ + +namespace Bluetooth { + +class DiscoveryListener; +class RemoteDevice; + +class DiscoveryAgent { + + public: + + static const int GIAC = BT_GIAC; + static const int LIAC = BT_LIAC; + + static const int PREKNOWN = BT_PREKNOWN; + static const int CACHED = BT_CACHED; + static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; + + RemoteDevicesList RetrieveDevices(int option); /* TODO */ + status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ + status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); + status_t CancelInquiry(DiscoveryListener* listener); + + /* + int searchServices(int[] attrSet, + UUID[] uuidSet, + RemoteDevice btDev, + DiscoveryListener discListener); + + bool cancelServiceSearch(int transID); + BString selectService(UUID uuid, int security, boolean master); + */ + + private: + DiscoveryAgent(LocalDevice* ld); + void SetLocalDeviceOwner(LocalDevice* ld); + + DiscoveryListener* fLastUsedListener; + LocalDevice* fLocalDevice; + + friend class LocalDevice; + +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DiscoveryAgent; +#endif + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryAgent.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryListener.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryListener.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryListener.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,76 +1,76 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _DISCOVERY_LISTENER_H -#define _DISCOVERY_LISTENER_H - -#include -#include - -#include - - -#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs -#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X -#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X - - -namespace Bluetooth { - -typedef BObjectList RemoteDevicesList; - -class RemoteDevice; -class DeviceClass; -class LocalDevice; - -class DiscoveryListener : public BLooper { - - public: - - static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED; - static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED; - static const int INQUIRY_ERROR = BT_INQUIRY_ERROR; - - static const int SERVICE_SEARCH_COMPLETED = 0x01; - static const int SERVICE_SEARCH_TERMINATED = 0x02; - static const int SERVICE_SEARCH_ERROR = 0x03; - static const int SERVICE_SEARCH_NO_RECORDS = 0x04; - static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06; - - virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod); - /* - virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord); - virtual void serviceSearchCompleted(int transID, int respCode); - */ - virtual void InquiryCompleted(int discType); - - /* JSR82 non-defined methods */ - virtual void InquiryStarted(status_t status); - - private: - - RemoteDevicesList GetRemoteDevicesList(void); - - void MessageReceived(BMessage* msg); - - LocalDevice* fLocalDevice; - RemoteDevicesList fRemoteDevicesList; - - friend class DiscoveryAgent; - - protected: - DiscoveryListener(); - void SetLocalDeviceOwner(LocalDevice* ld); -}; - -} - -#ifndef _BT_USE_EXPLICIT_NAMESPACE -using Bluetooth::DiscoveryListener; -#endif - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _DISCOVERY_LISTENER_H +#define _DISCOVERY_LISTENER_H + +#include +#include + +#include + + +#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs +#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X +#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X + + +namespace Bluetooth { + +typedef BObjectList RemoteDevicesList; + +class RemoteDevice; +class DeviceClass; +class LocalDevice; + +class DiscoveryListener : public BLooper { + + public: + + static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED; + static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED; + static const int INQUIRY_ERROR = BT_INQUIRY_ERROR; + + static const int SERVICE_SEARCH_COMPLETED = 0x01; + static const int SERVICE_SEARCH_TERMINATED = 0x02; + static const int SERVICE_SEARCH_ERROR = 0x03; + static const int SERVICE_SEARCH_NO_RECORDS = 0x04; + static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06; + + virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod); + /* + virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord); + virtual void serviceSearchCompleted(int transID, int respCode); + */ + virtual void InquiryCompleted(int discType); + + /* JSR82 non-defined methods */ + virtual void InquiryStarted(status_t status); + + private: + + RemoteDevicesList GetRemoteDevicesList(void); + + void MessageReceived(BMessage* msg); + + LocalDevice* fLocalDevice; + RemoteDevicesList fRemoteDevicesList; + + friend class DiscoveryAgent; + + protected: + DiscoveryListener(); + void SetLocalDeviceOwner(LocalDevice* ld); +}; + +} + +#ifndef _BT_USE_EXPLICIT_NAMESPACE +using Bluetooth::DiscoveryListener; +#endif + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/DiscoveryListener.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,41 +1,41 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_H_ -#define _BTHCI_H_ - -/* typedefs */ -typedef int32 hci_id; - -typedef enum { H2 = 2, H3, H4, H5 } transport_type; - -// TODO: something more authomatic here? -#define HCI_NUM_PACKET_TYPES 5 -typedef enum { BT_COMMAND = 0, - BT_EVENT, - BT_ACL, - BT_SCO, - BT_ESCO - } bt_packet_t; - - -/* packets sizes */ -#define HCI_MAX_ACL_SIZE 1024 -#define HCI_MAX_SCO_SIZE 255 -#define HCI_MAX_EVENT_SIZE 260 -#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4) - -/* fields sizes */ -#define HCI_LAP_SIZE 3 /* LAP */ -#define HCI_LINK_KEY_SIZE 16 /* link key */ -#define HCI_PIN_SIZE 16 /* PIN */ -#define HCI_EVENT_MASK_SIZE 8 /* event mask */ -#define HCI_CLASS_SIZE 3 /* class */ -#define HCI_FEATURES_SIZE 8 /* LMP features */ -#define HCI_DEVICE_NAME_SIZE 248 /* unit name size */ - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTHCI_H_ +#define _BTHCI_H_ + +/* typedefs */ +typedef int32 hci_id; + +typedef enum { H2 = 2, H3, H4, H5 } transport_type; + +// TODO: something more authomatic here? +#define HCI_NUM_PACKET_TYPES 5 +typedef enum { BT_COMMAND = 0, + BT_EVENT, + BT_ACL, + BT_SCO, + BT_ESCO + } bt_packet_t; + + +/* packets sizes */ +#define HCI_MAX_ACL_SIZE 1024 +#define HCI_MAX_SCO_SIZE 255 +#define HCI_MAX_EVENT_SIZE 260 +#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4) + +/* fields sizes */ +#define HCI_LAP_SIZE 3 /* LAP */ +#define HCI_LINK_KEY_SIZE 16 /* link key */ +#define HCI_PIN_SIZE 16 /* PIN */ +#define HCI_EVENT_MASK_SIZE 8 /* event mask */ +#define HCI_CLASS_SIZE 3 /* class */ +#define HCI_FEATURES_SIZE 8 /* LMP features */ +#define HCI_DEVICE_NAME_SIZE 248 /* unit name size */ + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_acl.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_acl.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_acl.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,39 +1,39 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_ACL_H_ -#define _BTHCI_ACL_H_ - -#include -#include - -#define HCI_ACL_HDR_SIZE 4 - -struct hci_acl_header { - uint16 handle; /* Handle & Flags(PB, BC) */ - uint16 alen; -} __attribute__ ((packed)) ; - -/* ACL handle and flags pack/unpack */ -#define pack_acl_handle_flags(h, pb, bc) (((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14)) -#define get_acl_handle(h) ((h) & 0x0fff) -#define get_acl_pb_flag(h) (((h) & 0x3000) >> 12) -#define get_acl_bc_flag(h) (((h) & 0xc000) >> 14) - -/* PB flag values */ -/* 00 - reserved for future use */ -#define HCI_ACL_PACKET_FRAGMENT 0x1 -#define HCI_ACL_PACKET_START 0x2 -/* 11 - reserved for future use */ - -/* BC flag values */ -#define HCI_ACL_POINT2POINT 0x0 /* only Host controller to Host */ -#define HCI_ACL_BROADCAST_ACTIVE 0x1 /* both directions */ -#define HCI_ACL_BROADCAST_PICONET 0x2 /* both directions */ - /* 11 - reserved for future use */ - -#endif +/* + * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * + * All rights reserved. Distributed under the terms of the MIT License. + * + */ + +#ifndef _BTHCI_ACL_H_ +#define _BTHCI_ACL_H_ + +#include +#include + +#define HCI_ACL_HDR_SIZE 4 + +struct hci_acl_header { + uint16 handle; /* Handle & Flags(PB, BC) */ + uint16 alen; +} __attribute__ ((packed)) ; + +/* ACL handle and flags pack/unpack */ +#define pack_acl_handle_flags(h, pb, bc) (((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14)) +#define get_acl_handle(h) ((h) & 0x0fff) +#define get_acl_pb_flag(h) (((h) & 0x3000) >> 12) +#define get_acl_bc_flag(h) (((h) & 0xc000) >> 14) + +/* PB flag values */ +/* 00 - reserved for future use */ +#define HCI_ACL_PACKET_FRAGMENT 0x1 +#define HCI_ACL_PACKET_START 0x2 +/* 11 - reserved for future use */ + +/* BC flag values */ +#define HCI_ACL_POINT2POINT 0x0 /* only Host controller to Host */ +#define HCI_ACL_BROADCAST_ACTIVE 0x1 /* both directions */ +#define HCI_ACL_BROADCAST_PICONET 0x2 /* both directions */ + /* 11 - reserved for future use */ + +#endif Property changes on: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_acl.h ___________________________________________________________________ Name: svn:eol-style + native Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_command.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_command.h 2008-07-08 14:34:15 UTC (rev 26318) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_command.h 2008-07-08 14:58:39 UTC (rev 26319) @@ -1,340 +1,340 @@ -/* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com - * - * All rights reserved. Distributed under the terms of the MIT License. - * - */ - -#ifndef _BTHCI_COMMAND_H_ -#define _BTHCI_COMMAND_H_ - -#include -#include - -#define HCI_COMMAND_HDR_SIZE 3 - -struct hci_command_header { - uint16 opcode; /* OCF & OGF */ - uint8 clen; -} __attribute__ ((packed)); - - -/* Command opcode pack/unpack */ -#define PACK_OPCODE(ogf, ocf) (uint16)((ocf & 0x03ff)|(ogf << 10)) -#define GET_OPCODE_OGF(op) (op >> 10) -#define GET_OPCODE_OCF(op) (op & 0x03ff) - - -/* - Informational Parameters Command definition - */ -#define OGF_INFORMATIONAL_PARAM 0x04 - - #define OCF_READ_LOCAL_VERSION 0x0001 - struct hci_rp_read_loc_version { - uint8 status; - uint8 hci_ver; - uint16 hci_rev; - uint8 lmp_ver; - uint16 manufacturer; - uint16 lmp_subver; - } __attribute__ ((packed)); - - #define OCF_READ_LOCAL_FEATURES 0x0003 - struct hci_rp_read_loc_features { - uint8 status; - uint8 features[8]; - } __attribute__ ((packed)); - - #define OCF_READ_BUFFER_SIZE 0x0005 - struct hci_rp_read_buffer_size { - uint8 status; - uint16 acl_mtu; - uint8 sco_mtu; - uint16 acl_max_pkt; - uint16 sco_max_pkt; - } __attribute__ ((packed)); - - #define OCF_READ_BD_ADDR 0x0009 - struct hci_rp_read_bd_addr { - uint8 status; - bdaddr_t bdaddr; - } __attribute__ ((packed)); - -/* - Host Controller and Baseband Command definition - */ -#define OGF_CONTROL_BASEBAND 0x03 - - #define OCF_RESET 0x0003 - /*struct hci_reset { - void no_fields; - } __attribute__ ((packed));*/ - - #define OCF_SET_EVENT_FLT 0x0005 - struct hci_cp_set_event_flt { - uint8 flt_type; - uint8 cond_type; - uint8 condition[0]; - } __attribute__ ((packed)); - - #define OCF_READ_STORED_LINK_KEY 0x000D - struct hci_read_stored_link_key { - bdaddr_t bdaddr; - uint8 all_keys_flag; - } __attribute__ ((packed)); - struct hci_read_stored_link_key_reply { - uint8 status; - uint16 max_num_keys; - uint16 num_keys_read; - } __attribute__ ((packed)); - - #define OCF_WRITE_STORED_LINK_KEY 0x0011 - struct hci_write_stored_link_key { - uint8 num_keys_to_write; - // these are repeated "num_keys_write" times - bdaddr_t bdaddr; - uint8 key[HCI_LINK_KEY_SIZE]; - } __attribute__ ((packed)); - struct hci_write_stored_link_key_reply { - uint8 status; - uint8 num_keys_written; - } __attribute__ ((packed)); - - - #define OCF_WRITE_LOCAL_NAME 0x0013 - #define OCF_READ_LOCAL_NAME 0x0014 - struct hci_rp_read_local_name { - uint8 status; - char local_name[HCI_DEVICE_NAME_SIZE]; - } __attribute__ ((packed)); - - #define OCF_WRITE_CA_TIMEOUT 0x0016 - #define OCF_WRITE_PG_TIMEOUT 0x0018 - - #define OCF_WRITE_SCAN_ENABLE 0x001A - #define HCI_SCAN_DISABLED 0x00 - #define HCI_SCAN_INQUIRY 0x01 - #define HCI_SCAN_PAGE 0x02 - #define HCI_SCAN_INQUIRY_PAGE 0x03 - struct hci_write_scan_enable { - uint8 scan; - } __attribute__ ((packed)); - - #define OCF_READ_AUTH_ENABLE 0x001F - #define OCF_WRITE_AUTH_ENABLE 0x0020 - #define HCI_AUTH_DISABLED 0x00 - #define HCI_AUTH_ENABLED 0x01 - struct hci_write_authentication_enable { - uint8 authentication; - } __attribute__ ((packed)); - - #define OCF_READ_ENCRYPT_MODE 0x0021 - #define OCF_WRITE_ENCRYPT_MODE 0x0022 - #define HCI_ENCRYPT_DISABLED 0x00 - #define HCI_ENCRYPT_P2P 0x01 - #define HCI_ENCRYPT_BOTH 0x02 - struct hci_write_encryption_mode_enable { - uint8 encryption; - } __attribute__ ((packed)); - - /* Filter types */ - #define HCI_FLT_CLEAR_ALL 0x00 - #define HCI_FLT_INQ_RESULT 0x01 - #define HCI_FLT_CONN_SETUP 0x02 - - /* CONN_SETUP Condition types */ - #define HCI_CONN_SETUP_ALLOW_ALL 0x00 - #define HCI_CONN_SETUP_ALLOW_CLASS 0x01 - #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02 - - /* CONN_SETUP Conditions */ - #define HCI_CONN_SETUP_AUTO_OFF 0x01 - #define HCI_CONN_SETUP_AUTO_ON 0x02 - - #define OCF_READ_CLASS_OF_DEV 0x0023 - - struct hci_read_dev_class_reply { - uint8 status; - uint8 dev_class[3]; - } __attribute__ ((packed)); - - #define OCF_WRITE_CLASS_OF_DEV 0x0024 - struct hci_write_dev_class { - uint8 dev_class[3]; - } __attribute__ ((packed)); - - #define OCF_READ_VOICE_SETTING 0x0025 - struct hci_rp_read_voice_setting { - uint8 status; - uint16 voice_setting; - } __attribute__ ((packed)); - - #define OCF_WRITE_VOICE_SETTING 0x0026 - struct hci_cp_write_voice_setting { - uint16 voice_setting; - } __attribute__ ((packed)); - - #define OCF_HOST_BUFFER_SIZE 0x0033 - struct hci_cp_host_buffer_size { - uint16 acl_mtu; - uint8 sco_mtu; - uint16 acl_max_pkt; - uint16 sco_max_pkt; - } __attribute__ ((packed)); - - /* Link Control Command definition */ - #define OGF_LINK_CONTROL 0x01 - - #define OCF_INQUIRY 0x0001 - struct hci_cp_inquiry { - uint8 lap[3]; - uint8 length; - uint8 num_rsp; - } __attribute__ ((packed)); - - #define OCF_INQUIRY_CANCEL 0x0002 - - #define OCF_CREATE_CONN 0x0005 - struct hci_cp_create_conn { - bdaddr_t bdaddr; - uint16 pkt_type; - uint8 pscan_rep_mode; [... truncated: 29455 lines follow ...] From bonefish at mail.berlios.de Tue Jul 8 18:15:41 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Tue, 8 Jul 2008 18:15:41 +0200 Subject: [Haiku-commits] r26320 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200807081615.m68GFftH026339@sheep.berlios.de> Author: bonefish Date: 2008-07-08 18:15:41 +0200 (Tue, 08 Jul 2008) New Revision: 26320 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26320&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Utility.cpp Log: Remove() was moving an additional array element. Mostly harmless, but would cause a crash when the array end was page-aligned and the next page was not accessible. Happened to me during a "rm -rf ...". Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Utility.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Utility.cpp 2008-07-08 14:58:39 UTC (rev 26319) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Utility.cpp 2008-07-08 16:15:41 UTC (rev 26320) @@ -60,8 +60,8 @@ if (index == -1) return false; + count--; memmove(&values[index], &values[index + 1], (count - index) * sizeof(off_t)); - count--; return true; } From korli at mail.berlios.de Tue Jul 8 18:41:53 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 8 Jul 2008 18:41:53 +0200 Subject: [Haiku-commits] r26321 - in haiku/trunk/src/add-ons/kernel/drivers/audio: ac97/auich ac97/auvia echo emuxki Message-ID: <200807081641.m68GfrTE009225@sheep.berlios.de> Author: korli Date: 2008-07-08 18:41:52 +0200 (Tue, 08 Jul 2008) New Revision: 26321 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26321&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c Log: init buffer_cycle Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2008-07-08 16:15:41 UTC (rev 26320) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2008-07-08 16:41:52 UTC (rev 26321) @@ -331,6 +331,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* allocate memory for our dma ops */ Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c 2008-07-08 16:15:41 UTC (rev 26320) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c 2008-07-08 16:41:52 UTC (rev 26321) @@ -313,6 +313,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* allocate memory for our dma ops */ Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-08 16:15:41 UTC (rev 26320) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-08 16:41:52 UTC (rev 26321) @@ -372,6 +372,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; status = lock(); Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-08 16:15:41 UTC (rev 26320) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-08 16:41:52 UTC (rev 26321) @@ -1636,6 +1636,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* Init voices list */ From stippi at mail.berlios.de Tue Jul 8 19:21:41 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 19:21:41 +0200 Subject: [Haiku-commits] r26322 - haiku/trunk/src/kits/interface Message-ID: <200807081721.m68HLfGd030018@sheep.berlios.de> Author: stippi Date: 2008-07-08 19:21:39 +0200 (Tue, 08 Jul 2008) New Revision: 26322 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26322&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: This is either a fix or a workaround for a problem in Pe, where the application modifies the scrollbars one by one and the changes would have some weird cyclic effect where the constrains of one scrollbar affected the scrolling already while they would be lifted afterwards. It sounds weird, but maybe it is simply a resulting behavior of the BeOS implementation which does not check the scrollbar restrictions in the BView code. Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-08 16:41:52 UTC (rev 26321) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-08 17:21:39 UTC (rev 26322) @@ -1532,11 +1532,14 @@ _CheckLockAndSwitchCurrent(); + float xDiff = where.x - fBounds.left; + float yDiff = where.y - fBounds.top; + // if we're attached to a window tell app_server about this change if (fOwner) { fOwner->fLink->StartMessage(AS_VIEW_SCROLL); - fOwner->fLink->Attach(where.x - fBounds.left); - fOwner->fLink->Attach(where.y - fBounds.top); + fOwner->fLink->Attach(xDiff); + fOwner->fLink->Attach(yDiff); fOwner->fLink->Flush(); @@ -1547,9 +1550,9 @@ fBounds.OffsetTo(where.x, where.y); // then set the new values of the scrollbars - if (fHorScroller) + if (fHorScroller && xDiff != 0.0) fHorScroller->SetValue(fBounds.left); - if (fVerScroller) + if (fVerScroller && yDiff != 0.0) fVerScroller->SetValue(fBounds.top); } From stippi at mail.berlios.de Tue Jul 8 19:41:19 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 19:41:19 +0200 Subject: [Haiku-commits] r26323 - haiku/trunk/src/servers/app/drawing Message-ID: <200807081741.m68HfJfq023601@sheep.berlios.de> Author: stippi Date: 2008-07-08 19:41:15 +0200 (Tue, 08 Jul 2008) New Revision: 26323 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26323&view=rev Modified: haiku/trunk/src/servers/app/drawing/DrawingEngine.cpp Log: Check if the Painter even has a clipping region set before trying to take the short cut when no text needs to be rendered. I've seen a crash yesterday in the app_server test environment when the decorater was drawing something, although it may also have been because I had a screwed up objects folder where some objects were not recompiled because I am switching back and forth between two app_server code folders. Modified: haiku/trunk/src/servers/app/drawing/DrawingEngine.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/DrawingEngine.cpp 2008-07-08 17:21:39 UTC (rev 26322) +++ haiku/trunk/src/servers/app/drawing/DrawingEngine.cpp 2008-07-08 17:41:15 UTC (rev 26323) @@ -1067,12 +1067,14 @@ BPoint penLocation = pt; // try a fast clipping path - float fontSize = fPainter->Font().Size(); - BRect clippingFrame = fPainter->ClippingRegion()->Frame(); - if (pt.x > clippingFrame.right || pt.y + fontSize < clippingFrame.top - || pt.y - fontSize > clippingFrame.bottom) { - penLocation.x += StringWidth(string, length, delta); - return penLocation; + if (fPainter->ClippingRegion()) { + float fontSize = fPainter->Font().Size(); + BRect clippingFrame = fPainter->ClippingRegion()->Frame(); + if (pt.x > clippingFrame.right || pt.y + fontSize < clippingFrame.top + || pt.y - fontSize > clippingFrame.bottom) { + penLocation.x += StringWidth(string, length, delta); + return penLocation; + } } // use a FontCacheRefernece to speed up the second pass of From stippi at mail.berlios.de Tue Jul 8 19:48:33 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 19:48:33 +0200 Subject: [Haiku-commits] r26324 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807081748.m68HmXfX024486@sheep.berlios.de> Author: stippi Date: 2008-07-08 19:48:30 +0200 (Tue, 08 Jul 2008) New Revision: 26324 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26324&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: When a BBitmap is drawn with scale, but also only partly, the inverse image scan generator matrix was calculated wrongly. The part of the offset that lies within the bitmap bounds needs to have the scale applied as well. Maybe this code can be simplified. Appearantly there is not a lot of code that uses BBitmap drawing this way, perhaps because the R5 version has had issues with rounding. But MediaPlayer uses this feature for drawing the peak levels and this is fixed by this change. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-08 17:41:15 UTC (rev 26323) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-08 17:48:30 UTC (rev 26324) @@ -45,6 +45,13 @@ #include "Painter.h" +//#define TRACE_PAINTER +#ifdef TRACE_PAINTER +# define TRACE(x...) printf(x) +#else +# define TRACE(x...) +#endif + #define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1); #define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return; @@ -1049,6 +1056,16 @@ // the native bitmap coordinate system BRect actualBitmapRect(bitmap->Bounds()); + TRACE("Painter::DrawBitmap()\n"); + TRACE(" actualBitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + actualBitmapRect.left, actualBitmapRect.top, + actualBitmapRect.right, actualBitmapRect.bottom); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, + bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + agg::rendering_buffer srcBuffer; srcBuffer.attach(bitmap->Bits(), bitmap->Width(), @@ -1304,10 +1321,16 @@ } if (!fSubpixelPrecise) { + align_rect_to_pixels(&bitmapRect); align_rect_to_pixels(&viewRect); - align_rect_to_pixels(&bitmapRect); } - + + TRACE("Painter::_DrawBitmap()\n"); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + double xScale = (viewRect.Width() + 1) / (bitmapRect.Width() + 1); double yScale = (viewRect.Height() + 1) / (bitmapRect.Height() + 1); @@ -1512,6 +1535,11 @@ double xScale, double yScale, BRect viewRect) const { + TRACE("Painter::_DrawBitmapGeneric32()\n"); + TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset); + TRACE(" scale: %.3f, %.3f\n", xScale, yScale); + TRACE(" viewRect: (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); // AGG pipeline // pixel format attached to bitmap @@ -1524,8 +1552,10 @@ // -actualBitmapRect.top); agg::trans_affine imgMatrix; + imgMatrix *= agg::trans_affine_translation(xOffset - viewRect.left, + yOffset - viewRect.top); imgMatrix *= agg::trans_affine_scaling(xScale, yScale); - imgMatrix *= agg::trans_affine_translation(xOffset, yOffset); + imgMatrix *= agg::trans_affine_translation(viewRect.left, viewRect.top); imgMatrix.invert(); // image interpolator From axeld at pinc-software.de Tue Jul 8 20:00:25 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Tue, 08 Jul 2008 20:00:25 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26320_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/file=5Fsystems/bfs?= In-Reply-To: <200807081615.m68GFftH026339@sheep.berlios.de> Message-ID: <39319160371-BeMail@zon> bonefish at BerliOS wrote: > Log: > Remove() was moving an additional array element. Mostly harmless, but > would cause a crash when the array end was page-aligned and the next > page was not accessible. Happened to me during a "rm -rf ...". Nice catch! Bye, Axel. From stippi at mail.berlios.de Tue Jul 8 20:25:49 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 20:25:49 +0200 Subject: [Haiku-commits] r26325 - haiku/trunk/src/system/kernel/arch/x86 Message-ID: <200807081825.m68IPnIc028924@sheep.berlios.de> Author: stippi Date: 2008-07-08 20:25:45 +0200 (Tue, 08 Jul 2008) New Revision: 26325 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26325&view=rev Modified: haiku/trunk/src/system/kernel/arch/x86/vm86.cpp Log: Applied patch by Jan Kloetzke: The PUSHF/POPF instructions were not emulated correctly. Modified: haiku/trunk/src/system/kernel/arch/x86/vm86.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/vm86.cpp 2008-07-08 17:48:30 UTC (rev 26324) +++ haiku/trunk/src/system/kernel/arch/x86/vm86.cpp 2008-07-08 18:25:45 UTC (rev 26325) @@ -44,8 +44,8 @@ #define PUSHF 0x9c #define STI 0xfb -#define I_FLAG (1 << 9) -#define DIRECTION_FLAG (1 << 10) +#define I_FLAG (1u << 9) +#define DIRECTION_FLAG (1u << 10) #define CSEG 0x2e #define SSEG 0x36 @@ -442,7 +442,7 @@ uint16 flags = state->regs.flags; /* store real IF */ - flags &= I_FLAG; + flags &= ~I_FLAG; flags |= (uint16)state->if_flag << 9; pushw(&state->regs, flags); @@ -475,10 +475,11 @@ case PUSHF: { TRACE_NP("PUSHF"); - uint16 flags = state->regs.flags & I_FLAG; + uint32 flags = state->regs.flags; /* store real IF */ - flags |= (uint16)state->if_flag << 9; + flags &= ~I_FLAG; + flags |= (uint32)state->if_flag << 9; if (prefix.size) pushl(&state->regs, flags); else From oruizdorantes at mail.berlios.de Tue Jul 8 20:39:46 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Tue, 8 Jul 2008 20:39:46 +0200 Subject: [Haiku-commits] r26326 - haiku/trunk/src/servers/bluetooth Message-ID: <200807081839.m68IdklJ030299@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-08 20:39:41 +0200 (Tue, 08 Jul 2008) New Revision: 26326 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26326&view=rev Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h haiku/trunk/src/servers/bluetooth/HCIDelegate.h haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h Log: Add new virtual method in the delegates to launch the device, Instantiation meant only to open/register the localdevice Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-08 18:25:45 UTC (rev 26325) +++ haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-08 18:39:41 UTC (rev 26326) @@ -15,7 +15,7 @@ } status_t -HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size) +HCIControllerAccessor::IssueCommand(raw_command rc, size_t size) { if (GetID() < 0) @@ -24,3 +24,11 @@ return B_ERROR; } + + +status_t +HCIControllerAccessor::Launch() { + + return B_OK; + +} Modified: haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-08 18:25:45 UTC (rev 26325) +++ haiku/trunk/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-08 18:39:41 UTC (rev 26326) @@ -17,7 +17,8 @@ public: HCIControllerAccessor(BPath* path); - status_t IssueCommand(raw_command* rc, size_t size); + status_t IssueCommand(raw_command rc, size_t size); + status_t Launch(); }; #endif Modified: haiku/trunk/src/servers/bluetooth/HCIDelegate.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCIDelegate.h 2008-07-08 18:25:45 UTC (rev 26325) +++ haiku/trunk/src/servers/bluetooth/HCIDelegate.h 2008-07-08 18:39:41 UTC (rev 26326) @@ -41,16 +41,15 @@ } + hci_id GetID(void) { return fHID; } - - virtual status_t IssueCommand(raw_command rc, size_t size) - { - return B_ERROR; - } - + + virtual status_t IssueCommand(raw_command rc, size_t size)=0; + virtual status_t Launch()=0; + protected: Modified: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-08 18:25:45 UTC (rev 26325) +++ haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-08 18:39:41 UTC (rev 26326) @@ -33,3 +33,11 @@ return ioctl(fFD, ISSUE_BT_COMMAND, rc, size); } + + +status_t +HCITransportAccessor::Launch() { + + return B_OK; + +} Modified: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h =================================================================== --- haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h 2008-07-08 18:25:45 UTC (rev 26325) +++ haiku/trunk/src/servers/bluetooth/HCITransportAccessor.h 2008-07-08 18:39:41 UTC (rev 26326) @@ -17,6 +17,8 @@ public: HCITransportAccessor(BPath* path); status_t IssueCommand(raw_command rc, size_t size); + status_t Launch(); + }; #endif From stippi at mail.berlios.de Tue Jul 8 22:01:36 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 22:01:36 +0200 Subject: [Haiku-commits] r26327 - in haiku/trunk/src/tests/servers/app: . lagging_get_mouse statusbar Message-ID: <200807082001.m68K1a89005970@sheep.berlios.de> Author: stippi Date: 2008-07-08 22:01:31 +0200 (Tue, 08 Jul 2008) New Revision: 26327 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26327&view=rev Added: haiku/trunk/src/tests/servers/app/lagging_get_mouse/ haiku/trunk/src/tests/servers/app/lagging_get_mouse/Jamfile haiku/trunk/src/tests/servers/app/lagging_get_mouse/main.cpp haiku/trunk/src/tests/servers/app/lagging_get_mouse/run haiku/trunk/src/tests/servers/app/statusbar/ haiku/trunk/src/tests/servers/app/statusbar/Jamfile haiku/trunk/src/tests/servers/app/statusbar/main.cpp haiku/trunk/src/tests/servers/app/statusbar/run Modified: haiku/trunk/src/tests/servers/app/Jamfile Log: Added two tests: * statusbar was used to test and improve some BStatusBar behavior * lagging_get_mouse demonstrates what the problem is with older applications using synchronous GetMouse() calls without specifying that they actually don't care about mouse history. Modified: haiku/trunk/src/tests/servers/app/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/Jamfile 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/Jamfile 2008-07-08 20:01:31 UTC (rev 26327) @@ -173,6 +173,7 @@ SubInclude HAIKU_TOP src tests servers app event_mask ; SubInclude HAIKU_TOP src tests servers app following ; SubInclude HAIKU_TOP src tests servers app idle_test ; +SubInclude HAIKU_TOP src tests servers app lagging_get_mouse ; SubInclude HAIKU_TOP src tests servers app lock_focus ; SubInclude HAIKU_TOP src tests servers app look_and_feel ; SubInclude HAIKU_TOP src tests servers app menu_crash ; @@ -183,6 +184,7 @@ SubInclude HAIKU_TOP src tests servers app resize_limits ; SubInclude HAIKU_TOP src tests servers app scrollbar ; SubInclude HAIKU_TOP src tests servers app scrolling ; +SubInclude HAIKU_TOP src tests servers app statusbar ; SubInclude HAIKU_TOP src tests servers app stress_test ; SubInclude HAIKU_TOP src tests servers app textview ; SubInclude HAIKU_TOP src tests servers app view_state ; Added: haiku/trunk/src/tests/servers/app/lagging_get_mouse/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/lagging_get_mouse/Jamfile 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/lagging_get_mouse/Jamfile 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src tests servers app statusbar ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +SimpleTest LaggingGetMouse : + main.cpp + : be ; + +if ( $(TARGET_PLATFORM) = libbe_test ) { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : LaggingGetMouse + : tests!apps ; +} + Added: haiku/trunk/src/tests/servers/app/lagging_get_mouse/main.cpp =================================================================== --- haiku/trunk/src/tests/servers/app/lagging_get_mouse/main.cpp 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/lagging_get_mouse/main.cpp 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,91 @@ +// main.cpp + +#include + +#include +#include +#include + +class TestView : public BView { + + public: + TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags); + + virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); + + private: + BList fMouseSamples; +}; + +// constructor +TestView::TestView(BRect frame, const char* name, + uint32 resizeFlags, uint32 flags) + : BView(frame, name, resizeFlags, flags), + fMouseSamples(128) +{ +} + +// Draw +void +TestView::Draw(BRect updateRect) +{ + int32 count = fMouseSamples.CountItems(); + if (count > 0) { + BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(0); + MovePenTo(*p); + } + + for (int32 i = 0; i < count; i++) { + BPoint* p = (BPoint*)fMouseSamples.ItemAtFast(i); + StrokeLine(*p); + } +} + +// MouseDown +void +TestView::MouseDown(BPoint where) +{ + // clear previous stroke + int32 count = fMouseSamples.CountItems(); + for (int32 i = 0; i < count; i++) + delete (BPoint*)fMouseSamples.ItemAtFast(i); + fMouseSamples.MakeEmpty(); + FillRect(Bounds(), B_SOLID_LOW); + + // sample new stroke + uint32 buttons; + GetMouse(&where, &buttons); + MovePenTo(where); + while (buttons) { + + StrokeLine(where); + fMouseSamples.AddItem(new BPoint(where)); + + snooze(20000); + GetMouse(&where, &buttons); + } +} + + +// main +int +main(int argc, char** argv) +{ + BApplication app("application/x.vnd-Haiku.BitmapBounds"); + + BRect frame(50.0, 50.0, 300.0, 250.0); + BWindow* window = new BWindow(frame, "Bitmap Bounds", B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE); + + BView* view = new TestView(window->Bounds(), "test", + B_FOLLOW_ALL, B_WILL_DRAW); + window->AddChild(view); + + window->Show(); + + app.Run(); + + return 0; +} Added: haiku/trunk/src/tests/servers/app/lagging_get_mouse/run =================================================================== --- haiku/trunk/src/tests/servers/app/lagging_get_mouse/run 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/lagging_get_mouse/run 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,18 @@ +#!/bin/sh + +../../../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then + ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server & +else + echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first." +fi + +sleep 1s + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/LaggingGetMouse; then + ../../../../../generated/tests/libbe_test/x86/apps/LaggingGetMouse +else + echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first." +fi + Added: haiku/trunk/src/tests/servers/app/statusbar/Jamfile =================================================================== --- haiku/trunk/src/tests/servers/app/statusbar/Jamfile 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/statusbar/Jamfile 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,17 @@ +SubDir HAIKU_TOP src tests servers app statusbar ; + +SetSubDirSupportedPlatformsBeOSCompatible ; +AddSubDirSupportedPlatforms libbe_test ; + +UseHeaders [ FDirName os app ] ; +UseHeaders [ FDirName os interface ] ; + +SimpleTest StatusBar : + main.cpp + : be ; + +if ( $(TARGET_PLATFORM) = libbe_test ) { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : StatusBar + : tests!apps ; +} + Added: haiku/trunk/src/tests/servers/app/statusbar/main.cpp =================================================================== --- haiku/trunk/src/tests/servers/app/statusbar/main.cpp 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/statusbar/main.cpp 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,97 @@ +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +enum { + MSG_PULSE = 'puls' +}; + +class Window : public BWindow { +public: + Window(BRect frame) + : BWindow(frame, "BStatusBar Test", B_TITLED_WINDOW_LOOK, + B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS + | B_QUIT_ON_WINDOW_CLOSE | B_NOT_ZOOMABLE), + fHomeFolderEntryCount(0), + fHomeFolderCurrentEntry(0) + { + frame = Bounds(); + BView* background = new BView(frame, "bg", B_FOLLOW_ALL, 0); + background->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(background); + + frame = background->Bounds(); + frame.InsetBy(10, 10); + fStatusBar = new BStatusBar(frame, "status", "Label: ", "-Trailing"); + fStatusBar->SetResizingMode(B_FOLLOW_ALL); + background->AddChild(fStatusBar); + + fHomeFolder.SetTo("/boot/home/"); + BEntry entry; + while (fHomeFolder.GetNextEntry(&entry) == B_OK) + fHomeFolderEntryCount++; + + fPulse = new BMessageRunner(BMessenger(this), + new BMessage(MSG_PULSE), 1000000); + } + + ~Window() + { + delete fPulse; + } + + virtual void MessageReceived(BMessage* message) + { + switch (message->what) { + case MSG_PULSE: { + BEntry entry; + if (fHomeFolder.GetNextEntry(&entry) < B_OK) { + fHomeFolderCurrentEntry = 0; + fHomeFolder.Rewind(); + fStatusBar->Reset("Label: ", "-Trailing"); + if (fHomeFolder.GetNextEntry(&entry) < B_OK) + break; + } else + fHomeFolderCurrentEntry++; + char name[B_FILE_NAME_LENGTH]; + if (entry.GetName(name) < B_OK) + break; + float value = 100.0 * fHomeFolderCurrentEntry + / (fHomeFolderEntryCount - 1); + fStatusBar->SetTo(value, "Text", name); + break; + } + default: + BWindow::MessageReceived(message); + } + } +private: + BStatusBar* fStatusBar; + BDirectory fHomeFolder; + int32 fHomeFolderEntryCount; + int32 fHomeFolderCurrentEntry; + BMessageRunner* fPulse; +}; + + +int +main(int argc, char* argv[]) +{ + BApplication app("application/x-vnd.stippi.statusbar_test"); + + BRect frame(50, 50, 350, 350); + Window* window = new Window(frame); + window->Show(); + + app.Run(); + return 0; +} + + Added: haiku/trunk/src/tests/servers/app/statusbar/run =================================================================== --- haiku/trunk/src/tests/servers/app/statusbar/run 2008-07-08 18:39:41 UTC (rev 26326) +++ haiku/trunk/src/tests/servers/app/statusbar/run 2008-07-08 20:01:31 UTC (rev 26327) @@ -0,0 +1,18 @@ +#!/bin/sh + +../../../../../generated/tests/libbe_test/x86/apps/run_haiku_registrar || exit + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server; then + ../../../../../generated/tests/libbe_test/x86/apps/haiku_app_server & +else + echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first." +fi + +sleep 1s + +if test -f ../../../../../generated/tests/libbe_test/x86/apps/StatusBar; then + ../../../../../generated/tests/libbe_test/x86/apps/StatusBar +else + echo "You need to \"TARGET_PLATFORM=r5 jam install-test-apps\" first." +fi + From stippi at mail.berlios.de Tue Jul 8 22:29:21 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 8 Jul 2008 22:29:21 +0200 Subject: [Haiku-commits] r26328 - haiku/trunk/src/servers/input Message-ID: <200807082029.m68KTL55008362@sheep.berlios.de> Author: stippi Date: 2008-07-08 22:29:18 +0200 (Tue, 08 Jul 2008) New Revision: 26328 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26328&view=rev Modified: haiku/trunk/src/servers/input/InputServer.cpp Log: All input device add-ons should already do this, but make sure that mouse messages have a "when" field with the event system time. Modified: haiku/trunk/src/servers/input/InputServer.cpp =================================================================== --- haiku/trunk/src/servers/input/InputServer.cpp 2008-07-08 20:01:31 UTC (rev 26327) +++ haiku/trunk/src/servers/input/InputServer.cpp 2008-07-08 20:29:18 UTC (rev 26328) @@ -1492,6 +1492,9 @@ PRINT(("new position : %f, %f\n", fMousePos.x, fMousePos.y)); } + if (!event->HasInt64("when")) + event->AddInt64("when", system_time()); + event->AddInt32("modifiers", fKeyInfo.modifiers); break; } From korli at mail.berlios.de Tue Jul 8 23:31:15 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 8 Jul 2008 23:31:15 +0200 Subject: [Haiku-commits] r26329 - haiku/trunk/src/add-ons/media/media-add-ons/multi_audio Message-ID: <200807082131.m68LVFwB014768@sheep.berlios.de> Author: korli Date: 2008-07-08 23:31:14 +0200 (Tue, 08 Jul 2008) New Revision: 26329 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26329&view=rev Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp Log: fixed warnings use playback rate as preferred rate (instead of record) Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp 2008-07-08 20:29:18 UTC (rev 26328) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp 2008-07-08 21:31:14 UTC (rev 26329) @@ -180,18 +180,18 @@ for (int32 i = 0; i < fBufferList.return_playback_buffers; i++) { for (int32 j = 0; j < fBufferList.return_playback_channels; j++) { - PRINT(("fBufferList.playback_buffers[%d][%d].base: %p\n", + PRINT(("fBufferList.playback_buffers[%ld][%ld].base: %p\n", i, j, fBufferList.playback_buffers[i][j].base)); - PRINT(("fBufferList.playback_buffers[%d][%d].stride: %i\n", + PRINT(("fBufferList.playback_buffers[%ld][%ld].stride: %li\n", i, j, fBufferList.playback_buffers[i][j].stride)); } } for (int32 i = 0; i < fBufferList.return_record_buffers; i++) { for (int32 j = 0; j < fBufferList.return_record_channels; j++) { - PRINT(("fBufferList.record_buffers[%d][%d].base: %p\n", + PRINT(("fBufferList.record_buffers[%ld][%ld].base: %p\n", i, j, fBufferList.record_buffers[i][j].base)); - PRINT(("fBufferList.record_buffers[%d][%d].stride: %i\n", + PRINT(("fBufferList.record_buffers[%ld][%ld].stride: %li\n", i, j, fBufferList.record_buffers[i][j].stride)); } } Modified: haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp =================================================================== --- haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2008-07-08 20:29:18 UTC (rev 26328) +++ haiku/trunk/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2008-07-08 21:31:14 UTC (rev 26329) @@ -129,7 +129,7 @@ fPreferredFormat.u.raw_audio.format = MultiAudio::convert_to_media_format(fDevice->FormatInfo().output.format); fPreferredFormat.u.raw_audio.valid_bits = MultiAudio::convert_to_valid_bits(fDevice->FormatInfo().output.format); fPreferredFormat.u.raw_audio.channel_count = 2; - fPreferredFormat.u.raw_audio.frame_rate = MultiAudio::convert_to_sample_rate(fDevice->FormatInfo().input.rate); // measured in Hertz + fPreferredFormat.u.raw_audio.frame_rate = MultiAudio::convert_to_sample_rate(fDevice->FormatInfo().output.rate); // measured in Hertz fPreferredFormat.u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN; // we'll use the consumer's preferred buffer size, if any @@ -224,7 +224,7 @@ && ( fDevice->Description().channels[i].designations & B_CHANNEL_LEFT || !(fDevice->Description().channels[i].designations & B_CHANNEL_SURROUND_BUS))) ) { - PRINT(("NodeRegistered() : creating an input for %i\n", i)); + PRINT(("NodeRegistered() : creating an input for %li\n", i)); PRINT(("%ld\t%d\t0x%lx\t0x%lx\n", fDevice->Description().channels[i].channel_id, fDevice->Description().channels[i].kind, @@ -270,7 +270,7 @@ && ( fDevice->Description().channels[i].designations & B_CHANNEL_LEFT || !(fDevice->Description().channels[i].designations & B_CHANNEL_SURROUND_BUS))) ) { - PRINT(("NodeRegistered() : creating an output for %i\n", i)); + PRINT(("NodeRegistered() : creating an output for %li\n", i)); PRINT(("%ld\t%d\t0x%lx\t0x%lx\n",fDevice->Description().channels[i].channel_id, fDevice->Description().channels[i].kind, fDevice->Description().channels[i].designations, @@ -320,7 +320,7 @@ index++; } - PRINT(("apply configuration in : %ld\n", system_time() - start)); + PRINT(("apply configuration in : %Ld\n", system_time() - start)); } @@ -409,7 +409,7 @@ node_input *channel = (node_input *)fInputs.ItemAt(*cookie); *_input = channel->fInput; *cookie += 1; - PRINT(("input.format : %u\n", channel->fInput.format.u.raw_audio.format)); + PRINT(("input.format : %lu\n", channel->fInput.format.u.raw_audio.format)); return B_OK; } @@ -1011,7 +1011,7 @@ } else { //WriteBuffer(buffer, *channel); if (channel->fBuffer != NULL) { - PRINT(("MultiAudioNode::HandleBuffer snoozing recycling channelId : %i, how_early:%lli\n", channel->fChannelId, how_early)); + PRINT(("MultiAudioNode::HandleBuffer snoozing recycling channelId : %li, how_early:%Ld\n", channel->fChannelId, howEarly)); //channel->fBuffer->Recycle(); snooze(100); if (channel->fBuffer != NULL) @@ -1019,7 +1019,7 @@ else channel->fBuffer = buffer; } else { - //PRINT(("MultiAudioNode::HandleBuffer writing channelId : %i, how_early:%lli\n", channel->fChannelId, how_early)); + //PRINT(("MultiAudioNode::HandleBuffer writing channelId : %li, how_early:%Ld\n", channel->fChannelId, how_early)); channel->fBuffer = buffer; } } @@ -1032,7 +1032,7 @@ bigtime_t lateness, bool realTimeEvent) { //CALLED(); - PRINT(("MultiAudioNode::HandleDataStatus status:%li, lateness:%li\n", event->data, lateness)); + PRINT(("MultiAudioNode::HandleDataStatus status:%li, lateness:%Li\n", event->data, lateness)); switch (event->data) { case B_DATA_NOT_AVAILABLE: break; @@ -1168,7 +1168,7 @@ { CALLED(); - PRINT(("id : %i\n", id)); + PRINT(("id : %li\n", id)); BParameter* parameter = NULL; for (int32 i = 0; i < fWeb->CountParameters(); i++) { parameter = fWeb->ParameterAt(i); @@ -1223,7 +1223,7 @@ } for (uint32 i = 0; i < *size / sizeof(float); i++) { - PRINT(("GetParameterValue B_CONTINUOUS_PARAMETER value[%i] : %f\n", i, ((float*)value)[i])); + PRINT(("GetParameterValue B_CONTINUOUS_PARAMETER value[%li] : %f\n", i, ((float*)value)[i])); } } else if (parameter->Type() == BParameter::B_DISCRETE_PARAMETER) { BDiscreteParameter* discrete = (BDiscreteParameter*)parameter; @@ -1235,7 +1235,7 @@ *size = sizeof(int32); for (uint32 i = 0; i < *size / sizeof(int32); i++) { - PRINT(("GetParameterValue B_DISCRETE_PARAMETER value[%i] : %i\n", i, ((int32*)value)[i])); + PRINT(("GetParameterValue B_DISCRETE_PARAMETER value[%li] : %li\n", i, ((int32*)value)[i])); } } } @@ -1249,7 +1249,7 @@ const void* value, size_t size) { CALLED(); - PRINT(("id : %i, performance_time : %lld, size : %i\n", id, performanceTime, size)); + PRINT(("id : %li, performance_time : %lld, size : %li\n", id, performanceTime, size)); BParameter* parameter = NULL; for (int32 i = 0; i < fWeb->CountParameters(); i++) { @@ -1270,7 +1270,7 @@ if (parameter->Type() == BParameter::B_CONTINUOUS_PARAMETER) { for (uint32 i = 0; i < size / sizeof(float); i++) { - PRINT(("SetParameterValue B_CONTINUOUS_PARAMETER value[%i] : %f\n", i, ((float*)value)[i])); + PRINT(("SetParameterValue B_CONTINUOUS_PARAMETER value[%li] : %f\n", i, ((float*)value)[i])); } info.item_count = 1; values[0].id = id; @@ -1283,7 +1283,7 @@ } } else if (parameter->Type() == BParameter::B_DISCRETE_PARAMETER) { for (uint32 i = 0; i < size / sizeof(int32); i++) { - PRINT(("SetParameterValue B_DISCRETE_PARAMETER value[%i] : %i\n", i, ((int32*)value)[i])); + PRINT(("SetParameterValue B_DISCRETE_PARAMETER value[%li] : %li\n", i, ((int32*)value)[i])); } BDiscreteParameter* discrete = (BDiscreteParameter*)parameter; @@ -1312,7 +1312,7 @@ CALLED(); BParameterWeb* web = new BParameterWeb; - PRINT(("MixControlInfo().control_count : %i\n", + PRINT(("MixControlInfo().control_count : %li\n", fDevice->MixControlInfo().control_count)); multi_mix_control* controls = fDevice->MixControlInfo().controls; @@ -1389,7 +1389,7 @@ i++; } - PRINT(("num parameters : %d\n", numParameters)); + PRINT(("num parameters : %ld\n", numParameters)); if (numParameters > 0) { (group->ParameterAt(numParameters - 1))->AddOutput( group->ParameterAt(numParameters)); @@ -1981,7 +1981,7 @@ && parameter->Type() != BParameter::B_DISCRETE_PARAMETER) continue; - PRINT(("getting parameter %i\n", parameter->ID())); + PRINT(("getting parameter %li\n", parameter->ID())); size_t size = bufferSize; while ((err = GetParameterValue(parameter->ID(), &lastChange, buffer, &size)) == B_NO_MEMORY && bufferSize < 128 * 1024) { From korli at mail.berlios.de Tue Jul 8 23:48:51 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Tue, 8 Jul 2008 23:48:51 +0200 Subject: [Haiku-commits] r26330 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200807082148.m68Lmpgp016452@sheep.berlios.de> Author: korli Date: 2008-07-08 23:48:50 +0200 (Tue, 08 Jul 2008) New Revision: 26330 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26330&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp Log: * some methods to access stream registers were defined with wrong types * use HDAC_BIDIR_STREAM_OFFSET and HDAC_OUTPUT_STREAM_OFFSET when applicable * use a PAGE_ALIGN macro Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-08 21:31:14 UTC (rev 26329) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-08 21:48:50 UTC (rev 26330) @@ -149,8 +149,8 @@ /* Physical addresses for buffer */ sem_id buffer_ready_sem; bigtime_t real_time; - uint32 frames_count; - uint32 buffer_cycle; + uint64 frames_count; + int32 buffer_cycle; uint32 rate, bps; /* Samplerate & bits per sample */ @@ -168,7 +168,7 @@ return controller->Read16(HDAC_STREAM_BASE + offset + reg); } - uint8 Read32(uint32 reg) + uint32 Read32(uint32 reg) { return controller->Read32(HDAC_STREAM_BASE + offset + reg); } @@ -178,12 +178,12 @@ *(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } - void Write16(uint32 reg, uint8 value) + void Write16(uint32 reg, uint16 value) { *(vuint16*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } - void Write32(uint32 reg, uint8 value) + void Write32(uint32 reg, uint32 value) { *(vuint32*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-08 21:31:14 UTC (rev 26329) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-08 21:48:50 UTC (rev 26330) @@ -26,6 +26,8 @@ (((controller)->num_input_streams + (controller)->num_output_streams \ + (index)) * HDAC_STREAM_SIZE) +#define PAGE_ALIGN(size) (((size) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1)) + static const struct { uint32 multi_rate; uint32 hw_rate; @@ -197,15 +199,15 @@ } for (uint32 i = 0; i < controller->num_output_streams; i++) { controller->Write8(HDAC_STREAM_CONTROL0 + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_OUTPUT_STREAM_OFFSET(controller, i), 0); controller->Write8(HDAC_STREAM_STATUS + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_OUTPUT_STREAM_OFFSET(controller, i), 0); } for (uint32 i = 0; i < controller->num_bidir_streams; i++) { controller->Write8(HDAC_STREAM_CONTROL0 + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_BIDIR_STREAM_OFFSET(controller, i), 0); controller->Write8(HDAC_STREAM_STATUS + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_BIDIR_STREAM_OFFSET(controller, i), 0); } // stop DMA @@ -305,7 +307,7 @@ posSize = 8 * (controller->num_input_streams + controller->num_output_streams + controller->num_bidir_streams); - memSize = (posOffset + posSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); + memSize = PAGE_ALIGN(posOffset + posSize); /* Allocate memory area */ controller->corb_rirb_pos_area = create_area("hda corb/rirb/pos", @@ -504,7 +506,7 @@ /* Calculate total size of all buffers (aligned to size of B_PAGE_SIZE) */ alloc = bufferSize * stream->num_buffers; - alloc = (alloc + B_PAGE_SIZE - 1) & (~(B_PAGE_SIZE -1)); + alloc = PAGE_ALIGN(alloc); /* Allocate memory for buffers */ stream->buffer_area = create_area("hda buffers", (void**)&buffer, @@ -533,7 +535,7 @@ /* Now allocate BDL for buffer range */ alloc = stream->num_buffers * sizeof(bdl_entry_t); - alloc = (alloc + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); + alloc = PAGE_ALIGN(alloc); stream->buffer_descriptors_area = create_area("hda buffer descriptors", (void**)&bufferDescriptors, B_ANY_KERNEL_ADDRESS, alloc, From stippi at mail.berlios.de Wed Jul 9 00:31:29 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 9 Jul 2008 00:31:29 +0200 Subject: [Haiku-commits] r26331 - haiku/trunk/src/kits/interface Message-ID: <200807082231.m68MVTY1021622@sheep.berlios.de> Author: stippi Date: 2008-07-09 00:31:26 +0200 (Wed, 09 Jul 2008) New Revision: 26331 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26331&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: honor 80 char limit in comment Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-08 21:48:50 UTC (rev 26330) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-08 22:31:26 UTC (rev 26331) @@ -1440,13 +1440,16 @@ // TODO: ServerWindow replies with an int32 here ConvertFromScreen(location); - // TODO: in beos R5, location is already converted to the view local coordinate system, - // so if an app checks the window message queue by itself, it might not find what it expects. - // NOTE: the fact that we have mouse coords in screen space in our queue avoids the problem - // that messages already in the queue will be outdated as soon as a window or even the - // view moves. The second situation being quite common actually, also with regards to - // scrolling. An app reading these messages would have to know the locations of the window - // and view for each message... otherwise it is potentially broken anyways. + // TODO: in beos R5, location is already converted to the view + // local coordinate system, so if an app checks the window message + // queue by itself, it might not find what it expects. + // NOTE: the fact that we have mouse coords in screen space in our + // queue avoids the problem that messages already in the queue will + // be outdated as soon as a window or even the view moves. The + // second situation being quite common actually, also with regards + // to scrolling. An app reading these messages would have to know + // the locations of the window and view for each message... + // otherwise it is potentially broken anyways. } else *buttons = 0; } From marcusoverhagen at mail.berlios.de Wed Jul 9 00:39:03 2008 From: marcusoverhagen at mail.berlios.de (marcusoverhagen at BerliOS) Date: Wed, 9 Jul 2008 00:39:03 +0200 Subject: [Haiku-commits] r26332 - haiku/trunk/src/add-ons/kernel/busses/scsi/ahci Message-ID: <200807082239.m68Md3Cs032304@sheep.berlios.de> Author: marcusoverhagen Date: 2008-07-09 00:39:03 +0200 (Wed, 09 Jul 2008) New Revision: 26332 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26332&view=rev Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp Log: Report SCSI_STATUS_GOOD after successful ATAPI commands. This makes CDDA-fs work with AHCI. Modified: haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-08 22:31:26 UTC (rev 26331) +++ haiku/trunk/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-08 22:39:03 UTC (rev 26332) @@ -111,6 +111,7 @@ if (fCcb) { fCcb->data_resid = fCcb->data_length - bytesTransfered; + fCcb->device_status = SCSI_STATUS_GOOD; fCcb->subsys_status = SCSI_REQ_CMP; if (tfd & (ATA_ERR | ATA_DF)) { fCcb->subsys_status = SCSI_REQ_CMP_ERR; From marcusoverhagen at arcor.de Wed Jul 9 02:17:18 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Wed, 09 Jul 2008 02:17:18 +0200 Subject: [Haiku-commits] r26330 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: <200807082148.m68Lmpgp016452@sheep.berlios.de> References: <200807082148.m68Lmpgp016452@sheep.berlios.de> Message-ID: <4874038E.8070008@arcor.de> korli at BerliOS schrieb: > - uint8 Read32(uint32 reg) > + uint32 Read32(uint32 reg) > - void Write16(uint32 reg, uint8 value) > + void Write16(uint32 reg, uint16 value) > - void Write32(uint32 reg, uint8 value) > + void Write32(uint32 reg, uint32 value) Wow! From bonefish at mail.berlios.de Wed Jul 9 03:57:00 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 9 Jul 2008 03:57:00 +0200 Subject: [Haiku-commits] r26333 - haiku/trunk/src/system/kernel/vm Message-ID: <200807090157.m691v0ZH031351@sheep.berlios.de> Author: bonefish Date: 2008-07-09 03:56:58 +0200 (Wed, 09 Jul 2008) New Revision: 26333 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26333&view=rev Modified: haiku/trunk/src/system/kernel/vm/vm.cpp Log: Changes related to the "caches" command: * The table used for sorting the caches could be too small for the number of caches in the system. We never checked that, which could cause a crash or triple faults when invoking the command. * We now allocate the table as an area. Also increased the table size to 102400 entries. * Also print the committed memory for non-RAM caches, if they are the root cache of a cache tree that has committed memory. Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-08 22:39:03 UTC (rev 26332) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-09 01:56:58 UTC (rev 26333) @@ -208,8 +208,8 @@ addr_t committed; }; -static const int kCacheInfoTableCount = 10240; -static cache_info sCacheInfoTable[kCacheInfoTableCount]; +static const int kCacheInfoTableCount = 100 * 1024; +static cache_info* sCacheInfoTable; #endif // DEBUG_CACHE_LIST @@ -3171,7 +3171,7 @@ if (level == 0) kprintf("/%lu", info.page_count); - if (cache->type == CACHE_TYPE_RAM) { + if (cache->type == CACHE_TYPE_RAM || level == 0 && info.committed > 0) { kprintf(", committed: %lld", cache->store->committed_size); if (level == 0) @@ -3204,6 +3204,11 @@ static int dump_caches(int argc, char **argv) { + if (sCacheInfoTable == NULL) { + kprintf("No cache info table!\n"); + return 0; + } + bool sortByPageCount = true; for (int32 i = 1; i < argc; i++) { @@ -3224,7 +3229,10 @@ while (cache) { totalCount++; if (cache->source == NULL) { - cache_info& info = sCacheInfoTable[rootCount++]; + cache_info stackInfo; + cache_info& info = rootCount < (uint32)kCacheInfoTableCount + ? sCacheInfoTable[rootCount] : stackInfo; + rootCount++; info.cache = cache; info.page_count = 0; info.committed = 0; @@ -3236,9 +3244,12 @@ cache = cache->debug_next; } - qsort(sCacheInfoTable, rootCount, sizeof(cache_info), - sortByPageCount - ? &cache_info_compare_page_count : &cache_info_compare_committed); + if (rootCount <= (uint32)kCacheInfoTableCount) { + qsort(sCacheInfoTable, rootCount, sizeof(cache_info), + sortByPageCount + ? &cache_info_compare_page_count + : &cache_info_compare_committed); + } kprintf("total committed memory: %lld, total used pages: %lu\n", totalCommitted, totalPages); @@ -3246,10 +3257,13 @@ "tree...\n\n", totalCount, rootCount, sortByPageCount ? "page count" : "committed size"); - for (uint32 i = 0; i < rootCount; i++) { - cache_info& info = sCacheInfoTable[i]; - dump_caches_recursively(info.cache, info, 0); - } + if (rootCount <= (uint32)kCacheInfoTableCount) { + for (uint32 i = 0; i < rootCount; i++) { + cache_info& info = sCacheInfoTable[i]; + dump_caches_recursively(info.cache, info, 0); + } + } else + kprintf("Cache info table too small! Can't sort and print caches!\n"); return 0; } @@ -3908,6 +3922,13 @@ B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); } +#if DEBUG_CACHE_LIST + create_area("cache info table", (void**)&sCacheInfoTable, + B_ANY_KERNEL_ADDRESS, + ROUNDUP(kCacheInfoTableCount * sizeof(cache_info), B_PAGE_SIZE), + B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); +#endif // DEBUG_CACHE_LIST + // add some debugger commands add_debugger_command("areas", &dump_area_list, "Dump a list of all areas"); add_debugger_command("area", &dump_area, "Dump info about a particular area"); From bonefish at mail.berlios.de Wed Jul 9 04:15:27 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Wed, 9 Jul 2008 04:15:27 +0200 Subject: [Haiku-commits] r26334 - in haiku/branches/developer/bonefish/vm/src: add-ons/kernel/busses/scsi/ahci add-ons/kernel/drivers/audio/ac97/auich add-ons/kernel/drivers/audio/ac97/auvia add-ons/kernel/drivers/audio/echo add-ons/kernel/drivers/audio/emuxki add-ons/kernel/drivers/audio/hda add-ons/kernel/file_systems/bfs add-ons/media/media-add-ons/multi_audio kits/interface servers/app/drawing servers/app/drawing/Painter servers/bluetooth servers/input system/kernel/arch/x86 system/kernel/vm tests/servers/app tests/servers/app/lagging_get_mouse tests/servers/app/statusbar Message-ID: <200807090215.m692FRAS032687@sheep.berlios.de> Author: bonefish Date: 2008-07-09 04:15:07 +0200 (Wed, 09 Jul 2008) New Revision: 26334 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26334&view=rev Added: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/ haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/Jamfile haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/main.cpp haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/run haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/ haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/Jamfile haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/main.cpp haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/run Removed: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/Jamfile haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/main.cpp haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/run haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/Jamfile haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/main.cpp haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/run Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/echo.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Utility.cpp haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp haiku/branches/developer/bonefish/vm/src/servers/app/drawing/DrawingEngine.cpp haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIDelegate.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.h haiku/branches/developer/bonefish/vm/src/servers/input/InputServer.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/vm86.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/tests/servers/app/Jamfile Log: Synchronized with trunk at r26333. Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/busses/scsi/ahci/sata_request.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -111,6 +111,7 @@ if (fCcb) { fCcb->data_resid = fCcb->data_length - bytesTransfered; + fCcb->device_status = SCSI_STATUS_GOOD; fCcb->subsys_status = SCSI_REQ_CMP; if (tfd & (ATA_ERR | ATA_DF)) { fCcb->subsys_status = SCSI_REQ_CMP_ERR; Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auich/auich.c 2008-07-09 02:15:07 UTC (rev 26334) @@ -331,6 +331,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* allocate memory for our dma ops */ Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/ac97/auvia/auvia.c 2008-07-09 02:15:07 UTC (rev 26334) @@ -313,6 +313,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* allocate memory for our dma ops */ Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/echo.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/echo/echo.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -372,6 +372,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; status = lock(); Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-09 02:15:07 UTC (rev 26334) @@ -1636,6 +1636,7 @@ stream->frames_count = 0; stream->real_time = 0; + stream->buffer_cycle = 0; stream->update_needed = false; /* Init voices list */ Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-09 02:15:07 UTC (rev 26334) @@ -149,8 +149,8 @@ /* Physical addresses for buffer */ sem_id buffer_ready_sem; bigtime_t real_time; - uint32 frames_count; - uint32 buffer_cycle; + uint64 frames_count; + int32 buffer_cycle; uint32 rate, bps; /* Samplerate & bits per sample */ @@ -168,7 +168,7 @@ return controller->Read16(HDAC_STREAM_BASE + offset + reg); } - uint8 Read32(uint32 reg) + uint32 Read32(uint32 reg) { return controller->Read32(HDAC_STREAM_BASE + offset + reg); } @@ -178,12 +178,12 @@ *(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } - void Write16(uint32 reg, uint8 value) + void Write16(uint32 reg, uint16 value) { *(vuint16*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } - void Write32(uint32 reg, uint8 value) + void Write32(uint32 reg, uint32 value) { *(vuint32*)(controller->regs + HDAC_STREAM_BASE + offset + reg) = value; } Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -26,6 +26,8 @@ (((controller)->num_input_streams + (controller)->num_output_streams \ + (index)) * HDAC_STREAM_SIZE) +#define PAGE_ALIGN(size) (((size) + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1)) + static const struct { uint32 multi_rate; uint32 hw_rate; @@ -197,15 +199,15 @@ } for (uint32 i = 0; i < controller->num_output_streams; i++) { controller->Write8(HDAC_STREAM_CONTROL0 + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_OUTPUT_STREAM_OFFSET(controller, i), 0); controller->Write8(HDAC_STREAM_STATUS + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_OUTPUT_STREAM_OFFSET(controller, i), 0); } for (uint32 i = 0; i < controller->num_bidir_streams; i++) { controller->Write8(HDAC_STREAM_CONTROL0 + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_BIDIR_STREAM_OFFSET(controller, i), 0); controller->Write8(HDAC_STREAM_STATUS + HDAC_STREAM_BASE - + HDAC_INPUT_STREAM_OFFSET(controller, i), 0); + + HDAC_BIDIR_STREAM_OFFSET(controller, i), 0); } // stop DMA @@ -305,7 +307,7 @@ posSize = 8 * (controller->num_input_streams + controller->num_output_streams + controller->num_bidir_streams); - memSize = (posOffset + posSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); + memSize = PAGE_ALIGN(posOffset + posSize); /* Allocate memory area */ controller->corb_rirb_pos_area = create_area("hda corb/rirb/pos", @@ -504,7 +506,7 @@ /* Calculate total size of all buffers (aligned to size of B_PAGE_SIZE) */ alloc = bufferSize * stream->num_buffers; - alloc = (alloc + B_PAGE_SIZE - 1) & (~(B_PAGE_SIZE -1)); + alloc = PAGE_ALIGN(alloc); /* Allocate memory for buffers */ stream->buffer_area = create_area("hda buffers", (void**)&buffer, @@ -533,7 +535,7 @@ /* Now allocate BDL for buffer range */ alloc = stream->num_buffers * sizeof(bdl_entry_t); - alloc = (alloc + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); + alloc = PAGE_ALIGN(alloc); stream->buffer_descriptors_area = create_area("hda buffer descriptors", (void**)&bufferDescriptors, B_ANY_KERNEL_ADDRESS, alloc, Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Utility.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Utility.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/file_systems/bfs/Utility.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -60,8 +60,8 @@ if (index == -1) return false; + count--; memmove(&values[index], &values[index + 1], (count - index) * sizeof(off_t)); - count--; return true; } Modified: haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioDevice.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -180,18 +180,18 @@ for (int32 i = 0; i < fBufferList.return_playback_buffers; i++) { for (int32 j = 0; j < fBufferList.return_playback_channels; j++) { - PRINT(("fBufferList.playback_buffers[%d][%d].base: %p\n", + PRINT(("fBufferList.playback_buffers[%ld][%ld].base: %p\n", i, j, fBufferList.playback_buffers[i][j].base)); - PRINT(("fBufferList.playback_buffers[%d][%d].stride: %i\n", + PRINT(("fBufferList.playback_buffers[%ld][%ld].stride: %li\n", i, j, fBufferList.playback_buffers[i][j].stride)); } } for (int32 i = 0; i < fBufferList.return_record_buffers; i++) { for (int32 j = 0; j < fBufferList.return_record_channels; j++) { - PRINT(("fBufferList.record_buffers[%d][%d].base: %p\n", + PRINT(("fBufferList.record_buffers[%ld][%ld].base: %p\n", i, j, fBufferList.record_buffers[i][j].base)); - PRINT(("fBufferList.record_buffers[%d][%d].stride: %i\n", + PRINT(("fBufferList.record_buffers[%ld][%ld].stride: %li\n", i, j, fBufferList.record_buffers[i][j].stride)); } } Modified: haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/add-ons/media/media-add-ons/multi_audio/MultiAudioNode.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -129,7 +129,7 @@ fPreferredFormat.u.raw_audio.format = MultiAudio::convert_to_media_format(fDevice->FormatInfo().output.format); fPreferredFormat.u.raw_audio.valid_bits = MultiAudio::convert_to_valid_bits(fDevice->FormatInfo().output.format); fPreferredFormat.u.raw_audio.channel_count = 2; - fPreferredFormat.u.raw_audio.frame_rate = MultiAudio::convert_to_sample_rate(fDevice->FormatInfo().input.rate); // measured in Hertz + fPreferredFormat.u.raw_audio.frame_rate = MultiAudio::convert_to_sample_rate(fDevice->FormatInfo().output.rate); // measured in Hertz fPreferredFormat.u.raw_audio.byte_order = B_MEDIA_HOST_ENDIAN; // we'll use the consumer's preferred buffer size, if any @@ -224,7 +224,7 @@ && ( fDevice->Description().channels[i].designations & B_CHANNEL_LEFT || !(fDevice->Description().channels[i].designations & B_CHANNEL_SURROUND_BUS))) ) { - PRINT(("NodeRegistered() : creating an input for %i\n", i)); + PRINT(("NodeRegistered() : creating an input for %li\n", i)); PRINT(("%ld\t%d\t0x%lx\t0x%lx\n", fDevice->Description().channels[i].channel_id, fDevice->Description().channels[i].kind, @@ -270,7 +270,7 @@ && ( fDevice->Description().channels[i].designations & B_CHANNEL_LEFT || !(fDevice->Description().channels[i].designations & B_CHANNEL_SURROUND_BUS))) ) { - PRINT(("NodeRegistered() : creating an output for %i\n", i)); + PRINT(("NodeRegistered() : creating an output for %li\n", i)); PRINT(("%ld\t%d\t0x%lx\t0x%lx\n",fDevice->Description().channels[i].channel_id, fDevice->Description().channels[i].kind, fDevice->Description().channels[i].designations, @@ -320,7 +320,7 @@ index++; } - PRINT(("apply configuration in : %ld\n", system_time() - start)); + PRINT(("apply configuration in : %Ld\n", system_time() - start)); } @@ -409,7 +409,7 @@ node_input *channel = (node_input *)fInputs.ItemAt(*cookie); *_input = channel->fInput; *cookie += 1; - PRINT(("input.format : %u\n", channel->fInput.format.u.raw_audio.format)); + PRINT(("input.format : %lu\n", channel->fInput.format.u.raw_audio.format)); return B_OK; } @@ -1011,7 +1011,7 @@ } else { //WriteBuffer(buffer, *channel); if (channel->fBuffer != NULL) { - PRINT(("MultiAudioNode::HandleBuffer snoozing recycling channelId : %i, how_early:%lli\n", channel->fChannelId, how_early)); + PRINT(("MultiAudioNode::HandleBuffer snoozing recycling channelId : %li, how_early:%Ld\n", channel->fChannelId, howEarly)); //channel->fBuffer->Recycle(); snooze(100); if (channel->fBuffer != NULL) @@ -1019,7 +1019,7 @@ else channel->fBuffer = buffer; } else { - //PRINT(("MultiAudioNode::HandleBuffer writing channelId : %i, how_early:%lli\n", channel->fChannelId, how_early)); + //PRINT(("MultiAudioNode::HandleBuffer writing channelId : %li, how_early:%Ld\n", channel->fChannelId, how_early)); channel->fBuffer = buffer; } } @@ -1032,7 +1032,7 @@ bigtime_t lateness, bool realTimeEvent) { //CALLED(); - PRINT(("MultiAudioNode::HandleDataStatus status:%li, lateness:%li\n", event->data, lateness)); + PRINT(("MultiAudioNode::HandleDataStatus status:%li, lateness:%Li\n", event->data, lateness)); switch (event->data) { case B_DATA_NOT_AVAILABLE: break; @@ -1168,7 +1168,7 @@ { CALLED(); - PRINT(("id : %i\n", id)); + PRINT(("id : %li\n", id)); BParameter* parameter = NULL; for (int32 i = 0; i < fWeb->CountParameters(); i++) { parameter = fWeb->ParameterAt(i); @@ -1223,7 +1223,7 @@ } for (uint32 i = 0; i < *size / sizeof(float); i++) { - PRINT(("GetParameterValue B_CONTINUOUS_PARAMETER value[%i] : %f\n", i, ((float*)value)[i])); + PRINT(("GetParameterValue B_CONTINUOUS_PARAMETER value[%li] : %f\n", i, ((float*)value)[i])); } } else if (parameter->Type() == BParameter::B_DISCRETE_PARAMETER) { BDiscreteParameter* discrete = (BDiscreteParameter*)parameter; @@ -1235,7 +1235,7 @@ *size = sizeof(int32); for (uint32 i = 0; i < *size / sizeof(int32); i++) { - PRINT(("GetParameterValue B_DISCRETE_PARAMETER value[%i] : %i\n", i, ((int32*)value)[i])); + PRINT(("GetParameterValue B_DISCRETE_PARAMETER value[%li] : %li\n", i, ((int32*)value)[i])); } } } @@ -1249,7 +1249,7 @@ const void* value, size_t size) { CALLED(); - PRINT(("id : %i, performance_time : %lld, size : %i\n", id, performanceTime, size)); + PRINT(("id : %li, performance_time : %lld, size : %li\n", id, performanceTime, size)); BParameter* parameter = NULL; for (int32 i = 0; i < fWeb->CountParameters(); i++) { @@ -1270,7 +1270,7 @@ if (parameter->Type() == BParameter::B_CONTINUOUS_PARAMETER) { for (uint32 i = 0; i < size / sizeof(float); i++) { - PRINT(("SetParameterValue B_CONTINUOUS_PARAMETER value[%i] : %f\n", i, ((float*)value)[i])); + PRINT(("SetParameterValue B_CONTINUOUS_PARAMETER value[%li] : %f\n", i, ((float*)value)[i])); } info.item_count = 1; values[0].id = id; @@ -1283,7 +1283,7 @@ } } else if (parameter->Type() == BParameter::B_DISCRETE_PARAMETER) { for (uint32 i = 0; i < size / sizeof(int32); i++) { - PRINT(("SetParameterValue B_DISCRETE_PARAMETER value[%i] : %i\n", i, ((int32*)value)[i])); + PRINT(("SetParameterValue B_DISCRETE_PARAMETER value[%li] : %li\n", i, ((int32*)value)[i])); } BDiscreteParameter* discrete = (BDiscreteParameter*)parameter; @@ -1312,7 +1312,7 @@ CALLED(); BParameterWeb* web = new BParameterWeb; - PRINT(("MixControlInfo().control_count : %i\n", + PRINT(("MixControlInfo().control_count : %li\n", fDevice->MixControlInfo().control_count)); multi_mix_control* controls = fDevice->MixControlInfo().controls; @@ -1389,7 +1389,7 @@ i++; } - PRINT(("num parameters : %d\n", numParameters)); + PRINT(("num parameters : %ld\n", numParameters)); if (numParameters > 0) { (group->ParameterAt(numParameters - 1))->AddOutput( group->ParameterAt(numParameters)); @@ -1981,7 +1981,7 @@ && parameter->Type() != BParameter::B_DISCRETE_PARAMETER) continue; - PRINT(("getting parameter %i\n", parameter->ID())); + PRINT(("getting parameter %li\n", parameter->ID())); size_t size = bufferSize; while ((err = GetParameterValue(parameter->ID(), &lastChange, buffer, &size)) == B_NO_MEMORY && bufferSize < 128 * 1024) { Modified: haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -1440,13 +1440,16 @@ // TODO: ServerWindow replies with an int32 here ConvertFromScreen(location); - // TODO: in beos R5, location is already converted to the view local coordinate system, - // so if an app checks the window message queue by itself, it might not find what it expects. - // NOTE: the fact that we have mouse coords in screen space in our queue avoids the problem - // that messages already in the queue will be outdated as soon as a window or even the - // view moves. The second situation being quite common actually, also with regards to - // scrolling. An app reading these messages would have to know the locations of the window - // and view for each message... otherwise it is potentially broken anyways. + // TODO: in beos R5, location is already converted to the view + // local coordinate system, so if an app checks the window message + // queue by itself, it might not find what it expects. + // NOTE: the fact that we have mouse coords in screen space in our + // queue avoids the problem that messages already in the queue will + // be outdated as soon as a window or even the view moves. The + // second situation being quite common actually, also with regards + // to scrolling. An app reading these messages would have to know + // the locations of the window and view for each message... + // otherwise it is potentially broken anyways. } else *buttons = 0; } @@ -1532,11 +1535,14 @@ _CheckLockAndSwitchCurrent(); + float xDiff = where.x - fBounds.left; + float yDiff = where.y - fBounds.top; + // if we're attached to a window tell app_server about this change if (fOwner) { fOwner->fLink->StartMessage(AS_VIEW_SCROLL); - fOwner->fLink->Attach(where.x - fBounds.left); - fOwner->fLink->Attach(where.y - fBounds.top); + fOwner->fLink->Attach(xDiff); + fOwner->fLink->Attach(yDiff); fOwner->fLink->Flush(); @@ -1547,9 +1553,9 @@ fBounds.OffsetTo(where.x, where.y); // then set the new values of the scrollbars - if (fHorScroller) + if (fHorScroller && xDiff != 0.0) fHorScroller->SetValue(fBounds.left); - if (fVerScroller) + if (fVerScroller && yDiff != 0.0) fVerScroller->SetValue(fBounds.top); } Modified: haiku/branches/developer/bonefish/vm/src/servers/app/drawing/DrawingEngine.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/app/drawing/DrawingEngine.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/app/drawing/DrawingEngine.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -1067,12 +1067,14 @@ BPoint penLocation = pt; // try a fast clipping path - float fontSize = fPainter->Font().Size(); - BRect clippingFrame = fPainter->ClippingRegion()->Frame(); - if (pt.x > clippingFrame.right || pt.y + fontSize < clippingFrame.top - || pt.y - fontSize > clippingFrame.bottom) { - penLocation.x += StringWidth(string, length, delta); - return penLocation; + if (fPainter->ClippingRegion()) { + float fontSize = fPainter->Font().Size(); + BRect clippingFrame = fPainter->ClippingRegion()->Frame(); + if (pt.x > clippingFrame.right || pt.y + fontSize < clippingFrame.top + || pt.y - fontSize > clippingFrame.bottom) { + penLocation.x += StringWidth(string, length, delta); + return penLocation; + } } // use a FontCacheRefernece to speed up the second pass of Modified: haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -45,6 +45,13 @@ #include "Painter.h" +//#define TRACE_PAINTER +#ifdef TRACE_PAINTER +# define TRACE(x...) printf(x) +#else +# define TRACE(x...) +#endif + #define CHECK_CLIPPING if (!fValidClipping) return BRect(0, 0, -1, -1); #define CHECK_CLIPPING_NO_RETURN if (!fValidClipping) return; @@ -1049,6 +1056,16 @@ // the native bitmap coordinate system BRect actualBitmapRect(bitmap->Bounds()); + TRACE("Painter::DrawBitmap()\n"); + TRACE(" actualBitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + actualBitmapRect.left, actualBitmapRect.top, + actualBitmapRect.right, actualBitmapRect.bottom); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, + bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + agg::rendering_buffer srcBuffer; srcBuffer.attach(bitmap->Bits(), bitmap->Width(), @@ -1304,10 +1321,16 @@ } if (!fSubpixelPrecise) { + align_rect_to_pixels(&bitmapRect); align_rect_to_pixels(&viewRect); - align_rect_to_pixels(&bitmapRect); } - + + TRACE("Painter::_DrawBitmap()\n"); + TRACE(" bitmapRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + bitmapRect.left, bitmapRect.top, bitmapRect.right, bitmapRect.bottom); + TRACE(" viewRect = (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); + double xScale = (viewRect.Width() + 1) / (bitmapRect.Width() + 1); double yScale = (viewRect.Height() + 1) / (bitmapRect.Height() + 1); @@ -1512,6 +1535,11 @@ double xScale, double yScale, BRect viewRect) const { + TRACE("Painter::_DrawBitmapGeneric32()\n"); + TRACE(" offset: %.1f, %.1f\n", xOffset, yOffset); + TRACE(" scale: %.3f, %.3f\n", xScale, yScale); + TRACE(" viewRect: (%.1f, %.1f) - (%.1f, %.1f)\n", + viewRect.left, viewRect.top, viewRect.right, viewRect.bottom); // AGG pipeline // pixel format attached to bitmap @@ -1524,8 +1552,10 @@ // -actualBitmapRect.top); agg::trans_affine imgMatrix; + imgMatrix *= agg::trans_affine_translation(xOffset - viewRect.left, + yOffset - viewRect.top); imgMatrix *= agg::trans_affine_scaling(xScale, yScale); - imgMatrix *= agg::trans_affine_translation(xOffset, yOffset); + imgMatrix *= agg::trans_affine_translation(viewRect.left, viewRect.top); imgMatrix.invert(); // image interpolator Modified: haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -15,7 +15,7 @@ } status_t -HCIControllerAccessor::IssueCommand(raw_command* rc, size_t size) +HCIControllerAccessor::IssueCommand(raw_command rc, size_t size) { if (GetID() < 0) @@ -24,3 +24,11 @@ return B_ERROR; } + + +status_t +HCIControllerAccessor::Launch() { + + return B_OK; + +} Modified: haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIControllerAccessor.h 2008-07-09 02:15:07 UTC (rev 26334) @@ -17,7 +17,8 @@ public: HCIControllerAccessor(BPath* path); - status_t IssueCommand(raw_command* rc, size_t size); + status_t IssueCommand(raw_command rc, size_t size); + status_t Launch(); }; #endif Modified: haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIDelegate.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIDelegate.h 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCIDelegate.h 2008-07-09 02:15:07 UTC (rev 26334) @@ -41,16 +41,15 @@ } + hci_id GetID(void) { return fHID; } - - virtual status_t IssueCommand(raw_command rc, size_t size) - { - return B_ERROR; - } - + + virtual status_t IssueCommand(raw_command rc, size_t size)=0; + virtual status_t Launch()=0; + protected: Modified: haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -33,3 +33,11 @@ return ioctl(fFD, ISSUE_BT_COMMAND, rc, size); } + + +status_t +HCITransportAccessor::Launch() { + + return B_OK; + +} Modified: haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.h 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.h 2008-07-09 02:15:07 UTC (rev 26334) @@ -17,6 +17,8 @@ public: HCITransportAccessor(BPath* path); status_t IssueCommand(raw_command rc, size_t size); + status_t Launch(); + }; #endif Modified: haiku/branches/developer/bonefish/vm/src/servers/input/InputServer.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/servers/input/InputServer.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/servers/input/InputServer.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -1492,6 +1492,9 @@ PRINT(("new position : %f, %f\n", fMousePos.x, fMousePos.y)); } + if (!event->HasInt64("when")) + event->AddInt64("when", system_time()); + event->AddInt32("modifiers", fKeyInfo.modifiers); break; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/vm86.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/vm86.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/arch/x86/vm86.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -44,8 +44,8 @@ #define PUSHF 0x9c #define STI 0xfb -#define I_FLAG (1 << 9) -#define DIRECTION_FLAG (1 << 10) +#define I_FLAG (1u << 9) +#define DIRECTION_FLAG (1u << 10) #define CSEG 0x2e #define SSEG 0x36 @@ -442,7 +442,7 @@ uint16 flags = state->regs.flags; /* store real IF */ - flags &= I_FLAG; + flags &= ~I_FLAG; flags |= (uint16)state->if_flag << 9; pushw(&state->regs, flags); @@ -475,10 +475,11 @@ case PUSHF: { TRACE_NP("PUSHF"); - uint16 flags = state->regs.flags & I_FLAG; + uint32 flags = state->regs.flags; /* store real IF */ - flags |= (uint16)state->if_flag << 9; + flags &= ~I_FLAG; + flags |= (uint32)state->if_flag << 9; if (prefix.size) pushl(&state->regs, flags); else Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-09 02:15:07 UTC (rev 26334) @@ -204,8 +204,8 @@ addr_t committed; }; -static const int kCacheInfoTableCount = 10240; -static cache_info sCacheInfoTable[kCacheInfoTableCount]; +static const int kCacheInfoTableCount = 100 * 1024; +static cache_info* sCacheInfoTable; #endif // DEBUG_CACHE_LIST @@ -3104,7 +3104,7 @@ if (level == 0) kprintf("/%lu", info.page_count); - if (cache->type == CACHE_TYPE_RAM) { + if (cache->type == CACHE_TYPE_RAM || level == 0 && info.committed > 0) { kprintf(", committed: %lld", cache->committed_size); if (level == 0) @@ -3137,6 +3137,11 @@ static int dump_caches(int argc, char **argv) { + if (sCacheInfoTable == NULL) { + kprintf("No cache info table!\n"); + return 0; + } + bool sortByPageCount = true; for (int32 i = 1; i < argc; i++) { @@ -3157,7 +3162,10 @@ while (cache) { totalCount++; if (cache->source == NULL) { - cache_info& info = sCacheInfoTable[rootCount++]; + cache_info stackInfo; + cache_info& info = rootCount < (uint32)kCacheInfoTableCount + ? sCacheInfoTable[rootCount] : stackInfo; + rootCount++; info.cache = cache; info.page_count = 0; info.committed = 0; @@ -3169,9 +3177,12 @@ cache = cache->debug_next; } - qsort(sCacheInfoTable, rootCount, sizeof(cache_info), - sortByPageCount - ? &cache_info_compare_page_count : &cache_info_compare_committed); + if (rootCount <= (uint32)kCacheInfoTableCount) { + qsort(sCacheInfoTable, rootCount, sizeof(cache_info), + sortByPageCount + ? &cache_info_compare_page_count + : &cache_info_compare_committed); + } kprintf("total committed memory: %lld, total used pages: %lu\n", totalCommitted, totalPages); @@ -3179,10 +3190,13 @@ "tree...\n\n", totalCount, rootCount, sortByPageCount ? "page count" : "committed size"); - for (uint32 i = 0; i < rootCount; i++) { - cache_info& info = sCacheInfoTable[i]; - dump_caches_recursively(info.cache, info, 0); - } + if (rootCount <= (uint32)kCacheInfoTableCount) { + for (uint32 i = 0; i < rootCount; i++) { + cache_info& info = sCacheInfoTable[i]; + dump_caches_recursively(info.cache, info, 0); + } + } else + kprintf("Cache info table too small! Can't sort and print caches!\n"); return 0; } @@ -3840,6 +3854,13 @@ B_ALREADY_WIRED, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); } +#if DEBUG_CACHE_LIST + create_area("cache info table", (void**)&sCacheInfoTable, + B_ANY_KERNEL_ADDRESS, + ROUNDUP(kCacheInfoTableCount * sizeof(cache_info), B_PAGE_SIZE), + B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); +#endif // DEBUG_CACHE_LIST + // add some debugger commands add_debugger_command("areas", &dump_area_list, "Dump a list of all areas"); add_debugger_command("area", &dump_area, "Dump info about a particular area"); Modified: haiku/branches/developer/bonefish/vm/src/tests/servers/app/Jamfile =================================================================== --- haiku/branches/developer/bonefish/vm/src/tests/servers/app/Jamfile 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/tests/servers/app/Jamfile 2008-07-09 02:15:07 UTC (rev 26334) @@ -173,6 +173,7 @@ SubInclude HAIKU_TOP src tests servers app event_mask ; SubInclude HAIKU_TOP src tests servers app following ; SubInclude HAIKU_TOP src tests servers app idle_test ; +SubInclude HAIKU_TOP src tests servers app lagging_get_mouse ; SubInclude HAIKU_TOP src tests servers app lock_focus ; SubInclude HAIKU_TOP src tests servers app look_and_feel ; SubInclude HAIKU_TOP src tests servers app menu_crash ; @@ -183,6 +184,7 @@ SubInclude HAIKU_TOP src tests servers app resize_limits ; SubInclude HAIKU_TOP src tests servers app scrollbar ; SubInclude HAIKU_TOP src tests servers app scrolling ; +SubInclude HAIKU_TOP src tests servers app statusbar ; SubInclude HAIKU_TOP src tests servers app stress_test ; SubInclude HAIKU_TOP src tests servers app textview ; SubInclude HAIKU_TOP src tests servers app view_state ; Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse (from rev 26333, haiku/trunk/src/tests/servers/app/lagging_get_mouse) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/Jamfile Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/Jamfile (from rev 26333, haiku/trunk/src/tests/servers/app/lagging_get_mouse/Jamfile) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/main.cpp Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/main.cpp (from rev 26333, haiku/trunk/src/tests/servers/app/lagging_get_mouse/main.cpp) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/run Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/lagging_get_mouse/run (from rev 26333, haiku/trunk/src/tests/servers/app/lagging_get_mouse/run) Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar (from rev 26333, haiku/trunk/src/tests/servers/app/statusbar) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/Jamfile Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/Jamfile (from rev 26333, haiku/trunk/src/tests/servers/app/statusbar/Jamfile) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/main.cpp Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/main.cpp (from rev 26333, haiku/trunk/src/tests/servers/app/statusbar/main.cpp) Deleted: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/run Copied: haiku/branches/developer/bonefish/vm/src/tests/servers/app/statusbar/run (from rev 26333, haiku/trunk/src/tests/servers/app/statusbar/run) From bonefish at mail.berlios.de Wed Jul 9 05:04:40 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 9 Jul 2008 05:04:40 +0200 Subject: [Haiku-commits] r26335 - haiku/trunk/src/system/kernel Message-ID: <200807090304.m6934elP006774@sheep.berlios.de> Author: bonefish Date: 2008-07-09 05:04:39 +0200 (Wed, 09 Jul 2008) New Revision: 26335 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26335&view=rev Modified: haiku/trunk/src/system/kernel/elf.cpp Log: Added TODO regarding memory leak. Too tired ATM to solve it. Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2008-07-09 02:15:07 UTC (rev 26334) +++ haiku/trunk/src/system/kernel/elf.cpp 2008-07-09 03:04:39 UTC (rev 26335) @@ -752,6 +752,11 @@ unregister_elf_image(image); +// TODO: We're leaking memory here. We can't just free those, since in case of +// pre-loaded images they have been allocated by the bootloader via +// kernel_args_malloc(). +// free(image->debug_symbols); +// free((void*)image->debug_string_table); free(image->elf_header); free(image->name); free(image); From bonefish at mail.berlios.de Wed Jul 9 05:58:44 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 9 Jul 2008 05:58:44 +0200 Subject: [Haiku-commits] r26336 - haiku/trunk/src/system/kernel Message-ID: <200807090358.m693wiO1010882@sheep.berlios.de> Author: bonefish Date: 2008-07-09 05:58:38 +0200 (Wed, 09 Jul 2008) New Revision: 26336 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26336&view=rev Modified: haiku/trunk/src/system/kernel/team.cpp Log: * Fixed serious memory leak in team_create_thread_start(). The destructor of the automatic KPath variable was never invoked, since normally arch_thread_enter_userspace() would not return and thus the function scope never be left. After a standard "jam @image" almost 42 MB of kernel heap were lost this way. * Added a few warning comments in functions that shouldn't use automatic variables with a destructor in the function scope either. Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2008-07-09 03:04:39 UTC (rev 26335) +++ haiku/trunk/src/system/kernel/team.cpp 2008-07-09 03:58:38 UTC (rev 26336) @@ -1041,20 +1041,25 @@ // the arguments are already on the user stack, we no longer need // them in this form - // find runtime_loader path - KPath runtimeLoaderPath; - err = find_directory(B_BEOS_SYSTEM_DIRECTORY, gBootDevice, false, - runtimeLoaderPath.LockBuffer(), runtimeLoaderPath.BufferSize()); - if (err < B_OK) { - TRACE(("team_create_thread_start: find_directory() failed: %s\n", - strerror(err))); - return err; + // NOTE: Normally arch_thread_enter_userspace() never returns, that is + // automatic variables with function scope will never be destroyed. + { + // find runtime_loader path + KPath runtimeLoaderPath; + err = find_directory(B_BEOS_SYSTEM_DIRECTORY, gBootDevice, false, + runtimeLoaderPath.LockBuffer(), runtimeLoaderPath.BufferSize()); + if (err < B_OK) { + TRACE(("team_create_thread_start: find_directory() failed: %s\n", + strerror(err))); + return err; + } + runtimeLoaderPath.UnlockBuffer(); + err = runtimeLoaderPath.Append("runtime_loader"); + + if (err == B_OK) + err = elf_load_user_image(runtimeLoaderPath.Path(), team, 0, &entry); } - runtimeLoaderPath.UnlockBuffer(); - err = runtimeLoaderPath.Append("runtime_loader"); - if (err == B_OK) - err = elf_load_user_image(runtimeLoaderPath.Path(), team, 0, &entry); if (err < B_OK) { // Luckily, we don't have to clean up the mess we created - that's // done for us by the normal team deletion process @@ -1247,6 +1252,8 @@ exec_team(const char *path, char**& _flatArgs, size_t flatArgsSize, int32 argCount, int32 envCount) { + // NOTE: Since this function normally doesn't return, don't use automatic + // variables that need destruction in the function scope. char** flatArgs = _flatArgs; struct team *team = thread_get_current_thread()->team; struct team_arg *teamArgs; @@ -2949,6 +2956,8 @@ _user_exec(const char *userPath, const char* const* userFlatArgs, size_t flatArgsSize, int32 argCount, int32 envCount) { + // NOTE: Since this function normally doesn't return, don't use automatic + // variables that need destruction in the function scope. char path[B_PATH_NAME_LENGTH]; if (!IS_USER_ADDRESS(userPath) || !IS_USER_ADDRESS(userFlatArgs) From anevilyak at gmail.com Wed Jul 9 06:03:22 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 8 Jul 2008 23:03:22 -0500 Subject: [Haiku-commits] r26336 - haiku/trunk/src/system/kernel In-Reply-To: <200807090358.m693wiO1010882@sheep.berlios.de> References: <200807090358.m693wiO1010882@sheep.berlios.de> Message-ID: On Tue, Jul 8, 2008 at 10:58 PM, bonefish at BerliOS wrote: > Author: bonefish > Date: 2008-07-09 05:58:38 +0200 (Wed, 09 Jul 2008) > New Revision: 26336 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26336&view=rev > > Modified: > haiku/trunk/src/system/kernel/team.cpp > Log: > * Fixed serious memory leak in team_create_thread_start(). The > destructor of the automatic KPath variable was never invoked, since > normally arch_thread_enter_userspace() would not return and thus the > function scope never be left. After a standard "jam @image" almost > 42 MB of kernel heap were lost this way. > * Added a few warning comments in functions that shouldn't use automatic > variables with a destructor in the function scope either. > Nice catch! Sleep is for the weak I see :) Rene From axeld at pinc-software.de Wed Jul 9 09:39:40 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 09 Jul 2008 09:39:40 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26330_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/audio/hda?= In-Reply-To: <4874038E.8070008@arcor.de> Message-ID: <1595968038-BeMail@zon> Marcus Overhagen wrote: > korli at BerliOS schrieb: > > - uint8 Read32(uint32 reg) > > + uint32 Read32(uint32 reg) > > > - void Write16(uint32 reg, uint8 value) > > + void Write16(uint32 reg, uint16 value) > > > - void Write32(uint32 reg, uint8 value) > > + void Write32(uint32 reg, uint32 value) > Wow! Indeed... maybe I should forbid myself to use copy&paste :-) Thanks, J?r?me! Bye, Axel. From stippi at mail.berlios.de Wed Jul 9 12:03:31 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 9 Jul 2008 12:03:31 +0200 Subject: [Haiku-commits] r26337 - haiku/trunk/src/kits/interface Message-ID: <200807091003.m69A3Vtu002687@sheep.berlios.de> Author: stippi Date: 2008-07-09 12:03:28 +0200 (Wed, 09 Jul 2008) New Revision: 26337 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26337&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: Implemented a simple fix for the message-pile-up problem of BView::GetMouse( , ,useHistory = true) in case the application calls GetMouse() in a loop with a longer delay then mouse messages arrive at the queue. The "when" field of the messages is used to discard old mouse moved messages. This also fixes the possible problem of finding the same message over and over in case it is not removed from the queue for other reasons. This fix makes selecting text in Pe for example usable. Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-09 03:58:38 UTC (rev 26336) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-09 10:03:28 UTC (rev 26337) @@ -1410,6 +1410,30 @@ if (!Window()->_StealMouseMessage(message, deleteMessage)) continue; + if (message->what == B_MOUSE_MOVED) { + // Check if the message is too old. Some applications + // check the message queue in such a way that mouse + // messages *must* pile up. This check makes them work + // as intended, although these applications could simply + // use the version of BView::GetMouse() that does not + // check the history. Also note that it isn't a problem + // to delete the message in case there is not a newer + // one. If we don't find a message in the queue, we will + // just fall back to asking the app_sever directly. So + // the imposed delay will not be a problem on slower + // computers. This check also prevents another problem, + // when the message that we use is *not* removed from + // the queue. Subsequent calls to GetMouse() would find + // this message over and over! + bigtime_t eventTime; + if (message->FindInt64("when", &eventTime) == B_OK + && system_time() - eventTime > 10000) { + // just discard the message + if (deleteMessage) + delete message; + continue; + } + } message->FindPoint("screen_where", location); message->FindInt32("buttons", (int32 *)buttons); queue->Unlock(); From axeld at mail.berlios.de Wed Jul 9 12:59:06 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 Jul 2008 12:59:06 +0200 Subject: [Haiku-commits] r26338 - in haiku/trunk/src/system/kernel: device_manager fs Message-ID: <200807091059.m69Ax6LS012669@sheep.berlios.de> Author: axeld Date: 2008-07-09 12:59:02 +0200 (Wed, 09 Jul 2008) New Revision: 26338 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26338&view=rev Modified: haiku/trunk/src/system/kernel/device_manager/devfs.cpp haiku/trunk/src/system/kernel/fs/rootfs.cpp Log: * Both, rootfs, and devfs did not correctly report the number of entries returned by fs_read_dir(). * Removed superfluous white space. Modified: haiku/trunk/src/system/kernel/device_manager/devfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/device_manager/devfs.cpp 2008-07-09 10:03:28 UTC (rev 26337) +++ haiku/trunk/src/system/kernel/device_manager/devfs.cpp 2008-07-09 10:59:02 UTC (rev 26338) @@ -1427,6 +1427,7 @@ cookie->current = nextChildNode; cookie->state = nextState; + *_num = 1; return B_OK; } Modified: haiku/trunk/src/system/kernel/fs/rootfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/rootfs.cpp 2008-07-09 10:03:28 UTC (rev 26337) +++ haiku/trunk/src/system/kernel/fs/rootfs.cpp 2008-07-09 10:59:02 UTC (rev 26338) @@ -588,7 +588,7 @@ static status_t -rootfs_read(fs_volume *_volume, fs_vnode *_vnode, void *_cookie, +rootfs_read(fs_volume *_volume, fs_vnode *_vnode, void *_cookie, off_t pos, void *buffer, size_t *_length) { return EINVAL; @@ -596,10 +596,10 @@ static status_t -rootfs_write(fs_volume *_volume, fs_vnode *vnode, void *cookie, +rootfs_write(fs_volume *_volume, fs_vnode *vnode, void *cookie, off_t pos, const void *buffer, size_t *_length) { - TRACE(("rootfs_write: vnode %p, cookie %p, pos 0x%Lx , len 0x%lx\n", + TRACE(("rootfs_write: vnode %p, cookie %p, pos 0x%Lx , len 0x%lx\n", vnode, cookie, pos, *_length)); return EPERM; @@ -638,7 +638,7 @@ notify_entry_created(fs->id, dir->id, name, vnode->id); - mutex_unlock(&fs->lock); + mutex_unlock(&fs->lock); return B_OK; err: @@ -767,6 +767,7 @@ cookie->current = nextChildNode; cookie->state = nextState; + *_num = 1; status = B_OK; err: @@ -971,7 +972,7 @@ rootfs_remove_from_dir(fs, fromDirectory, vnode); // Add it back to the dir with the new name. - // We need to do this even in the same directory, + // We need to do this even in the same directory, // so that it keeps sorted correctly. rootfs_insert_in_dir(fs, toDirectory, vnode); @@ -1044,7 +1045,7 @@ if (statMask & B_STAT_MODIFICATION_TIME) vnode->modification_time = stat->st_mtime; - if (statMask & B_STAT_CREATION_TIME) + if (statMask & B_STAT_CREATION_TIME) vnode->creation_time = stat->st_crtime; mutex_unlock(&fs->lock); From revol at free.fr Wed Jul 9 13:04:49 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 09 Jul 2008 13:04:49 +0200 CEST Subject: [Haiku-commits] r26336 - haiku/trunk/src/system/kernel In-Reply-To: Message-ID: <2374432211-BeMail@laptop> > On Tue, Jul 8, 2008 at 10:58 PM, bonefish at BerliOS > wrote: > > Author: bonefish > > Date: 2008-07-09 05:58:38 +0200 (Wed, 09 Jul 2008) > > New Revision: 26336 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26336&view=rev > > > > Modified: > > haiku/trunk/src/system/kernel/team.cpp > > Log: > > * Fixed serious memory leak in team_create_thread_start(). The > > destructor of the automatic KPath variable was never invoked, > > since > > normally arch_thread_enter_userspace() would not return and thus > > the > > function scope never be left. After a standard "jam @image" almost > > 42 MB of kernel heap were lost this way. > > * Added a few warning comments in functions that shouldn't use > > automatic > > variables with a destructor in the function scope either. > > > > Nice catch! Sleep is for the weak I see :) > Eh, when I say C++ in kernel is dangerous :D Fran?ois. From stefano.ceccherini at gmail.com Wed Jul 9 13:08:25 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Wed, 9 Jul 2008 13:08:25 +0200 Subject: [Haiku-commits] r26336 - haiku/trunk/src/system/kernel In-Reply-To: <2374432211-BeMail@laptop> References: <2374432211-BeMail@laptop> Message-ID: <894b9700807090408o75443386n4569f49cd92b9ff2@mail.gmail.com> 2008/7/9 Fran?ois Revol : > Eh, when I say C++ in kernel is dangerous :D I was going to post something similar :) From axeld at mail.berlios.de Wed Jul 9 13:16:07 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 Jul 2008 13:16:07 +0200 Subject: [Haiku-commits] r26339 - in haiku/trunk: headers/posix headers/private/libroot src/system/libroot/os src/system/libroot/posix Message-ID: <200807091116.m69BG7gU031404@sheep.berlios.de> Author: axeld Date: 2008-07-09 13:16:00 +0200 (Wed, 09 Jul 2008) New Revision: 26339 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26339&view=rev Added: haiku/trunk/headers/private/libroot/dirent_private.h Modified: haiku/trunk/headers/posix/dirent.h haiku/trunk/src/system/libroot/os/fs_attr.c haiku/trunk/src/system/libroot/os/fs_index.c haiku/trunk/src/system/libroot/os/fs_query.cpp haiku/trunk/src/system/libroot/posix/dirent.c Log: * Made DIR definition private, and moved it into the new dirent_private.h header. * Added fields necessary to make it possible to retrieve more than one dirent from the underlying file system. * Unless some app creates a DIR on its own to it to feed readdir(), this change should be binary compatible. If we find an application misbehaving, we can still make it a GCC4 only thing. * fs_attr/fs_index/fs_query now all use readdir() directly (as that one contains the logic to iterate through a number of dirents in userspace). Modified: haiku/trunk/headers/posix/dirent.h =================================================================== --- haiku/trunk/headers/posix/dirent.h 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/headers/posix/dirent.h 2008-07-09 11:16:00 UTC (rev 26339) @@ -1,6 +1,7 @@ -/* -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _DIRENT_H #define _DIRENT_H @@ -17,10 +18,7 @@ char d_name[1]; /* name of the entry (null byte terminated) */ } dirent_t; -typedef struct { - int fd; - struct dirent ent; -} DIR; +typedef struct __DIR DIR; #ifndef MAXNAMLEN # ifdef NAME_MAX Added: haiku/trunk/headers/private/libroot/dirent_private.h =================================================================== --- haiku/trunk/headers/private/libroot/dirent_private.h 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/headers/private/libroot/dirent_private.h 2008-07-09 11:16:00 UTC (rev 26339) @@ -0,0 +1,22 @@ +/* + * Copyright 2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef DIRENT_PRIVATE_H +#define DIRENT_PRIVATE_H + + +#include + + +#define DIR_BUFFER_SIZE 4096 +#define DIRENT_BUFFER_SIZE (DIR_BUFFER_SIZE - 2 * sizeof(int)) + +struct __DIR { + int fd; + short next_entry; + unsigned short entries_left; + struct dirent first_entry; +}; + +#endif /* DIRENT_PRIVATE_H */ Modified: haiku/trunk/src/system/libroot/os/fs_attr.c =================================================================== --- haiku/trunk/src/system/libroot/os/fs_attr.c 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/src/system/libroot/os/fs_attr.c 2008-07-09 11:16:00 UTC (rev 26339) @@ -1,5 +1,5 @@ -/* - * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. +/* + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -10,10 +10,12 @@ #include #include +#include "dirent_private.h" #include "syscalls.h" -// ToDo: think about adding special syscalls for the read/write/stat functions to speed them up +// TODO: think about adding special syscalls for the read/write/stat functions +// to speed them up #define RETURN_AND_SET_ERRNO(status) \ { \ @@ -24,11 +26,8 @@ return status; \ } -// for the DIR structure -#define BUFFER_SIZE 2048 - -ssize_t +ssize_t fs_read_attr(int fd, const char *attribute, uint32 type, off_t pos, void *buffer, size_t readBytes) { @@ -48,7 +47,7 @@ } -ssize_t +ssize_t fs_write_attr(int fd, const char *attribute, uint32 type, off_t pos, const void *buffer, size_t writeBytes) { @@ -65,7 +64,7 @@ } -int +int fs_remove_attr(int fd, const char *attribute) { status_t status = _kern_remove_attr(fd, attribute); @@ -74,7 +73,7 @@ } -int +int fs_stat_attr(int fd, const char *attribute, struct attr_info *attrInfo) { struct stat stat; @@ -96,17 +95,17 @@ /* -int +int fs_open_attr(const char *path, const char *attribute, uint32 type, int openMode) { - // ToDo: implement fs_open_attr() - or remove it completely + // TODO: implement fs_open_attr() - or remove it completely // if it will be implemented, rename the current fs_open_attr() to fs_fopen_attr() return B_ERROR; } */ -int +int fs_open_attr(int fd, const char *attribute, uint32 type, int openMode) { status_t status; @@ -120,7 +119,7 @@ } -int +int fs_close_attr(int fd) { status_t status = _kern_close(fd); @@ -141,13 +140,14 @@ } /* allocate the memory for the DIR structure */ - if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) { + if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) { errno = B_NO_MEMORY; _kern_close(fd); return NULL; } dir->fd = fd; + dir->entries_left = 0; return dir; } @@ -167,7 +167,7 @@ } -int +int fs_close_attr_dir(DIR *dir) { int status = _kern_close(dir->fd); @@ -181,22 +181,13 @@ struct dirent * fs_read_attr_dir(DIR *dir) { - ssize_t count = _kern_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1); - if (count <= 0) { - if (count < 0) - errno = count; - return NULL; - } - - return &dir->ent; + return readdir(dir); } -void +void fs_rewind_attr_dir(DIR *dir) { - int status = _kern_rewind_dir(dir->fd); - if (status < 0) - errno = status; + rewinddir(dir); } Modified: haiku/trunk/src/system/libroot/os/fs_index.c =================================================================== --- haiku/trunk/src/system/libroot/os/fs_index.c 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/src/system/libroot/os/fs_index.c 2008-07-09 11:16:00 UTC (rev 26339) @@ -1,7 +1,7 @@ -/* -** Copyright 2002, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. -*/ +/* + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ #include @@ -10,7 +10,8 @@ #include #include -#include "syscalls.h" +#include +#include #define RETURN_AND_SET_ERRNO(status) \ @@ -22,10 +23,7 @@ return status; \ } -// for the DIR structure -#define BUFFER_SIZE 2048 - int fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags) { @@ -35,7 +33,7 @@ } -int +int fs_remove_index(dev_t device, const char *name) { status_t status = _kern_remove_index(device, name); @@ -44,7 +42,7 @@ } -int +int fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo) { struct stat stat; @@ -75,19 +73,20 @@ } /* allocate the memory for the DIR structure */ - if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) { + if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) { errno = B_NO_MEMORY; _kern_close(fd); return NULL; } dir->fd = fd; + dir->entries_left = 0; return dir; } -int +int fs_close_index_dir(DIR *dir) { int status = _kern_close(dir->fd); @@ -101,22 +100,13 @@ struct dirent * fs_read_index_dir(DIR *dir) { - ssize_t count = _kern_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1); - if (count <= 0) { - if (count < 0) - errno = count; - return NULL; - } - - return &dir->ent; + return readdir(dir); } -void +void fs_rewind_index_dir(DIR *dir) { - int status = _kern_rewind_dir(dir->fd); - if (status < 0) - errno = status; + rewinddir(dir); } Modified: haiku/trunk/src/system/libroot/os/fs_query.cpp =================================================================== --- haiku/trunk/src/system/libroot/os/fs_query.cpp 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/src/system/libroot/os/fs_query.cpp 2008-07-09 11:16:00 UTC (rev 26339) @@ -1,5 +1,5 @@ -/* - * Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. +/* + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -11,13 +11,10 @@ #include #include -#include "syscalls.h" +#include +#include -// for the DIR structure -#define BUFFER_SIZE 2048 - - static DIR * open_query_etc(dev_t device, const char *query, uint32 flags, port_id port, int32 token) @@ -35,13 +32,16 @@ } // allocate a DIR - DIR *dir = (DIR *)malloc(BUFFER_SIZE); + DIR *dir = (DIR *)malloc(DIR_BUFFER_SIZE); if (!dir) { _kern_close(fd); errno = B_NO_MEMORY; return NULL; } + dir->fd = fd; + dir->entries_left = 0; + return dir; } @@ -84,24 +84,7 @@ struct dirent * fs_read_query(DIR *dir) { - // check parameters - if (dir == NULL) { - errno = B_BAD_VALUE; - return NULL; - } - - // read - int32 bufferSize = BUFFER_SIZE - ((uint8 *)&dir->ent - (uint8 *)dir); - ssize_t result = _kern_read_dir(dir->fd, &dir->ent, bufferSize, 1); - if (result < 0) { - errno = result; - return NULL; - } - if (result == 0) { - errno = B_ENTRY_NOT_FOUND; - return NULL; - } - return &dir->ent; + return readdir(dir); } Modified: haiku/trunk/src/system/libroot/posix/dirent.c =================================================================== --- haiku/trunk/src/system/libroot/posix/dirent.c 2008-07-09 10:59:02 UTC (rev 26338) +++ haiku/trunk/src/system/libroot/posix/dirent.c 2008-07-09 11:16:00 UTC (rev 26339) @@ -1,19 +1,18 @@ -/* -** Copyright 2004, Axel D?rfler, axeld at pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2004-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ -#include - #include #include +#include #include +#include +#include -#define BUFFER_SIZE 4096 - #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ errno = err; \ @@ -34,13 +33,14 @@ } /* allocate the memory for the DIR structure */ - if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) { + if ((dir = (DIR *)malloc(DIR_BUFFER_SIZE)) == NULL) { errno = B_NO_MEMORY; _kern_close(fd); return NULL; } dir->fd = fd; + dir->entries_left = 0; return dir; } @@ -60,26 +60,42 @@ struct dirent * readdir(DIR *dir) { - /* get the next entry and return a pointer to a dirent structure - * containing the data - */ - - ssize_t count = _kern_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1); + ssize_t count; + + if (dir->entries_left > 0) { + struct dirent *dirent + = (struct dirent *)((uint8 *)&dir->first_entry + dir->next_entry); + + dir->entries_left--; + dir->next_entry += dirent->d_reclen; + + return dirent; + } + + // we need to retrieve new entries + + count = _kern_read_dir(dir->fd, &dir->first_entry, DIRENT_BUFFER_SIZE, + USHRT_MAX); if (count <= 0) { if (count < 0) errno = count; + // end of directory return NULL; } - - return &dir->ent; + + dir->entries_left = count - 1; + dir->next_entry = dir->first_entry.d_reclen; + + return &dir->first_entry; } int readdir_r(DIR *dir, struct dirent *entry, struct dirent **_result) { - ssize_t count = _kern_read_dir(dir->fd, entry, sizeof(struct dirent) + B_FILE_NAME_LENGTH, 1); + ssize_t count = _kern_read_dir(dir->fd, entry, sizeof(struct dirent) + + B_FILE_NAME_LENGTH, 1); if (count < B_OK) return count; @@ -99,15 +115,17 @@ status_t status = _kern_rewind_dir(dir->fd); if (status < 0) errno = status; + else + dir->entries_left = 0; } -/** This is no POSIX compatible call; it's not exported in the headers - * but here for BeOS compatiblity. +#ifndef _KERNEL_MODE + +/* This is no POSIX compatible call; it's not exported in the headers + * but here for BeOS compatiblity. */ -// ToDo: disable this for the kernel build! (will be possible once we use Kernel build rules for the kernel only) - int dirfd(DIR *dir); int @@ -115,3 +133,5 @@ { return dir->fd; } + +#endif // !_KERNEL_MODE From revol at free.fr Wed Jul 9 13:20:49 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Wed, 09 Jul 2008 13:20:49 +0200 CEST Subject: [Haiku-commits] =?windows-1252?q?r26339_-_in_haiku/trunk=3A_heade?= =?windows-1252?q?rs/posix_headers/private/libroot_src/system/libroot/os_s?= =?windows-1252?q?rc/system/libroot/posix?= In-Reply-To: <200807091116.m69BG7gU031404@sheep.berlios.de> Message-ID: <3334047022-BeMail@laptop> > * Made DIR definition private, and moved it into the new > dirent_private.h > header. Hmm there is at least one app that spoons the DIR field to use the fd. QEMU maybe, not sure... Fran?ois. From axeld at pinc-software.de Wed Jul 9 13:28:55 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 09 Jul 2008 13:28:55 +0200 CEST Subject: [Haiku-commits] r26339 - in haiku/trunk: headers/posix headers/private/libroot src/system/libroot/os src/system/libroot/posix In-Reply-To: <3334047022-BeMail@laptop> Message-ID: <15350680370-BeMail@zon> "Fran?ois Revol" wrote: > > * Made DIR definition private, and moved it into the new > > dirent_private.h header. > Hmm there is at least one app that spoons the DIR field to use the > fd. > QEMU maybe, not sure... With the exception that they don't compile anymore without changes, the location of the "fd" has not changed. Also, there is a dirfd() function on BeOS that you can and should use instead. Bye, Axel. From axeld at mail.berlios.de Wed Jul 9 15:04:54 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 Jul 2008 15:04:54 +0200 Subject: [Haiku-commits] r26340 - in haiku/trunk: headers/private/kernel/fs src/system/kernel/fs Message-ID: <200807091304.m69D4sT0017961@sheep.berlios.de> Author: axeld Date: 2008-07-09 15:04:54 +0200 (Wed, 09 Jul 2008) New Revision: 26340 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26340&view=rev Modified: haiku/trunk/headers/private/kernel/fs/node_monitor.h haiku/trunk/src/system/kernel/fs/node_monitor.cpp Log: * {add|remove}_node_listener() erroneously had "dev_t" as type of "node". Modified: haiku/trunk/headers/private/kernel/fs/node_monitor.h =================================================================== --- haiku/trunk/headers/private/kernel/fs/node_monitor.h 2008-07-09 11:16:00 UTC (rev 26339) +++ haiku/trunk/headers/private/kernel/fs/node_monitor.h 2008-07-09 13:04:54 UTC (rev 26340) @@ -17,9 +17,9 @@ class NotificationListener; -extern status_t remove_node_listener(dev_t device, dev_t node, +extern status_t remove_node_listener(dev_t device, ino_t node, NotificationListener& listener); -extern status_t add_node_listener(dev_t device, dev_t node, uint32 flags, +extern status_t add_node_listener(dev_t device, ino_t node, uint32 flags, NotificationListener& listener); extern "C" { Modified: haiku/trunk/src/system/kernel/fs/node_monitor.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/node_monitor.cpp 2008-07-09 11:16:00 UTC (rev 26339) +++ haiku/trunk/src/system/kernel/fs/node_monitor.cpp 2008-07-09 13:04:54 UTC (rev 26340) @@ -264,7 +264,7 @@ { node_monitor *monitor = listener->monitor; - // remove it from the listener and I/O context lists + // remove it from the listener and I/O context lists monitor->listeners.Remove(listener); list_remove_link(listener); @@ -317,7 +317,7 @@ if (monitor == NULL) return B_NO_MEMORY; - // initialize monitor + // initialize monitor monitor->device = device; monitor->node = node; @@ -477,7 +477,7 @@ \param message The message to be sent. \param interestedListeners An array of listener lists. \param interestedListenerCount The number of elements in the - \a interestedListeners array. + \a interestedListeners array. \return - \c B_OK, if everything went fine, - another error code otherwise. @@ -950,7 +950,7 @@ status_t -remove_node_listener(dev_t device, dev_t node, NotificationListener& listener) +remove_node_listener(dev_t device, ino_t node, NotificationListener& listener) { return sNodeMonitorService.RemoveListener(get_current_io_context(true), device, node, listener); @@ -958,7 +958,7 @@ status_t -add_node_listener(dev_t device, dev_t node, uint32 flags, +add_node_listener(dev_t device, ino_t node, uint32 flags, NotificationListener& listener) { return sNodeMonitorService.AddListener(get_current_io_context(true), From stippi at mail.berlios.de Wed Jul 9 16:13:09 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 9 Jul 2008 16:13:09 +0200 Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807091413.m69ED9QU028649@sheep.berlios.de> Author: stippi Date: 2008-07-09 16:13:03 +0200 (Wed, 09 Jul 2008) New Revision: 26341 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26341&view=rev Modified: haiku/trunk/headers/os/interface/View.h haiku/trunk/src/kits/interface/View.cpp haiku/trunk/src/kits/interface/Window.cpp Log: * Introduced a new view event mask flag: B_FULL_POINTER_HISTORY which, when set, prevents any old mouse moved message discarding. * BWindow::DispatchMessage(B_MOUSE_MOVED) checks the event time of the message and discards too old events, but only if there is another event in the queue and the view does not specify B_FULL_POINTER_HISTORY. * BView::GetMouse() ignores the checkHistory flag passed to the function in case the event mask specifies B_NO_POINTER_HISTORY. B_FULL_POINTER_HISTORY on the other hand prevents the dropping of old messages. Modified: haiku/trunk/headers/os/interface/View.h =================================================================== --- haiku/trunk/headers/os/interface/View.h 2008-07-09 13:04:54 UTC (rev 26340) +++ haiku/trunk/headers/os/interface/View.h 2008-07-09 14:13:03 UTC (rev 26341) @@ -43,7 +43,11 @@ enum { B_LOCK_WINDOW_FOCUS = 0x00000001, B_SUSPEND_VIEW_FOCUS = 0x00000002, - B_NO_POINTER_HISTORY = 0x00000004 + B_NO_POINTER_HISTORY = 0x00000004, + // new in Haiku (unless this flag is + // specified, both BWindow and BView::GetMouse() + // will filter out older mouse moved messages) + B_FULL_POINTER_HISTORY = 0x00000008 }; enum { Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-09 13:04:54 UTC (rev 26340) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-09 14:13:03 UTC (rev 26341) @@ -1393,7 +1393,11 @@ { _CheckOwnerLockAndSwitchCurrent(); - if (checkMessageQueue) { + uint32 eventOptions = fEventOptions | fMouseEventOptions; + bool noHistory = eventOptions & B_NO_POINTER_HISTORY; + bool fullHistory = eventOptions & B_FULL_POINTER_HISTORY; + + if (checkMessageQueue && !noHistory) { Window()->UpdateIfNeeded(); BMessageQueue *queue = Window()->MessageQueue(); queue->Lock(); @@ -1410,7 +1414,7 @@ if (!Window()->_StealMouseMessage(message, deleteMessage)) continue; - if (message->what == B_MOUSE_MOVED) { + if (!fullHistory && message->what == B_MOUSE_MOVED) { // Check if the message is too old. Some applications // check the message queue in such a way that mouse // messages *must* pile up. This check makes them work Modified: haiku/trunk/src/kits/interface/Window.cpp =================================================================== --- haiku/trunk/src/kits/interface/Window.cpp 2008-07-09 13:04:54 UTC (rev 26340) +++ haiku/trunk/src/kits/interface/Window.cpp 2008-07-09 14:13:03 UTC (rev 26341) @@ -1092,8 +1092,20 @@ case B_MOUSE_MOVED: { if (BView *view = dynamic_cast(target)) { - if (((view->fEventOptions | view->fMouseEventOptions) - & B_NO_POINTER_HISTORY) != 0) { + + uint32 eventOptions = view->fEventOptions + | view->fMouseEventOptions; + bool noHistory = eventOptions & B_NO_POINTER_HISTORY; + bool fullHistory = eventOptions & B_FULL_POINTER_HISTORY; + + bigtime_t eventTime; + if (noHistory + || msg->FindInt64("when", (int64*)&eventTime) < B_OK) { + eventTime = system_time(); + } + + if (noHistory || (!fullHistory + && (system_time() - eventTime > 20000))) { // filter out older mouse moved messages in the queue _DequeueAll(); BMessageQueue *queue = MessageQueue(); @@ -1102,6 +1114,9 @@ BMessage *moved; for (int32 i = 0; (moved = queue->FindMessage(i)) != NULL; i++) { if (moved != msg && moved->what == B_MOUSE_MOVED) { + // there is a newer mouse moved message in the + // queue, just ignore the current one, the newer one + // will be handled here eventually queue->Unlock(); return; } @@ -1116,14 +1131,6 @@ msg->FindInt32("buttons", (int32*)&buttons); msg->FindInt32("be:transit", (int32*)&transit); -#if 0 - bigtime_t when; - if (msg->FindInt64("when", (int64*)&when) < B_OK) - printf("BWindow B_MOUSE_MOVED no when\n"); - else if (system_time() - when > 5000) - printf("BWindow B_MOUSE_MOVED lagging behind\n"); -#endif - BMessage* dragMessage = NULL; if (msg->HasMessage("be:drag_message")) { dragMessage = new BMessage(); From axeld at mail.berlios.de Wed Jul 9 16:23:30 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 Jul 2008 16:23:30 +0200 Subject: [Haiku-commits] r26342 - haiku/trunk/src/system/kernel Message-ID: <200807091423.m69ENUhn029649@sheep.berlios.de> Author: axeld Date: 2008-07-09 16:23:29 +0200 (Wed, 09 Jul 2008) New Revision: 26342 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26342&view=rev Modified: haiku/trunk/src/system/kernel/module.cpp Log: Work-in-progress of the module notification implementation: * Most things are working, it just doesn't notify the listeners on changes yet. Modified: haiku/trunk/src/system/kernel/module.cpp =================================================================== --- haiku/trunk/src/system/kernel/module.cpp 2008-07-09 14:13:03 UTC (rev 26341) +++ haiku/trunk/src/system/kernel/module.cpp 2008-07-09 14:23:29 UTC (rev 26342) @@ -19,15 +19,20 @@ #include #include +#include + #include #include #include #include +#include #include #include #include +#include #include #include +#include #include @@ -138,13 +143,68 @@ namespace Module { -struct module_listener : DoublyLinkedListLink { +struct entry { + dev_t device; + ino_t node; +}; + +struct hash_entry : entry { + HashTableLink link; +}; + +struct NodeHashDefinition { + typedef entry* KeyType; + typedef hash_entry ValueType; + + size_t Hash(ValueType* entry) const + { return HashKey(entry); } + HashTableLink* GetLink(ValueType* entry) const + { return &entry->link; } + + size_t HashKey(KeyType key) const + { + return ((uint32)(key->node >> 32) + (uint32)key->node) ^ key->device; + } + + bool Compare(KeyType key, ValueType* entry) const + { + return key->device == entry->device + && key->node == entry->node; + } +}; + +typedef OpenHashTable NodeHash; + +struct module_listener : DoublyLinkedListLinkImpl { + ~module_listener() + { + free((char*)prefix); + } + NotificationListener* listener; const char* prefix; }; typedef DoublyLinkedList ModuleListenerList; +class DirectoryWatcher : public NotificationListener { +public: + DirectoryWatcher(); + virtual ~DirectoryWatcher(); + + virtual void EventOccured(NotificationService& service, + const KMessage* event); +}; + +class ModuleWatcher : public NotificationListener { +public: + ModuleWatcher(); + virtual ~ModuleWatcher(); + + virtual void EventOccured(NotificationService& service, + const KMessage* event); +}; + class ModuleNotificationService : public NotificationService { public: ModuleNotificationService(); @@ -159,31 +219,29 @@ status_t RemoveListener(const KMessage* eventSpecifier, NotificationListener& listener); + bool HasNode(dev_t device, ino_t node); + virtual const char* Name() { return "modules"; } private: + status_t _AddNode(dev_t device, ino_t node, uint32 flags, + NotificationListener& listener); + status_t _AddDirectoryNode(dev_t device, ino_t node); + status_t _AddModuleNode(dev_t device, ino_t node); + + status_t _AddDirectory(const char* prefix); + status_t _ScanDirectory(char* directoryPath, const char* prefix, + size_t& prefixPosition); + status_t _ScanDirectory(Stack& stack, DIR* dir, + const char* prefix, size_t prefixPosition); + recursive_lock fLock; ModuleListenerList fListeners; + NodeHash fNodes; + DirectoryWatcher fDirectoryWatcher; + ModuleWatcher fModuleWatcher; }; -class DirectoryWatcher : public NotificationListener { -public: - DirectoryWatcher(); - virtual ~DirectoryWatcher(); - - virtual void EventOccured(NotificationService& service, - const KMessage* event); -}; - -class ModuleWatcher : public NotificationListener { -public: - ModuleWatcher(); - virtual ~ModuleWatcher(); - - virtual void EventOccured(NotificationService& service, - const KMessage* event); -}; - } // namespace Module using namespace Module; @@ -926,7 +984,7 @@ while (*iterator->current_header != NULL) { module_info* info = *iterator->current_header; - // TODO: we mightS want to create a module here and cache it in the + // TODO: we might want to create a module here and cache it in the // hash table iterator->current_header++; @@ -1124,8 +1182,14 @@ if (opcode == B_ENTRY_MOVED) { // Determine wether it's a move within, out of, or into one // of our watched directories. - ino_t from = event->GetInt64("from directory", -1); - ino_t to = event->GetInt64("to directory", -1); + directory = event->GetInt64("to directory", -1); + if (!sModuleNotificationService.HasNode(device, directory)) { + directory = event->GetInt64("from directory", -1); + opcode = B_ENTRY_REMOVED; + } else { + // Move within, doesn't sound like a good idea for modules + opcode = B_ENTRY_CREATED; + } } KPath path(B_PATH_NAME_LENGTH + 1); @@ -1137,6 +1201,7 @@ dprintf("module \"%s\" %s\n", path.Leaf(), opcode == B_ENTRY_CREATED ? "added" : "removed"); + //sModuleNotificationService.Notify(path.Path(), opcode); } @@ -1181,7 +1246,30 @@ ModuleNotificationService::AddListener(const KMessage* eventSpecifier, NotificationListener& listener) { - return B_ERROR; + const char* prefix = eventSpecifier->GetString("prefix", NULL); + if (prefix == NULL) + return B_BAD_VALUE; + + module_listener* moduleListener = new(std::nothrow) module_listener; + if (moduleListener == NULL) + return B_NO_MEMORY; + + moduleListener->prefix = strdup(prefix); + if (moduleListener->prefix == NULL) { + delete moduleListener; + return B_NO_MEMORY; + } + + status_t status = _AddDirectory(prefix); + if (status != B_OK) { + delete moduleListener; + return status; + } + + moduleListener->listener = &listener; + fListeners.Add(moduleListener); + + return B_OK; } @@ -1201,6 +1289,205 @@ } +bool +ModuleNotificationService::HasNode(dev_t device, ino_t node) +{ + RecursiveLocker _(fLock); + + struct entry entry = {device, node}; + return fNodes.Lookup(&entry) != NULL; +} + + +status_t +ModuleNotificationService::_AddNode(dev_t device, ino_t node, uint32 flags, + NotificationListener& listener) +{ + RecursiveLocker locker(fLock); + + if (HasNode(device, node)) + return B_OK; + + struct hash_entry* entry = new(std::nothrow) hash_entry; + if (entry == NULL) + return B_NO_MEMORY; + + status_t status = add_node_listener(device, node, flags, listener); + if (status != B_OK) { + delete entry; + return status; + } + + //dprintf(" add %s %ld:%Ld\n", flags == B_WATCH_DIRECTORY ? "dir" : "file", device, node); + + entry->device = device; + entry->node = node; + fNodes.Insert(entry); + + return B_OK; +} + + +status_t +ModuleNotificationService::_AddDirectoryNode(dev_t device, ino_t node) +{ + return _AddNode(device, node, B_WATCH_DIRECTORY, fDirectoryWatcher); +} + + +status_t +ModuleNotificationService::_AddModuleNode(dev_t device, ino_t node) +{ + return _AddNode(device, node, B_WATCH_STAT, fModuleWatcher); +} + + +status_t +ModuleNotificationService::_AddDirectory(const char* prefix) +{ + for (uint32 i = 0; i < kNumModulePaths; i++) { + if (sDisableUserAddOns && i >= kFirstNonSystemModulePath) + break; + + KPath pathBuffer; + if (find_directory(kModulePaths[i], gBootDevice, true, + pathBuffer.LockBuffer(), pathBuffer.BufferSize()) != B_OK) + continue; + + pathBuffer.UnlockBuffer(); + pathBuffer.Append("kernel"); + pathBuffer.Append(prefix); + + size_t prefixPosition = strlen(prefix); + status_t status = _ScanDirectory(pathBuffer.LockBuffer(), prefix, + prefixPosition); + + pathBuffer.UnlockBuffer(); + + if (status != B_OK) + return status; + } + + return B_OK; +} + + +status_t +ModuleNotificationService::_ScanDirectory(char* directoryPath, + const char* prefix, size_t& prefixPosition) +{ + DIR* dir = NULL; + while (true) { + dir = opendir(directoryPath); + if (dir != NULL || prefixPosition == 0) + break; + + // the full prefix is not accessible, remove path components + const char* parentPrefix = prefix + prefixPosition - 1; + while (parentPrefix != prefix && parentPrefix[0] != '/') + parentPrefix--; + + size_t cutPosition = parentPrefix - prefix; + size_t length = strlen(directoryPath); + directoryPath[length - prefixPosition + cutPosition] = '\0'; + prefixPosition = cutPosition; + } + + if (dir == NULL) + return B_ERROR; + + Stack stack; + stack.Push(dir); + + while (stack.Pop(&dir)) { + status_t status = _ScanDirectory(stack, dir, prefix, prefixPosition); + if (status != B_OK) + return status; + } + + return B_OK; +} + + +status_t +ModuleNotificationService::_ScanDirectory(Stack& stack, DIR* dir, + const char* prefix, size_t prefixPosition) +{ + bool directMatchAdded = false; + struct dirent* dirent; + + while ((dirent = readdir(dir)) != NULL) { + if (dirent->d_name[0] == '.') + continue; + + bool directMatch = false; + + if (prefix[prefixPosition] != '\0') { + // the start must match + const char* startPrefix = prefix + prefixPosition; + if (startPrefix[0] == '/') + startPrefix++; + + const char* endPrefix = strchr(startPrefix, '/'); + size_t length; + + if (endPrefix != NULL) + length = endPrefix - startPrefix; + else + length = strlen(startPrefix); + + if (strncmp(dirent->d_name, startPrefix, length)) + continue; + + if (dirent->d_name[length] == '\0') + directMatch = true; + } + + struct stat stat; + status_t status = vfs_read_stat(dir->fd, dirent->d_name, true, &stat, + true); + if (status != B_OK) + continue; + + if (S_ISDIR(stat.st_mode)) { + int fd = _kern_open_dir(dir->fd, dirent->d_name); + if (fd < 0) + continue; + + DIR* subDir = (DIR*)malloc(DIR_BUFFER_SIZE); + if (subDir == NULL) { + close(fd); + continue; + } + + subDir->fd = fd; + subDir->entries_left = 0; + + stack.Push(subDir); + + if (_AddDirectoryNode(stat.st_dev, stat.st_ino) == B_OK + && directMatch) + directMatchAdded = true; + } else if (S_ISREG(stat.st_mode)) { + if (_AddModuleNode(stat.st_dev, stat.st_ino) == B_OK && directMatch) + directMatchAdded = true; + } + } + + if (!directMatchAdded) { + // We need to monitor this directory to see if a matching file + // is added. + struct stat stat; + status_t status = vfs_read_stat(dir->fd, NULL, true, &stat, true); + if (status == B_OK) + _AddDirectoryNode(stat.st_dev, stat.st_ino); + } + + closedir(dir); + return B_OK; +} + + // #pragma mark - Exported Kernel API (private part) From axeld at pinc-software.de Wed Jul 9 16:47:16 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 09 Jul 2008 16:47:16 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26341_-_in_haiku/trunk=3A_headers/os/i?= =?utf-8?q?nterface_src/kits/interface?= In-Reply-To: <200807091413.m69ED9QU028649@sheep.berlios.de> Message-ID: <27251194077-BeMail@zon> stippi at mail.berlios.de wrote: > Log: > * Introduced a new view event mask flag: B_FULL_POINTER_HISTORY > which, > when set, prevents any old mouse moved message discarding. > * BWindow::DispatchMessage(B_MOUSE_MOVED) checks the event time of > the > message and discards too old events, but only if there is another > event > in the queue and the view does not specify B_FULL_POINTER_HISTORY. DispatchMessage() is a bit too late (because of transit), and it ignores transit messages altogether. Those must definitely not be removed. Not sure if I like that so much in general, though. Asynchronous message passing somehow doesn't fit very well with the deletion process. Bye, Axel. From bonefish at mail.berlios.de Wed Jul 9 17:17:39 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 9 Jul 2008 17:17:39 +0200 Subject: [Haiku-commits] r26343 - haiku/trunk/src/system/kernel Message-ID: <200807091517.m69FHdnR003326@sheep.berlios.de> Author: bonefish Date: 2008-07-09 17:17:39 +0200 (Wed, 09 Jul 2008) New Revision: 26343 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26343&view=rev Modified: haiku/trunk/src/system/kernel/elf.cpp Log: insert_preloaded_image() now copies the debug symbols and string table over to the kernel heap. This allows us to simply free them in unload_elf_image(). Now we no longer leak the memory for non-preloaded images. On my T61 this amounted to more than 10 MB of kernel heap after booting. Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2008-07-09 14:23:29 UTC (rev 26342) +++ haiku/trunk/src/system/kernel/elf.cpp 2008-07-09 15:17:39 UTC (rev 26343) @@ -752,11 +752,8 @@ unregister_elf_image(image); -// TODO: We're leaking memory here. We can't just free those, since in case of -// pre-loaded images they have been allocated by the bootloader via -// kernel_args_malloc(). -// free(image->debug_symbols); -// free((void*)image->debug_string_table); + free(image->debug_symbols); + free((void*)image->debug_string_table); free(image->elf_header); free(image->name); free(image); @@ -897,10 +894,29 @@ } else sKernelImage = image; - image->debug_symbols = preloadedImage->debug_symbols; + // copy debug symbols to the kernel heap + if (preloadedImage->debug_symbols != NULL) { + int32 debugSymbolsSize = sizeof(Elf32_Sym) + * preloadedImage->num_debug_symbols; + image->debug_symbols = (Elf32_Sym*)malloc(debugSymbolsSize); + if (image->debug_symbols != NULL) { + memcpy(image->debug_symbols, preloadedImage->debug_symbols, + debugSymbolsSize); + } + } image->num_debug_symbols = preloadedImage->num_debug_symbols; - image->debug_string_table = preloadedImage->debug_string_table; + // copy debug string table to the kernel heap + if (preloadedImage->debug_string_table != NULL) { + image->debug_string_table = (char*)malloc( + preloadedImage->debug_string_table_size); + if (image->debug_string_table != NULL) { + memcpy((void*)image->debug_string_table, + preloadedImage->debug_string_table, + preloadedImage->debug_string_table_size); + } + } + register_elf_image(image); preloadedImage->id = image->id; // modules_init() uses this information to get the preloaded images From bonefish at mail.berlios.de Wed Jul 9 17:25:01 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Wed, 9 Jul 2008 17:25:01 +0200 Subject: [Haiku-commits] r26344 - in haiku/trunk: headers/private/kernel src/system/kernel Message-ID: <200807091525.m69FP1T4003992@sheep.berlios.de> Author: bonefish Date: 2008-07-09 17:25:01 +0200 (Wed, 09 Jul 2008) New Revision: 26344 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26344&view=rev Modified: haiku/trunk/headers/private/kernel/boot_splash.h haiku/trunk/src/system/kernel/boot_splash.cpp haiku/trunk/src/system/kernel/main.cpp Log: * Added an explicit boot_splash_uninit(). Not really needed, but makes it clear when boot_splash_set_stage() must no longer be used. * Free the memory associated with the kernel args before starting the init process. Unlike the original TODO stated there are quite a few more users of the kernel args (including the boot splash screen), hence we can't really do that earlier, unless we decide to copy the data over to the kernel heap. Modified: haiku/trunk/headers/private/kernel/boot_splash.h =================================================================== --- haiku/trunk/headers/private/kernel/boot_splash.h 2008-07-09 15:17:39 UTC (rev 26343) +++ haiku/trunk/headers/private/kernel/boot_splash.h 2008-07-09 15:25:01 UTC (rev 26344) @@ -29,6 +29,7 @@ #endif void boot_splash_init(uint8 * boot_splash); +void boot_splash_uninit(void); void boot_splash_set_stage(int stage); #ifdef __cplusplus Modified: haiku/trunk/src/system/kernel/boot_splash.cpp =================================================================== --- haiku/trunk/src/system/kernel/boot_splash.cpp 2008-07-09 15:17:39 UTC (rev 26343) +++ haiku/trunk/src/system/kernel/boot_splash.cpp 2008-07-09 15:25:01 UTC (rev 26344) @@ -186,6 +186,13 @@ void +boot_splash_uninit(void) +{ + sInfo = NULL; +} + + +void boot_splash_set_stage(int stage) { TRACE("boot_splash_set_stage: stage=%d\n", stage); Modified: haiku/trunk/src/system/kernel/main.cpp =================================================================== --- haiku/trunk/src/system/kernel/main.cpp 2008-07-09 15:17:39 UTC (rev 26343) +++ haiku/trunk/src/system/kernel/main.cpp 2008-07-09 15:25:01 UTC (rev 26344) @@ -245,17 +245,6 @@ boot_splash_set_stage(BOOT_SPLASH_STAGE_1_INIT_MODULES); module_init(&sKernelArgs); - // ToDo: the preloaded image debug data is placed in the kernel args, and - // thus, if they are enabled, the kernel args shouldn't be freed, so - // that we don't have to copy them. - // What is yet missing is a mechanism that controls this (via driver settings). - if (0) { - // module_init() is supposed to be the last user of the kernel args - // Note: don't confuse the kernel_args structure (which is never freed) - // with the kernel args ranges it contains (and which are freed here). - vm_free_kernel_args(&sKernelArgs); - } - // init userland debugging TRACE("Init Userland debugging\n"); init_user_debug(); @@ -297,10 +286,17 @@ device_manager_init_post_modules(&sKernelArgs); boot_splash_set_stage(BOOT_SPLASH_STAGE_7_RUN_BOOT_SCRIPT); -// kernel_args_free(sKernelArgs.boot_splash); -// NOTE: We could introduce a syscall to draw more icons indicating -// stages in the boot script itself. Then we should not free the image. + boot_splash_uninit(); + // NOTE: We could introduce a syscall to draw more icons indicating + // stages in the boot script itself. Then we should not free the image. + // In that case we should copy it over to the kernel heap, so that we + // can still free the kernel args. + // The boot splash screen is the last user of the kernel args. + // Note: don't confuse the kernel_args structure (which is never freed) + // with the kernel args ranges it contains (and which are freed here). + vm_free_kernel_args(&sKernelArgs); + // start the init process { KPath bootScriptPath; From axeld at pinc-software.de Wed Jul 9 18:05:48 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 09 Jul 2008 18:05:48 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26344_-_in_haiku/trunk=3A_headers/priv?= =?utf-8?q?ate/kernel_src/system/kernel?= In-Reply-To: <200807091525.m69FP1T4003992@sheep.berlios.de> Message-ID: <31963905773-BeMail@zon> bonefish at BerliOS wrote: > Log: > * Added an explicit boot_splash_uninit(). Not really needed, but > makes > it clear when boot_splash_set_stage() must no longer be used. > * Free the memory associated with the kernel args before starting the > init process. Unlike the original TODO stated there are quite a few > more users of the kernel args (including the boot splash screen), > hence we can't really do that earlier, unless we decide to copy the > data over to the kernel heap. That change isn't correct, though, as it renders the debug symbols invalid always. Bye, Axel. From axeld at pinc-software.de Wed Jul 9 18:07:12 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Wed, 09 Jul 2008 18:07:12 +0200 CEST Subject: [Haiku-commits] r26343 - haiku/trunk/src/system/kernel In-Reply-To: <200807091517.m69FHdnR003326@sheep.berlios.de> Message-ID: <32047452492-BeMail@zon> bonefish at BerliOS wrote: > Log: > insert_preloaded_image() now copies the debug symbols and string > table > over to the kernel heap. This allows us to simply free them in > unload_elf_image(). Now we no longer leak the memory for non- > preloaded > images. On my T61 this amounted to more than 10 MB of kernel heap > after > booting. Wow, that's quite a lot! You can obviously disregard my earlier comment to your next commit, then :-) Bye, Axel. From oruizdorantes at mail.berlios.de Wed Jul 9 19:01:46 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 9 Jul 2008 19:01:46 +0200 Subject: [Haiku-commits] r26345 - in haiku/trunk: headers/os/bluetooth/HCI src/add-ons/kernel/drivers/bluetooth/h2/h2generic src/servers/bluetooth Message-ID: <200807091701.m69H1koJ017343@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-09 19:01:30 +0200 (Wed, 09 Jul 2008) New Revision: 26345 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26345&view=rev Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI_transport.h haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h Log: -Move the launching of the Local Device to an IOCTL from the open hook to be more compatible with the net_stack -Implement Launch method in the accesors regarding previous comment -Fix KDL at removing device Modified: haiku/trunk/headers/os/bluetooth/HCI/btHCI_transport.h =================================================================== --- haiku/trunk/headers/os/bluetooth/HCI/btHCI_transport.h 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/headers/os/bluetooth/HCI/btHCI_transport.h 2008-07-09 17:01:30 UTC (rev 26345) @@ -13,11 +13,11 @@ #include #include -typedef enum { ANCILLYANT = 1, - RUNNING, - LEAVING, - SENDING, - PROCESSING +typedef enum { ANCILLYANT = (1<<0), + RUNNING = (1<<1), + LEAVING = (1<<2), + SENDING = (1<<3), + PROCESSING = (1<<4) } bt_transport_status_t; typedef uint8 bt_stat_t; @@ -84,6 +84,7 @@ enum { ISSUE_BT_COMMAND = B_DEVICE_OP_CODES_END + BT_IOCTLS_OFFSET , + BT_UP, GET_STATICS, GET_NOTIFICATION_PORT, GET_HCI_ID Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-09 17:01:30 UTC (rev 26345) @@ -429,8 +429,8 @@ } acquire_sem(bdev->lock); - // Set HCI_RUNNING - if ( TEST_AND_SET(&bdev->state, RUNNING) ) { + // Set RUNNING + if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) { flowf("dev already running! - reOpened device!\n"); return B_ERROR; } @@ -451,7 +451,7 @@ // dumping the USB frames init_room(&bdev->eventRoom); init_room(&bdev->aclRoom); - //Init_room(new_bt_dev->scoRoom); + //init_room(new_bt_dev->scoRoom); list_init(&bdev->snetBufferRecycleTrash); @@ -470,37 +470,15 @@ hdev = bdev->num; } bdev->hdev = hdev; + - // H: set the special flags - // EVENTS - err = submit_rx_event(bdev); - if (err != B_OK) - goto unrun; -#if BT_DRIVER_SUPPORTS_ACL - // ACL - for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { - err = submit_rx_acl(bdev); - if (err != B_OK && i == 0 ) - goto unrun; - } -#endif - -#if BT_DRIVER_SUPPORTS_SCO - // TODO: SCO / eSCO -#endif - *cookie = bdev; release_sem(bdev->lock); flowf(" successful\n"); return B_OK; -unrun: - CLEAR_BIT(bdev->state, RUNNING); // Set the flaq in the HCI world - flowf("Queuing failed device stops running\n"); - - return err; } @@ -617,13 +595,42 @@ snb_put(snbuf, params, size); err = submit_tx_command(bdev, snbuf); - + debugf("device launched %ld\n", err); break; + case BT_UP: + + // EVENTS + err = submit_rx_event(bdev); + if (err != B_OK) { + CLEAR_BIT(bdev->state, ANCILLYANT); + flowf("Queuing failed device stops running\n"); + break; + } + + #if BT_DRIVER_SUPPORTS_ACL // ACL + for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { + err = submit_rx_acl(bdev); + if (err != B_OK && i == 0 ) { + CLEAR_BIT(bdev->state, ANCILLYANT); // Set the flaq in the HCI world + flowf("Queuing failed device stops running\n"); + break; + } + } + #endif + + SET_BIT(bdev->state, RUNNING); + + #if BT_DRIVER_SUPPORTS_SCO + // TODO: SCO / eSCO + #endif + flowf("device launched\n"); + break; + case GET_STATICS: memcpy(params, &bdev->stat, sizeof(bt_hci_statistics)); err = B_OK; - break; + break; case GET_HCI_ID: *(hci_id*)params = bdev->hdev; Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c 2008-07-09 17:01:30 UTC (rev 26345) @@ -62,12 +62,14 @@ void nb_destroy(net_buffer* nbuf) { + if (nbuf == NULL) + return; /* Free possible allocated */ if (nbuf->COOKIEFIELD != NULL) free((void*)nbuf->COOKIEFIELD); -// TODO check for survivers... + // TODO check for survivers... if (nb != NULL) nb->free(nbuf); Modified: haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/servers/bluetooth/BluetoothServer.cpp 2008-07-09 17:01:30 UTC (rev 26345) @@ -135,6 +135,9 @@ } status = B_WOULD_BLOCK; + + /* TODO: This should be by user request only! */ + ldi->Launch(); } case BT_MSG_COUNT_LOCAL_DEVICES: Modified: haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/servers/bluetooth/HCITransportAccessor.cpp 2008-07-09 17:01:30 UTC (rev 26345) @@ -38,6 +38,7 @@ status_t HCITransportAccessor::Launch() { - return B_OK; + uint32 dummy; + return ioctl(fFD, BT_UP, &dummy, sizeof(uint32)); } Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.cpp 2008-07-09 17:01:30 UTC (rev 26345) @@ -29,7 +29,13 @@ return fHCIDelegate->GetID(); } +status_t +LocalDeviceHandler::Launch(void) +{ + return fHCIDelegate->Launch(); +} + bool LocalDeviceHandler::Available() { Modified: haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h =================================================================== --- haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h 2008-07-09 15:25:01 UTC (rev 26344) +++ haiku/trunk/src/servers/bluetooth/LocalDeviceHandler.h 2008-07-09 17:01:30 UTC (rev 26345) @@ -20,10 +20,11 @@ public: - virtual hci_id GetID(); + hci_id GetID(); - virtual bool Available(); + bool Available(); void Acquire(void); + status_t Launch(void); BMessage* GetPropertiesMessage(void) { return fProperties; } bool IsPropertyAvailable(const BString& property); From korli at mail.berlios.de Wed Jul 9 20:26:17 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 9 Jul 2008 20:26:17 +0200 Subject: [Haiku-commits] r26346 - haiku/trunk/src/preferences/print Message-ID: <200807091826.m69IQHoM012202@sheep.berlios.de> Author: korli Date: 2008-07-09 20:26:16 +0200 (Wed, 09 Jul 2008) New Revision: 26346 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26346&view=rev Modified: haiku/trunk/src/preferences/print/AddPrinterDialog.cpp Log: fix warning Modified: haiku/trunk/src/preferences/print/AddPrinterDialog.cpp =================================================================== --- haiku/trunk/src/preferences/print/AddPrinterDialog.cpp 2008-07-09 17:01:30 UTC (rev 26345) +++ haiku/trunk/src/preferences/print/AddPrinterDialog.cpp 2008-07-09 18:26:16 UTC (rev 26346) @@ -400,7 +400,6 @@ // Now get ports... BString portId, portName; - status_t err; msg.MakeEmpty(); msg.what = B_GET_PROPERTY; msg.AddSpecifier("Ports"); From axeld at mail.berlios.de Wed Jul 9 23:32:38 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Wed, 9 Jul 2008 23:32:38 +0200 Subject: [Haiku-commits] r26347 - in haiku/trunk: headers/private/kernel/util src/system/kernel/messaging Message-ID: <200807092132.m69LWckb030175@sheep.berlios.de> Author: axeld Date: 2008-07-09 23:32:37 +0200 (Wed, 09 Jul 2008) New Revision: 26347 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26347&view=rev Modified: haiku/trunk/headers/private/kernel/util/KMessage.h haiku/trunk/src/system/kernel/messaging/KMessage.cpp Log: * Made Dump() const. * Removed superfluous whitespace. Modified: haiku/trunk/headers/private/kernel/util/KMessage.h =================================================================== --- haiku/trunk/headers/private/kernel/util/KMessage.h 2008-07-09 18:26:16 UTC (rev 26346) +++ haiku/trunk/headers/private/kernel/util/KMessage.h 2008-07-09 21:32:37 UTC (rev 26347) @@ -1,4 +1,4 @@ -/* +/* * Copyright 2005-2007, Ingo Weinhold, bonefish at users.sf.net. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -135,7 +135,7 @@ status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1, port_message_info* messageInfo = NULL); - void Dump(void (*printFunc)(const char*,...)); + void Dump(void (*printFunc)(const char*,...)) const; private: friend class KMessageField; @@ -201,7 +201,7 @@ type_code TypeCode() const; bool HasFixedElementSize() const; int32 ElementSize() const; // if HasFixedElementSize() - + status_t AddElement(const void *data, int32 size = -1); status_t AddElements(const void *data, int32 count, int32 elementSize = -1); const void *ElementAt(int32 index, int32 *size = NULL) const; Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp =================================================================== --- haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-07-09 18:26:16 UTC (rev 26346) +++ haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-07-09 21:32:37 UTC (rev 26347) @@ -1,4 +1,4 @@ -/* +/* * Copyright 2005-2007, Ingo Weinhold, bonefish at users.sf.net. * All rights reserved. Distributed under the terms of the MIT License. */ @@ -601,7 +601,7 @@ void -KMessage::Dump(void (*printFunc)(const char*,...)) +KMessage::Dump(void (*printFunc)(const char*,...)) const { Header* header = _Header(); printFunc("KMessage: buffer: %p (size/capacity: %ld/%ld), flags: 0x0lx\n", @@ -946,7 +946,7 @@ KMessageField::ElementSize() const { KMessage::FieldHeader* header = _Header(); - return (header ? header->elementSize : -1); + return (header ? header->elementSize : -1); } // AddElement @@ -992,7 +992,7 @@ KMessageField::CountElements() const { KMessage::FieldHeader* header = _Header(); - return (header ? header->elementCount : 0); + return (header ? header->elementCount : 0); } // SetTo From bonefish at mail.berlios.de Thu Jul 10 00:59:46 2008 From: bonefish at mail.berlios.de (bonefish at BerliOS) Date: Thu, 10 Jul 2008 00:59:46 +0200 Subject: [Haiku-commits] r26348 - haiku/trunk/src/system/kernel/debug Message-ID: <200807092259.m69Mxk8Q008137@sheep.berlios.de> Author: bonefish Date: 2008-07-10 00:59:45 +0200 (Thu, 10 Jul 2008) New Revision: 26348 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26348&view=rev Modified: haiku/trunk/src/system/kernel/debug/blue_screen.cpp Log: Blue screen pagination: * Changed prompt and keys: Now it's 'q' to quit (abort) the debugger command and 's' to skip the following output. * Don't offer or try to quit a command in the boot debug output. * Cleanup the prompt and go to the next line also when aborting the command. Modified: haiku/trunk/src/system/kernel/debug/blue_screen.cpp =================================================================== --- haiku/trunk/src/system/kernel/debug/blue_screen.cpp 2008-07-09 21:32:37 UTC (rev 26347) +++ haiku/trunk/src/system/kernel/debug/blue_screen.cpp 2008-07-09 22:59:45 UTC (rev 26348) @@ -103,6 +103,8 @@ static void next_line(void) { + bool abortCommand = false; + #if USE_SCROLLING // TODO: scrolling is usually too slow; we could probably just remove it if (sScreen.y == sScreen.rows - 1) @@ -121,7 +123,9 @@ // Use the paging mechanism: either, we're in the debugger, and a // command is being executed, or we're currently showing boot debug // output - const char *text = "Press key to continue, Q to quit, A to abort"; + const char *text = in_command_invocation() + ? "Press key to continue, Q to quit, S to skip output" + : "Press key to continue, Q or S to skip output"; int32 length = strlen(text); if (sScreen.x + length > sScreen.columns) { // make sure we don't overwrite too much @@ -136,11 +140,10 @@ } char c = blue_screen_getchar(); - if (c == 'q') { + if (c == 's') { sScreen.ignore_output = true; - } else if (c == 'a') { - abort_debugger_command(); - // should not return + } else if (c == 'q') { + abortCommand = in_command_invocation(); sScreen.ignore_output = true; } @@ -162,6 +165,11 @@ } #endif sScreen.x = 0; + + if (abortCommand) { + abort_debugger_command(); + // should not return + } } From korli at mail.berlios.de Thu Jul 10 01:14:57 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Thu, 10 Jul 2008 01:14:57 +0200 Subject: [Haiku-commits] r26349 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200807092314.m69NEvg4025775@sheep.berlios.de> Author: korli Date: 2008-07-10 01:14:57 +0200 (Thu, 10 Jul 2008) New Revision: 26349 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26349&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h Log: reduced buffer size: with 4096, no buffer is received by the multiaudio addon Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-09 22:59:45 UTC (rev 26348) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-09 23:14:57 UTC (rev 26349) @@ -41,8 +41,7 @@ #define MAX_INPUTS 32 #define MAX_IO_WIDGETS 8 -/* FIXME: Find out why we need so much! */ -#define DEFAULT_FRAMES_PER_BUFFER 4096 +#define DEFAULT_FRAMES_PER_BUFFER 512 #define STREAM_MAX_BUFFERS 10 #define STREAM_MIN_BUFFERS 2 From marcusoverhagen at arcor.de Thu Jul 10 01:16:23 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Thu, 10 Jul 2008 01:16:23 +0200 Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <200807091413.m69ED9QU028649@sheep.berlios.de> References: <200807091413.m69ED9QU028649@sheep.berlios.de> Message-ID: <487546C7.9000106@arcor.de> stippi at mail.berlios.de schrieb: > * Introduced a new view event mask flag: B_FULL_POINTER_HISTORY which, > when set, prevents any old mouse moved message discarding. > * BWindow::DispatchMessage(B_MOUSE_MOVED) checks the event time of the > message and discards too old events, but only if there is another event > in the queue and the view does not specify B_FULL_POINTER_HISTORY. > * BView::GetMouse() ignores the checkHistory flag passed to the function > in case the event mask specifies B_NO_POINTER_HISTORY. > B_FULL_POINTER_HISTORY on the other hand prevents the dropping of old > messages. Hi Stephan, its nice that you started working on the slow mouse issues, but I really don't think your current solution is good. I think we don't need a B_FULL_POINTER_HISTORY flag. The default mouse sampling rate is 100 samples per second for PS/2, 40 samples per second for serial, and 125 for USB. Those can be increased by the drivers, up to 200 for ps2 and 1000 for USB. I don't know what haiku currently is using, we should check this, but calling BView::MouseMoved at that rate certainly shouldn't be a problem. Additionally as Axel already said, your change ignores transitions. I think that transitions were completely broken even before your changes, I couldn't find out where "be:transit" in the message is ever populated. The BeBook BView::MouseMoved describes that the entered view and exit view both get a MouseMoved event, this doesn't seem to be implemented, too. BView::GetMouse() with checkQueue = false is supposed to return the current position and button state, how do we do it, can we bypass the queue and directly get the state from input_server (shared memory?) The BeBook says: > If checkQueue is true, and the view's parent window has pending > update events, GetMouse() causes those update events to be processed. Is this probably our problem? do we need to process any further drawing(?) events each time GetMouse is called? Or another idea: if the problems occur usually inside MouseDown, MouseUp or MouseMoved. perhaps we should stop inserting events in the queue while these Hooks are active (waiting with a small timeout, perhaps 5ms) and drop those mouse events, except if its a view enter/leave transition. regards Marcus From bonefish at mail.berlios.de Thu Jul 10 04:45:47 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 04:45:47 +0200 Subject: [Haiku-commits] r26350 - haiku/branches/developer/bonefish/vm/headers/private/kernel/util Message-ID: <200807100245.m6A2jlYL019305@sheep.berlios.de> Author: bonefish Date: 2008-07-10 04:45:44 +0200 (Thu, 10 Jul 2008) New Revision: 26350 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26350&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/util/DoublyLinkedList.h Log: Reimplemented Swap(). It was broken for adjacent elements. Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/util/DoublyLinkedList.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/util/DoublyLinkedList.h 2008-07-09 23:14:57 UTC (rev 26349) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/util/DoublyLinkedList.h 2008-07-10 02:45:44 UTC (rev 26350) @@ -484,34 +484,20 @@ DOUBLY_LINKED_LIST_CLASS_NAME::Swap(Element *a, Element *b) { if (a && b && a != b) { - Link *aLink = sGetLink(a); - Link *bLink = sGetLink(b); - Element *aPrev = aLink->previous; - Element *bPrev = bLink->previous; - Element *aNext = aLink->next; - Element *bNext = bLink->next; - // place a - if (bPrev) - sGetLink(bPrev)->next = a; - else - fFirst = a; - if (bNext) - sGetLink(bNext)->previous = a; - else - fLast = a; - aLink->previous = bPrev; - aLink->next = bNext; - // place b - if (aPrev) - sGetLink(aPrev)->next = b; - else - fFirst = b; - if (aNext) - sGetLink(aNext)->previous = b; - else - fLast = b; - bLink->previous = aPrev; - bLink->next = aNext; + Element *aNext = sGetLink(a)->next; + Element *bNext = sGetLink(b)->next; + if (a == bNext) { + Remove(a); + Insert(b, a); + } else if (b == aNext) { + Remove(b); + Insert(a, b); + } else { + Remove(a); + Remove(b); + Insert(aNext, b); + Insert(bNext, a); + } } } From bonefish at mail.berlios.de Thu Jul 10 04:52:09 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 04:52:09 +0200 Subject: [Haiku-commits] r26351 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel src/system/kernel/cache src/system/kernel/fs src/system/kernel/slab src/system/kernel/vm Message-ID: <200807100252.m6A2q9Nx019614@sheep.berlios.de> Author: bonefish Date: 2008-07-10 04:51:59 +0200 (Thu, 10 Jul 2008) New Revision: 26351 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26351&view=rev Added: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp Removed: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_low_memory.h haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_low_memory.cpp Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/cache/block_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_map.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/main.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/sem.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/slab/Slab.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_daemons.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp Log: Made the low memory handling code a bit more generic. It manages three kinds of resources, now (pages, memory, and semaphores). Copied: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h (from rev 26333, haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_low_memory.h) =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_low_memory.h 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h 2008-07-10 02:51:59 UTC (rev 26351) @@ -0,0 +1,52 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2005-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_LOW_RESOURCE_MANAGER_H +#define _KERNEL_LOW_RESOURCE_MANAGER_H + + +#include + + +/* warning levels for low resource handlers */ +enum { + B_NO_LOW_RESOURCE = 0, + B_LOW_RESOURCE_NOTE, + B_LOW_RESOURCE_WARNING, + B_LOW_RESOURCE_CRITICAL, +}; + +enum { + B_KERNEL_RESOURCE_PAGES = 0x01, /* physical pages */ + B_KERNEL_RESOURCE_MEMORY = 0x02, /* reservable memory */ + B_KERNEL_RESOURCE_SEMAPHORES = 0x04, /* semaphores */ + + B_ALL_KERNEL_RESOURCES = B_KERNEL_RESOURCE_PAGES + | B_KERNEL_RESOURCE_MEMORY + | B_KERNEL_RESOURCE_SEMAPHORES +}; + +typedef void (*low_resource_func)(void *data, uint32 resources, int32 level); + +#ifdef __cplusplus +extern "C" { +#endif + +status_t low_resource_manager_init(void); +status_t low_resource_manager_init_post_thread(void); +int32 low_resource_state(uint32 resources); +void low_resource(uint32 resource, uint64 requirements); + +// these calls might get public some day +status_t register_low_resource_handler(low_resource_func function, void *data, + uint32 resources, int32 priority); +status_t unregister_low_resource_handler(low_resource_func function, + void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* _KERNEL_LOW_RESOURCE_MANAGER_H */ Deleted: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_low_memory.h Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/Jamfile =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/Jamfile 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/Jamfile 2008-07-10 02:51:59 UTC (rev 26351) @@ -29,6 +29,7 @@ kernel_daemon.cpp linkhack.c lock.cpp + low_resource_manager.cpp main.cpp module.cpp Notifications.cpp Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/block_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/block_cache.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/block_cache.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -129,7 +129,7 @@ void Free(void *buffer); void *Allocate(); - static void LowMemoryHandler(void *data, int32 level); + static void LowMemoryHandler(void *data, uint32 resources, int32 level); private: cached_block *_GetUnusedBlock(); @@ -658,7 +658,8 @@ return; mutex_init(&lock, "block cache"); - register_low_memory_handler(&block_cache::LowMemoryHandler, this, 0); + register_low_resource_handler(&block_cache::LowMemoryHandler, this, + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY, 0); } @@ -667,7 +668,7 @@ { deleting = true; - unregister_low_memory_handler(&block_cache::LowMemoryHandler, this); + unregister_low_resource_handler(&block_cache::LowMemoryHandler, this); mutex_destroy(&lock); @@ -826,7 +827,7 @@ void -block_cache::LowMemoryHandler(void *data, int32 level) +block_cache::LowMemoryHandler(void *data, uint32 resources, int32 level) { block_cache *cache = (block_cache *)data; MutexLocker locker(&cache->lock); @@ -845,18 +846,19 @@ int32 free = 1; int32 accessed = 1; - switch (vm_low_memory_state()) { - case B_NO_LOW_MEMORY: + switch (low_resource_state( + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY)) { + case B_NO_LOW_RESOURCE: return; - case B_LOW_MEMORY_NOTE: + case B_LOW_RESOURCE_NOTE: free = 50; accessed = 2; break; - case B_LOW_MEMORY_WARNING: + case B_LOW_RESOURCE_WARNING: free = 200; accessed = 10; break; - case B_LOW_MEMORY_CRITICAL: + case B_LOW_RESOURCE_CRITICAL: free = LONG_MAX; accessed = LONG_MAX; break; @@ -912,16 +914,17 @@ // (if there is enough memory left, we don't free any) int32 free = 1; - switch (vm_low_memory_state()) { - case B_NO_LOW_MEMORY: + switch (low_resource_state( + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY)) { + case B_NO_LOW_RESOURCE: return; - case B_LOW_MEMORY_NOTE: + case B_LOW_RESOURCE_NOTE: free = 1; break; - case B_LOW_MEMORY_WARNING: + case B_LOW_RESOURCE_WARNING: free = 5; break; - case B_LOW_MEMORY_CRITICAL: + case B_LOW_RESOURCE_CRITICAL: free = 20; break; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_cache.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -16,13 +16,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include //#define TRACE_FILE_CACHE @@ -117,7 +117,7 @@ static void reserve_pages(file_cache_ref *ref, size_t reservePages, bool isWrite) { - if (vm_low_memory_state() != B_NO_LOW_MEMORY) { + if (low_resource_state(B_KERNEL_RESOURCE_PAGES) != B_NO_LOW_RESOURCE) { vm_cache *cache = ref->cache; cache->Lock(); @@ -579,14 +579,18 @@ if (doWrite) { // in low memory situations, we bypass the cache beyond a // certain I/O size - if (size >= BYPASS_IO_SIZE && vm_low_memory_state() != B_NO_LOW_MEMORY) + if (size >= BYPASS_IO_SIZE + && low_resource_state(B_KERNEL_RESOURCE_PAGES) + != B_NO_LOW_RESOURCE) { function = write_to_file; - else + } else function = write_to_cache; } else { - if (size >= BYPASS_IO_SIZE && vm_low_memory_state() != B_NO_LOW_MEMORY) + if (size >= BYPASS_IO_SIZE + && low_resource_state(B_KERNEL_RESOURCE_PAGES) + != B_NO_LOW_RESOURCE) { function = read_from_file; - else + } else function = read_into_cache; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_map.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_map.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/cache/file_map.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -20,7 +20,6 @@ #include #include #include -#include //#define TRACE_FILE_MAP Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,6 @@ #include #include #include -#include #include "fifo.h" @@ -814,10 +814,12 @@ } else { list_add_item(&sUnusedVnodeList, vnode); if (++sUnusedVnodes > kMaxUnusedVnodes - && vm_low_memory_state() != B_NO_LOW_MEMORY) { + && low_resource_state( + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY) + != B_NO_LOW_RESOURCE) { // there are too many unused vnodes so we free the oldest one - // ToDo: evaluate this mechanism - vnode = (struct vnode *)list_remove_head_item(&sUnusedVnodeList); + // TODO: evaluate this mechanism + vnode = (struct vnode*)list_remove_head_item(&sUnusedVnodeList); vnode->busy = true; freeNode = true; sUnusedVnodes--; @@ -1015,21 +1017,21 @@ static void -vnode_low_memory_handler(void */*data*/, int32 level) +vnode_low_resource_handler(void */*data*/, uint32 resources, int32 level) { - TRACE(("vnode_low_memory_handler(level = %ld)\n", level)); + TRACE(("vnode_low_resource_handler(level = %ld)\n", level)); uint32 count = 1; switch (level) { - case B_NO_LOW_MEMORY: + case B_NO_LOW_RESOURCE: return; - case B_LOW_MEMORY_NOTE: + case B_LOW_RESOURCE_NOTE: count = sUnusedVnodes / 100; break; - case B_LOW_MEMORY_WARNING: + case B_LOW_RESOURCE_WARNING: count = sUnusedVnodes / 10; break; - case B_LOW_MEMORY_CRITICAL: + case B_LOW_RESOURCE_CRITICAL: count = sUnusedVnodes; break; } @@ -3868,7 +3870,8 @@ extern "C" void vfs_free_unused_vnodes(int32 level) { - vnode_low_memory_handler(NULL, level); + vnode_low_resource_handler(NULL, + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY, level); } @@ -4393,7 +4396,8 @@ add_debugger_command("vnode_usage", &dump_vnode_usage, "info about vnode usage"); #endif - register_low_memory_handler(&vnode_low_memory_handler, NULL, 0); + register_low_resource_handler(&vnode_low_resource_handler, NULL, + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY, 0); file_map_init(); Copied: haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp (from rev 26333, haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_low_memory.cpp) =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_low_memory.cpp 2008-07-09 01:56:58 UTC (rev 26333) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -0,0 +1,379 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold at gmx.de. + * Copyright 2005-2008, Axel D?rfler, axeld at pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + + +//#define TRACE_LOW_RESOURCE_MANAGER +#ifdef TRACE_LOW_RESOURCE_MANAGER +# define TRACE(x) dprintf x +#else +# define TRACE(x) ; +#endif + + +struct low_resource_handler + : public DoublyLinkedListLinkImpl { + low_resource_func function; + void *data; + uint32 resources; + int32 priority; +}; + +typedef DoublyLinkedList HandlerList; + + +static const bigtime_t kLowResourceInterval = 3000000; // 3 secs +static const bigtime_t kWarnResourceInterval = 500000; // 0.5 secs + +// page limits +static const size_t kNotePagesLimit = 2048; +static const size_t kWarnPagesLimit = 256; +static const size_t kCriticalPagesLimit = 32; + +// memory limits +static const off_t kMinNoteMemoryLimit = 16 * 1024 * 1024; +static const off_t kMinWarnMemoryLimit = 4 * 1024 * 1024; +static const off_t kMinCriticalMemoryLimit = 1 * 1024 * 1024; +static off_t sNoteMemoryLimit; +static off_t sWarnMemoryLimit; +static off_t sCriticalMemoryLimit; + + +static int32 sLowPagesState = B_NO_LOW_RESOURCE; +static int32 sLowMemoryState = B_NO_LOW_RESOURCE; +static int32 sLowSemaphoresState = B_NO_LOW_RESOURCE; +static uint32 sLowResources = 0; // resources that are not B_NO_LOW_RESOURCE +static bigtime_t sLastMeasurement; + +static recursive_lock sLowResourceLock + = RECURSIVE_LOCK_INITIALIZER("low resource"); +static sem_id sLowResourceWaitSem; +static HandlerList sLowResourceHandlers; + + +static int32 +low_resource_state_no_update(uint32 resources) +{ + int32 state = B_NO_LOW_RESOURCE; + + if ((resources & B_KERNEL_RESOURCE_PAGES) != 0) + state = max_c(state, sLowPagesState); + if ((resources & B_KERNEL_RESOURCE_MEMORY) != 0) + state = max_c(state, sLowMemoryState); + if ((resources & B_KERNEL_RESOURCE_SEMAPHORES) != 0) + state = max_c(state, sLowSemaphoresState); + + return state; +} + + +/*! Calls low resource handlers for the given resources. + sLowResourceLock must be held. +*/ +static void +call_handlers(uint32 lowResources) +{ + if (sLowResourceHandlers.IsEmpty()) + return; + + // Add a marker, so we can drop the lock while calling the handlers and + // still iterate safely. + low_resource_handler marker; + sLowResourceHandlers.Insert(&marker, false); + + while (low_resource_handler *handler + = sLowResourceHandlers.GetNext(&marker)) { + // swap with handler + sLowResourceHandlers.Swap(&marker, handler); + marker.priority = handler->priority; + + int32 resources = handler->resources & lowResources; + if (resources != 0) { + recursive_lock_unlock(&sLowResourceLock); + handler->function(handler->data, resources, + low_resource_state_no_update(resources)); + recursive_lock_lock(&sLowResourceLock); + } + } + + // remove marker + sLowResourceHandlers.Remove(&marker); +} + + +static void +compute_state(void) +{ + sLastMeasurement = system_time(); + + sLowResources = B_ALL_KERNEL_RESOURCES; + + // free pages state + uint32 freePages = vm_page_num_free_pages(); + + if (freePages < kCriticalPagesLimit) { + sLowPagesState = B_LOW_RESOURCE_CRITICAL; + } else if (freePages < kWarnPagesLimit) { + sLowPagesState = B_LOW_RESOURCE_WARNING; + } else if (freePages < kNotePagesLimit) { + sLowPagesState = B_LOW_RESOURCE_NOTE; + } else { + sLowPagesState = B_NO_LOW_RESOURCE; + sLowResources &= ~B_KERNEL_RESOURCE_PAGES; + } + + // free memory state + off_t freeMemory = vm_available_memory(); + + if (freeMemory < sCriticalMemoryLimit) { + sLowMemoryState = B_LOW_RESOURCE_CRITICAL; + } else if (freeMemory < sWarnMemoryLimit) { + sLowMemoryState = B_LOW_RESOURCE_WARNING; + } else if (freeMemory < sNoteMemoryLimit) { + sLowMemoryState = B_LOW_RESOURCE_NOTE; + } else { + sLowMemoryState = B_NO_LOW_RESOURCE; + sLowResources &= ~B_KERNEL_RESOURCE_MEMORY; + } + + // free semaphores state + uint32 maxSems = sem_max_sems(); + uint32 freeSems = maxSems - sem_used_sems(); + + if (freeSems < maxSems >> 16) { + sLowSemaphoresState = B_LOW_RESOURCE_CRITICAL; + } else if (freeSems < maxSems >> 8) { + sLowSemaphoresState = B_LOW_RESOURCE_WARNING; + } else if (freeSems < maxSems >> 4) { + sLowSemaphoresState = B_LOW_RESOURCE_NOTE; + } else { + sLowSemaphoresState = B_NO_LOW_RESOURCE; + sLowResources &= ~B_KERNEL_RESOURCE_SEMAPHORES; + } +} + + +static int32 +low_resource_manager(void *) +{ + bigtime_t timeout = kLowResourceInterval; + while (true) { + int32 state = low_resource_state_no_update(B_ALL_KERNEL_RESOURCES); + if (state != B_LOW_RESOURCE_CRITICAL) { + acquire_sem_etc(sLowResourceWaitSem, 1, B_RELATIVE_TIMEOUT, + timeout); + } + + RecursiveLocker _(&sLowResourceLock); + + compute_state(); + state = low_resource_state_no_update(B_ALL_KERNEL_RESOURCES); + + TRACE(("low_resource_manager: state = %ld, %ld free pages, %lld free " + "memory, %lu free semaphores\n", state, vm_page_num_free_pages(), + vm_available_memory(), sem_max_sems() - sem_used_sems())); + + if (state < B_LOW_RESOURCE_NOTE) + continue; + + call_handlers(sLowResources); + + if (state == B_LOW_RESOURCE_WARNING) + timeout = kWarnResourceInterval; + else + timeout = kLowResourceInterval; + } + return 0; +} + + +static int +dump_handlers(int argc, char **argv) +{ + HandlerList::Iterator iterator = sLowResourceHandlers.GetIterator(); + kprintf("function data resources prio function-name\n"); + + while (iterator.HasNext()) { + low_resource_handler *handler = iterator.Next(); + + const char* symbol = NULL; + elf_debug_lookup_symbol_address((addr_t)handler->function, NULL, + &symbol, NULL, NULL); + + char resources[16]; + snprintf(resources, sizeof(resources), "%c %c %c", + handler->resources & B_KERNEL_RESOURCE_PAGES ? 'p' : ' ', + handler->resources & B_KERNEL_RESOURCE_MEMORY ? 'm' : ' ', + handler->resources & B_KERNEL_RESOURCE_SEMAPHORES ? 's' : ' '); + + kprintf("%p %p %s %4ld %s\n", handler->function, handler->data, + resources, handler->priority, symbol); + } + + return 0; +} + + +// #pragma mark - private kernel API + + +void +low_resource(uint32 resource, uint64 requirements) +{ + // TODO: take requirements into account + + switch (resource) { + case B_KERNEL_RESOURCE_PAGES: + vm_schedule_page_scanner(requirements); + break; + case B_KERNEL_RESOURCE_MEMORY: +// TODO:... + break; + case B_KERNEL_RESOURCE_SEMAPHORES: +// TODO:... + break; + } + + release_sem(sLowResourceWaitSem); +} + + +int32 +low_resource_state(uint32 resources) +{ + recursive_lock_lock(&sLowResourceLock); + + if (system_time() - sLastMeasurement > 500000) + compute_state(); + + int32 state = low_resource_state_no_update(resources); + + recursive_lock_unlock(&sLowResourceLock); + + return state; +} + + +status_t +low_resource_manager_init(void) +{ + new(&sLowResourceHandlers) HandlerList; + // static initializers do not work in the kernel, + // so we have to do it here, manually + + // compute the free memory limits + off_t totalMemory = (off_t)vm_page_num_pages() * B_PAGE_SIZE; + sNoteMemoryLimit = totalMemory / 16; + if (sNoteMemoryLimit < kMinNoteMemoryLimit) { + sNoteMemoryLimit = kMinNoteMemoryLimit; + sWarnMemoryLimit = kMinWarnMemoryLimit; + sCriticalMemoryLimit = kMinCriticalMemoryLimit; + } else { + sWarnMemoryLimit = totalMemory / 64; + sCriticalMemoryLimit = totalMemory / 256; + } + + return B_OK; +} + + +status_t +low_resource_manager_init_post_thread(void) +{ + sLowResourceWaitSem = create_sem(0, "low resource wait"); + if (sLowResourceWaitSem < B_OK) + return sLowResourceWaitSem; + + thread_id thread = spawn_kernel_thread(&low_resource_manager, + "low resource manager", B_LOW_PRIORITY, NULL); + send_signal_etc(thread, SIGCONT, B_DO_NOT_RESCHEDULE); + + add_debugger_command("low_resource", &dump_handlers, + "Dump list of low resource handlers"); + return B_OK; +} + + +status_t +unregister_low_resource_handler(low_resource_func function, void *data) +{ + TRACE(("unregister_low_resource_handler(function = %p, data = %p)\n", + function, data)); + + RecursiveLocker locker(&sLowResourceLock); + HandlerList::Iterator iterator = sLowResourceHandlers.GetIterator(); + + while (iterator.HasNext()) { + low_resource_handler *handler = iterator.Next(); + + if (handler->function == function && handler->data == data) { + sLowResourceHandlers.Remove(handler); + free(handler); + return B_OK; + } + } + + return B_ENTRY_NOT_FOUND; +} + + +/*! Registers a low resource handler. The higher the \a priority, the earlier + the handler will be called in low resource situations. +*/ +status_t +register_low_resource_handler(low_resource_func function, void *data, + uint32 resources, int32 priority) +{ + TRACE(("register_low_resource_handler(function = %p, data = %p)\n", + function, data)); + + low_resource_handler *newHandler = (low_resource_handler *)malloc( + sizeof(low_resource_handler)); + if (newHandler == NULL) + return B_NO_MEMORY; + + newHandler->function = function; + newHandler->data = data; + newHandler->resources = resources; + newHandler->priority = priority; + + RecursiveLocker locker(&sLowResourceLock); + + // sort it in after priority (higher priority comes first) + + HandlerList::ReverseIterator iterator + = sLowResourceHandlers.GetReverseIterator(); + low_resource_handler *last = NULL; + while (iterator.HasNext()) { + low_resource_handler *handler = iterator.Next(); + + if (handler->priority >= priority) { + sLowResourceHandlers.Insert(last, newHandler); + return B_OK; + } + last = handler; + } + + sLowResourceHandlers.Add(newHandler, false); + return B_OK; +} Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/main.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/main.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/main.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -128,6 +129,7 @@ vm_init(&sKernelArgs); // Before vm_init_post_sem() is called, we have to make sure that // the boot loader allocated region is not used anymore + low_resource_manager_init(); // now we can use the heap and create areas arch_platform_init_post_vm(&sKernelArgs); @@ -174,6 +176,7 @@ TRACE("init VM threads\n"); vm_init_post_thread(&sKernelArgs); + low_resource_manager_init_post_thread(); TRACE("init ELF loader\n"); elf_init(&sKernelArgs); TRACE("init scheduler\n"); Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/sem.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/sem.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/sem.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/slab/Slab.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/slab/Slab.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/slab/Slab.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -6,6 +6,7 @@ */ +#include #include "slab_private.h" #include @@ -17,14 +18,13 @@ #include #include -#include +#include #include #include #include #include #include #include -#include // TODO kMagazineCapacity should be dynamically tuned per cache. @@ -477,9 +477,9 @@ static void -object_cache_low_memory(void *_self, int32 level) +object_cache_low_memory(void *_self, uint32 resources, int32 level) { - if (level == B_NO_LOW_MEMORY) + if (level == B_NO_LOW_RESOURCE) return; object_cache *cache = (object_cache *)_self; @@ -497,11 +497,11 @@ size_t minimumAllowed; switch (level) { - case B_LOW_MEMORY_NOTE: + case B_LOW_RESOURCE_NOTE: minimumAllowed = cache->pressure / 2 + 1; break; - case B_LOW_MEMORY_WARNING: + case B_LOW_RESOURCE_WARNING: cache->pressure /= 2; minimumAllowed = 0; break; @@ -594,7 +594,8 @@ cache->free_pages = area_free_pages; } - register_low_memory_handler(object_cache_low_memory, cache, 5); + register_low_resource_handler(object_cache_low_memory, cache, + B_KERNEL_RESOURCE_PAGES | B_KERNEL_RESOURCE_MEMORY, 5); MutexLocker _(sObjectCacheListLock); sObjectCaches.Add(cache); @@ -745,7 +746,7 @@ if (!(cache->flags & CACHE_NO_DEPOT)) object_depot_destroy(&cache->depot); - unregister_low_memory_handler(object_cache_low_memory, cache); + unregister_low_resource_handler(object_cache_low_memory, cache); if (!cache->full.IsEmpty()) panic("cache destroy: still has full slabs"); Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/Jamfile 2008-07-10 02:51:59 UTC (rev 26351) @@ -7,7 +7,6 @@ vm_address_space.cpp vm_cache.cpp vm_daemons.cpp - vm_low_memory.cpp vm_page.cpp VMAnonymousCache.cpp VMAnonymousNoSwapCache.cpp Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -3793,8 +3792,6 @@ TRACE(("heap at 0x%lx\n", heapBase)); heap_init(heapBase, heapSize); - vm_low_memory_init(); - size_t slabInitialSize = args->num_cpus * 2 * B_PAGE_SIZE; addr_t slabInitialBase = vm_allocate_early(args, slabInitialSize, slabInitialSize, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA); @@ -3913,7 +3910,6 @@ { vm_page_init_post_thread(args); vm_daemon_init(); - vm_low_memory_init_post_thread(); return heap_init_post_thread(); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_daemons.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_daemons.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_daemons.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -13,7 +13,6 @@ #include #include #include -#include #include Deleted: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_low_memory.cpp Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 02:45:44 UTC (rev 26350) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 02:51:59 UTC (rev 26351) @@ -18,12 +18,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -990,8 +990,11 @@ vm_cache *cache = page->cache; // TODO: write back temporary ones as soon as we have swap file support - if (cache->temporary/* && vm_low_memory_state() == B_NO_LOW_MEMORY*/) + if (cache->temporary + /*&& low_resource_state(B_KERNEL_RESOURCE_PAGES) + == B_NO_LOW_RESOURCE*/) { continue; + } // we need our own reference to the store, as it might // currently be destructed @@ -1249,7 +1252,7 @@ freeConditionEntry.Add(&sFreePageQueue); locker.Unlock(); - vm_low_memory(count); + low_resource(B_KERNEL_RESOURCE_PAGES, count); //snooze(50000); // sleep for 50ms From superstippi at gmx.de Thu Jul 10 08:27:45 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 08:27:45 +0200 Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <487546C7.9000106@arcor.de> References: <200807091413.m69ED9QU028649@sheep.berlios.de> <487546C7.9000106@arcor.de> Message-ID: <20080710082745.687.1@stippis2.1215669831.fake> Hi Marcus, I understand your concerns, but you have written most of them without a good overview of the concerning codebase. Marcus Overhagen wrote: > stippi at mail.berlios.de schrieb: > > > * Introduced a new view event mask flag: B_FULL_POINTER_HISTORY which, > > when set, prevents any old mouse moved message discarding. > > * BWindow::DispatchMessage(B_MOUSE_MOVED) checks the event time of the > > message and discards too old events, but only if there is another > > event in the queue and the view does not specify > > B_FULL_POINTER_HISTORY. > > * BView::GetMouse() ignores the checkHistory flag passed to the function > > in case the event mask specifies B_NO_POINTER_HISTORY. > > B_FULL_POINTER_HISTORY on the other hand prevents the dropping of old > > messages. > > its nice that you started working on the slow mouse issues, but I really > don't think your current solution is good. > > I think we don't need a B_FULL_POINTER_HISTORY flag. The default mouse > sampling rate is 100 samples per second for PS/2, 40 samples per second > for serial, and 125 for USB. Those can be increased by the drivers, up to > 200 for ps2 and 1000 for USB. > I don't know what haiku currently is using, we should check this, but > calling BView::MouseMoved at that rate certainly shouldn't be a problem. But that's the point, if it isn't a problem, then my solution doesn't change anything! In another words, if an application is fast enough to handle 1000 messages per second, then my change will not have any effect. If it isn't, then my change will remove old mouse messages from the queue. The point that Ingo was making is that most applications will not have any use for that many mouse messages. I may add that mouse messages are only generated when the mouse actually moves, so it's not that the applications get constantly flooded with messages. The movement samples may be finer than they need to be though and Ingo has presented a solution, but I believe it may have other drawbacks (like pretty much no mouse history at all). In any case, my change doesn't have anything to do with it as long as applications are fast enough to handle it. The change only addresses a lagging problem *if* it occurs. > Additionally as Axel already said, your change ignores transitions. That is correct and I will need to fix that. When I first worked on BView::GetMouse() the day before, I was still thinking about it, but in my last change, I had forgotten it. Will fix that. > I > think that transitions were completely broken even before your changes, Why? > I > couldn't find out where "be:transit" in the message is ever populated. But it is, see BWindow::_SanitizeMessage(). It is even more reliable than on BeOS the way we (Axel) implemented it. Appearantly, on R5, transit is handled by the app_server, but that brings some problems. In Haiku, the window keeps track with the fLastMouseMovedView in all situations and uses that to pass transit correctly. > The BeBook BView::MouseMoved describes that the entered view and exit > view both get a MouseMoved event, this doesn't seem to be implemented, > too. But it is. Is it not working? > BView::GetMouse() with checkQueue = false is supposed to return the > current position and button state, how do we do it, can we bypass the > queue and directly get the state from input_server (shared memory?) Yes we do. If checkQueue = false, we will not even look at the queue but send a synchronous message to the app_server and get the absolutely most current position. I suppose you have not looked at BView::GetMouse() before you wrote this? The problem is that most applications don't pass checkQueue = false, which I have pointed out in my first mail to the development list. Pe calls GetMouse(checkQueue = true) in a loop that has a snooze(20000) inserted. That's got to build up the mouse queue, because mouse messages come way faster than at 20000 ?s inbetween. > The BeBook says: > > If checkQueue is true, and the view's parent window has pending update > > events, GetMouse() causes those update events to be processed. > > Is this probably our problem? do we need to process any further > drawing(?) events each time GetMouse is called? Again, that's handled. Otherwise applications wouldn't update their UI anymore because they block in MouseDown(). But that is not the problem, and it can be seen when looking at BView::GetMouse(). > Or another idea: if the problems occur usually inside MouseDown, MouseUp > or MouseMoved. perhaps we should stop inserting events in the queue while > these Hooks are active (waiting with a small timeout, perhaps 5ms) and > drop those mouse events, except if its a view enter/leave transition. It may make things more complicated than need be. Really, my solution is quite simple and only kicks in when necessary. Optionally with the new flag, applications can explicitely turn it off. The only problem is that I forgot to special case certain transit messages. Best regards, -Stephan From superstippi at gmx.de Thu Jul 10 08:30:00 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 08:30:00 +0200 Subject: [Haiku-commits] r26349 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: <200807092314.m69NEvg4025775@sheep.berlios.de> References: <200807092314.m69NEvg4025775@sheep.berlios.de> Message-ID: <20080710083000.743.2@stippis2.1215669831.fake> korli at BerliOS wrote: > Author: korli > Date: 2008-07-10 01:14:57 +0200 (Thu, 10 Jul 2008) New Revision: 26349 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26349&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/drivers/audio/hda/driver.h > Log: > reduced buffer size: with 4096, no buffer is received by the multiaudio > addon Doesn't that hint at a problem in the multiaudio add-on or somewhere along the code paths? In the OSS node I have had to use much bigger buffers on Haiku and it works fine. It may be the latency calculation that is wrong. Best regards, -Stephan From stefano.ceccherini at gmail.com Thu Jul 10 08:30:58 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Thu, 10 Jul 2008 08:30:58 +0200 Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <487546C7.9000106@arcor.de> References: <200807091413.m69ED9QU028649@sheep.berlios.de> <487546C7.9000106@arcor.de> Message-ID: <894b9700807092330x4fd0f7e8n8f0b7f43f94803f9@mail.gmail.com> 2008/7/10 Marcus Overhagen : > Additionally as Axel already said, your change ignores transitions. I > think that transitions were completely broken even before your changes, > I couldn't find out where "be:transit" in the message is ever populated. > The BeBook BView::MouseMoved describes that the entered view and exit > view both get a MouseMoved event, this doesn't seem to be implemented, too. Check BWindow::_SanitizeMessage(). From axeld at pinc-software.de Thu Jul 10 08:50:09 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 10 Jul 2008 08:50:09 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26349_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/audio/hda?= In-Reply-To: <200807092314.m69NEvg4025775@sheep.berlios.de> Message-ID: <1536010362-BeMail@zon> korli at BerliOS wrote: > Log: > reduced buffer size: with 4096, no buffer is received by the > multiaudio addon Any reason why this is? Bye, Axel. From stippi at mail.berlios.de Thu Jul 10 09:21:19 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 09:21:19 +0200 Subject: [Haiku-commits] r26352 - haiku/trunk/src/kits/interface Message-ID: <200807100721.m6A7LJaf027239@sheep.berlios.de> Author: stippi Date: 2008-07-10 09:21:16 +0200 (Thu, 10 Jul 2008) New Revision: 26352 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26352&view=rev Modified: haiku/trunk/src/kits/interface/Window.cpp Log: * Made the mouse moved message dropping code slightly nicer to read. * Don't drop messages which carry an important transit value. (Thanks, Axel!) Modified: haiku/trunk/src/kits/interface/Window.cpp =================================================================== --- haiku/trunk/src/kits/interface/Window.cpp 2008-07-10 02:51:59 UTC (rev 26351) +++ haiku/trunk/src/kits/interface/Window.cpp 2008-07-10 07:21:16 UTC (rev 26352) @@ -1096,16 +1096,20 @@ uint32 eventOptions = view->fEventOptions | view->fMouseEventOptions; bool noHistory = eventOptions & B_NO_POINTER_HISTORY; - bool fullHistory = eventOptions & B_FULL_POINTER_HISTORY; + bool dropIfLate = !(eventOptions & B_FULL_POINTER_HISTORY); bigtime_t eventTime; - if (noHistory - || msg->FindInt64("when", (int64*)&eventTime) < B_OK) { + if (msg->FindInt64("when", (int64*)&eventTime) < B_OK) eventTime = system_time(); - } - if (noHistory || (!fullHistory - && (system_time() - eventTime > 20000))) { + uint32 transit; + msg->FindInt32("be:transit", (int32*)&transit); + // don't drop late messages with these important transit values + if (transit == B_ENTERED_VIEW || transit == B_EXITED_VIEW) + dropIfLate = false; + + if (noHistory + || (dropIfLate && (system_time() - eventTime > 20000))) { // filter out older mouse moved messages in the queue _DequeueAll(); BMessageQueue *queue = MessageQueue(); @@ -1126,10 +1130,8 @@ BPoint where; uint32 buttons; - uint32 transit; msg->FindPoint("be:view_where", &where); msg->FindInt32("buttons", (int32*)&buttons); - msg->FindInt32("be:transit", (int32*)&transit); BMessage* dragMessage = NULL; if (msg->HasMessage("be:drag_message")) { From stippi at mail.berlios.de Thu Jul 10 09:35:50 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 09:35:50 +0200 Subject: [Haiku-commits] r26353 - haiku/trunk/src/kits/interface Message-ID: <200807100735.m6A7ZoT0028036@sheep.berlios.de> Author: stippi Date: 2008-07-10 09:35:47 +0200 (Thu, 10 Jul 2008) New Revision: 26353 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26353&view=rev Modified: haiku/trunk/src/kits/interface/Window.cpp Log: Added TODO about a problem that the late mouse moved message dropping code may have. Modified: haiku/trunk/src/kits/interface/Window.cpp =================================================================== --- haiku/trunk/src/kits/interface/Window.cpp 2008-07-10 07:21:16 UTC (rev 26352) +++ haiku/trunk/src/kits/interface/Window.cpp 2008-07-10 07:35:47 UTC (rev 26353) @@ -1108,6 +1108,16 @@ if (transit == B_ENTERED_VIEW || transit == B_EXITED_VIEW) dropIfLate = false; + // TODO: The dropping code may have the following problem: + // On slower computers, 20ms may just be to abitious a delay. + // There, we might constantly check the message queue for a + // newer message, not find any, and still use the only but + // later than 20ms message, which of course makes the whole + // thing later than need be. An adaptive delay would be + // kind of neat, but would probably use additional BWindow + // members to count the successful versus fruitless queue + // searches and the delay value itself or something similar. + if (noHistory || (dropIfLate && (system_time() - eventTime > 20000))) { // filter out older mouse moved messages in the queue From stippi at mail.berlios.de Thu Jul 10 10:07:02 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:07:02 +0200 Subject: [Haiku-commits] r26354 - haiku/trunk/src/servers/app/drawing/Painter/drawing_modes Message-ID: <200807100807.m6A872DD031890@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:06:59 +0200 (Thu, 10 Jul 2008) New Revision: 26354 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26354&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingMode.h Log: patch by Andrej Spielmann (GSOC): * Added marco definitions for subpixel based blending of two 32 bit pixels. Modified: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingMode.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingMode.h 2008-07-10 07:35:47 UTC (rev 26353) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingMode.h 2008-07-10 08:06:59 UTC (rev 26354) @@ -1,6 +1,7 @@ /* - * Copyright 2005, Stephan A?mus . All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. * * Base class for different drawing modes. * @@ -34,6 +35,16 @@ d[3] = 255; \ } +#define BLEND_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + d[0] = (((((b) - _p.data8[0]) * (a1)) + (_p.data8[0] << 8)) >> 8); \ + d[1] = (((((g) - _p.data8[1]) * (a2)) + (_p.data8[1] << 8)) >> 8); \ + d[2] = (((((r) - _p.data8[2]) * (a3)) + (_p.data8[2] << 8)) >> 8); \ + d[3] = 255; \ +} + // BLEND_FROM // // This macro assumes source alpha in range 0..255 and @@ -49,6 +60,14 @@ d[3] = 255; \ } +#define BLEND_FROM_SUBPIX(d, r1, g1, b1, r2, g2, b2, a1, a2, a3) \ +{ \ + d[0] = (((((b2) - (b1)) * (a1)) + ((b1) << 8)) >> 8); \ + d[1] = (((((g2) - (g1)) * (a2)) + ((g1) << 8)) >> 8); \ + d[2] = (((((r2) - (r1)) * (a3)) + ((r1) << 8)) >> 8); \ + d[3] = 255; \ +} + // BLEND16 // // This macro assumes source alpha in range 0..65025 and @@ -65,8 +84,17 @@ d[3] = 255; \ } +// BLEND16_SUBPIX +#define BLEND16_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + d[0] = (((((b) - _p.data8[0]) * (a1)) + (_p.data8[0] << 16)) >> 16); \ + d[1] = (((((g) - _p.data8[1]) * (a2)) + (_p.data8[1] << 16)) >> 16); \ + d[2] = (((((r) - _p.data8[2]) * (a3)) + (_p.data8[2] << 16)) >> 16); \ + d[3] = 255; \ +} - // BLEND_COMPOSITE // // This macro assumes source alpha in range 0..255 and @@ -99,6 +127,43 @@ } \ } +// BLEND_COMPOSITE_SUBPIX +#define BLEND_COMPOSITE_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + if (_p.data8[3] == 255) { \ + d[0] = (((((b) - _p.data8[0]) * (a1)) + (_p.data8[0] << 8)) >> 8); \ + d[1] = (((((g) - _p.data8[1]) * (a2)) + (_p.data8[1] << 8)) >> 8); \ + d[2] = (((((r) - _p.data8[2]) * (a3)) + (_p.data8[2] << 8)) >> 8); \ + d[3] = 255; \ + } else { \ + if (_p.data8[3] == 0) { \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = (a1 + a2 + a3)/3; \ + } else { \ + uint8 alphaRest1 = 255 - (a1); \ + uint8 alphaRest2 = 255 - (a2); \ + uint8 alphaRest3 = 255 - (a3); \ + uint32 alphaTemp1 = (65025 - alphaRest1 * (255 - _p.data8[3])); \ + uint32 alphaTemp2 = (65025 - alphaRest2 * (255 - _p.data8[3])); \ + uint32 alphaTemp3 = (65025 - alphaRest3 * (255 - _p.data8[3])); \ + uint32 alphaDest1 = _p.data8[3] * alphaRest1; \ + uint32 alphaDest2 = _p.data8[3] * alphaRest2; \ + uint32 alphaDest3 = _p.data8[3] * alphaRest3; \ + uint32 alphaSrc1 = 255 * (a1); \ + uint32 alphaSrc2 = 255 * (a2); \ + uint32 alphaSrc3 = 255 * (a3); \ + d[0] = (_p.data8[0] * alphaDest1 + (b) * alphaSrc1) / alphaTemp1; \ + d[1] = (_p.data8[1] * alphaDest2 + (g) * alphaSrc2) / alphaTemp2; \ + d[2] = (_p.data8[2] * alphaDest3 + (r) * alphaSrc3) / alphaTemp3; \ + d[3] = (alphaTemp1 + alphaTemp2 + alphaTemp3)/765; \ + } \ + } \ +} + // BLEND_COMPOSITE16 // // This macro assumes source alpha in range 0..65025 and @@ -110,6 +175,14 @@ BLEND_COMPOSITE(d, r, g, b, _a); \ } +// BLEND_COMPOSITE16_SUBPIX +#define BLEND_COMPOSITE16_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + uint16 _a1 = (a1) / 255; \ + uint16 _a2 = (a2) / 255; \ + uint16 _a3 = (a3) / 255; \ + BLEND_COMPOSITE_SUBPIX(d, r, g, b, _a1, _a2, _a3); \ +} static inline uint8 @@ -121,6 +194,5 @@ return uint8((308 * red + 600 * green + 116 * blue) / 1024); } - #endif // DRAWING_MODE_H From stippi at mail.berlios.de Thu Jul 10 10:09:15 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:09:15 +0200 Subject: [Haiku-commits] r26355 - haiku/trunk/src/servers/app/drawing/Painter/drawing_modes Message-ID: <200807100809.m6A89FXH031986@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:08:59 +0200 (Thu, 10 Jul 2008) New Revision: 26355 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26355&view=rev Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAddSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCCSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolidSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolidSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolidSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyTextSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeEraseSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeInvertSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeMaxSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeMinSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeOverSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeOverSolidSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelectSUBPIX.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSubtractSUBPIX.h Log: patch by Andrej Spielmann (GSOC): Added complementary functions to the set of functions that implement a drawing_mode, these new functions interpret the coverage values passed from the AGG rasterizer or another scanline storage as subpixel triplets. Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAddSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAddSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAddSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,101 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ADD on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ADD_SUBPIX_H +#define DRAWING_MODE_ADD_SUBPIX_H + +#include "DrawingMode.h" + + +// BLEND_ADD_SUBPIX +#define BLEND_ADD_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + uint8 rt = min_c(255, _p.data8[2] + (r)); \ + uint8 gt = min_c(255, _p.data8[1] + (g)); \ + uint8 bt = min_c(255, _p.data8[0] + (b)); \ + BLEND_SUBPIX(d, rt, gt, bt, a1, a2, a3); \ +} + + +// BLEND_ADD +#define BLEND_ADD(d, r, g, b, a) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + uint8 rt = min_c(255, _p.data8[2] + (r)); \ + uint8 gt = min_c(255, _p.data8[1] + (g)); \ + uint8 bt = min_c(255, _p.data8[0] + (b)); \ + BLEND(d, rt, gt, bt, a); \ +} + + +//ASSIGN_ADD +#define ASSIGN_ADD(d, r, g, b) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + d[0] = min_c(255, _p.data8[0] + (b)); \ + d[1] = min_c(255, _p.data8[1] + (g)); \ + d[2] = min_c(255, _p.data8[2] + (r)); \ + d[3] = 255; \ +} + + +// blend_hline_add_subpix +void +blend_hline_add_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + if (cover == 255) { + do { + rgb_color color = pattern->ColorAt(x, y); + + ASSIGN_ADD(p, color.red, color.green, color.blue); + + p += 4; + x++; + len -= 3; + } while (len); + } else { + do { + rgb_color color = pattern->ColorAt(x, y); + + BLEND_ADD(p, color.red, color.green, color.blue, cover); + + x++; + p += 4; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_add_subpix +void +blend_solid_hspan_add_subpix(int x, int y, unsigned len, const color_type& c, + const uint8* covers, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_ADD_SUBPIX(p, color.red, color.green, color.blue, + covers[2], covers[1], covers[0]); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + + +#endif // DRAWING_MODE_ADD_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCCSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCCSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCCSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,113 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Constant Composite" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_CC_SUBPIX_H +#define DRAWING_MODE_ALPHA_CC_SUBPIX_H + +#include "DrawingMode.h" + +// BLEND_ALPHA_CC_SUBPIX +#define BLEND_ALPHA_CC_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + BLEND_COMPOSITE16_SUBPIX(d, r, g, b, a1, a2, a3); \ +} + + +// BLEND_ALPHA_CC +#define BLEND_ALPHA_CC(d, r, g, b, a) \ +{ \ + BLEND_COMPOSITE16(d, r, g, b, a); \ +} + + +// ASSIGN_ALPHA_CC +#define ASSIGN_ALPHA_CC(d, r, g, b) \ +{ \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = 255; \ +} + + +// blend_hline_alpha_cc_subpix +void +blend_hline_alpha_cc_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + rgb_color color = pattern->HighColor(); + uint16 alpha = color.alpha * cover; + if (alpha == 255 * 255) { + // cache the low and high color as 32bit values + // high color + uint32 vh; + uint8* p8 = (uint8*)&vh; + p8[0] = color.blue; + p8[1] = color.green; + p8[2] = color.red; + p8[3] = 255; + // low color + color = pattern->LowColor(); + uint32 vl; + p8 = (uint8*)&vl; + p8[0] = color.blue; + p8[1] = color.green; + p8[2] = color.red; + p8[3] = 255; + // row offset as 32 bit pointer + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + if (pattern->IsHighColor(x, y)) + *p32 = vh; + else + *p32 = vl; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_ALPHA_CC(p, color.red, color.green, color.blue, alpha); + x++; + p += 4; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_alpha_cc_subpix +void +blend_solid_hspan_alpha_cc_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint8 hAlpha = pattern->HighColor().alpha; + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + alphaRed = hAlpha * covers[0]; + alphaGreen = hAlpha * covers[1]; + alphaBlue = hAlpha * covers[2]; + rgb_color color = pattern->ColorAt(x, y); + BLEND_ALPHA_CC_SUBPIX(p, color.red, color.green, color.blue, + alphaBlue,alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_ALPHA_CC_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,113 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Constant Overlay" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_CO_SUBPIX_H +#define DRAWING_MODE_ALPHA_CO_SUBPIX_H + +#include "DrawingMode.h" + +// BLEND_ALPHA_CO_SUBPIX +#define BLEND_ALPHA_CO_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + BLEND16_SUBPIX(d, r, g, b, a1, a2, a3); \ +} + + +// BLEND_ALPHA_CO +#define BLEND_ALPHA_CO(d, r, g, b, a) \ +{ \ + BLEND16(d, r, g, b, a); \ +} + + +// ASSIGN_ALPHA_CO +#define ASSIGN_ALPHA_CO(d, r, g, b) \ +{ \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = 255; \ +} + + +// blend_hline_alpha_co_subpix +void +blend_hline_alpha_co_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + rgb_color color = pattern->HighColor(); + uint16 alpha = color.alpha * cover; + if (alpha == 255 * 255) { + // cache the low and high color as 32bit values + // high color + uint32 vh; + uint8* p8 = (uint8*)&vh; + p8[0] = color.blue; + p8[1] = color.green; + p8[2] = color.red; + p8[3] = 255; + // low color + color = pattern->LowColor(); + uint32 vl; + p8 = (uint8*)&vl; + p8[0] = color.blue; + p8[1] = color.green; + p8[2] = color.red; + p8[3] = 255; + // row offset as 32bit pointer + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + if (pattern->IsHighColor(x, y)) + *p32 = vh; + else + *p32 = vl; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_ALPHA_CO(p, color.red, color.green, color.blue, alpha); + x++; + p += 4; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_alpha_co_subpix +void +blend_solid_hspan_alpha_co_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint8 hAlpha = pattern->HighColor().alpha; + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + alphaRed = hAlpha * covers[0]; + alphaGreen = hAlpha * covers[1]; + alphaBlue = hAlpha * covers[2]; + rgb_color color = pattern->ColorAt(x, y); + BLEND_ALPHA_CO_SUBPIX(p, color.red, color.green, color.blue, + alphaBlue, alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_ALPHA_CO_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolidSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolidSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolidSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,81 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Constant Overlay" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_CO_SOLID_SUBPIX_H +#define DRAWING_MODE_ALPHA_CO_SOLID_SUBPIX_H + +#include "DrawingModeAlphaCOSUBPIX.h" + +// blend_hline_alpha_co_solid_subpix +void +blend_hline_alpha_co_solid_subpix(int x, int y, unsigned len, + const color_type& c, uint8 cover, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint16 alpha = pattern->HighColor().alpha * cover; + if (alpha == 255 * 255) { + // cache the color as 32bit values + uint32 v; + uint8* p8 = (uint8*)&v; + p8[0] = c.b; + p8[1] = c.g; + p8[2] = c.r; + p8[3] = 255; + // row offset as 32bit pointer + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + *p32 = v; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + if (len < 12) { + do { + BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha); + x++; + p += 4; + len -= 3; + } while (len); + } else { + alpha = alpha >> 8; + blend_line32(p, len / 3, c.r, c.g, c.b, alpha); + } + } +} + + +// blend_solid_hspan_alpha_co_solid_subpix +void +blend_solid_hspan_alpha_co_solid_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint8 hAlpha = pattern->HighColor().alpha; + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + alphaRed = hAlpha * covers[0]; + alphaGreen = hAlpha * covers[1]; + alphaBlue = hAlpha * covers[2]; + BLEND_ALPHA_CO_SUBPIX(p, c.r, c.g, c.b, + alphaBlue, alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + + +#endif // DRAWING_MODE_ALPHA_CO_SOLID_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,87 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Pixel Composite" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_PC_SUBPIX_H +#define DRAWING_MODE_ALPHA_PC_SUBPIX_H + +#include "DrawingMode.h" + +// BLEND_ALPHA_PC_SUBPIX +#define BLEND_ALPHA_PC_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + BLEND_COMPOSITE16_SUBPIX(d, r, g, b, a1, a2, a3); \ +} + + +// BLEND_ALPHA_PC +#define BLEND_ALPHA_PC(d, r, g, b, a) \ +{ \ + BLEND_COMPOSITE16(d, r, g, b, a); \ +} + + +// ASSIGN_ALPHA_PC +#define ASSIGN_ALPHA_PC(d, r, g, b) \ +{ \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = 255; \ +} + + +// blend_hline_alpha_pc_subpix +void +blend_hline_alpha_pc_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + uint16 alpha = color.alpha * cover; + if (alpha) { + if (alpha == 255) { + ASSIGN_ALPHA_PC(p, color.red, color.green, color.blue); + } else { + BLEND_ALPHA_PC(p, color.red, color.green, color.blue, alpha); + } + } + x++; + p += 4; + len -= 3; + } while (len); +} + + +// blend_solid_hspan_alpha_pc_subpix +void +blend_solid_hspan_alpha_pc_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + rgb_color color = pattern->ColorAt(x, y); + alphaRed = color.alpha * covers[0]; + alphaGreen = color.alpha * covers[1]; + alphaBlue = color.alpha * covers[2]; + BLEND_ALPHA_PC_SUBPIX(p, color.red, color.green, color.blue, + alphaBlue, alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_ALPHA_PC_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,85 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Constant Overlay" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_PO_SUBPIX_H +#define DRAWING_MODE_ALPHA_PO_SUBPIX_H + +#include "DrawingMode.h" + +// BLEND_ALPHA_PO_SUBPIX +#define BLEND_ALPHA_PO_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + BLEND16_SUBPIX(d, r, g, b, a1, a2, a3); \ +} + +// BLEND_ALPHA_PO +#define BLEND_ALPHA_PO(d, r, g, b, a) \ +{ \ + BLEND16(d, r, g, b, a); \ +} + +// ASSIGN_ALPHA_PO +#define ASSIGN_ALPHA_PO(d, r, g, b) \ +{ \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = 255; \ +} + + +// blend_hline_alpha_po_subpix +void +blend_hline_alpha_po_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + uint16 alpha = color.alpha * cover; + if (alpha) { + if (alpha == 255) { + ASSIGN_ALPHA_PO(p, color.red, color.green, color.blue); + } else { + BLEND_ALPHA_PO(p, color.red, color.green, color.blue, alpha); + } + } + x++; + p += 4; + len -= 3; + } while(len); +} + + +// blend_solid_hspan_alpha_po_subpix +void +blend_solid_hspan_alpha_po_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + rgb_color color = pattern->ColorAt(x, y); + alphaRed = color.alpha * covers[0]; + alphaGreen = color.alpha * covers[1]; + alphaBlue = color.alpha * covers[2]; + BLEND_ALPHA_PO_SUBPIX(p, color.red, color.green, color.blue, + alphaBlue, alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_ALPHA_PO_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolidSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolidSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolidSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,79 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ALPHA in "Constant Overlay" mode on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_ALPHA_PO_SOLID_SUBPIX_H +#define DRAWING_MODE_ALPHA_PO_SOLID_SUBPIX_H + +#include "DrawingModeAlphaPOSUBPIX.h" + +// blend_hline_alpha_po_solid_subpix +void +blend_hline_alpha_po_solid_subpix(int x, int y, unsigned len, + const color_type& c, uint8 cover, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint16 alpha = c.a * cover; + if (alpha == 255 * 255) { + // cache the color as 32bit values + uint32 v; + uint8* p8 = (uint8*)&v; + p8[0] = c.b; + p8[1] = c.g; + p8[2] = c.r; + p8[3] = 255; + // row offset as 32bit pointer + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + *p32 = v; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + if (len < 12) { + do { + BLEND_ALPHA_CO(p, c.r, c.g, c.b, alpha); + x++; + p += 4; + len -= 3; + } while (len); + } else { + alpha = alpha >> 8; + blend_line32(p, len / 3, c.r, c.g, c.b, alpha); + } + } +} + + +// blend_solid_hspan_alpha_po_solid_subpix +void +blend_solid_hspan_alpha_po_solid_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + uint16 alphaRed; + uint16 alphaGreen; + uint16 alphaBlue; + do { + alphaRed = c.a * covers[0]; + alphaGreen = c.a * covers[1]; + alphaBlue = c.a * covers[2]; + BLEND_ALPHA_PO_SUBPIX(p, c.r, c.g, c.b, + alphaBlue, alphaGreen, alphaRed); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_ALPHA_PO_SOLID_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,101 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_ADD on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_BLEND_SUBPIX_H +#define DRAWING_MODE_BLEND_SUBPIX_H + +#include "DrawingMode.h" + + +// BLEND_BLEND_SUBPIX +#define BLEND_BLEND_SUBPIX(d, r, g, b, a1, a2, a3) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + uint8 bt = (_p.data8[0] + (b)) >> 1; \ + uint8 gt = (_p.data8[1] + (g)) >> 1; \ + uint8 rt = (_p.data8[2] + (r)) >> 1; \ + BLEND_SUBPIX(d, rt, gt, bt, a1, a2, a3); \ +} + + +// BLEND_BLEND +#define BLEND_BLEND(d, r, g, b, a) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + uint8 bt = (_p.data8[0] + (b)) >> 1; \ + uint8 gt = (_p.data8[1] + (g)) >> 1; \ + uint8 rt = (_p.data8[2] + (r)) >> 1; \ + BLEND(d, rt, gt, bt, a); \ +} + + +// ASSIGN_BLEND +#define ASSIGN_BLEND(d, r, g, b) \ +{ \ + pixel32 _p; \ + _p.data32 = *(uint32*)d; \ + d[0] = (_p.data8[0] + (b)) >> 1; \ + d[1] = (_p.data8[1] + (g)) >> 1; \ + d[2] = (_p.data8[2] + (r)) >> 1; \ + d[3] = 255; \ +} + + +// blend_hline_blend_subpix +void +blend_hline_blend_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + if (cover == 255) { + do { + rgb_color color = pattern->ColorAt(x, y); + + ASSIGN_BLEND(p, color.red, color.green, color.blue); + + p += 4; + x++; + len -= 3; + } while (len); + } else { + do { + rgb_color color = pattern->ColorAt(x, y); + + BLEND_BLEND(p, color.red, color.green, color.blue, cover); + + p += 4; + x++; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_blend_subpix +void +blend_solid_hspan_blend_subpix(int x, int y, unsigned len, const color_type& c, + const uint8* covers, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_BLEND_SUBPIX(p, color.red, color.green, color.blue, + covers[2], covers[1], covers[0]); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + + +#endif // DRAWING_MODE_BLEND_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,107 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_COPY on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_COPY_SUBPIX_H +#define DRAWING_MODE_COPY_SUBPIX_H + +#include "DrawingMode.h" + +// BLEND_COPY_SUBPIX +#define BLEND_COPY_SUBPIX(d, r2, g2, b2, a1, a2, a3, r1, g1, b1) \ +{ \ + BLEND_FROM_SUBPIX(d, r1, g1, b1, r2, g2, b2, a1, a2, a3); \ +} + + +// BLEND_COPY +#define BLEND_COPY(d, r2, g2, b2, a, r1, g1, b1) \ +{ \ + BLEND_FROM(d, r1, g1, b1, r2, g2, b2, a); \ +} + + +// ASSIGN_COPY +#define ASSIGN_COPY(d, r, g, b, a) \ +{ \ + d[0] = (b); \ + d[1] = (g); \ + d[2] = (r); \ + d[3] = (a); \ +} + + +// blend_hline_copy_subpix +void +blend_hline_copy_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + if (cover == 255) { + // cache the low and high color as 32bit values + // high color + rgb_color color = pattern->HighColor(); + uint32 vh; + uint8* p8 = (uint8*)&vh; + p8[0] = (uint8)color.blue; + p8[1] = (uint8)color.green; + p8[2] = (uint8)color.red; + p8[3] = 255; + // low color + color = pattern->LowColor(); + uint32 vl; + p8 = (uint8*)&vl; + p8[0] = (uint8)color.blue; + p8[1] = (uint8)color.green; + p8[2] = (uint8)color.red; + p8[3] = 255; + // row offset as 32bit pointer + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + if (pattern->IsHighColor(x, y)) + *p32 = vh; + else + *p32 = vl; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + rgb_color l = pattern->LowColor(); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_COPY(p, color.red, color.green, color.blue, cover, + l.red, l.green, l.blue); + x++; + p += 4; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_copy_subpix +void +blend_solid_hspan_copy_subpix(int x, int y, unsigned len, const color_type& c, + const uint8* covers, agg_buffer* buffer, const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + rgb_color l = pattern->LowColor(); + do { + rgb_color color = pattern->ColorAt(x, y); + BLEND_COPY_SUBPIX(p, color.red, color.green, color.blue, + covers[2], covers[1], covers[0], l.red, l.green, l.blue); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_COPY_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolidSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolidSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolidSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,63 @@ +/* + * Copyright 2005, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * DrawingMode implementing B_OP_COPY ignoring the pattern (solid) on B_RGBA32. + * + */ + +#ifndef DRAWING_MODE_COPY_SOLID_SUBPIX_H +#define DRAWING_MODE_COPY_SOLID_SUBPIX_H + +#include "DrawingModeOverSUBPIX.h" + +// blend_hline_copy_solid_subpix +void +blend_hline_copy_solid_subpix(int x, int y, unsigned len, const color_type& c, + uint8 cover, agg_buffer* buffer, const PatternHandler* pattern) +{ + if (cover == 255) { + uint32 v; + uint8* p8 = (uint8*)&v; + p8[0] = (uint8)c.b; + p8[1] = (uint8)c.g; + p8[2] = (uint8)c.r; + p8[3] = 255; + uint32* p32 = (uint32*)(buffer->row_ptr(y)) + x; + do { + *p32 = v; + p32++; + x++; + len -= 3; + } while (len); + } else { + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + BLEND_OVER(p, c.r, c.g, c.b, cover); + x++; + p += 4; + len -= 3; + } while (len); + } +} + + +// blend_solid_hspan_copy_solid_subpix +void +blend_solid_hspan_copy_solid_subpix(int x, int y, unsigned len, + const color_type& c, const uint8* covers, agg_buffer* buffer, + const PatternHandler* pattern) +{ + uint8* p = buffer->row_ptr(y) + (x << 2); + do { + BLEND_OVER_SUBPIX(p, c.r, c.g, c.b, covers[2], covers[1], covers[0]); + covers += 3; + p += 4; + x++; + len -= 3; + } while (len); +} + +#endif // DRAWING_MODE_COPY_SOLID_SUBPIX_H + Added: haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyTextSUBPIX.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyTextSUBPIX.h 2008-07-10 08:06:59 UTC (rev 26354) +++ haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyTextSUBPIX.h 2008-07-10 08:08:59 UTC (rev 26355) @@ -0,0 +1,66 @@ +/* + * Copyright 2006, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * [... truncated: 861 lines follow ...] From stippi at mail.berlios.de Thu Jul 10 10:11:07 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:11:07 +0200 Subject: [Haiku-commits] r26356 - haiku/trunk/headers/libs/agg Message-ID: <200807100811.m6A8B7J7032306@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:11:04 +0200 (Thu, 10 Jul 2008) New Revision: 26356 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26356&view=rev Modified: haiku/trunk/headers/libs/agg/agg_renderer_base.h Log: patch by Andrej Spielmann (GSOC): * Prepared the AGG base_renderer code with two more functions needed to handle subpixel scanline coverage values. Modified: haiku/trunk/headers/libs/agg/agg_renderer_base.h =================================================================== --- haiku/trunk/headers/libs/agg/agg_renderer_base.h 2008-07-10 08:08:59 UTC (rev 26355) +++ haiku/trunk/headers/libs/agg/agg_renderer_base.h 2008-07-10 08:11:04 UTC (rev 26356) @@ -205,7 +205,23 @@ m_ren->blend_hline(x1, y, x2 - x1 + 1, c, cover); } + + //-------------------------------------------------------------------- + void blend_hline_subpix(int x1, int y, int x2, + const color_type& c, cover_type cover) + { + if(x1 > x2) { int t = x2; x2 = x1; x1 = t; } + if(y > ymax()) return; + if(y < ymin()) return; + if(x1 > xmax()) return; + if(x2 < xmin()) return; + if(x1 < xmin()) x1 = xmin(); + if(x2 > xmax()) x2 = xmax(); + + m_ren->blend_hline_subpix(x1, y, x2 - x1 + 1, c, cover); + } + //-------------------------------------------------------------------- void blend_vline(int x, int y1, int y2, const color_type& c, cover_type cover) @@ -280,7 +296,30 @@ } m_ren->blend_solid_hspan(x, y, len, c, covers); } + + //-------------------------------------------------------------------- + void blend_solid_hspan_subpix(int x, int y, int len, + const color_type& c, + const cover_type* covers) + { + if(y > ymax()) return; + if(y < ymin()) return; + if(x < xmin()) + { + len -= 3 * (xmin() - x); + if(len <= 0) return; + covers += 3*(xmin() - x); + x = xmin(); + } + if(x + len / 3 > xmax()) + { + len = 3 * (xmax() - x + 1); + if(len <= 0) return; + } + m_ren->blend_solid_hspan_subpix(x, y, len, c, covers); + } + //-------------------------------------------------------------------- void blend_solid_vspan(int x, int y, int len, const color_type& c, From stippi at mail.berlios.de Thu Jul 10 10:12:41 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:12:41 +0200 Subject: [Haiku-commits] r26357 - haiku/trunk/src/servers/app Message-ID: <200807100812.m6A8Cf62032524@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:12:38 +0200 (Thu, 10 Jul 2008) New Revision: 26357 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26357&view=rev Modified: haiku/trunk/src/servers/app/ServerApp.h Log: patch by Andrej Spielmann (GSOC): Removed trailing whitespace. Modified: haiku/trunk/src/servers/app/ServerApp.h =================================================================== --- haiku/trunk/src/servers/app/ServerApp.h 2008-07-10 08:11:04 UTC (rev 26356) +++ haiku/trunk/src/servers/app/ServerApp.h 2008-07-10 08:12:38 UTC (rev 26357) @@ -98,7 +98,7 @@ bool _HasWindowUnderMouse(); port_id fMessagePort; - port_id fClientReplyPort; + port_id fClientReplyPort; // our BApplication's event port BMessenger fHandlerMessenger; From stippi at mail.berlios.de Thu Jul 10 10:16:02 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:16:02 +0200 Subject: [Haiku-commits] r26358 - in haiku/trunk/src/servers/app: . drawing/Painter Message-ID: <200807100816.m6A8G2W8000035@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:15:59 +0200 (Thu, 10 Jul 2008) New Revision: 26358 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26358&view=rev Added: haiku/trunk/src/servers/app/agg_scanline_u_subpix.h haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h Log: Patch by Andrej Spielmann (GSOC): Two new AGG classes were needed to handle subpixel scanline coverage values. Added: haiku/trunk/src/servers/app/agg_scanline_u_subpix.h =================================================================== --- haiku/trunk/src/servers/app/agg_scanline_u_subpix.h 2008-07-10 08:12:38 UTC (rev 26357) +++ haiku/trunk/src/servers/app/agg_scanline_u_subpix.h 2008-07-10 08:15:59 UTC (rev 26358) @@ -0,0 +1,117 @@ +/* + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) + * + * + * Class scanline_u8_subpix, a slightly modified version of + * scanline_u8 customized to store 3 covers per pixel + * + */ + +#ifndef AGG_SCANLINE_U_SUBPIX_INCLUDED +#define AGG_SCANLINE_U_SUBPIX_INCLUDED + +#include + +namespace agg +{ + //======================================================scanline_u8_subpix + //------------------------------------------------------------------------ + class scanline_u8_subpix + { + public: + typedef scanline_u8_subpix self_type; + typedef int8u cover_type; + typedef int16 coord_type; + + //-------------------------------------------------------------------- + struct span + { + coord_type x; + coord_type len; + cover_type* covers; + }; + + typedef span* iterator; + typedef const span* const_iterator; + + //-------------------------------------------------------------------- + scanline_u8_subpix() : + m_min_x(0), + m_last_x(0x7FFFFFF0), + m_cur_span(0) + {} + + //-------------------------------------------------------------------- + void reset(int min_x, int max_x) + { + unsigned max_len = 3*(max_x - min_x + 2); + if(max_len > m_spans.size()) + { + m_spans.resize(max_len); + m_covers.resize(max_len); + } + m_last_x = 0x7FFFFFF0; + m_min_x = min_x; + m_cur_span = &m_spans[0]; + } + + //-------------------------------------------------------------------- + void add_cell(int x, unsigned cover1, unsigned cover2, unsigned cover3) + { + x -= m_min_x; + m_covers[3*x] = (cover_type)cover1; + m_covers[3*x+1] = (cover_type)cover2; + m_covers[3*x+2] = (cover_type)cover3; + if(x == m_last_x+1) + { + m_cur_span->len += 3; + } + else + { + m_cur_span++; + m_cur_span->x = (coord_type)(x + m_min_x); + m_cur_span->len = 3; + m_cur_span->covers = &m_covers[3*x]; + } + m_last_x = x; + } + + //-------------------------------------------------------------------- + void finalize(int y) + { + m_y = y; + } + + //-------------------------------------------------------------------- + void reset_spans() + { + m_last_x = 0x7FFFFFF0; + m_cur_span = &m_spans[0]; + } + + //-------------------------------------------------------------------- + int y() const { return m_y; } + unsigned num_spans() const { return unsigned(m_cur_span - &m_spans[0]); } + const_iterator begin() const { return &m_spans[1]; } + iterator begin() { return &m_spans[1]; } + + private: + scanline_u8_subpix(const self_type&); + const self_type& operator = (const self_type&); + + private: + int m_min_x; + int m_last_x; + int m_y; + pod_array m_covers; + pod_array m_spans; + span* m_cur_span; + }; + +} + +#endif + Property changes on: haiku/trunk/src/servers/app/agg_scanline_u_subpix.h ___________________________________________________________________ Name: svn:executable + * Added: haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h 2008-07-10 08:12:38 UTC (rev 26357) +++ haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h 2008-07-10 08:15:59 UTC (rev 26358) @@ -0,0 +1,85 @@ +/* + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) + * + * + */ + +#include + +#include "agg_basics.h" +#include "agg_array.h" +#include "agg_renderer_base.h" +#include "agg_renderer_scanline.h" + + +namespace agg +{ + + //============================================render_scanline_subpix_solid + template + void render_scanline_subpix_solid(const Scanline& sl, + BaseRenderer& ren, + const ColorT& color) + { + int y = sl.y(); + unsigned num_spans = sl.num_spans(); + typename Scanline::const_iterator span = sl.begin(); + + for(;;) + { + int x = span->x; + if(span->len > 0) + { + ren.blend_solid_hspan_subpix(x, y, (unsigned)span->len, + color, + span->covers); + } + else + { + ren.blend_hline_subpix(x, y, (unsigned)(x - span->len - 1), + color, + *(span->covers)); + } + if(--num_spans == 0) break; + ++span; + } + } + + + //==========================================renderer_scanline_subpix_solid + template class renderer_scanline_subpix_solid + { + public: + typedef BaseRenderer base_ren_type; + typedef typename base_ren_type::color_type color_type; + + //-------------------------------------------------------------------- + renderer_scanline_subpix_solid() : m_ren(0) {} + renderer_scanline_subpix_solid(base_ren_type& ren) : m_ren(&ren) {} + void attach(base_ren_type& ren) + { + m_ren = &ren; + } + + //-------------------------------------------------------------------- + void color(const color_type& c) { m_color = c; } + const color_type& color() const { return m_color; } + + //-------------------------------------------------------------------- + void prepare() {} + + //-------------------------------------------------------------------- + template void render(const Scanline& sl) + { + render_scanline_subpix_solid(sl, *m_ren, m_color); + } + + private: + base_ren_type* m_ren; + color_type m_color; + }; + +} From stippi at mail.berlios.de Thu Jul 10 10:19:24 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:19:24 +0200 Subject: [Haiku-commits] r26359 - haiku/trunk/src/servers/app Message-ID: <200807100819.m6A8JOOm000306@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:19:22 +0200 (Thu, 10 Jul 2008) New Revision: 26359 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26359&view=rev Added: haiku/trunk/src/servers/app/agg_scanline_storage_subpix.h Log: Patch by Andrej Spielmann (GSOC): Sorry, actually this third AGG class is also needed to handle subpixel scanline coverage. NOTE: I am trying to break up the large patch into digestable pieces. The comments come from me not from Andrej, so I am to blame for any confusion! :-) Added: haiku/trunk/src/servers/app/agg_scanline_storage_subpix.h =================================================================== --- haiku/trunk/src/servers/app/agg_scanline_storage_subpix.h 2008-07-10 08:15:59 UTC (rev 26358) +++ haiku/trunk/src/servers/app/agg_scanline_storage_subpix.h 2008-07-10 08:19:22 UTC (rev 26359) @@ -0,0 +1,682 @@ +/* + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. + * + * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) + * + * + * Class scanline_storage_subpix, a slightly modified version of + * scanline_storage customized to store 3 covers per pixel + * + */ + +#ifndef AGG_SCANLINE_STORAGE_SUBPIX_INCLUDED +#define AGG_SCANLINE_STORAGE_SUBPIX_INCLUDED + +#include +#include +#include +#include "agg_array.h" +#include "agg_scanline_storage_aa.h" + + +namespace agg +{ + //--------------------------------------------scanline_storage_subpix + template class scanline_storage_subpix + { + public: + typedef T cover_type; + + //--------------------------------------------------------------- + struct span_data + { + int32 x; + int32 len; // If negative, it's a solid span, covers is valid + int covers_id; // The index of the cells in the scanline_cell_storage + }; + + //--------------------------------------------------------------- + struct scanline_data + { + int y; + unsigned num_spans; + unsigned start_span; + }; + + + //--------------------------------------------------------------- + class embedded_scanline + { + public: + + //----------------------------------------------------------- + class const_iterator + { + public: + struct span + { + int32 x; + int32 len; // If negative, it's a solid span, covers is valid + const T* covers; + }; + + const_iterator() : m_storage(0) {} + const_iterator(const embedded_scanline& sl) : + m_storage(sl.m_storage), + m_span_idx(sl.m_scanline.start_span) + { + init_span(); + } + + const span& operator*() const { return m_span; } + const span* operator->() const { return &m_span; } + + void operator ++ () + { + ++m_span_idx; + init_span(); + } + + private: + void init_span() + { + const span_data& s = m_storage->span_by_index(m_span_idx); + m_span.x = s.x; + m_span.len = s.len; + m_span.covers = m_storage->covers_by_index(s.covers_id); + } + + const scanline_storage_subpix* m_storage; + unsigned m_span_idx; + span m_span; + }; + + friend class const_iterator; + + + //----------------------------------------------------------- + embedded_scanline(const scanline_storage_subpix& storage) : + m_storage(&storage) + { + init(0); + } + + //----------------------------------------------------------- + void reset(int, int) {} + unsigned num_spans() const { return m_scanline.num_spans; } + int y() const { return m_scanline.y; } + const_iterator begin() const { return const_iterator(*this); } + + //----------------------------------------------------------- + void init(unsigned scanline_idx) + { + m_scanline_idx = scanline_idx; + m_scanline = m_storage->scanline_by_index(m_scanline_idx); + } + + private: + const scanline_storage_subpix* m_storage; + scanline_data m_scanline; + unsigned m_scanline_idx; + }; + + + //--------------------------------------------------------------- + scanline_storage_subpix() : + m_covers(), + m_spans(256-2), // Block increment size + m_scanlines(), + m_min_x( 0x7FFFFFFF), + m_min_y( 0x7FFFFFFF), + m_max_x(-0x7FFFFFFF), + m_max_y(-0x7FFFFFFF), + m_cur_scanline(0) + { + m_fake_scanline.y = 0; + m_fake_scanline.num_spans = 0; + m_fake_scanline.start_span = 0; + m_fake_span.x = 0; + m_fake_span.len = 0; + m_fake_span.covers_id = 0; + } + + // Renderer Interface + //--------------------------------------------------------------- + void prepare() + { + m_covers.remove_all(); + m_scanlines.remove_all(); + m_spans.remove_all(); + m_min_x = 0x7FFFFFFF; + m_min_y = 0x7FFFFFFF; + m_max_x = -0x7FFFFFFF; + m_max_y = -0x7FFFFFFF; + m_cur_scanline = 0; + } + + //--------------------------------------------------------------- + template void render(const Scanline& sl) + { + scanline_data sl_this; + + int y = sl.y(); + if(y < m_min_y) m_min_y = y; + if(y > m_max_y) m_max_y = y; + + sl_this.y = y; + sl_this.num_spans = sl.num_spans(); + sl_this.start_span = m_spans.size(); + typename Scanline::const_iterator span_iterator = sl.begin(); + + unsigned num_spans = sl_this.num_spans; + for(;;) + { + span_data sp; + + sp.x = span_iterator->x; + sp.len = span_iterator->len; + int len = abs(int(sp.len)); + sp.covers_id = + m_covers.add_cells(span_iterator->covers, + (unsigned(len))); + m_spans.add(sp); + int x1 = sp.x; + int x2 = sp.x + len/3 - 1; + if(x1 < m_min_x) m_min_x = x1; + if(x2 > m_max_x) m_max_x = x2; + if(--num_spans == 0) break; + ++span_iterator; + } + m_scanlines.add(sl_this); + } + + + //--------------------------------------------------------------- + // Iterate scanlines interface + int min_x() const { return m_min_x; } + int min_y() const { return m_min_y; } + int max_x() const { return m_max_x; } + int max_y() const { return m_max_y; } + + //--------------------------------------------------------------- + bool rewind_scanlines() + { + m_cur_scanline = 0; + return m_scanlines.size() > 0; + } + + + //--------------------------------------------------------------- + template bool sweep_scanline(Scanline& sl) + { + sl.reset_spans(); + for(;;) + { + if(m_cur_scanline >= m_scanlines.size()) return false; + const scanline_data& sl_this = m_scanlines[m_cur_scanline]; + + unsigned num_spans = sl_this.num_spans; + unsigned span_idx = sl_this.start_span; + do + { + const span_data& sp = m_spans[span_idx++]; + const T* covers = covers_by_index(sp.covers_id); + if(sp.len < 0) + { + sl.add_span(sp.x, unsigned(-sp.len), *covers); + } + else + { + sl.add_cells(sp.x, sp.len, covers); + } + } + while(--num_spans); + ++m_cur_scanline; + if(sl.num_spans()) + { + sl.finalize(sl_this.y); + break; + } + } + return true; + } + + + //--------------------------------------------------------------- + // Specialization for embedded_scanline + bool sweep_scanline(embedded_scanline& sl) + { + do + { + if(m_cur_scanline >= m_scanlines.size()) return false; + sl.init(m_cur_scanline); + ++m_cur_scanline; + } + while(sl.num_spans() == 0); + return true; + } + + //--------------------------------------------------------------- + unsigned byte_size() const + { + unsigned i; + unsigned size = sizeof(int32) * 4; // min_x, min_y, max_x, max_y + + for(i = 0; i < m_scanlines.size(); ++i) + { + size += sizeof(int32) * 3; // scanline size in bytes + + const scanline_data& sl_this = m_scanlines[i]; + + unsigned num_spans = sl_this.num_spans; + unsigned span_idx = sl_this.start_span; + do + { + const span_data& sp = m_spans[span_idx++]; + + size += sizeof(int32) * 2; // X, span_len + if(sp.len < 0) + { + size += sizeof(T); // cover + } + else + { + size += sizeof(T) * unsigned(sp.len); // covers + } + } + while(--num_spans); + } + return size; + } + + + //--------------------------------------------------------------- + static void write_int32(int8u* dst, int32 val) + { + dst[0] = ((const int8u*)&val)[0]; + dst[1] = ((const int8u*)&val)[1]; + dst[2] = ((const int8u*)&val)[2]; + dst[3] = ((const int8u*)&val)[3]; + } + + + //--------------------------------------------------------------- + void serialize(int8u* data) const + { + unsigned i; + + write_int32(data, min_x()); // min_x + data += sizeof(int32); + write_int32(data, min_y()); // min_y + data += sizeof(int32); + write_int32(data, max_x()); // max_x + data += sizeof(int32); + write_int32(data, max_y()); // max_y + data += sizeof(int32); + + for(i = 0; i < m_scanlines.size(); ++i) + { + const scanline_data& sl_this = m_scanlines[i]; + + int8u* size_ptr = data; + data += sizeof(int32); // Reserve space for scanline size in bytes + + write_int32(data, sl_this.y); // Y + data += sizeof(int32); + + write_int32(data, sl_this.num_spans); // num_spans + data += sizeof(int32); + + unsigned num_spans = sl_this.num_spans; + unsigned span_idx = sl_this.start_span; + do + { + const span_data& sp = m_spans[span_idx++]; + const T* covers = covers_by_index(sp.covers_id); + + write_int32(data, sp.x); // X + data += sizeof(int32); + + write_int32(data, sp.len); // span_len + data += sizeof(int32); + + if(sp.len < 0) + { + memcpy(data, covers, sizeof(T)); + data += sizeof(T); + } + else + { + memcpy(data, covers, unsigned(sp.len) * sizeof(T)); + data += sizeof(T) * unsigned(sp.len); + } + } + while(--num_spans); + write_int32(size_ptr, int32(unsigned(data - size_ptr))); + } + } + + + //--------------------------------------------------------------- + const scanline_data& scanline_by_index(unsigned i) const + { + return (i < m_scanlines.size()) ? m_scanlines[i] : m_fake_scanline; + } + + //--------------------------------------------------------------- + const span_data& span_by_index(unsigned i) const + { + return (i < m_spans.size()) ? m_spans[i] : m_fake_span; + } + + //--------------------------------------------------------------- + const T* covers_by_index(int i) const + { + return m_covers[i]; + } + + private: + scanline_cell_storage m_covers; + pod_bvector m_spans; + pod_bvector m_scanlines; + span_data m_fake_span; + scanline_data m_fake_scanline; + int m_min_x; + int m_min_y; + int m_max_x; + int m_max_y; + unsigned m_cur_scanline; + }; + + + typedef scanline_storage_subpix scanline_storage_subpix8; //--------scanline_storage_subpix8 + typedef scanline_storage_subpix scanline_storage_subpix16; //--------scanline_storage_subpix16 + typedef scanline_storage_subpix scanline_storage_subpix32; //--------scanline_storage_subpix32 + + + //--------------------------------------serialized_scanlines_adaptor_subpix + template class serialized_scanlines_adaptor_subpix + { + public: + typedef T cover_type; + + //--------------------------------------------------------------------- + class embedded_scanline + { + public: + typedef T cover_type; + + //----------------------------------------------------------------- + class const_iterator + { + public: + struct span + { + int32 x; + int32 len; // If negative, it's a solid span, "covers" is valid + const T* covers; + }; + + const_iterator() : m_ptr(0) {} + const_iterator(const embedded_scanline& sl) : + m_ptr(sl.m_ptr), + m_dx(sl.m_dx) + { + init_span(); + } + + const span& operator*() const { return m_span; } + const span* operator->() const { return &m_span; } + + void operator ++ () + { + if(m_span.len < 0) + { + m_ptr += sizeof(T); + } + else + { + m_ptr += m_span.len * sizeof(T); + } + init_span(); + } + + private: + int read_int32() + { + int32 val; + ((int8u*)&val)[0] = *m_ptr++; + ((int8u*)&val)[1] = *m_ptr++; + ((int8u*)&val)[2] = *m_ptr++; + ((int8u*)&val)[3] = *m_ptr++; + return val; + } + + void init_span() + { + m_span.x = read_int32() + m_dx; + m_span.len = read_int32(); + m_span.covers = m_ptr; + } + + const int8u* m_ptr; + span m_span; + int m_dx; + }; + + friend class const_iterator; + + + //----------------------------------------------------------------- + embedded_scanline() : m_ptr(0), m_y(0), m_num_spans(0) {} + + //----------------------------------------------------------------- + void reset(int, int) {} + unsigned num_spans() const { return m_num_spans; } + int y() const { return m_y; } + const_iterator begin() const { return const_iterator(*this); } + + + private: + //----------------------------------------------------------------- + int read_int32() + { + int32 val; + ((int8u*)&val)[0] = *m_ptr++; + ((int8u*)&val)[1] = *m_ptr++; + ((int8u*)&val)[2] = *m_ptr++; + ((int8u*)&val)[3] = *m_ptr++; + return val; + } + + public: + //----------------------------------------------------------------- + void init(const int8u* ptr, int dx, int dy) + { + m_ptr = ptr; + m_y = read_int32() + dy; + m_num_spans = unsigned(read_int32()); + m_dx = dx; + } + + private: + const int8u* m_ptr; + int m_y; + unsigned m_num_spans; + int m_dx; + }; + + + + public: + //-------------------------------------------------------------------- + serialized_scanlines_adaptor_subpix() : + m_data(0), + m_end(0), + m_ptr(0), + m_dx(0), + m_dy(0), + m_min_x(0x7FFFFFFF), + m_min_y(0x7FFFFFFF), + m_max_x(-0x7FFFFFFF), + m_max_y(-0x7FFFFFFF) + {} + + //-------------------------------------------------------------------- + serialized_scanlines_adaptor_subpix(const int8u* data, unsigned size, + double dx, double dy) : + m_data(data), + m_end(data + size), + m_ptr(data), + m_dx(iround(dx)), + m_dy(iround(dy)), + m_min_x(0x7FFFFFFF), + m_min_y(0x7FFFFFFF), + m_max_x(-0x7FFFFFFF), + m_max_y(-0x7FFFFFFF) + {} + + //-------------------------------------------------------------------- + void init(const int8u* data, unsigned size, double dx, double dy) + { + m_data = data; + m_end = data + size; + m_ptr = data; + m_dx = iround(dx); + m_dy = iround(dy); + m_min_x = 0x7FFFFFFF; + m_min_y = 0x7FFFFFFF; + m_max_x = -0x7FFFFFFF; + m_max_y = -0x7FFFFFFF; + } + + private: + //-------------------------------------------------------------------- + int read_int32() + { + int32 val; + ((int8u*)&val)[0] = *m_ptr++; + ((int8u*)&val)[1] = *m_ptr++; + ((int8u*)&val)[2] = *m_ptr++; + ((int8u*)&val)[3] = *m_ptr++; + return val; + } + + //-------------------------------------------------------------------- + unsigned read_int32u() + { + int32u val; + ((int8u*)&val)[0] = *m_ptr++; + ((int8u*)&val)[1] = *m_ptr++; + ((int8u*)&val)[2] = *m_ptr++; + ((int8u*)&val)[3] = *m_ptr++; + return val; + } + + public: + // Iterate scanlines interface + //-------------------------------------------------------------------- + bool rewind_scanlines() + { + m_ptr = m_data; + if(m_ptr < m_end) + { + m_min_x = read_int32() + m_dx; + m_min_y = read_int32() + m_dy; + m_max_x = read_int32() + m_dx; + m_max_y = read_int32() + m_dy; + } + return m_ptr < m_end; + } + + //-------------------------------------------------------------------- + int min_x() const { return m_min_x; } + int min_y() const { return m_min_y; } + int max_x() const { return m_max_x; } + int max_y() const { return m_max_y; } + + //-------------------------------------------------------------------- + template bool sweep_scanline(Scanline& sl) + { + sl.reset_spans(); + for(;;) + { + if(m_ptr >= m_end) return false; + + read_int32(); // Skip scanline size in bytes + int y = read_int32() + m_dy; + unsigned num_spans = read_int32(); + + do + { + int x = read_int32() + m_dx; + int len = read_int32(); + + if(len < 0) + { + sl.add_span(x, unsigned(-len), *m_ptr); + m_ptr += sizeof(T); + } + else + { + sl.add_cells(x, len, m_ptr); + m_ptr += len * sizeof(T); + } + } + while(--num_spans); + + if(sl.num_spans()) + { + sl.finalize(y); + break; + } + } + return true; + } + + + //-------------------------------------------------------------------- + // Specialization for embedded_scanline + bool sweep_scanline(embedded_scanline& sl) + { + do + { + if(m_ptr >= m_end) return false; + + unsigned byte_size = read_int32u(); + sl.init(m_ptr, m_dx, m_dy); + m_ptr += byte_size - sizeof(int32); + } + while(sl.num_spans() == 0); + return true; + } + + private: + const int8u* m_data; + const int8u* m_end; + const int8u* m_ptr; + int m_dx; + int m_dy; + int m_min_x; + int m_min_y; + int m_max_x; + int m_max_y; + }; + + + + typedef serialized_scanlines_adaptor_subpix + serialized_scanlines_adaptor_subpix8; //serialized_scanlines_adaptor_subpix8 + + typedef serialized_scanlines_adaptor_subpix + serialized_scanlines_adaptor_subpix16; //serialized_scanlines_adaptor_subpix16 + + typedef serialized_scanlines_adaptor_subpix + serialized_scanlines_adaptor_subpix32; //serialized_scanlines_adaptor_subpix32 + +} + + +#endif + From stippi at mail.berlios.de Thu Jul 10 10:22:45 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:22:45 +0200 Subject: [Haiku-commits] r26360 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807100822.m6A8Mjvg000792@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:22:41 +0200 (Thu, 10 Jul 2008) New Revision: 26360 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26360&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_region.h Log: Patch by Andrej Spielmann (GSOC): * Extend the existing agg_renderer_region with the two new subpixel methods. * Remove trailing whitespace. Modified: haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_region.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_region.h 2008-07-10 08:19:22 UTC (rev 26359) +++ haiku/trunk/src/servers/app/drawing/Painter/agg_renderer_region.h 2008-07-10 08:22:41 UTC (rev 26360) @@ -1,5 +1,6 @@ /* * Copyright 2005-2006, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . * All rights reserved. Distributed under the terms of the MIT License. * * Copyright 2002-2004 Maxim Shemanarev (http://www.antigrain.com) @@ -38,7 +39,7 @@ m_bounds(m_ren.xmin(), m_ren.ymin(), m_ren.xmax(), m_ren.ymax()) { } - + //-------------------------------------------------------------------- const pixfmt_type& ren() const { return m_ren.ren(); } pixfmt_type& ren() { return m_ren.ren(); } @@ -62,7 +63,7 @@ int bounding_ymax() const { return m_bounds.y2; } //-------------------------------------------------------------------- - void first_clip_box() + void first_clip_box() { m_curr_cb = 0; if(m_region && m_region->CountRects() > 0) @@ -75,15 +76,15 @@ } //-------------------------------------------------------------------- - bool next_clip_box() - { + bool next_clip_box() + { if(m_region && (int)(++m_curr_cb) < m_region->CountRects()) { clipping_rect cb = m_region->RectAtInt(m_curr_cb); m_ren.clip_box_naked(cb.left, cb.top, cb.right, cb.bottom); return true; } - return false; + return false; } //-------------------------------------------------------------------- @@ -94,7 +95,7 @@ m_curr_cb = 0; m_bounds = m_ren.clip_box(); } - + //-------------------------------------------------------------------- void set_clipping_region(BRegion* region) { @@ -121,7 +122,7 @@ { m_ren.clear(c); } - + //-------------------------------------------------------------------- void copy_pixel(int x, int y, const color_type& c) { @@ -190,7 +191,7 @@ } //-------------------------------------------------------------------- - void blend_hline(int x1, int y, int x2, + void blend_hline(int x1, int y, int x2, const color_type& c, cover_type cover) { first_clip_box(); @@ -201,8 +202,20 @@ while(next_clip_box()); } + //-------------------------------------------------------------------- + void blend_hline_subpix(int x1, int y, int x2, + const color_type& c, cover_type cover) + { + first_clip_box(); + do + { + m_ren.blend_hline_subpix(x1, y, x2, c, cover); + } + while(next_clip_box()); + } + //-------------------------------------------------------------------- - void blend_vline(int x, int y1, int y2, + void blend_vline(int x, int y1, int y2, const color_type& c, cover_type cover) { first_clip_box(); @@ -225,7 +238,7 @@ } //-------------------------------------------------------------------- - void blend_bar(int x1, int y1, int x2, int y2, + void blend_bar(int x1, int y1, int x2, int y2, const color_type& c, cover_type cover) { first_clip_box(); @@ -238,7 +251,7 @@ //-------------------------------------------------------------------- - void blend_solid_hspan(int x, int y, int len, + void blend_solid_hspan(int x, int y, int len, const color_type& c, const cover_type* covers) { first_clip_box(); @@ -249,8 +262,20 @@ while(next_clip_box()); } + //-------------------------------------------------------------------- + void blend_solid_hspan_subpix(int x, int y, int len, + const color_type& c, const cover_type* covers) + { + first_clip_box(); + do + { + m_ren.blend_solid_hspan_subpix(x, y, len, c, covers); + } + while(next_clip_box()); + } + //-------------------------------------------------------------------- - void blend_solid_vspan(int x, int y, int len, + void blend_solid_vspan(int x, int y, int len, const color_type& c, const cover_type* covers) { first_clip_box(); @@ -262,8 +287,8 @@ } //-------------------------------------------------------------------- - void blend_color_hspan(int x, int y, int len, - const color_type* colors, + void blend_color_hspan(int x, int y, int len, + const color_type* colors, const cover_type* covers, cover_type cover = cover_full) { @@ -276,8 +301,8 @@ } //-------------------------------------------------------------------- - void blend_color_vspan(int x, int y, int len, - const color_type* colors, + void blend_color_vspan(int x, int y, int len, + const color_type* colors, const cover_type* covers, cover_type cover = cover_full) { @@ -290,8 +315,8 @@ } //-------------------------------------------------------------------- - void blend_color_hspan_no_clip(int x, int y, int len, - const color_type* colors, + void blend_color_hspan_no_clip(int x, int y, int len, + const color_type* colors, const cover_type* covers, cover_type cover = cover_full) { @@ -299,8 +324,8 @@ } //-------------------------------------------------------------------- - void blend_color_vspan_no_clip(int x, int y, int len, - const color_type* colors, + void blend_color_vspan_no_clip(int x, int y, int len, + const color_type* colors, const cover_type* covers, cover_type cover = cover_full) { @@ -308,9 +333,9 @@ } //-------------------------------------------------------------------- - void copy_from(const rendering_buffer& from, - const rect_i* rc=0, - int x_to=0, + void copy_from(const rendering_buffer& from, + const rect_i* rc=0, + int x_to=0, int y_to=0) { first_clip_box(); @@ -320,10 +345,10 @@ } while(next_clip_box()); } - + private: renderer_region(const renderer_region&); - const renderer_region& + const renderer_region& operator = (const renderer_region&); base_ren_type m_ren; From stippi at mail.berlios.de Thu Jul 10 10:26:50 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:26:50 +0200 Subject: [Haiku-commits] r26361 - in haiku/trunk/src/servers/app: . drawing/Painter drawing/Painter/drawing_modes Message-ID: <200807100826.m6A8Qocs001490@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:26:38 +0200 (Thu, 10 Jul 2008) New Revision: 26361 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26361&view=rev Modified: haiku/trunk/src/servers/app/FontCacheEntry.cpp haiku/trunk/src/servers/app/FontCacheEntry.h haiku/trunk/src/servers/app/FontEngine.cpp haiku/trunk/src/servers/app/FontEngine.h haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.h haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp haiku/trunk/src/servers/app/drawing/Painter/Painter.h haiku/trunk/src/servers/app/drawing/Painter/defines.h haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/PixelFormat.cpp haiku/trunk/src/servers/app/drawing/Painter/drawing_modes/PixelFormat.h Log: Patch by Andrej Spielmann (GSOC): * Integrate the subpixel rendering with the existing drawing backend and the font rendering. * The font cache has got an additional rendering type for extracting and caching glyph bitmaps that store subpixel coverage values. Modified: haiku/trunk/src/servers/app/FontCacheEntry.cpp =================================================================== --- haiku/trunk/src/servers/app/FontCacheEntry.cpp 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/FontCacheEntry.cpp 2008-07-10 08:26:38 UTC (rev 26361) @@ -5,14 +5,15 @@ * Authors: * Maxim Shemanarev * Stephan A?mus + * Andrej Spielmann, */ //---------------------------------------------------------------------------- // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // @@ -35,7 +36,13 @@ BLocker FontCacheEntry::sUsageUpdateLock("FontCacheEntry usage lock"); +glyph_rendering +FontCacheEntry::sDefaultRenderType; +bool +FontCacheEntry::sDefaultHinting; + + class FontCacheEntry::GlyphCachePool { public: enum block_size_e { block_size = 16384-16 }; @@ -49,7 +56,7 @@ const GlyphCache* FindGlyph(uint16 glyphCode) const { unsigned msb = (glyphCode >> 8) & 0xFF; - if (fGlyphs[msb]) + if (fGlyphs[msb]) return fGlyphs[msb][glyphCode & 0xFF]; return 0; } @@ -120,7 +127,7 @@ // TODO: encoding from font FT_Encoding charMap = FT_ENCODING_NONE; - bool hinting = true; // TODO: font.Hinting(); + bool hinting = sDefaultHinting; // TODO: font.Hinting(); if (!fEngine.Init(font.Path(), 0, font.Size(), charMap, renderingType, hinting)) { @@ -188,6 +195,10 @@ gray8Adapter.init(glyph->data, glyph->data_size, x, y); break; + case glyph_data_subpix: + gray8Adapter.init(glyph->data, glyph->data_size, x, y); + break; + case glyph_data_outline: pathAdapter.init(glyph->data, glyph->data_size, x, y, scale); break; @@ -213,7 +224,7 @@ // TODO: read more of these from the font FT_Encoding charMap = FT_ENCODING_NONE; - bool hinting = true; // TODO: font.Hinting(); + bool hinting = sDefaultHinting; // TODO: font.Hinting(); sprintf(signature, "%ld,%u,%d,%d,%.1f,%d", font.GetFamilyAndStyle(), charMap, @@ -235,15 +246,31 @@ fUseCounter++; } + +void +FontCacheEntry::SetDefaultRenderType(glyph_rendering renderingType) +{ + sDefaultRenderType = renderingType; +} + + +void +FontCacheEntry::SetDefaultHinting(bool hinting) +{ + sDefaultHinting = hinting; +} + + // _RenderTypeFor /*static*/ glyph_rendering FontCacheEntry::_RenderTypeFor(const ServerFont& font) { - glyph_rendering renderingType = glyph_ren_native_gray8; + glyph_rendering renderingType = sDefaultRenderType; if (font.Rotation() != 0.0 || font.Shear() != 90.0 || font.FalseBoldWidth() != 0.0 || font.Flags() & B_DISABLE_ANTIALIASING - || font.Size() > 30) { + || font.Size() > 30 + || !sDefaultHinting) { renderingType = glyph_ren_outline; } return renderingType; Modified: haiku/trunk/src/servers/app/FontCacheEntry.h =================================================================== --- haiku/trunk/src/servers/app/FontCacheEntry.h 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/FontCacheEntry.h 2008-07-10 08:26:38 UTC (rev 26361) @@ -5,6 +5,7 @@ * Authors: * Maxim Shemanarev * Stephan A?mus + * Andrej Spielmann, */ //---------------------------------------------------------------------------- @@ -60,6 +61,7 @@ typedef GlyphGray8Adapter::embedded_scanline GlyphGray8Scanline; typedef FontEngine::MonoAdapter GlyphMonoAdapter; typedef GlyphMonoAdapter::embedded_scanline GlyphMonoScanline; + typedef FontEngine::SubpixAdapter SubpixAdapter; typedef agg::conv_curve CurveConverter; typedef agg::conv_contour ContourConverter; @@ -92,6 +94,13 @@ static void GenerateSignature(char* signature, const ServerFont& font); + + static void SetDefaultRenderType(glyph_rendering renderType); + static glyph_rendering DefaultRenderType() + { return sDefaultRenderType; } + static void SetDefaultHinting(bool hinting); + static bool DefaultHinting() + { return sDefaultHinting; } // private to FontCache class: void UpdateUsage(); @@ -110,6 +119,8 @@ GlyphCachePool* fGlyphCache; FontEngine fEngine; + static glyph_rendering sDefaultRenderType; + static bool sDefaultHinting; static BLocker sUsageUpdateLock; bigtime_t fLastUsedTime; Modified: haiku/trunk/src/servers/app/FontEngine.cpp =================================================================== --- haiku/trunk/src/servers/app/FontEngine.cpp 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/FontEngine.cpp 2008-07-10 08:26:38 UTC (rev 26361) @@ -6,14 +6,15 @@ * Maxim Shemanarev * Stephan A?mus * Anthony Lee + * Andrej Spielmann, */ //---------------------------------------------------------------------------- // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // @@ -26,12 +27,18 @@ #include "FontEngine.h" +#include FT_GLYPH_H +#include FT_OUTLINE_H +#include FT_LCD_FILTER_H + #include #include #include + + static const bool kFlipY = true; @@ -54,7 +61,7 @@ template bool decompose_ft_outline(const FT_Outline& outline, bool flip_y, PathStorage& path) -{ +{ typedef typename PathStorage::value_type value_type; FT_Vector v_last; @@ -114,7 +121,7 @@ x1 = int26p6_to_dbl(v_start.x); y1 = int26p6_to_dbl(v_start.y); if (flip_y) y1 = -y1; - path.move_to(value_type(dbl_to_int26p6(x1)), + path.move_to(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1))); while(point < limit) { @@ -127,7 +134,7 @@ x1 = int26p6_to_dbl(point->x); y1 = int26p6_to_dbl(point->y); if (flip_y) y1 = -y1; - path.line_to(value_type(dbl_to_int26p6(x1)), + path.line_to(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1))); //path.line_to(conv(point->x), flip_y ? -conv(point->y) : conv(point->y)); continue; @@ -155,9 +162,9 @@ x2 = int26p6_to_dbl(vec.x); y2 = int26p6_to_dbl(vec.y); if (flip_y) { y1 = -y1; y2 = -y2; } - path.curve3(value_type(dbl_to_int26p6(x1)), + path.curve3(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1)), - value_type(dbl_to_int26p6(x2)), + value_type(dbl_to_int26p6(x2)), value_type(dbl_to_int26p6(y2))); continue; } @@ -173,14 +180,14 @@ x2 = int26p6_to_dbl(v_middle.x); y2 = int26p6_to_dbl(v_middle.y); if (flip_y) { y1 = -y1; y2 = -y2; } - path.curve3(value_type(dbl_to_int26p6(x1)), + path.curve3(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1)), - value_type(dbl_to_int26p6(x2)), + value_type(dbl_to_int26p6(x2)), value_type(dbl_to_int26p6(y2))); - //path.curve3(conv(v_control.x), - // flip_y ? -conv(v_control.y) : conv(v_control.y), - // conv(v_middle.x), + //path.curve3(conv(v_control.x), + // flip_y ? -conv(v_control.y) : conv(v_control.y), + // conv(v_middle.x), // flip_y ? -conv(v_middle.y) : conv(v_middle.y)); v_control = vec; @@ -192,14 +199,14 @@ x2 = int26p6_to_dbl(v_start.x); y2 = int26p6_to_dbl(v_start.y); if (flip_y) { y1 = -y1; y2 = -y2; } - path.curve3(value_type(dbl_to_int26p6(x1)), + path.curve3(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1)), - value_type(dbl_to_int26p6(x2)), + value_type(dbl_to_int26p6(x2)), value_type(dbl_to_int26p6(y2))); - //path.curve3(conv(v_control.x), - // flip_y ? -conv(v_control.y) : conv(v_control.y), - // conv(v_start.x), + //path.curve3(conv(v_control.x), + // flip_y ? -conv(v_control.y) : conv(v_control.y), + // conv(v_start.x), // flip_y ? -conv(v_start.y) : conv(v_start.y)); goto Close; } @@ -210,9 +217,9 @@ if (point + 1 > limit || FT_CURVE_TAG(tags[1]) != FT_CURVE_TAG_CUBIC) return false; - vec1.x = point[0].x; + vec1.x = point[0].x; vec1.y = point[0].y; - vec2.x = point[1].x; + vec2.x = point[1].x; vec2.y = point[1].y; point += 2; @@ -231,18 +238,18 @@ x3 = int26p6_to_dbl(vec.x); y3 = int26p6_to_dbl(vec.y); if (flip_y) { y1 = -y1; y2 = -y2; y3 = -y3; } - path.curve4(value_type(dbl_to_int26p6(x1)), + path.curve4(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1)), - value_type(dbl_to_int26p6(x2)), + value_type(dbl_to_int26p6(x2)), value_type(dbl_to_int26p6(y2)), - value_type(dbl_to_int26p6(x3)), + value_type(dbl_to_int26p6(x3)), value_type(dbl_to_int26p6(y3))); - //path.curve4(conv(vec1.x), - // flip_y ? -conv(vec1.y) : conv(vec1.y), - // conv(vec2.x), + //path.curve4(conv(vec1.x), + // flip_y ? -conv(vec1.y) : conv(vec1.y), + // conv(vec2.x), // flip_y ? -conv(vec2.y) : conv(vec2.y), - // conv(vec.x), + // conv(vec.x), // flip_y ? -conv(vec.y) : conv(vec.y)); continue; } @@ -254,18 +261,18 @@ x3 = int26p6_to_dbl(v_start.x); y3 = int26p6_to_dbl(v_start.y); if (flip_y) { y1 = -y1; y2 = -y2; y3 = -y3; } - path.curve4(value_type(dbl_to_int26p6(x1)), + path.curve4(value_type(dbl_to_int26p6(x1)), value_type(dbl_to_int26p6(y1)), - value_type(dbl_to_int26p6(x2)), + value_type(dbl_to_int26p6(x2)), value_type(dbl_to_int26p6(y2)), - value_type(dbl_to_int26p6(x3)), + value_type(dbl_to_int26p6(x3)), value_type(dbl_to_int26p6(y3))); - //path.curve4(conv(vec1.x), - // flip_y ? -conv(vec1.y) : conv(vec1.y), - // conv(vec2.x), + //path.curve4(conv(vec1.x), + // flip_y ? -conv(vec1.y) : conv(vec1.y), + // conv(vec2.x), // flip_y ? -conv(vec2.y) : conv(vec2.y), - // conv(v_start.x), + // conv(v_start.x), // flip_y ? -conv(v_start.y) : conv(v_start.y)); goto Close; } @@ -275,12 +282,13 @@ path.close_polygon(); Close: - first = last + 1; + first = last + 1; } return true; } + // decompose_ft_bitmap_mono template void @@ -314,6 +322,7 @@ } } + // decompose_ft_bitmap_gray8 template void @@ -360,6 +369,142 @@ } +// decompose_ft_bitmap_subpix +template +void +decompose_ft_bitmap_subpix(const FT_Bitmap& bitmap, int x, int y, + bool flip_y, Scanline& sl, ScanlineStorage& storage) +{ + //Filtering weights + const uint8 filter[5] = { 0x10, 0x40, 0x70, 0x40, 0x10 }; + + int i, j; + const uint8* buf = (const uint8*)bitmap.buffer; + int pitch = bitmap.pitch; + sl.reset(x-1, x + bitmap.width/3 + 1); + storage.prepare(); + if (flip_y) { + buf += bitmap.pitch * (bitmap.rows - 1); + y += bitmap.rows; + pitch = -pitch; + } + for (i = 0; i < bitmap.rows; i++) { + sl.reset_spans(); + + if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { + // font has built-in mono bitmap + agg::bitset_iterator bits(buf, 0); + int j; + for (j = 0; j < bitmap.width; j++) { + if (bits.bit()) + sl.add_cell(x + j, + agg::cover_full, agg::cover_full, agg::cover_full); + ++bits; + } + } else { + const uint8* p = buf; + uint32 coverRed; + uint32 coverGreen; + uint32 coverBlue; + int w = bitmap.width/3; + if (w && !(p[0] == p[1] && p[1] == p[2] + && (w == 1 || (p[3] == p[4] && p[4] == p[5])))){ + coverRed = 0; + coverGreen = (p[0] * filter[0]) >> 8; + coverBlue = (p[0] * filter[1] + p[1] * filter[0]) >> 8; + coverGreen = coverGreen | ( -(coverGreen >> 8)); + coverBlue = coverBlue | ( -(coverBlue >> 8)); + if (coverRed || coverGreen || coverBlue){ + sl.add_cell(x - 1, coverRed, coverGreen, coverBlue); + } + } + for (j = 0; j < w; j++) { + if (p[0] == p[1] && p[1] == p[2] + && (j == 0 || (p[-3] == p[-2] && p[-2] == p[-1])) + && (j == w-1 || (p[3] == p[4] && p[4] == p[5]))){ + coverRed = p[0]; + coverGreen = p[0]; + coverBlue = p[0]; + } else if (p[0] == p[1] && p[1] == p[2] + && (j < w-1 && p[3] == p[4] && p[4] == p[5]) + && (j == w-2 || (p[6] == p[7] && p[7] == p[8]))){ + coverRed = ((j > 0 ? p[-2] * filter[4] + + p[-1] * filter[3] : 0) + + p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) + >> 8; + coverGreen = ((j > 0 ? p[-1] * filter[4] : 0) + + p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1]) + >> 8; + coverBlue = (p[0] * filter[4] + + p[1] * filter[3] + p[2] * filter[2]) >> 8; + coverRed = coverRed | ( -(coverRed >> 8)); + coverGreen = coverGreen | ( -(coverGreen >> 8)); + coverBlue = coverBlue | ( -(coverBlue >> 8)); + } else if (p[0] == p[1] && p[1] == p[2] + && (j > 0 && p[-3] == p[-2] && p[-2] == p[-1]) + && (j == 1 || (p[-6] == p[-5] && p[-5] == p[-4]))){ + coverRed = (p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) >> 8; + coverGreen = (p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1] + + (j < w-1 ? p[3] * filter[0] : 0)) + >> 8; + coverBlue = (p[0] * filter[4] + p[1] * filter[3] + + p[2] * filter[2] + + (j < w-1 ? p[3] * filter[1] + + p[4] * filter[0] : 0)) + >> 8; + coverRed = coverRed | ( -(coverRed >> 8)); + coverGreen = coverGreen | ( -(coverGreen >> 8)); + coverBlue = coverBlue | ( -(coverBlue >> 8)); + } else { + coverRed = ((j > 0 ? p[-2] * filter[4] + + p[-1] * filter[3] : 0) + + p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) + >> 8; + coverGreen = ((j > 0 ? p[-1] * filter[4] : 0) + + p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1] + + (j < w-1 ? p[3] * filter[0] : 0)) + >> 8; + coverBlue = (p[0] * filter[4] + p[1] * filter[3] + + p[2] * filter[2] + + (j < w-1 ? p[3] * filter[1] + + p[4] * filter[0] : 0)) + >> 8; + coverRed = coverRed | ( -(coverRed >> 8)); + coverGreen = coverGreen | ( -(coverGreen >> 8)); + coverBlue = coverBlue | ( -(coverBlue >> 8)); + } + if (coverRed || coverGreen || coverBlue) { + sl.add_cell(x + j, coverRed, coverGreen, coverBlue); + } + p += 3; + } + if (w && !(p[-3] == p[-2] && p[-2] == p[-1] + && (w == 1 || (p[-6] == p[-5] && p[-5] == p[-4])))){ + coverRed = (p[-2] * filter[4] + p[-1] * filter[3]) >> 8; + coverGreen = (p[-1] * filter[4]) >> 8; + coverBlue = 0; + coverRed = coverRed | ( -(coverRed >> 8)); + coverGreen = coverGreen | ( -(coverGreen >> 8)); + if (coverRed || coverGreen || coverBlue){ + sl.add_cell(x + w, coverRed, coverGreen, coverBlue); + } + } + } + + buf += pitch; + if (sl.num_spans()) { + sl.finalize(y - i - 1); + storage.render(sl); + } + } +} + // #pragma mark - @@ -386,8 +531,10 @@ , fCurves(fPath) , fScanlineAA() , fScanlineBin() + , fScanlineSubpix() , fScanlineStorageAA() , fScanlineStorageBin() + , fScanlineStorageSubpix() { fCurves.approximation_scale(4.0); @@ -396,6 +543,7 @@ fLibraryInitialized = true; } + // destructor FontEngine::~FontEngine() { @@ -405,6 +553,7 @@ FT_Done_FreeType(fLibrary); } + // CountFaces unsigned FontEngine::CountFaces() const @@ -415,14 +564,14 @@ return 0; } + // PrepareGlyph bool FontEngine::PrepareGlyph(unsigned glyphCode) { fGlyphIndex = FT_Get_Char_Index(fFace, glyphCode); fLastError = FT_Load_Glyph(fFace, fGlyphIndex, - fHinting ? FT_LOAD_DEFAULT : FT_LOAD_NO_HINTING); -// fHinting ? FT_LOAD_FORCE_AUTOHINT : FT_LOAD_NO_HINTING); + (fHinting ? (FT_LOAD_DEFAULT | FT_LOAD_TARGET_LCD) : FT_LOAD_NO_HINTING)); if (fLastError != 0) return false; @@ -430,7 +579,7 @@ fAdvanceX = int26p6_to_dbl(fFace->glyph->advance.x); fAdvanceY = int26p6_to_dbl(fFace->glyph->advance.y); fInsetLeft = int26p6_to_dbl(fFace->glyph->metrics.horiBearingX); - fInsetRight = int26p6_to_dbl(fFace->glyph->metrics.horiBearingX + fInsetRight = int26p6_to_dbl(fFace->glyph->metrics.horiBearingX + fFace->glyph->metrics.width - fFace->glyph->metrics.horiAdvance); switch(fGlyphRendering) { @@ -445,17 +594,17 @@ fBounds.y1 = fScanlineStorageBin.min_y(); fBounds.x2 = fScanlineStorageBin.max_x(); fBounds.y2 = fScanlineStorageBin.max_y(); - fDataSize = fScanlineStorageBin.byte_size(); + fDataSize = fScanlineStorageBin.byte_size(); fDataType = glyph_data_mono; return true; } break; - - + + case glyph_ren_native_gray8: fLastError = FT_Render_Glyph(fFace->glyph, FT_RENDER_MODE_NORMAL); if (fLastError == 0) { - decompose_ft_bitmap_gray8(fFace->glyph->bitmap, + decompose_ft_bitmap_gray8(fFace->glyph->bitmap, fFace->glyph->bitmap_left, kFlipY ? -fFace->glyph->bitmap_top : fFace->glyph->bitmap_top, kFlipY, fScanlineAA, fScanlineStorageAA); @@ -463,13 +612,31 @@ fBounds.y1 = fScanlineStorageAA.min_y(); fBounds.x2 = fScanlineStorageAA.max_x(); fBounds.y2 = fScanlineStorageAA.max_y(); - fDataSize = fScanlineStorageAA.byte_size(); + fDataSize = fScanlineStorageAA.byte_size(); fDataType = glyph_data_gray8; return true; } break; - - + + + case glyph_ren_subpix: + fLastError = FT_Render_Glyph(fFace->glyph, FT_RENDER_MODE_LCD); + if (fLastError == 0) { + decompose_ft_bitmap_subpix(fFace->glyph->bitmap, + fFace->glyph->bitmap_left, kFlipY ? + -fFace->glyph->bitmap_top : fFace->glyph->bitmap_top, + kFlipY, fScanlineSubpix, fScanlineStorageSubpix); + fBounds.x1 = fScanlineStorageSubpix.min_x(); + fBounds.y1 = fScanlineStorageSubpix.min_y(); + fBounds.x2 = fScanlineStorageSubpix.max_x(); + fBounds.y2 = fScanlineStorageSubpix.max_y(); + fDataSize = fScanlineStorageSubpix.byte_size(); + fDataType = glyph_data_subpix; + return true; + } + break; + + case glyph_ren_outline: fPath.remove_all(); if (decompose_ft_outline(fFace->glyph->outline, kFlipY, fPath)) { @@ -500,20 +667,25 @@ break; case glyph_data_gray8: - fScanlineStorageAA.serialize(data); + fScanlineStorageAA.serialize(data); break; - case glyph_data_outline: + case glyph_data_subpix: + fScanlineStorageSubpix.serialize(data); + break; + + case glyph_data_outline: fPath.serialize(data); break; - case glyph_data_invalid: + case glyph_data_invalid: default: break; } } } + // GetKerning bool FontEngine::GetKerning(unsigned first, unsigned second, @@ -561,7 +733,7 @@ if (fLastError != 0) return false; - + switch(ren_type) { case glyph_ren_native_mono: fGlyphRendering = glyph_ren_native_mono; @@ -571,6 +743,10 @@ fGlyphRendering = glyph_ren_native_gray8; break; + case glyph_ren_subpix: + fGlyphRendering = glyph_ren_subpix; + break; + case glyph_ren_outline: if (FT_IS_SCALABLE(fFace)) fGlyphRendering = glyph_ren_outline; Modified: haiku/trunk/src/servers/app/FontEngine.h =================================================================== --- haiku/trunk/src/servers/app/FontEngine.h 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/FontEngine.h 2008-07-10 08:26:38 UTC (rev 26361) @@ -5,14 +5,15 @@ * Authors: * Maxim Shemanarev * Stephan A?mus + * Andrej Spielmann, */ //---------------------------------------------------------------------------- // Anti-Grain Geometry - Version 2.4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) // -// Permission to copy, use, modify, sell and distribute this software -// is granted provided this copyright notice appears in all copies. +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. // This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // @@ -39,11 +40,15 @@ #include #include +#include "agg_scanline_storage_subpix.h" +#include "agg_scanline_u_subpix.h" + enum glyph_rendering { glyph_ren_native_mono, glyph_ren_native_gray8, glyph_ren_outline, + glyph_ren_subpix }; @@ -51,15 +56,18 @@ glyph_data_invalid = 0, glyph_data_mono = 1, glyph_data_gray8 = 2, - glyph_data_outline = 3 + glyph_data_outline = 3, + glyph_data_subpix = 4 }; class FontEngine { public: + typedef agg::serialized_scanlines_adaptor_subpix SubpixAdapter; typedef agg::serialized_scanlines_adaptor_aa Gray8Adapter; typedef agg::serialized_scanlines_adaptor_bin MonoAdapter; typedef agg::scanline_storage_aa8 ScanlineStorageAA; + typedef agg::scanline_storage_subpix8 ScanlineStorageSubpix; typedef agg::scanline_storage_bin ScanlineStorageBin; typedef agg::serialized_integer_path_adaptor PathAdapter; @@ -113,12 +121,12 @@ int fLastError; bool fLibraryInitialized; - FT_Library fLibrary; // handle to library + FT_Library fLibrary; // handle to library FT_Face fFace; // FreeType font face handle glyph_rendering fGlyphRendering; bool fHinting; - + // members needed to generate individual glyphs according // to glyph rendering type unsigned fGlyphIndex; @@ -131,7 +139,7 @@ double fInsetRight; // these members are for caching memory allocations - // when rendering glyphs + // when rendering glyphs typedef agg::path_storage_integer PathStorageType; typedef agg::conv_curve CurveConverterType; @@ -139,9 +147,11 @@ CurveConverterType fCurves; agg::scanline_u8 fScanlineAA; agg::scanline_bin fScanlineBin; - + agg::scanline_u8_subpix fScanlineSubpix; + ScanlineStorageAA fScanlineStorageAA; ScanlineStorageBin fScanlineStorageBin; + ScanlineStorageSubpix fScanlineStorageSubpix; }; Modified: haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.cpp 2008-07-10 08:26:38 UTC (rev 26361) @@ -1,6 +1,7 @@ /* - * Copyright 2005-2007, Stephan A?mus . All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2005-2007, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. */ @@ -29,19 +30,22 @@ // constructor -AGGTextRenderer::AGGTextRenderer(renderer_type& solidRenderer, - renderer_bin_type& binRenderer, scanline_unpacked_type& scanline) +AGGTextRenderer::AGGTextRenderer(renderer_subpix_type& subpixRenderer, + renderer_type& solidRenderer, renderer_bin_type& binRenderer, + scanline_unpacked_type& scanline) : fPathAdaptor() , fGray8Adaptor() , fGray8Scanline() , fMonoAdaptor() , fMonoScanline() + , fSubpixAdaptor() , fCurves(fPathAdaptor) , fContour(fCurves) , fSolidRenderer(solidRenderer) , fBinRenderer(binRenderer) + , fSubpixRenderer(subpixRenderer) , fScanline(scanline) , fRasterizer() @@ -175,7 +179,7 @@ // the glyph is different depending on wether we // deal with non-(rotated/sheared) text, in which // case we have a native FT bitmap. For rotated or - // sheared text, we use AGG vector outlines and + // sheared text, we use AGG vector outlines and // a transformation pipeline, which will be applied // _after_ we retrieve the outline, and that's why // we simply pass x and y, which are untransformed. @@ -210,15 +214,21 @@ if (fClippingFrame.Intersects(glyphBounds)) { switch (glyph->data_type) { case glyph_data_mono: - agg::render_scanlines(fRenderer.fMonoAdaptor, + agg::render_scanlines(fRenderer.fMonoAdaptor, fRenderer.fMonoScanline, fRenderer.fBinRenderer); break; case glyph_data_gray8: - agg::render_scanlines(fRenderer.fGray8Adaptor, + agg::render_scanlines(fRenderer.fGray8Adaptor, fRenderer.fGray8Scanline, fRenderer.fSolidRenderer); break; + case glyph_data_subpix: + agg::render_scanlines(fRenderer.fGray8Adaptor, + fRenderer.fGray8Scanline, + fRenderer.fSubpixRenderer); + break; + case glyph_data_outline: { fVector = true; if (fRenderer.fContour.width() == 0.0) { Modified: haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.h =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.h 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/drawing/Painter/AGGTextRenderer.h 2008-07-10 08:26:38 UTC (rev 26361) @@ -1,6 +1,7 @@ /* - * Copyright 2005-2007, Stephan A?mus . All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2005-2007, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef AGG_TEXT_RENDERER_H #define AGG_TEXT_RENDERER_H @@ -21,7 +22,8 @@ class AGGTextRenderer { public: - AGGTextRenderer(renderer_type& solidRenderer, + AGGTextRenderer(renderer_subpix_type& subpixRenderer, + renderer_type& solidRenderer, renderer_bin_type& binRenderer, scanline_unpacked_type& scanline); virtual ~AGGTextRenderer(); @@ -62,12 +64,14 @@ FontCacheEntry::GlyphGray8Scanline fGray8Scanline; FontCacheEntry::GlyphMonoAdapter fMonoAdaptor; FontCacheEntry::GlyphMonoScanline fMonoScanline; + FontCacheEntry::SubpixAdapter fSubpixAdaptor; FontCacheEntry::CurveConverter fCurves; FontCacheEntry::ContourConverter fContour; renderer_type& fSolidRenderer; renderer_bin_type& fBinRenderer; + renderer_subpix_type& fSubpixRenderer; scanline_unpacked_type& fScanline; rasterizer_type fRasterizer; // NOTE: the object has it's own rasterizer object Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-10 08:22:41 UTC (rev 26360) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-10 08:26:38 UTC (rev 26361) @@ -1,6 +1,7 @@ /* - * Copyright 2005-2007, Stephan A?mus . All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2005-2007, Stephan A?mus . + * Copyright 2008, Andrej Spielmann . + * All rights reserved. Distributed under the terms of the MIT License. * * API to the Anti-Grain Geometry based "Painter" drawing backend. Manages * rendering pipe-lines for stroke, fills, bitmap and text rendering. @@ -64,6 +65,7 @@ fUnpackedScanline(), fPackedScanline(), fRasterizer(), + fSubpixRenderer(fBaseRenderer), fRenderer(fBaseRenderer), fRendererBin(fBaseRenderer), @@ -74,6 +76,7 @@ fValidClipping(false), fDrawingText(false), fAttached(false), + fSubpixelAntialias(true), fPenSize(1.0), fClippingRegion(NULL), @@ -85,7 +88,7 @@ fMiterLimit(B_DEFAULT_MITER_LIMIT), fPatternHandler(), - fTextRenderer(fRenderer, fRendererBin, fUnpackedScanline) + fTextRenderer(fSubpixRenderer, fRenderer, fRendererBin, fUnpackedScanline) { fPixelFormat.SetDrawingMode(fDrawingMode, fAlphaSrcMode, fAlphaFncMode, false); @@ -230,6 +233,14 @@ } } +void +Painter::SetSubpixelAntialiasing(bool subpixelAntialias) +{ + if (fSubpixelAntialias != subpixelAntialias) { + fSubpixelAntialias = subpixelAntialias; + } +} + // SetBlendingMode void Painter::SetBlendingMode(source_alpha srcAlpha, alpha_function alphaFunc) @@ -322,7 +333,7 @@ return; } } - + fPath.remove_all(); if (a == b) { @@ -381,7 +392,7 @@ a.y++; } } - + fPath.move_to(a.x, a.y); fPath.line_to(b.x, b.y); @@ -685,8 +696,8 @@ return _Clipped(rect); } } - + // account for stricter interpretation of coordinates in AGG // the rectangle ranges from the top-left (.0, .0) // to the bottom-right (.9999, .9999) corner of pixels @@ -787,7 +798,7 @@ agg::rounded_rect rect; rect.rect(lt.x, lt.y, rb.x, rb.y); rect.radius(xRadius, yRadius); - + return _StrokePath(rect); } else { // NOTE: This implementation might seem a little strange, but it makes @@ -796,10 +807,10 @@ // The fact that the bounding box of the round rect is not enlarged // by fPenSize/2 is actually on purpose, though one could argue it is unexpected. - // enclose the right and bottom edge + // enclose the right and bottom edge rb.x++; rb.y++; - + agg::rounded_rect outer; outer.rect(lt.x, lt.y, rb.x, rb.y); outer.radius(xRadius, yRadius); @@ -813,10 +824,10 @@ agg::rounded_rect inner; inner.rect(lt.x + fPenSize, lt.y + fPenSize, rb.x - fPenSize, rb.y - fPenSize); inner.radius(max_c(0.0, xRadius - fPenSize), max_c(0.0, yRadius - fPenSize)); - + fRasterizer.add_path(inner); } - + // make the inner rect work as a hole fRasterizer.filling_rule(agg::fill_even_odd); @@ -824,10 +835,10 @@ agg::render_scanlines(fRasterizer, fPackedScanline, fRenderer); else agg::render_scanlines(fRasterizer, fUnpackedScanline, fRenderer); - + // reset to default fRasterizer.filling_rule(agg::fill_non_zero); - + return _Clipped(_BoundingBox(outer)); [... truncated: 468 lines follow ...] From stippi at mail.berlios.de Thu Jul 10 10:30:00 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:30:00 +0200 Subject: [Haiku-commits] r26362 - in haiku/trunk: headers/private/app src/servers/app Message-ID: <200807100830.m6A8U0S4001574@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:29:50 +0200 (Thu, 10 Jul 2008) New Revision: 26362 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26362&view=rev Modified: haiku/trunk/headers/private/app/ServerProtocol.h haiku/trunk/src/servers/app/Desktop.cpp haiku/trunk/src/servers/app/Desktop.h haiku/trunk/src/servers/app/DesktopSettings.cpp haiku/trunk/src/servers/app/DesktopSettings.h haiku/trunk/src/servers/app/DesktopSettingsPrivate.h haiku/trunk/src/servers/app/ProfileMessageSupport.cpp haiku/trunk/src/servers/app/ServerApp.cpp Log: Patch by Andrej Spielmann (GSOC): * Extend the app_server protocol by configuration options to turn subpixel font rendering on/off and also make the glyph hinting optional (aligning of glyph shapes to the pixel grid). * Implement the setting in the app_server and also handle the persistency. Modified: haiku/trunk/headers/private/app/ServerProtocol.h =================================================================== --- haiku/trunk/headers/private/app/ServerProtocol.h 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/headers/private/app/ServerProtocol.h 2008-07-10 08:29:50 UTC (rev 26362) @@ -6,6 +6,7 @@ * DarkWyrm * J?r?me Duval, jerome.duval at free.fr * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #ifndef APP_SERVER_PROTOCOL_H #define APP_SERVER_PROTOCOL_H @@ -188,6 +189,11 @@ AS_GET_SHOW_ALL_DRAGGERS, AS_SET_SHOW_ALL_DRAGGERS, + AS_SET_FONT_SUBPIXEL_ANTIALIASING, + AS_GET_FONT_SUBPIXEL_ANTIALIASING, + AS_SET_HINTING, + AS_GET_HINTING, + // Graphics calls AS_SET_HIGH_COLOR, AS_SET_LOW_COLOR, Modified: haiku/trunk/src/servers/app/Desktop.cpp =================================================================== --- haiku/trunk/src/servers/app/Desktop.cpp 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/Desktop.cpp 2008-07-10 08:29:50 UTC (rev 26362) @@ -6,6 +6,7 @@ * Adrian Oanca * Stephan A?mus * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ /*! Class used to encapsulate desktop management */ @@ -2462,6 +2463,14 @@ void +Desktop::Redraw() +{ + BRegion dirty(fVirtualScreen.Frame()); + MarkDirty(dirty); +} + + +void Desktop::_RebuildClippingForAllWindows(BRegion& stillAvailableOnScreen) { // the available region on screen starts with the entire screen area Modified: haiku/trunk/src/servers/app/Desktop.h =================================================================== --- haiku/trunk/src/servers/app/Desktop.h 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/Desktop.h 2008-07-10 08:29:50 UTC (rev 26362) @@ -6,6 +6,7 @@ * Adrian Oanca * Stephan A?mus * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #ifndef DESKTOP_H #define DESKTOP_H @@ -190,6 +191,7 @@ #endif // USE_MULTI_LOCKER void MarkDirty(BRegion& region); + void Redraw(); BRegion& BackgroundRegion() { return fBackgroundRegion; } Modified: haiku/trunk/src/servers/app/DesktopSettings.cpp =================================================================== --- haiku/trunk/src/servers/app/DesktopSettings.cpp 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/DesktopSettings.cpp 2008-07-10 08:29:50 UTC (rev 26362) @@ -5,12 +5,15 @@ * Authors: * Stephan A?mus * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #include "DesktopSettings.h" #include "DesktopSettingsPrivate.h" #include "Desktop.h" +#include "FontCache.h" +#include "FontCacheEntry.h" #include "FontManager.h" #include "ServerConfig.h" @@ -60,7 +63,7 @@ strlcpy(fMenuInfo.f_style, fPlainFont.Style(), B_FONT_STYLE_LENGTH); fMenuInfo.font_size = fPlainFont.Size(); fMenuInfo.background_color.set_to(216, 216, 216); - + fMenuInfo.separator = 0; // look of the separator (R5: (0, 1, 2), default 0) fMenuInfo.click_to_open = true; // always true @@ -69,6 +72,11 @@ fWorkspacesCount = 4; memcpy(fShared.colors, BPrivate::kDefaultColors, sizeof(rgb_color) * kNumColors); + + fFontSubpixelAntialiasing = false; + FontCacheEntry::SetDefaultRenderType(glyph_ren_native_gray8); + fHinting = true; + FontCacheEntry::SetDefaultHinting(true); } @@ -101,7 +109,7 @@ BPath path(basePath); path.Append("workspaces"); - + BFile file; status = file.SetTo(path.Path(), B_READ_ONLY); if (status == B_OK) { @@ -127,7 +135,7 @@ path = basePath; path.Append("fonts"); - + status = file.SetTo(path.Path(), B_READ_ONLY); if (status == B_OK) { BMessage settings; @@ -136,6 +144,8 @@ const char* family; const char* style; float size; + bool subpix; + bool hinting; if (settings.FindString("plain family", &family) == B_OK && settings.FindString("plain style", &style) == B_OK && settings.FindFloat("plain size", &size) == B_OK) { @@ -158,6 +168,15 @@ fFixedFont.SetStyle(fontStyle); fFixedFont.SetSize(size); } + if (settings.FindBool("font subpix", &subpix) == B_OK) { + fFontSubpixelAntialiasing = subpix; + FontCacheEntry::SetDefaultRenderType( + (subpix) ? glyph_ren_subpix : glyph_ren_native_gray8); + } + if (settings.FindBool("hinting", &hinting) == B_OK) { + fHinting = hinting; + FontCacheEntry::SetDefaultHinting(fHinting); + } gFontManager->Unlock(); } } @@ -166,7 +185,7 @@ path = basePath; path.Append("mouse"); - + status = file.SetTo(path.Path(), B_READ_ONLY); if (status == B_OK) { BMessage settings; @@ -183,7 +202,7 @@ path = basePath; path.Append("appearance"); - + status = file.SetTo(path.Path(), B_READ_ONLY); if (status == B_OK) { BMessage settings; @@ -192,7 +211,7 @@ float fontSize; if (settings.FindFloat("font size", &fontSize) == B_OK) fMenuInfo.font_size = fontSize; - + const char* fontFamily; if (settings.FindString("font family", &fontFamily) == B_OK) strlcpy(fMenuInfo.f_family, fontFamily, B_FONT_FAMILY_LENGTH); @@ -274,6 +293,9 @@ settings.AddString("fixed style", fFixedFont.Style()); settings.AddFloat("fixed size", fFixedFont.Size()); + settings.AddBool("font subpix",fFontSubpixelAntialiasing); + settings.AddBool("hinting",fHinting); + BFile file; status = file.SetTo(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_READ_WRITE); if (status == B_OK) { @@ -521,6 +543,42 @@ } +void +DesktopSettingsPrivate::SetFontSubpixelAntialiasing(bool subpix) +{ + if (fFontSubpixelAntialiasing != subpix) { + fFontSubpixelAntialiasing = subpix; + FontCacheEntry::SetDefaultRenderType( + (subpix)?glyph_ren_subpix:glyph_ren_native_gray8); + Save(kFontSettings); + } +} + + +bool +DesktopSettingsPrivate::FontSubpixelAntialiasing() const +{ + return fFontSubpixelAntialiasing; +} + + +void +DesktopSettingsPrivate::SetHinting(bool hinting) +{ + if (fHinting != hinting) { + fHinting = hinting; + FontCacheEntry::SetDefaultHinting(hinting); + Save(kFontSettings); + } +} + + +bool +DesktopSettingsPrivate::Hinting() const +{ + return fHinting; +} + // #pragma mark - read access @@ -613,6 +671,19 @@ } +bool +DesktopSettings::FontSubpixelAntialiasing() const +{ + return fSettings->FontSubpixelAntialiasing(); +} + + +bool +DesktopSettings::Hinting() const +{ + return fSettings->Hinting(); +} + // #pragma mark - write access @@ -691,3 +762,16 @@ } +void +LockedDesktopSettings::SetFontSubpixelAntialiasing(bool subpix) +{ + fSettings->SetFontSubpixelAntialiasing(subpix); +} + + +void +LockedDesktopSettings::SetHinting(bool hinting) +{ + fSettings->SetHinting(hinting); +} + Modified: haiku/trunk/src/servers/app/DesktopSettings.h =================================================================== --- haiku/trunk/src/servers/app/DesktopSettings.h 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/DesktopSettings.h 2008-07-10 08:29:50 UTC (rev 26362) @@ -4,6 +4,7 @@ * * Authors: * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #ifndef DESKTOP_SETTINGS_H #define DESKTOP_SETTINGS_H @@ -52,6 +53,9 @@ rgb_color UIColor(color_which which) const; + bool FontSubpixelAntialiasing() const; + bool Hinting() const; + protected: DesktopSettingsPrivate* fSettings; }; @@ -74,6 +78,9 @@ void SetUIColor(color_which which, const rgb_color color); + void SetFontSubpixelAntialiasing(bool subpix); + void SetHinting(bool hinting); + private: Desktop* fDesktop; }; Modified: haiku/trunk/src/servers/app/DesktopSettingsPrivate.h =================================================================== --- haiku/trunk/src/servers/app/DesktopSettingsPrivate.h 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/DesktopSettingsPrivate.h 2008-07-10 08:29:50 UTC (rev 26362) @@ -4,6 +4,7 @@ * * Authors: * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #ifndef DESKTOP_SETTINGS_PRIVATE_H #define DESKTOP_SETTINGS_PRIVATE_H @@ -54,6 +55,12 @@ void SetUIColor(color_which which, const rgb_color color); rgb_color UIColor(color_which which) const; + + void SetFontSubpixelAntialiasing(bool subpix); + bool FontSubpixelAntialiasing() const; + void SetHinting(bool hinting); + bool Hinting() const; + private: void _SetDefaults(); status_t _Load(); @@ -70,6 +77,9 @@ int32 fWorkspacesCount; BMessage fWorkspaceMessages[kMaxWorkspaces]; + bool fFontSubpixelAntialiasing; + bool fHinting; + server_read_only_memory& fShared; }; Modified: haiku/trunk/src/servers/app/ProfileMessageSupport.cpp =================================================================== --- haiku/trunk/src/servers/app/ProfileMessageSupport.cpp 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/ProfileMessageSupport.cpp 2008-07-10 08:29:50 UTC (rev 26362) @@ -9,7 +9,7 @@ #include "ProfileMessageSupport.h" -#include "ServerProtocol.h" +#include void @@ -174,6 +174,11 @@ case AS_GET_DECORATOR_SETTINGS: string = "AS_GET_DECORATOR_SETTINGS"; break; case AS_GET_SHOW_ALL_DRAGGERS: string = "AS_GET_SHOW_ALL_DRAGGERS"; break; case AS_SET_SHOW_ALL_DRAGGERS: string = "AS_SET_SHOW_ALL_DRAGGERS"; break; + + case AS_SET_FONT_SUBPIXEL_ANTIALIASING: string = "AS_SET_FONT_SUBPIXEL_ANTIALIASING"; break; + case AS_GET_FONT_SUBPIXEL_ANTIALIASING: string = "AS_GET_FONT_SUBPIXEL_ANTIALIASING"; break; + case AS_SET_HINTING: string = "AS_SET_HINTING"; break; + case AS_GET_HINTING: string = "AS_GET_HINTING"; break; // Graphics calls case AS_SET_HIGH_COLOR: string = "AS_SET_HIGH_COLOR"; break; Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2008-07-10 08:26:38 UTC (rev 26361) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2008-07-10 08:29:50 UTC (rev 26362) @@ -9,6 +9,7 @@ * Stefano Ceccherini (burton666 at libero.it) * Axel D?rfler, axeld at pinc-software.de * J?r?me Duval, jerome.duval at free.fr + * Andrej Spielmann, */ /*! @@ -2535,6 +2536,46 @@ break; } + case AS_SET_FONT_SUBPIXEL_ANTIALIASING: + { + bool subpix; + if (link.Read(&subpix) == B_OK) { + LockedDesktopSettings settings(fDesktop); + settings.SetFontSubpixelAntialiasing(subpix); + } + fDesktop->Redraw(); + break; + } + + case AS_GET_FONT_SUBPIXEL_ANTIALIASING: + { + DesktopSettings settings(fDesktop); + fLink.StartMessage(B_OK); + fLink.Attach(settings.FontSubpixelAntialiasing()); + fLink.Flush(); + break; + } + + case AS_SET_HINTING: + { + bool hinting; + if (link.Read(&hinting) == B_OK) { + LockedDesktopSettings settings(fDesktop); + settings.SetHinting(hinting); + } + fDesktop->Redraw(); + break; + } + + case AS_GET_HINTING: + { + DesktopSettings settings(fDesktop); + fLink.StartMessage(B_OK); + fLink.Attach(settings.Hinting()); + fLink.Flush(); + break; + } + default: printf("ServerApp %s received unhandled message code %ld\n", Signature(), code); From stippi at mail.berlios.de Thu Jul 10 10:31:50 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:31:50 +0200 Subject: [Haiku-commits] r26363 - haiku/trunk/src/kits/interface Message-ID: <200807100831.m6A8Vo83001936@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:31:48 +0200 (Thu, 10 Jul 2008) New Revision: 26363 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26363&view=rev Modified: haiku/trunk/src/kits/interface/Font.cpp Log: Patch by Andrej Spielmann (GSOC): * Add a private BFont API that sets/gets the subpixel and hinting configuration of the app_server. Currently, the options are boolean, but may be changed to modes later. Modified: haiku/trunk/src/kits/interface/Font.cpp =================================================================== --- haiku/trunk/src/kits/interface/Font.cpp 2008-07-10 08:29:50 UTC (rev 26362) +++ haiku/trunk/src/kits/interface/Font.cpp 2008-07-10 08:31:48 UTC (rev 26363) @@ -7,6 +7,7 @@ * J?r?me Duval, jerome.duval at free.fr * Axel D?rfler, axeld at pinc-software.de * Stephan A?mus + * Andrej Spielmann, */ @@ -183,7 +184,7 @@ delete family; return B_NO_MEMORY; } - + link.ReadString(style->name); link.Read(&style->face); link.Read(&style->flags); @@ -365,12 +366,12 @@ \param family the new family for the system font \param style the new style for the system font \param size the size for the system font to have - + R5 used a global area offset table to set the system fonts in the Font preferences panel. Bleah. */ void -_set_system_font_(const char *which, font_family family, font_style style, +_set_system_font_(const char *which, font_family family, font_style style, float size) { BPrivate::AppServerLink link; @@ -405,6 +406,59 @@ } +void +_set_font_subpixel_antialiasing_(bool subpix) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_SET_FONT_SUBPIXEL_ANTIALIASING); + link.Attach(subpix); + link.Flush(); +} + + +status_t +_get_font_subpixel_antialiasing_(bool* subpix) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_FONT_SUBPIXEL_ANTIALIASING); + int32 status = B_ERROR; + if (link.FlushWithReply(status) != B_OK + || status < B_OK) + return status; + link.Read(subpix); + return B_OK; +} + + +void +_set_hinting_(bool hinting) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_SET_HINTING); + link.Attach(hinting); + link.Flush(); +} + + +status_t +_get_hinting_(bool* hinting) +{ + + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_HINTING); + int32 status = B_ERROR; + if (link.FlushWithReply(status) != B_OK + || status < B_OK) + return status; + link.Read(hinting); + return B_OK; +} + + /*! \brief Returns the number of installed font families \return The number of installed font families @@ -469,7 +523,7 @@ \param flags if non-NULL, the values of the flags IS_FIXED and B_HAS_TUNED_FONT are returned \return B_ERROR if the index does not correspond to a font style - + The face value returned by this function is not very reliable. At the same time, the value returned should be fairly reliable, returning the proper flag for 90%-99% of font names. @@ -500,7 +554,7 @@ // #pragma mark - -BFont::BFont() +BFont::BFont() : // initialise for be_plain_font (avoid circular definition) fFamilyID(0), @@ -619,7 +673,7 @@ \param family Font family to set \param face Font face to set. \return B_ERROR if family does not exists or face is an invalid value. - + To comply with the BeBook, this function will only set valid values - i.e. passing a nonexistent family will cause only the face to be set. Additionally, if a particular face does not exist in a family, the closest @@ -817,8 +871,8 @@ _GetExtraFlags(); return (font_direction)(fExtraFlags >> B_PRIVATE_FONT_DIRECTION_SHIFT); } - + bool BFont::IsFixed() const { @@ -830,7 +884,7 @@ /*! \brief Returns true if the font is fixed-width and contains both full and half-width characters - + This was left unimplemented as of R5. It was a way to work with both Kanji and Roman characters in the same fixed-width font. */ @@ -943,7 +997,7 @@ void -BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, +BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, uint32 mode, float width, BString resultArray[]) const { if (stringArray && resultArray && numStrings > 0) { @@ -967,7 +1021,7 @@ void -BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, +BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, uint32 mode, float width, char *resultArray[]) const { if (stringArray && numStrings > 0) { @@ -1018,7 +1072,7 @@ void -BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], +BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], int32 numStrings, float widthArray[]) const { if (!stringArray || !lengthArray || numStrings < 1 || !widthArray) @@ -1232,7 +1286,7 @@ link.Attach(fShear); link.Attach(fFalseBoldWidth); link.Attach(fSpacing); - + link.Attach(fFlags); link.Attach(mode); link.Attach(string_escapement); From stippi at mail.berlios.de Thu Jul 10 10:33:24 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 10:33:24 +0200 Subject: [Haiku-commits] r26364 - haiku/trunk/src/preferences/fonts Message-ID: <200807100833.m6A8XOMo001984@sheep.berlios.de> Author: stippi Date: 2008-07-10 10:33:15 +0200 (Thu, 10 Jul 2008) New Revision: 26364 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26364&view=rev Added: haiku/trunk/src/preferences/fonts/AdvancedSettingsView.cpp haiku/trunk/src/preferences/fonts/AdvancedSettingsView.h Modified: haiku/trunk/src/preferences/fonts/FontSelectionView.cpp haiku/trunk/src/preferences/fonts/FontSelectionView.h haiku/trunk/src/preferences/fonts/FontView.h haiku/trunk/src/preferences/fonts/FontsSettings.cpp haiku/trunk/src/preferences/fonts/Jamfile haiku/trunk/src/preferences/fonts/MainWindow.cpp haiku/trunk/src/preferences/fonts/MainWindow.h Log: Patch by Andrej Spielmann (GSOC): * Extend the Fonts preflet to offer the new subpixel rendering and hinting options in a new "Advanced Settings" tab. * Remove trailing white space. Added: haiku/trunk/src/preferences/fonts/AdvancedSettingsView.cpp =================================================================== --- haiku/trunk/src/preferences/fonts/AdvancedSettingsView.cpp 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/AdvancedSettingsView.cpp 2008-07-10 08:33:15 UTC (rev 26364) @@ -0,0 +1,279 @@ +/* + * Copyright 2008, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Andrej Spielmann, + */ + + +#include "AdvancedSettingsView.h" +#include "MainWindow.h" + +#include +#include +#include +#include +#include + +#include + + +#define INSTANT_UPDATE + // if defined, the changes will take place immediately and not only on exit +#define DISABLE_HINTING_CONTROL + // if defined, the hinting menu is disabled (hinting not properly + // implemented) + +static const int32 kMsgSetAntialiasing = 'anti'; +static const int32 kMsgSetHinting = 'hint'; +static const char* kSubpixelLabel = "Subpixel antialiasing"; +static const char* kGrayscaleLabel = "Grayscale antialiasing"; +static const char* kNoHintingLabel = "Off"; +static const char* kFullHintingLabel = "On"; + +// private font API +extern void _set_font_subpixel_antialiasing_(bool subpix); +extern status_t _get_font_subpixel_antialiasing_(bool* subpix); +extern void _set_hinting_(bool subpix); +extern status_t _get_hinting_(bool* subpix); + + +// #pragma mark - + + +AdvancedSettingsView::AdvancedSettingsView(BRect _rect, const char* name) + : BView(_rect, name, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW) +{ + if (_get_font_subpixel_antialiasing_(&fCurrentSubpixelAntialiasing) != B_OK) + fCurrentSubpixelAntialiasing = false; + fSavedSubpixelAntialiasing = fCurrentSubpixelAntialiasing; + + if (_get_hinting_(&fCurrentHinting) != B_OK) + fCurrentHinting = true; + fSavedHinting = fCurrentHinting; + + fDivider = StringWidth("Character hinting:") + 5; + + fAntialiasingMenu = new BPopUpMenu("Antialiasing menu"); + fHintingMenu = new BPopUpMenu("Hinting menu"); + + // antialiasing menu + BRect rect(Bounds()); + fAntialiasingMenuField = new BMenuField(rect, "antialiasing", + "Antialiasing type:", fAntialiasingMenu, false); + fAntialiasingMenuField->SetDivider(fDivider); + fAntialiasingMenuField->SetAlignment(B_ALIGN_RIGHT); + fAntialiasingMenuField->ResizeToPreferred(); + AddChild(fAntialiasingMenuField); + _BuildAntialiasingMenu(); + + // hinting menu + float shift = fAntialiasingMenuField->Bounds().Height()+5; + rect.top += shift; + rect.bottom += shift; + fHintingMenuField = new BMenuField(rect, "hinting", + "Character hinting:", fHintingMenu, false); + fHintingMenuField->SetDivider(fDivider); + fHintingMenuField->SetAlignment(B_ALIGN_RIGHT); + fHintingMenuField->ResizeToPreferred(); + AddChild(fHintingMenuField); + _BuildHintingMenu(); + +#ifdef DISABLE_HINTING_CONTROL + fHintingMenuField->SetEnabled(false); +#endif + + _SetCurrentAntialiasing(); + _SetCurrentHinting(); +} + + +AdvancedSettingsView::~AdvancedSettingsView() +{ +#ifndef INSTANT_UPDATE + _set_font_subpixel_antialiasing_(fCurrentSubpixelAntialiasing); + _set_hinting(fCurrentHinting); +#endif +} + + +void +AdvancedSettingsView::GetPreferredSize(float *_width, float *_height) +{ + // don't change the width if it is large enough + if (_width) { + *_width = (StringWidth(kSubpixelLabel) > StringWidth(kGrayscaleLabel) ? + StringWidth(kSubpixelLabel) : StringWidth(kGrayscaleLabel)) + + fDivider + 30; + if (*_width < Bounds().Width()) + *_width = Bounds().Width(); + } + + *_height = fHintingMenuField->Frame().bottom; +} + + +void +AdvancedSettingsView::SetDivider(float divider) +{ + fAntialiasingMenuField->SetDivider(divider); + fHintingMenuField->SetDivider(divider); + fDivider = divider; +} + + +void +AdvancedSettingsView::RelayoutIfNeeded() +{ + float width, height; + GetPreferredSize(&width, &height); + + if (width > Bounds().Width() || height > Bounds().Height()) { + ResizeTo(width, height); + } +} + + +void +AdvancedSettingsView::AttachedToWindow() +{ + if (Parent() != NULL) + SetViewColor(Parent()->ViewColor()); + else + SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fAntialiasingMenu->SetTargetForItems(this); + fHintingMenu->SetTargetForItems(this); +} + + +void +AdvancedSettingsView::MessageReceived(BMessage *msg) +{ + switch (msg->what) { + case kMsgSetAntialiasing: + { + bool subpixelAntialiasing; + if (msg->FindBool("antialiasing", &subpixelAntialiasing) != B_OK + || subpixelAntialiasing == fCurrentSubpixelAntialiasing) + break; + fCurrentSubpixelAntialiasing = subpixelAntialiasing; +#ifdef INSTANT_UPDATE + _set_font_subpixel_antialiasing_(fCurrentSubpixelAntialiasing); +#endif + Window()->PostMessage(kMsgUpdate); + break; + } + case kMsgSetHinting: + { + bool hinting; + if (msg->FindBool("hinting", &hinting) != B_OK + || hinting == fCurrentHinting) + break; + fCurrentHinting = hinting; +#ifdef INSTANT_UPDATE + _set_hinting_(fCurrentHinting); +#endif + Window()->PostMessage(kMsgUpdate); + break; + } + default: + BView::MessageReceived(msg); + } +} + + +void +AdvancedSettingsView::_BuildAntialiasingMenu() +{ + BMessage* message = new BMessage(kMsgSetAntialiasing); + message->AddBool("antialiasing", false); + + BMenuItem* item = new BMenuItem(kGrayscaleLabel, message); + + fAntialiasingMenu->AddItem(item); + + BMessage* message2 = new BMessage(kMsgSetAntialiasing); + message2->AddBool("antialiasing", true); + + BMenuItem* item2 = new BMenuItem(kSubpixelLabel, message2); + + fAntialiasingMenu->AddItem(item2); +} + + +void +AdvancedSettingsView::_BuildHintingMenu() +{ + BMessage* message = new BMessage(kMsgSetHinting); + message->AddBool("hinting", false); + + BMenuItem* item = new BMenuItem(kNoHintingLabel, message); + + fHintingMenu->AddItem(item); + + BMessage* message2 = new BMessage(kMsgSetHinting); + message2->AddBool("hinting", true); + + BMenuItem* item2 = new BMenuItem(kFullHintingLabel, message2); + + fHintingMenu->AddItem(item2); +} + + +void +AdvancedSettingsView::_SetCurrentAntialiasing() +{ + BMenuItem *item = fAntialiasingMenu->FindItem( + fCurrentSubpixelAntialiasing ? kSubpixelLabel : kGrayscaleLabel); + if (item != NULL) + item->SetMarked(true); +} + + +void +AdvancedSettingsView::_SetCurrentHinting() +{ + BMenuItem *item = fHintingMenu->FindItem( + fCurrentHinting ? kFullHintingLabel : kNoHintingLabel); + if (item != NULL) + item->SetMarked(true); +} + + +void +AdvancedSettingsView::SetDefaults() +{ +} + + +bool +AdvancedSettingsView::IsDefaultable() +{ + return false; +} + + +bool +AdvancedSettingsView::IsRevertable() +{ + return (fCurrentSubpixelAntialiasing != fSavedSubpixelAntialiasing) + || (fCurrentHinting != fSavedHinting); +} + + +void +AdvancedSettingsView::Revert() +{ + if (!IsRevertable()) + return; + + fCurrentSubpixelAntialiasing = fSavedSubpixelAntialiasing; + fCurrentHinting = fSavedHinting; +#ifdef INSTANT_UPDATE + _set_font_subpixel_antialiasing_(fCurrentSubpixelAntialiasing); + _set_hinting_(fCurrentHinting); +#endif + _SetCurrentAntialiasing(); + _SetCurrentHinting(); +} Added: haiku/trunk/src/preferences/fonts/AdvancedSettingsView.h =================================================================== --- haiku/trunk/src/preferences/fonts/AdvancedSettingsView.h 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/AdvancedSettingsView.h 2008-07-10 08:33:15 UTC (rev 26364) @@ -0,0 +1,56 @@ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Andrej Spielmann, + */ +#ifndef ADVANCED_SETTINGS_VIEW_H +#define ADVANCED_SETTINGS_VIEW_H + + +#include + +class BBox; +class BMenuField; +class BPopUpMenu; + + +class AdvancedSettingsView : public BView { + public: + AdvancedSettingsView(BRect rect, const char* name); + virtual ~AdvancedSettingsView(); + + virtual void GetPreferredSize(float *_width, float *_height); + virtual void RelayoutIfNeeded(); + virtual void AttachedToWindow(); + virtual void MessageReceived(BMessage *msg); + + void SetDivider(float divider); + + void SetDefaults(); + void Revert(); + bool IsDefaultable(); + bool IsRevertable(); + + private: + void _BuildAntialiasingMenu(); + void _SetCurrentAntialiasing(); + void _BuildHintingMenu(); + void _SetCurrentHinting(); + + protected: + float fDivider; + + BMenuField* fAntialiasingMenuField; + BPopUpMenu* fAntialiasingMenu; + BMenuField* fHintingMenuField; + BPopUpMenu* fHintingMenu; + + bool fSavedSubpixelAntialiasing; + bool fCurrentSubpixelAntialiasing; + bool fSavedHinting; + bool fCurrentHinting; +}; + +#endif /* ADVANCED_SETTINGS_VIEW_H */ Modified: haiku/trunk/src/preferences/fonts/FontSelectionView.cpp =================================================================== --- haiku/trunk/src/preferences/fonts/FontSelectionView.cpp 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/FontSelectionView.cpp 2008-07-10 08:33:15 UTC (rev 26364) @@ -114,7 +114,7 @@ // it doesn't overlap the box outline. rect = fPreviewBox->Bounds().InsetByCopy(3, 3); fPreviewText = new BStringView(rect, "preview text", - "The quick brown fox jumps over the lazy dog.", + "The quick brown fox jumps over the lazy dog.", B_FOLLOW_LEFT_RIGHT); fPreviewText->SetFont(&fCurrentFont); fPreviewBox->AddChild(fPreviewText); @@ -172,7 +172,7 @@ GetPreferredSize(&width, &height); if (width > Bounds().Width()) { - fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f, + fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f, fFontsMenuField->Bounds().top); ResizeTo(width, height); } @@ -424,7 +424,7 @@ void FontSelectionView::UpdateFontsMenu() { - int32 numFamilies = count_font_families(); + int32 numFamilies = count_font_families(); fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true); BFont font; @@ -434,8 +434,8 @@ font_style currentStyle; fCurrentFont.GetFamilyAndStyle(¤tFamily, ¤tStyle); - for (int32 i = 0; i < numFamilies; i++) { - font_family family; + for (int32 i = 0; i < numFamilies; i++) { + font_family family; uint32 flags; if (get_font_family(i, &family, &flags) != B_OK) continue; @@ -457,10 +457,10 @@ BMenuItem* familyItem = new BMenuItem(stylesMenu, message); fFontsMenu->AddItem(familyItem); - int32 numStyles = count_font_styles(family); + int32 numStyles = count_font_styles(family); for (int32 j = 0; j < numStyles; j++) { - font_style style; + font_style style; if (get_font_style(family, j, &style, &flags) != B_OK) continue; Modified: haiku/trunk/src/preferences/fonts/FontSelectionView.h =================================================================== --- haiku/trunk/src/preferences/fonts/FontSelectionView.h 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/FontSelectionView.h 2008-07-10 08:33:15 UTC (rev 26364) @@ -61,5 +61,5 @@ BFont fCurrentFont; float fMaxFontNameWidth; }; - + #endif /* FONT_SELECTION_VIEW_H */ Modified: haiku/trunk/src/preferences/fonts/FontView.h =================================================================== --- haiku/trunk/src/preferences/fonts/FontView.h 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/FontView.h 2008-07-10 08:33:15 UTC (rev 26364) @@ -12,6 +12,7 @@ #include "FontSelectionView.h" +#include "AdvancedSettingsView.h" class FontView : public BView { @@ -29,9 +30,9 @@ bool IsRevertable(); private: - FontSelectionView *fPlainView; - FontSelectionView *fBoldView; - FontSelectionView *fFixedView; + FontSelectionView *fPlainView; + FontSelectionView *fBoldView; + FontSelectionView *fFixedView; }; - + #endif /* FONT_VIEW_H */ Modified: haiku/trunk/src/preferences/fonts/FontsSettings.cpp =================================================================== --- haiku/trunk/src/preferences/fonts/FontsSettings.cpp 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/FontsSettings.cpp 2008-07-10 08:33:15 UTC (rev 26364) @@ -32,27 +32,27 @@ path.Append(kSettingsFile); BFile file(path.Path(), B_READ_ONLY); - if (file.InitCheck() != B_OK) + if (file.InitCheck() != B_OK) SetDefaults(); else if (msg.Unflatten(&file) != B_OK) SetDefaults(); else msg.FindPoint("windowlocation", &fCorner); } -} - +} + FontsSettings::~FontsSettings() { BPath path; BMessage msg; - - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) + + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) return; - + path.Append(kSettingsFile); BFile file(path.Path(), B_WRITE_ONLY|B_CREATE_FILE); - + if (file.InitCheck() == B_OK) { msg.AddPoint("windowlocation", fCorner); msg.Flatten(&file); Modified: haiku/trunk/src/preferences/fonts/Jamfile =================================================================== --- haiku/trunk/src/preferences/fonts/Jamfile 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/Jamfile 2008-07-10 08:33:15 UTC (rev 26364) @@ -5,6 +5,7 @@ Preference Fonts : FontSelectionView.cpp + AdvancedSettingsView.cpp FontsSettings.cpp FontView.cpp main.cpp Modified: haiku/trunk/src/preferences/fonts/MainWindow.cpp =================================================================== --- haiku/trunk/src/preferences/fonts/MainWindow.cpp 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/MainWindow.cpp 2008-07-10 08:33:15 UTC (rev 26364) @@ -6,6 +6,7 @@ * Mark Hogben * DarkWyrm * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ @@ -25,7 +26,7 @@ MainWindow::MainWindow() - : BWindow(BRect(100, 100, 445, 340), "Fonts", B_TITLED_WINDOW, + : BWindow(BRect(100, 100, 445, 410), "Fonts", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) { BRect rect = Bounds(); @@ -36,7 +37,8 @@ rect.left = 10; rect.top = rect.bottom - 10; fDefaultsButton = new BButton(rect, "defaults", "Defaults", - new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); + new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT + | B_FOLLOW_BOTTOM, B_WILL_DRAW); fDefaultsButton->ResizeToPreferred(); fDefaultsButton->SetEnabled(false); float buttonHeight = fDefaultsButton->Bounds().Height(); @@ -56,11 +58,13 @@ rect.top += 5; rect.bottom -= 20 + buttonHeight; rect.left += 5; - BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); + BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); rect = tabView->ContainerView()->Bounds().InsetByCopy(5, 8); fFontsView = new FontView(rect); + fAdvancedSettings = new AdvancedSettingsView(rect, "Advanced"); + tabView->AddTab(fFontsView); fFontsView->UpdateFonts(); @@ -83,7 +87,8 @@ tabView->ContainerView()->ResizeBy(0, heightDiff); } - ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 20 + buttonHeight); + ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 20 + + buttonHeight); view->AddChild(tabView); fFontsView->ResizeToPreferred(); @@ -99,6 +104,23 @@ _Center(); } + tabView->AddTab(fAdvancedSettings); + + fAdvancedSettings->RelayoutIfNeeded(); + fAdvancedSettings->GetPreferredSize(&width, &height); + + widthDiff = width + 10 - tabView->ContainerView()->Bounds().Width(); + if (widthDiff > 0) { + tabView->ResizeBy(widthDiff, 0); + tabView->ContainerView()->ResizeBy(widthDiff, 0); + } + + heightDiff = height + 16 - tabView->ContainerView()->Bounds().Height(); + if (heightDiff > 0) { + tabView->ResizeBy(0, heightDiff); + tabView->ContainerView()->ResizeBy(0, heightDiff); + } + fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000); // every 3 seconds @@ -127,19 +149,25 @@ { switch (message->what) { case kMsgUpdate: - fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); - fRevertButton->SetEnabled(fFontsView->IsRevertable()); + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable() + || fAdvancedSettings->IsDefaultable()); + fRevertButton->SetEnabled(fFontsView->IsRevertable() + || fAdvancedSettings->IsRevertable()); break; case kMsgSetDefaults: fFontsView->SetDefaults(); + fAdvancedSettings->SetDefaults(); fDefaultsButton->SetEnabled(false); - fRevertButton->SetEnabled(fFontsView->IsRevertable()); + fRevertButton->SetEnabled(fFontsView->IsRevertable() + || fAdvancedSettings->IsRevertable()); break; case kMsgRevert: fFontsView->Revert(); - fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); + fAdvancedSettings->Revert(); + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable() + || fAdvancedSettings->IsDefaultable()); fRevertButton->SetEnabled(false); break; Modified: haiku/trunk/src/preferences/fonts/MainWindow.h =================================================================== --- haiku/trunk/src/preferences/fonts/MainWindow.h 2008-07-10 08:31:48 UTC (rev 26363) +++ haiku/trunk/src/preferences/fonts/MainWindow.h 2008-07-10 08:33:15 UTC (rev 26364) @@ -12,6 +12,7 @@ #include "FontsSettings.h" +#include "AdvancedSettingsView.h" #include @@ -31,12 +32,13 @@ private: void _Center(); - BMessageRunner* fRunner; - FontView* fFontsView; - BButton* fDefaultsButton; - BButton* fRevertButton; + BMessageRunner* fRunner; + FontView* fFontsView; + BButton* fDefaultsButton; + BButton* fRevertButton; - FontsSettings fSettings; + FontsSettings fSettings; + AdvancedSettingsView* fAdvancedSettings; }; static const int32 kMsgUpdate = 'updt'; From superstippi at gmx.de Thu Jul 10 11:06:39 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 11:06:39 +0200 Subject: [Haiku-commits] r26364 - haiku/trunk/src/preferences/fonts In-Reply-To: <200807100833.m6A8XOMo001984@sheep.berlios.de> References: <200807100833.m6A8XOMo001984@sheep.berlios.de> Message-ID: <20080710110639.7862.12@stippis2.1215669831.fake> Hi all, to actually see subpixel rendering in action, the file headers/libs/freetype2/freetype/config/ftoption.h has to define #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING I am hesitant to turn this on in the source, since according to the comment above the config option, it would potentially violate patents. Since we are distributing images in contries where software patents apply, people may have to turn this on individually. Personally, I wouldn't be concerned so much, but I am not just turning this on without consensus. Before you reply, please read this (please really do, it's not that long): Technically, subpixel rendering means this: * The realization that you can reliably address individual RGB subpixels of an LCD and use this as "three times the horizontal resolution". * To render glyphs or other shapes three times the width .(You may guess rightfully that that is not very technically challenging.) * To do something against the resulting color fringes. ClearType applies some filtering which technically blurrs the result again, which I personally find counterproductive. Currently Andrej's implementation does the same, although it special cases triplets of same coverage which makes it a bit sharper than ClearType. I have an idea for yet another method, but it looks to me like the anti-color-fringes implementation is yet the most technically challenging of these three points. All in all, I have a hard time not finding the ideas behind all this trivial. That's of course not meant to discredit the work done by Andrej to implement it all, it was a lot of work and changes in many places. But technically, it just isn't rocket sience and really boils down to these three points I outlined. I simply don't find the patents justified, but that's just me. Maybe a lot of neat ideas have a level of simplicity to them that could be called elegance. So FMPOV, it boils down to the idea itself, which clearly has examples of prior art even mentioned in the patents. Best regards, -Stephan From korli at users.berlios.de Thu Jul 10 11:12:43 2008 From: korli at users.berlios.de (=?ISO-8859-1?Q?J=E9r=F4me_Duval?=) Date: Thu, 10 Jul 2008 11:12:43 +0200 Subject: [Haiku-commits] r26349 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: <1536010362-BeMail@zon> References: <200807092314.m69NEvg4025775@sheep.berlios.de> <1536010362-BeMail@zon> Message-ID: 2008/7/10 Axel D?rfler : > korli at BerliOS wrote: >> Log: >> reduced buffer size: with 4096, no buffer is received by the >> multiaudio addon > > Any reason why this is? > It seems like a bug in the media addons/media kit. I have yet to understand why it happens, one thing at a time. Bye, J?r?me From superstippi at gmx.de Thu Jul 10 11:21:46 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 11:21:46 +0200 Subject: [Haiku-commits] r26349 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda In-Reply-To: References: <200807092314.m69NEvg4025775@sheep.berlios.de> <1536010362-BeMail@zon> Message-ID: <20080710112146.8222.13@stippis2.1215669831.fake> J?r?me Duval wrote: > 2008/7/10 Axel D?rfler : > > korli at BerliOS wrote: > >> Log: > >> reduced buffer size: with 4096, no buffer is received by the > >> multiaudio addon > > > > Any reason why this is? > > > > It seems like a bug in the media addons/media kit. I have yet to > understand why it happens, one thing at a time. Ok, no worries! :-) Best regards, -Stephan From axeld at mail.berlios.de Thu Jul 10 12:06:18 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 12:06:18 +0200 Subject: [Haiku-commits] r26365 - in haiku/trunk: headers/private/kernel/util src/system/kernel/fs src/system/kernel/messaging Message-ID: <200807101006.m6AA6Ihn011614@sheep.berlios.de> Author: axeld Date: 2008-07-10 12:06:17 +0200 (Thu, 10 Jul 2008) New Revision: 26365 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26365&view=rev Modified: haiku/trunk/headers/private/kernel/util/KMessage.h haiku/trunk/src/system/kernel/fs/vfs_boot.cpp haiku/trunk/src/system/kernel/messaging/KMessage.cpp Log: * Moved KMessage field printing from vfs_boot.cpp::get_boot_partitions() into KMessage::Dump(). * Improved message dump output a bit (more concise). * get_boot_partitions() now simply calls KMessage::Dump() instead. * Added a KMessage::IsEmpty() method. Modified: haiku/trunk/headers/private/kernel/util/KMessage.h =================================================================== --- haiku/trunk/headers/private/kernel/util/KMessage.h 2008-07-10 08:33:15 UTC (rev 26364) +++ haiku/trunk/headers/private/kernel/util/KMessage.h 2008-07-10 10:06:17 UTC (rev 26365) @@ -55,6 +55,7 @@ status_t FindField(const char *name, type_code type, KMessageField *field) const; status_t GetNextField(KMessageField *field) const; + bool IsEmpty() const; status_t AddData(const char *name, type_code type, const void *data, int32 numBytes, bool isFixedSize = true); @@ -135,7 +136,7 @@ status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1, port_message_info* messageInfo = NULL); - void Dump(void (*printFunc)(const char*,...)) const; + void Dump(void (*printFunc)(const char*, ...)) const; private: friend class KMessageField; Modified: haiku/trunk/src/system/kernel/fs/vfs_boot.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs_boot.cpp 2008-07-10 08:33:15 UTC (rev 26364) +++ haiku/trunk/src/system/kernel/fs/vfs_boot.cpp 2008-07-10 10:06:17 UTC (rev 26365) @@ -85,7 +85,7 @@ if (!strncmp(b->ContentName(), "System", 6)) return -1; - return compare; + return compare; } @@ -278,7 +278,7 @@ // #pragma mark - -/*! Make the boot partition (and probably others) available. +/*! Make the boot partition (and probably others) available. The partitions that are a boot candidate a put into the /a partitions stack. If the user selected a boot device, there is will only be one entry in this stack; if not, the most likely is put up first. @@ -290,54 +290,8 @@ const KMessage& bootVolume = args->boot_volume; dprintf("get_boot_partitions(): boot volume message:\n"); - KMessageField field; - while (bootVolume.GetNextField(&field) == B_OK) { - type_code type = field.TypeCode(); - uint32 bigEndianType = B_HOST_TO_BENDIAN_INT32(type); - dprintf("field: \"%s\", type: %.4s (0x%lx):\n", field.Name(), - (char*)&bigEndianType, type); + bootVolume.Dump(&dprintf); - if (field.CountElements() == 0) - dprintf("\n"); - - int32 size; - for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { - dprintf(" [%2d] ", i); - bool isIntType = false; - int64 intData = 0; - switch (type) { - case B_BOOL_TYPE: - dprintf("%s\n", (*(bool*)data ? "true" : "false")); - break; - case B_INT8_TYPE: - isIntType = true; - intData = *(int8*)data; - break; - case B_INT16_TYPE: - isIntType = true; - intData = *(int16*)data; - break; - case B_INT32_TYPE: - isIntType = true; - intData = *(int32*)data; - break; - case B_INT64_TYPE: - isIntType = true; - intData = *(int64*)data; - break; - case B_STRING_TYPE: - dprintf("\"%s\"\n", (char*)data); - break; - default: - dprintf("data: \"%p\", %ld bytes\n", (char*)data, size); - break; - } - if (isIntType) - dprintf("%lld (0x%llx)\n", intData, intData); - } - } - - // create boot method int32 bootMethodType = bootVolume.GetInt32(BOOT_METHOD, BOOT_METHOD_DEFAULT); Modified: haiku/trunk/src/system/kernel/messaging/KMessage.cpp =================================================================== --- haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-07-10 08:33:15 UTC (rev 26364) +++ haiku/trunk/src/system/kernel/messaging/KMessage.cpp 2008-07-10 10:06:17 UTC (rev 26365) @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -300,6 +301,14 @@ return B_OK; } + +bool +KMessage::IsEmpty() const +{ + return _LastFieldHeader() == NULL; +} + + // AddData status_t KMessage::AddData(const char *name, type_code type, const void *data, @@ -601,7 +610,7 @@ void -KMessage::Dump(void (*printFunc)(const char*,...)) const +KMessage::Dump(void (*printFunc)(const char*, ...)) const { Header* header = _Header(); printFunc("KMessage: buffer: %p (size/capacity: %ld/%ld), flags: 0x0lx\n", @@ -610,10 +619,54 @@ KMessageField field; while (GetNextField(&field) == B_OK) { type_code type = field.TypeCode(); - int32 count = field.CountElements(); - printFunc(" field: %-20s: type: 0x%lx ('%c%c%c%c'), %ld element%s\n", - field.Name(), type, (char)(type >> 24), (char)(type >> 16), - (char)(type >> 8), (char)type, count, count == 1 ? "" : "s"); + uint32 bigEndianType = B_HOST_TO_BENDIAN_INT32(type); + int nameSpacing = 17 - strlen(field.Name()); + if (nameSpacing < 0) + nameSpacing = 0; + + printFunc(" field: \"%s\"%*s (%.4s): ", field.Name(), nameSpacing, "", + (char*)&bigEndianType); + + if (field.CountElements() != 1) + printFunc("\n"); + + int32 size; + for (int i = 0; const void* data = field.ElementAt(i, &size); i++) { + if (field.CountElements() != 1) + printFunc(" [%2d] ", i); + + bool isIntType = false; + int64 intData = 0; + switch (type) { + case B_BOOL_TYPE: + printFunc("%s\n", (*(bool*)data ? "true" : "false")); + break; + case B_INT8_TYPE: + isIntType = true; + intData = *(int8*)data; + break; + case B_INT16_TYPE: + isIntType = true; + intData = *(int16*)data; + break; + case B_INT32_TYPE: + isIntType = true; + intData = *(int32*)data; + break; + case B_INT64_TYPE: + isIntType = true; + intData = *(int64*)data; + break; + case B_STRING_TYPE: + printFunc("\"%s\"\n", (char*)data); + break; + default: + printFunc("data at %p, %ld bytes\n", (char*)data, size); + break; + } + if (isIntType) + printFunc("%lld (0x%llx)\n", intData, intData); + } } } From superstippi at gmx.de Thu Jul 10 12:34:10 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 12:34:10 +0200 Subject: [Haiku-commits] r26365 - in haiku/trunk: headers/private/kernel/util src/system/kernel/fs src/system/kernel/messaging In-Reply-To: <200807101006.m6AA6Ihn011614@sheep.berlios.de> References: <200807101006.m6AA6Ihn011614@sheep.berlios.de> Message-ID: <20080710123410.10299.17@stippis2.1215669831.fake> axeld at BerliOS wrote: > Author: axeld > Date: 2008-07-10 12:06:17 +0200 (Thu, 10 Jul 2008) New Revision: 26365 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26365&view=rev > > Modified: > haiku/trunk/headers/private/kernel/util/KMessage.h > haiku/trunk/src/system/kernel/fs/vfs_boot.cpp > haiku/trunk/src/system/kernel/messaging/KMessage.cpp > Log: > * Moved KMessage field printing from vfs_boot.cpp::get_boot_partitions() > into > KMessage::Dump(). > * Improved message dump output a bit (more concise). > * get_boot_partitions() now simply calls KMessage::Dump() instead. > * Added a KMessage::IsEmpty() method. This breaks the build. Linking runtime_loader.a(KMessage.o): In function 'BPrivate::KMessage::Dump(void (*)(char const *,...)) const': KMessage.cpp:(.text+0xa44): undefined reference to '__swap_int32' Best regards, -Stephan From axeld at mail.berlios.de Thu Jul 10 13:52:57 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 13:52:57 +0200 Subject: [Haiku-commits] r26366 - haiku/trunk/src/system/runtime_loader Message-ID: <200807101152.m6ABqvCo009185@sheep.berlios.de> Author: axeld Date: 2008-07-10 13:52:57 +0200 (Thu, 10 Jul 2008) New Revision: 26366 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26366&view=rev Modified: haiku/trunk/src/system/runtime_loader/utility.cpp Log: * Added a __swap_int32() function to the runtime_loader - this fixes the build, since KMessage needs it now. Modified: haiku/trunk/src/system/runtime_loader/utility.cpp =================================================================== --- haiku/trunk/src/system/runtime_loader/utility.cpp 2008-07-10 10:06:17 UTC (rev 26365) +++ haiku/trunk/src/system/runtime_loader/utility.cpp 2008-07-10 11:52:57 UTC (rev 26366) @@ -58,6 +58,14 @@ } +extern "C" uint32 +__swap_int32(uint32 value) +{ + return value >> 24 | (value >> 8) & 0xff00 | value << 24 + | (value << 8) & 0xff0000; +} + + // Copied from libroot/os/thread.c: From axeld at pinc-software.de Thu Jul 10 13:53:24 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 10 Jul 2008 13:53:24 +0200 CEST Subject: [Haiku-commits] r26365 - in haiku/trunk: headers/private/kernel/util src/system/kernel/fs src/system/kernel/messaging In-Reply-To: <20080710123410.10299.17@stippis2.1215669831.fake> Message-ID: <19731004722-BeMail@zon> Stephan Assmus wrote: > This breaks the build. Linking runtime_loader.a(KMessage.o): In > function > 'BPrivate::KMessage::Dump(void (*)(char const *,...)) const': > KMessage.cpp:(.text+0xa44): undefined reference to '__swap_int32' Thanks for the note, it's fixed now. Bye, Axel. From axeld at pinc-software.de Thu Jul 10 14:04:04 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 10 Jul 2008 14:04:04 +0200 CEST Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <20080710082745.687.1@stippis2.1215669831.fake> Message-ID: <20370106381-BeMail@zon> Stephan Assmus wrote: > > I don't know what haiku currently is using, we should check this, > > but > > calling BView::MouseMoved at that rate certainly shouldn't be a > > problem. > But that's the point, if it isn't a problem, then my solution doesn't > change anything! In another words, if an application is fast enough > to > handle 1000 messages per second, then my change will not have any > effect. > If it isn't, then my change will remove old mouse messages from the > queue. > The point that Ingo was making is that most applications will not > have any > use for that many mouse messages. I may add that mouse messages are > only > generated when the mouse actually moves, so it's not that the > applications > get constantly flooded with messages. The movement samples may be > finer > than they need to be though and Ingo has presented a solution, but I > believe it may have other drawbacks (like pretty much no mouse > history at > all). In any case, my change doesn't have anything to do with it as > long as > applications are fast enough to handle it. The change only addresses > a > lagging problem *if* it occurs. I would be in favor of Ingo's suggestion if we changed it so that up to a specific number (say, 5 -- or just one if B_NO_POINTER_HISTORY is used) messages can be stored in this shared memory. Then, we would make sure there: a) is a pointer history for those apps that are fast enough b) there is a (minimal) pointer history for those apps that aren't fast enough (but those could use your new flag, instead) c) GetMouse() and DispatchMessage() would not need any extra code d) it doesn't matter how slow the system is, it would always work reliable. Ingo's suggestion has the added advantage that no actual messages are sent for each mouse button when it's not needed, so that save some cycles. But that can be done at later point, too. Bye, Axel. From axeld at mail.berlios.de Thu Jul 10 14:19:23 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 14:19:23 +0200 Subject: [Haiku-commits] r26367 - haiku/trunk/headers/private/kernel/util Message-ID: <200807101219.m6ACJNqS011268@sheep.berlios.de> Author: axeld Date: 2008-07-10 14:19:22 +0200 (Thu, 10 Jul 2008) New Revision: 26367 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26367&view=rev Modified: haiku/trunk/headers/private/kernel/util/OpenHashTable.h Log: * Added comment about a missing Remove() variant. Modified: haiku/trunk/headers/private/kernel/util/OpenHashTable.h =================================================================== --- haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2008-07-10 11:52:57 UTC (rev 26366) +++ haiku/trunk/headers/private/kernel/util/OpenHashTable.h 2008-07-10 12:19:22 UTC (rev 26367) @@ -1,9 +1,6 @@ /* * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. - * - * Authors: - * Hugo Santos, hugosantos at gmail.com */ #ifndef _KERNEL_UTIL_OPEN_HASH_TABLE_H #define _KERNEL_UTIL_OPEN_HASH_TABLE_H @@ -20,7 +17,7 @@ struct Foo : HashTableLink { int bar; - + HashTableLink otherLink; }; @@ -126,6 +123,8 @@ fItemCount++; } + // TODO: a ValueType* Remove(const KeyType& key) method is missing + bool Remove(ValueType *value) { if (!RemoveUnchecked(value)) From superstippi at gmx.de Thu Jul 10 14:20:27 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Thu, 10 Jul 2008 14:20:27 +0200 Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <20370106381-BeMail@zon> References: <20370106381-BeMail@zon> Message-ID: <20080710142027.10792.19@stippis2.1215669831.fake> Hi, Axel D?rfler wrote: > I would be in favor of Ingo's suggestion if we changed it so that up to a > specific number (say, 5 -- or just one if B_NO_POINTER_HISTORY is used) > messages can be stored in this shared memory. Then, we would make sure > there: > a) is a pointer history for those apps that are fast enough b) there is a > (minimal) pointer history for those apps that aren't fast enough (but > those could use your new flag, instead) Ok. >c) GetMouse() and DispatchMessage() would not need any extra code I am not sure about that, since Ingo's solution works at the BWindow level (global), while the no-history-flag works at the view level. So I guess the BWindow level code would always have to provide the history and there will have to at least be some extra code in GetMouse(). > d) it doesn't matter how slow the system is, it would always work > reliable. The current method does work reliable. It may do too much on a slow system as per my TODO comment, which is obviously undesired. But reliable it is. > Ingo's suggestion has the added advantage that no actual messages are > sent for each mouse button when it's not needed, so that save some cycles. > But that can be done at later point, too. To me it looks, like the proposed method would have some benefits, but not all the ones you outlined (reduced complexity and added reliability). Since the current solution works, I am inclined to be lazy, especially since I have some other stuff that interests me currently. Like experimenting with subpixel rendering methods or implementing playlist loading/saving in MediaPlayer or looping and repeat modes... :-) But someone else, please feel free to implement it! :-P Best regards, -Stephan From axeld at mail.berlios.de Thu Jul 10 14:21:06 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 14:21:06 +0200 Subject: [Haiku-commits] r26368 - in haiku/trunk: headers/private/kernel/disk_device_manager src/system/kernel/disk_device_manager Message-ID: <200807101221.m6ACL6Lm011588@sheep.berlios.de> Author: axeld Date: 2008-07-10 14:21:05 +0200 (Thu, 10 Jul 2008) New Revision: 26368 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26368&view=rev Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp Log: * RescanDiskSystems() now locks the disk device manager, as it clobbers the disk system lists. * Added module watching; on module changes, it will now automatically rescan the disk systems. Modified: haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h =================================================================== --- haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2008-07-10 12:19:22 UTC (rev 26367) +++ haiku/trunk/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2008-07-10 12:21:05 UTC (rev 26368) @@ -102,6 +102,7 @@ struct DiskSystemMap; struct PartitionMap; struct PartitionSet; + class DiskSystemWatcher; class DeviceWatcher; static status_t _CheckMediaStatusDaemon(void* self); @@ -132,6 +133,7 @@ PartitionSet *fObsoletePartitions; thread_id fMediaChecker; volatile bool fTerminating; + DiskSystemWatcher *fDiskSystemWatcher; DeviceWatcher *fDeviceWatcher; static KDiskDeviceManager *sDefaultManager; Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2008-07-10 12:19:22 UTC (rev 26367) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp 2008-07-10 12:21:05 UTC (rev 26368) @@ -21,11 +21,13 @@ #include #include -#include +#include -#include +#include +#include #include #include +#include #include #include @@ -92,6 +94,30 @@ }; +class KDiskDeviceManager::DiskSystemWatcher : public NotificationListener { +public: + DiskSystemWatcher(KDiskDeviceManager* manager) + : + fManager(manager) + { + } + + virtual ~DiskSystemWatcher() + { + } + + virtual void EventOccured(NotificationService& service, + const KMessage* event) + { + if (event->GetInt32("opcode", -1) != B_ENTRY_REMOVED) + fManager->RescanDiskSystems(); + } + +private: + KDiskDeviceManager* fManager; +}; + + // DeviceWatcher class KDiskDeviceManager::DeviceWatcher : public NotificationListener { public: @@ -170,6 +196,7 @@ fObsoletePartitions(new(nothrow) PartitionSet), fMediaChecker(-1), fTerminating(false), + fDiskSystemWatcher(NULL), fDeviceWatcher(new(nothrow) DeviceWatcher(this)) { if (InitCheck() != B_OK) @@ -905,9 +932,17 @@ { // do another scan, this will populate the devfs directories InitialDeviceScan(); + + // start monitoring the disk systems + fDiskSystemWatcher = new(std::nothrow) DiskSystemWatcher(this); + if (fDiskSystemWatcher != NULL) { + start_watching_modules(kFileSystemPrefix, *fDiskSystemWatcher); + start_watching_modules(kPartitioningSystemPrefix, + *fDiskSystemWatcher); + } + // start monitoring all dirs under /dev/disk - status_t result = _AddRemoveMonitoring("/dev/disk", true); - return result; + return _AddRemoveMonitoring("/dev/disk", true); } @@ -959,10 +994,14 @@ { DiskSystemMap addedSystems; + Lock(); + // rescan for partitioning and file systems _RescanDiskSystems(addedSystems, false); _RescanDiskSystems(addedSystems, true); + Unlock(); + // rescan existing devices with the new disk systems int32 cookie = 0; while (KDiskDevice *device = RegisterNextDevice(&cookie)) { From axeld at mail.berlios.de Thu Jul 10 14:42:03 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 14:42:03 +0200 Subject: [Haiku-commits] r26369 - haiku/trunk/src/system/kernel Message-ID: <200807101242.m6ACg3HH013247@sheep.berlios.de> Author: axeld Date: 2008-07-10 14:42:02 +0200 (Thu, 10 Jul 2008) New Revision: 26369 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26369&view=rev Modified: haiku/trunk/src/system/kernel/module.cpp Log: * Completed module watching mechanism. Modified: haiku/trunk/src/system/kernel/module.cpp =================================================================== --- haiku/trunk/src/system/kernel/module.cpp 2008-07-10 12:21:05 UTC (rev 26368) +++ haiku/trunk/src/system/kernel/module.cpp 2008-07-10 12:42:02 UTC (rev 26369) @@ -149,7 +149,13 @@ }; struct hash_entry : entry { + ~hash_entry() + { + free((char*)path); + } + HashTableLink link; + const char* path; }; struct NodeHashDefinition { @@ -187,6 +193,21 @@ typedef DoublyLinkedList ModuleListenerList; +struct module_notification : DoublyLinkedListLinkImpl { + ~module_notification() + { + free((char*)name); + } + + int32 opcode; + dev_t device; + ino_t directory; + ino_t node; + const char* name; +}; + +typedef DoublyLinkedList NotificationList; + class DirectoryWatcher : public NotificationListener { public: DirectoryWatcher(); @@ -221,13 +242,20 @@ bool HasNode(dev_t device, ino_t node); + void Notify(int32 opcode, dev_t device, ino_t directory, + ino_t node, const char* name); + virtual const char* Name() { return "modules"; } + static void HandleNotifications(void *data, int iteration); + private: - status_t _AddNode(dev_t device, ino_t node, uint32 flags, - NotificationListener& listener); + status_t _RemoveNode(dev_t device, ino_t node); + status_t _AddNode(dev_t device, ino_t node, const char* path, + uint32 flags, NotificationListener& listener); status_t _AddDirectoryNode(dev_t device, ino_t node); - status_t _AddModuleNode(dev_t device, ino_t node); + status_t _AddModuleNode(dev_t device, ino_t node, int fd, + const char* name); status_t _AddDirectory(const char* prefix); status_t _ScanDirectory(char* directoryPath, const char* prefix, @@ -235,11 +263,16 @@ status_t _ScanDirectory(Stack& stack, DIR* dir, const char* prefix, size_t prefixPosition); + void _Notify(int32 opcode, dev_t device, ino_t directory, + ino_t node, const char* name); + void _HandleNotifications(); + recursive_lock fLock; ModuleListenerList fListeners; NodeHash fNodes; DirectoryWatcher fDirectoryWatcher; ModuleWatcher fModuleWatcher; + NotificationList fNotifications; }; } // namespace Module @@ -1177,6 +1210,7 @@ int32 opcode = event->GetInt32("opcode", -1); dev_t device = event->GetInt32("device", -1); ino_t directory = event->GetInt64("directory", -1); + ino_t node = event->GetInt64("node", -1); const char *name = event->GetString("name", NULL); if (opcode == B_ENTRY_MOVED) { @@ -1192,16 +1226,7 @@ } } - KPath path(B_PATH_NAME_LENGTH + 1); - if (path.InitCheck() != B_OK || vfs_entry_ref_to_path(device, directory, - name, path.LockBuffer(), path.BufferSize()) != B_OK) - return; - - path.UnlockBuffer(); - - dprintf("module \"%s\" %s\n", path.Leaf(), - opcode == B_ENTRY_CREATED ? "added" : "removed"); - //sModuleNotificationService.Notify(path.Path(), opcode); + sModuleNotificationService.Notify(opcode, device, directory, node, name); } @@ -1224,6 +1249,11 @@ if (event->GetInt32("opcode", -1) != B_STAT_CHANGED || (event->GetInt32("fields", 0) & B_STAT_MODIFICATION_TIME) == 0) return; + + dev_t device = event->GetInt32("device", -1); + ino_t node = event->GetInt64("node", -1); + + sModuleNotificationService.Notify(B_STAT_CHANGED, device, -1, node, NULL); } @@ -1300,9 +1330,30 @@ status_t -ModuleNotificationService::_AddNode(dev_t device, ino_t node, uint32 flags, - NotificationListener& listener) +ModuleNotificationService::_RemoveNode(dev_t device, ino_t node) { + RecursiveLocker _(fLock); + + struct entry key = {device, node}; + hash_entry* entry = fNodes.Lookup(&key); + if (entry == NULL) + return B_ENTRY_NOT_FOUND; + + remove_node_listener(device, node, entry->path != NULL + ? (NotificationListener&)fModuleWatcher + : (NotificationListener&)fDirectoryWatcher); + + fNodes.Remove(entry); + delete entry; + + return B_OK; +} + + +status_t +ModuleNotificationService::_AddNode(dev_t device, ino_t node, const char* path, + uint32 flags, NotificationListener& listener) +{ RecursiveLocker locker(fLock); if (HasNode(device, node)) @@ -1312,13 +1363,23 @@ if (entry == NULL) return B_NO_MEMORY; + if (path != NULL) { + entry->path = strdup(path); + if (entry->path == NULL) { + delete entry; + return B_NO_MEMORY; + } + } else + entry->path = NULL; + status_t status = add_node_listener(device, node, flags, listener); if (status != B_OK) { delete entry; return status; } - //dprintf(" add %s %ld:%Ld\n", flags == B_WATCH_DIRECTORY ? "dir" : "file", device, node); + //dprintf(" add %s %ld:%Ld (%s)\n", flags == B_WATCH_DIRECTORY + // ? "dir" : "file", device, node, path); entry->device = device; entry->node = node; @@ -1331,20 +1392,42 @@ status_t ModuleNotificationService::_AddDirectoryNode(dev_t device, ino_t node) { - return _AddNode(device, node, B_WATCH_DIRECTORY, fDirectoryWatcher); + return _AddNode(device, node, NULL, B_WATCH_DIRECTORY, fDirectoryWatcher); } status_t -ModuleNotificationService::_AddModuleNode(dev_t device, ino_t node) +ModuleNotificationService::_AddModuleNode(dev_t device, ino_t node, int fd, + const char* name) { - return _AddNode(device, node, B_WATCH_STAT, fModuleWatcher); + struct vnode* vnode; + status_t status = vfs_get_vnode_from_fd(fd, true, &vnode); + if (status != B_OK) + return status; + + ino_t directory; + vfs_vnode_to_node_ref(vnode, &device, &directory); + + KPath path; + status = path.InitCheck(); + if (status == B_OK) { + status = vfs_entry_ref_to_path(device, directory, name, + path.LockBuffer(), path.BufferSize()); + } + if (status != B_OK) + return status; + + path.UnlockBuffer(); + + return _AddNode(device, node, path.Path(), B_WATCH_STAT, fModuleWatcher); } status_t ModuleNotificationService::_AddDirectory(const char* prefix) { + status_t status = B_ERROR; + for (uint32 i = 0; i < kNumModulePaths; i++) { if (sDisableUserAddOns && i >= kFirstNonSystemModulePath) break; @@ -1359,16 +1442,17 @@ pathBuffer.Append(prefix); size_t prefixPosition = strlen(prefix); - status_t status = _ScanDirectory(pathBuffer.LockBuffer(), prefix, + status_t scanStatus = _ScanDirectory(pathBuffer.LockBuffer(), prefix, prefixPosition); pathBuffer.UnlockBuffer(); + // It's enough if we succeed for one directory if (status != B_OK) - return status; + status = scanStatus; } - return B_OK; + return status; } @@ -1469,7 +1553,8 @@ && directMatch) directMatchAdded = true; } else if (S_ISREG(stat.st_mode)) { - if (_AddModuleNode(stat.st_dev, stat.st_ino) == B_OK && directMatch) + if (_AddModuleNode(stat.st_dev, stat.st_ino, dir->fd, + dirent->d_name) == B_OK && directMatch) directMatchAdded = true; } } @@ -1488,6 +1573,143 @@ } +void +ModuleNotificationService::_Notify(int32 opcode, dev_t device, ino_t directory, + ino_t node, const char* name) +{ + // construct path + + KPath pathBuffer; + const char* path; + + if (name != NULL) { + // we have an entry ref + if (pathBuffer.InitCheck() != B_OK + || vfs_entry_ref_to_path(device, directory, name, + pathBuffer.LockBuffer(), pathBuffer.BufferSize()) != B_OK) + return; + + pathBuffer.UnlockBuffer(); + path = pathBuffer.Path(); + } else { + // we only have a node ref + RecursiveLocker _(fLock); + + struct entry key = {device, node}; + hash_entry* entry = fNodes.Lookup(&key); + if (entry == NULL || entry->path == NULL) + return; + + path = entry->path; + } + + // remove kModulePaths from path + + for (uint32 i = 0; i < kNumModulePaths; i++) { + KPath modulePath; + if (find_directory(kModulePaths[i], gBootDevice, true, + modulePath.LockBuffer(), modulePath.BufferSize()) != B_OK) + continue; + + modulePath.UnlockBuffer(); + modulePath.Append("kernel"); + + if (strncmp(path, modulePath.Path(), modulePath.Length())) + continue; + + path += modulePath.Length(); + if (path[i] == '/') + path++; + + break; + } + + KMessage event; + + // find listeners by prefix/path + + ModuleListenerList::Iterator iterator = fListeners.GetIterator(); + while (iterator.HasNext()) { + module_listener* listener = iterator.Next(); + + if (strncmp(path, listener->prefix, strlen(listener->prefix))) + continue; + + if (event.IsEmpty()) { + // construct message only when needed + event.AddInt32("opcode", opcode); + event.AddString("path", path); + } + + // notify them! + listener->listener->EventOccured(*this, &event); + + // we might need to watch new files now + if (opcode == B_ENTRY_CREATED) + _AddDirectory(listener->prefix); + + } + + // remove notification listeners, if needed + + if (opcode == B_ENTRY_REMOVED) + _RemoveNode(device, node); +} + + +void +ModuleNotificationService::_HandleNotifications() +{ + RecursiveLocker _(fLock); + + NotificationList::Iterator iterator = fNotifications.GetIterator(); + while (iterator.HasNext()) { + module_notification* notification = iterator.Next(); + + _Notify(notification->opcode, notification->device, + notification->directory, notification->node, notification->name); + + iterator.Remove(); + delete notification; + } +} + + +void +ModuleNotificationService::Notify(int32 opcode, dev_t device, ino_t directory, + ino_t node, const char* name) +{ + module_notification* notification = new(std::nothrow) module_notification; + if (notification == NULL) + return; + + if (name != NULL) { + notification->name = strdup(name); + if (notification->name == NULL) { + delete notification; + return; + } + } else + notification->name = NULL; + + notification->opcode = opcode; + notification->device = device; + notification->directory = directory; + notification->node = node; + + RecursiveLocker _(fLock); + fNotifications.Add(notification); +} + + +/*static*/ void +ModuleNotificationService::HandleNotifications(void */*data*/, + int /*iteration*/) +{ + sModuleNotificationService._HandleNotifications(); +} + + // #pragma mark - Exported Kernel API (private part) @@ -1591,6 +1813,10 @@ new(&sModuleNotificationService) ModuleNotificationService(); + register_kernel_daemon(&ModuleNotificationService::HandleNotifications, + NULL, 10); + // once every second + sDisableUserAddOns = get_safemode_boolean(B_SAFEMODE_DISABLE_USER_ADD_ONS, false); From axeld at pinc-software.de Thu Jul 10 14:54:47 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Thu, 10 Jul 2008 14:54:47 +0200 CEST Subject: [Haiku-commits] r26341 - in haiku/trunk: headers/os/interface In-Reply-To: <20080710142027.10792.19@stippis2.1215669831.fake> Message-ID: <23413307172-BeMail@zon> Stephan Assmus wrote: > >c) GetMouse() and DispatchMessage() would not need any extra code > I am not sure about that, since Ingo's solution works at the BWindow > level > (global), while the no-history-flag works at the view level. So I > guess the > BWindow level code would always have to provide the history and there > will > have to at least be some extra code in GetMouse(). With no history, the code could always choose the latest message in the queue, though, so at least the app_server wouldn't need to send all mouse messages separately this way (it would only do that if one view had the all-pointer-history flag set). > > d) it doesn't matter how slow the system is, it would always work > > reliable. > The current method does work reliable. It may do too much on a slow > system > as per my TODO comment, which is obviously undesired. But reliable it > is. Reliability was the wrong term without a context - I meant a reliably working pointer history :-) > > Ingo's suggestion has the added advantage that no actual messages > > are > > sent for each mouse button when it's not needed, so that save some > > cycles. > > But that can be done at later point, too. > To me it looks, like the proposed method would have some benefits, > but not > all the ones you outlined (reduced complexity and added reliability). > Since > the current solution works, I am inclined to be lazy, especially > since I > have some other stuff that interests me currently. Like experimenting > with > subpixel rendering methods or implementing playlist loading/saving in > MediaPlayer or looping and repeat modes... :-) But someone else, > please > feel free to implement it! :-P As long as it's still acceptable on slow systems (which I guess it is), the suggested changes would definitely fall under the category of optimizations, now. At least I don't plan to look into that before R1/ alpha, and maybe I've forgotten about it when we're there ;-) Bye, Axel. From stippi at mail.berlios.de Thu Jul 10 14:59:24 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Thu, 10 Jul 2008 14:59:24 +0200 Subject: [Haiku-commits] r26370 - haiku/trunk/src/servers/app Message-ID: <200807101259.m6ACxOnt014690@sheep.berlios.de> Author: stippi Date: 2008-07-10 14:59:20 +0200 (Thu, 10 Jul 2008) New Revision: 26370 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26370&view=rev Modified: haiku/trunk/src/servers/app/FontEngine.cpp Log: * I have experiemented with a different method of countering the colored edges problem of subpixel-anti-alised font rendering. Personally I find the method better than filtering the subpixels, since it is a straighter transition between unfiltered subpixel aa and grayscale aa. There is no added blur affecting also innocent neighboring pixels. The filter method is better at hiding jagged diagonal lines though, so Andrej and I agreed to move this to a general discussion on the mailing list. Screenshots forthcomming... * Some additional coding style improvements. Modified: haiku/trunk/src/servers/app/FontEngine.cpp =================================================================== --- haiku/trunk/src/servers/app/FontEngine.cpp 2008-07-10 12:42:02 UTC (rev 26369) +++ haiku/trunk/src/servers/app/FontEngine.cpp 2008-07-10 12:59:20 UTC (rev 26370) @@ -295,7 +295,6 @@ decompose_ft_bitmap_mono(const FT_Bitmap& bitmap, int x, int y, bool flip_y, Scanline& sl, ScanlineStorage& storage) { - int i; const uint8* buf = (const uint8*)bitmap.buffer; int pitch = bitmap.pitch; sl.reset(x, x + bitmap.width); @@ -305,11 +304,10 @@ y += bitmap.rows; pitch = -pitch; } - for (i = 0; i < bitmap.rows; i++) { + for (int i = 0; i < bitmap.rows; i++) { sl.reset_spans(); agg::bitset_iterator bits(buf, 0); - int j; - for (j = 0; j < bitmap.width; j++) { + for (int j = 0; j < bitmap.width; j++) { if (bits.bit()) sl.add_cell(x + j, agg::cover_full); ++bits; @@ -329,7 +327,6 @@ decompose_ft_bitmap_gray8(const FT_Bitmap& bitmap, int x, int y, bool flip_y, Scanline& sl, ScanlineStorage& storage) { - int i, j; const uint8* buf = (const uint8*)bitmap.buffer; int pitch = bitmap.pitch; sl.reset(x, x + bitmap.width); @@ -339,21 +336,20 @@ y += bitmap.rows; pitch = -pitch; } - for (i = 0; i < bitmap.rows; i++) { + for (int i = 0; i < bitmap.rows; i++) { sl.reset_spans(); if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { // font has built-in mono bitmap agg::bitset_iterator bits(buf, 0); - int j; - for (j = 0; j < bitmap.width; j++) { + for (int j = 0; j < bitmap.width; j++) { if (bits.bit()) sl.add_cell(x + j, agg::cover_full); ++bits; } } else { const uint8* p = buf; - for (j = 0; j < bitmap.width; j++) { + for (int j = 0; j < bitmap.width; j++) { if (*p) sl.add_cell(x + j, *p); ++p; @@ -369,131 +365,216 @@ } +#define AVERAGE_BASED_SUBPIXEL_FILTERING +// NOTE stippi: My basic idea is that filtering tries to minimize colored +// edges, but it does so by blurring the coverage values. This will also +// affect neighboring pixels and add blur where there were perfectly sharp +// edges. Andrej's method of filtering adds a special case for perfectly +// sharp edges, but the drawback here is that there will be a visible +// transition between blurred and non-blurred subpixels. I had the idea that +// when simply fading the subpixels towards the plain gray-scale-aa values, +// there must be a sweet spot for when colored edges become non-disturbing +// and there is still a benefit of sharpness compared to straight gray-scale- +// aa. The define above enables this method against the colored edges. My +// method still has a drawback, since jaggies in diagonal lines will be more +// visible again than with the filter method. + + // decompose_ft_bitmap_subpix template void decompose_ft_bitmap_subpix(const FT_Bitmap& bitmap, int x, int y, bool flip_y, Scanline& sl, ScanlineStorage& storage) { - //Filtering weights +#ifdef AVERAGE_BASED_SUBPIXEL_FILTERING + // The weight with which the average of the subpixels is applied to counter + // color fringes (0 = full sharpness ... 255 = grayscale anti-aliasing) + // TODO: This could be a config option, but don't forget to include the + // value in the font cache entry signature generation! + const uint8 averageWeight = 100; + const uint8 subpixelWeight = 255 - averageWeight; + + const uint8* buf = (const uint8*)bitmap.buffer; + int pitch = bitmap.pitch; + sl.reset(x, x + bitmap.width / 3); + storage.prepare(); + + if (flip_y) { + buf += bitmap.pitch * (bitmap.rows - 1); + y += bitmap.rows; + pitch = -pitch; + } + + for (int i = 0; i < bitmap.rows; i++) { + sl.reset_spans(); + + if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { + // font has built-in mono bitmap + agg::bitset_iterator bits(buf, 0); + for (int j = 0; j < bitmap.width; j++) { + if (bits.bit()) { + sl.add_cell(x + j, + agg::cover_full, agg::cover_full, agg::cover_full); + } + ++bits; + } + } else { + const uint8* p = buf; + uint32 coverR; + uint32 coverG; + uint32 coverB; + int w = bitmap.width / 3; + + for (int j = 0; j < w; j++) { + uint32 average = (p[0] + p[1] + p[2] + 2) / 3; + coverR = (p[0] * subpixelWeight + average * averageWeight) >> 8; + coverG = (p[1] * subpixelWeight + average * averageWeight) >> 8; + coverB = (p[2] * subpixelWeight + average * averageWeight) >> 8; + + if (coverR || coverG || coverB) + sl.add_cell(x + j, coverR, coverG, coverB); + + p += 3; + } + } + + buf += pitch; + if (sl.num_spans()) { + sl.finalize(y - i - 1); + storage.render(sl); + } + } +#else // filter based anti-colored edges method + // Filtering weights const uint8 filter[5] = { 0x10, 0x40, 0x70, 0x40, 0x10 }; - int i, j; const uint8* buf = (const uint8*)bitmap.buffer; int pitch = bitmap.pitch; - sl.reset(x-1, x + bitmap.width/3 + 1); + sl.reset(x - 1, x + bitmap.width / 3 + 1); + // -1 and +1 to account for additional edge pixels needed by filtering storage.prepare(); if (flip_y) { buf += bitmap.pitch * (bitmap.rows - 1); y += bitmap.rows; pitch = -pitch; } - for (i = 0; i < bitmap.rows; i++) { + for (int i = 0; i < bitmap.rows; i++) { sl.reset_spans(); if (bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { // font has built-in mono bitmap agg::bitset_iterator bits(buf, 0); - int j; - for (j = 0; j < bitmap.width; j++) { - if (bits.bit()) + for (int j = 0; j < bitmap.width; j++) { + if (bits.bit()) { sl.add_cell(x + j, agg::cover_full, agg::cover_full, agg::cover_full); + } ++bits; } } else { const uint8* p = buf; - uint32 coverRed; - uint32 coverGreen; - uint32 coverBlue; - int w = bitmap.width/3; + uint32 coverR; + uint32 coverG; + uint32 coverB; + int w = bitmap.width / 3; + // handle the left extra edge pixel if (w && !(p[0] == p[1] && p[1] == p[2] - && (w == 1 || (p[3] == p[4] && p[4] == p[5])))){ - coverRed = 0; - coverGreen = (p[0] * filter[0]) >> 8; - coverBlue = (p[0] * filter[1] + p[1] * filter[0]) >> 8; - coverGreen = coverGreen | ( -(coverGreen >> 8)); - coverBlue = coverBlue | ( -(coverBlue >> 8)); - if (coverRed || coverGreen || coverBlue){ - sl.add_cell(x - 1, coverRed, coverGreen, coverBlue); - } + && (w == 1 || (p[3] == p[4] && p[4] == p[5])))) { + + coverR = 0; + coverG = (p[0] * filter[0]) >> 8; + coverB = (p[0] * filter[1] + p[1] * filter[0]) >> 8; + coverG = coverG | ( -(coverG >> 8)); + coverB = coverB | ( -(coverB >> 8)); + + if (coverR || coverG || coverB) + sl.add_cell(x - 1, coverR, coverG, coverB); } - for (j = 0; j < w; j++) { + for (int j = 0; j < w; j++) { if (p[0] == p[1] && p[1] == p[2] && (j == 0 || (p[-3] == p[-2] && p[-2] == p[-1])) - && (j == w-1 || (p[3] == p[4] && p[4] == p[5]))){ - coverRed = p[0]; - coverGreen = p[0]; - coverBlue = p[0]; + && (j == w-1 || (p[3] == p[4] && p[4] == p[5]))) { + + coverR = p[0]; + coverG = p[0]; + coverB = p[0]; + } else if (p[0] == p[1] && p[1] == p[2] - && (j < w-1 && p[3] == p[4] && p[4] == p[5]) - && (j == w-2 || (p[6] == p[7] && p[7] == p[8]))){ - coverRed = ((j > 0 ? p[-2] * filter[4] - + p[-1] * filter[3] : 0) - + p[0] * filter[2] + p[1] * filter[1] - + p[2] * filter[0]) - >> 8; - coverGreen = ((j > 0 ? p[-1] * filter[4] : 0) - + p[0] * filter[3] + p[1] * filter[2] - + p[2] * filter[1]) - >> 8; - coverBlue = (p[0] * filter[4] - + p[1] * filter[3] + p[2] * filter[2]) >> 8; - coverRed = coverRed | ( -(coverRed >> 8)); - coverGreen = coverGreen | ( -(coverGreen >> 8)); - coverBlue = coverBlue | ( -(coverBlue >> 8)); + && (j < w-1 && p[3] == p[4] && p[4] == p[5]) + && (j == w-2 || (p[6] == p[7] && p[7] == p[8]))) { + + coverR = ((j > 0 ? p[-2] * filter[4] + + p[-1] * filter[3] : 0) + + p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) + >> 8; + coverG = ((j > 0 ? p[-1] * filter[4] : 0) + + p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1]) + >> 8; + coverB = (p[0] * filter[4] + + p[1] * filter[3] + p[2] * filter[2]) >> 8; + coverR = coverR | ( -(coverR >> 8)); + coverG = coverG | ( -(coverG >> 8)); + coverB = coverB | ( -(coverB >> 8)); + } else if (p[0] == p[1] && p[1] == p[2] - && (j > 0 && p[-3] == p[-2] && p[-2] == p[-1]) - && (j == 1 || (p[-6] == p[-5] && p[-5] == p[-4]))){ - coverRed = (p[0] * filter[2] + p[1] * filter[1] - + p[2] * filter[0]) >> 8; - coverGreen = (p[0] * filter[3] + p[1] * filter[2] - + p[2] * filter[1] - + (j < w-1 ? p[3] * filter[0] : 0)) - >> 8; - coverBlue = (p[0] * filter[4] + p[1] * filter[3] - + p[2] * filter[2] - + (j < w-1 ? p[3] * filter[1] - + p[4] * filter[0] : 0)) - >> 8; - coverRed = coverRed | ( -(coverRed >> 8)); - coverGreen = coverGreen | ( -(coverGreen >> 8)); - coverBlue = coverBlue | ( -(coverBlue >> 8)); + && (j > 0 && p[-3] == p[-2] && p[-2] == p[-1]) + && (j == 1 || (p[-6] == p[-5] && p[-5] == p[-4]))) { + + coverR = (p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) >> 8; + coverG = (p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1] + + (j < w-1 ? p[3] * filter[0] : 0)) + >> 8; + coverB = (p[0] * filter[4] + p[1] * filter[3] + + p[2] * filter[2] + + (j < w-1 ? p[3] * filter[1] + + p[4] * filter[0] : 0)) + >> 8; + coverR = coverR | ( -(coverR >> 8)); + coverG = coverG | ( -(coverG >> 8)); + coverB = coverB | ( -(coverB >> 8)); + } else { - coverRed = ((j > 0 ? p[-2] * filter[4] - + p[-1] * filter[3] : 0) - + p[0] * filter[2] + p[1] * filter[1] - + p[2] * filter[0]) - >> 8; - coverGreen = ((j > 0 ? p[-1] * filter[4] : 0) - + p[0] * filter[3] + p[1] * filter[2] - + p[2] * filter[1] - + (j < w-1 ? p[3] * filter[0] : 0)) - >> 8; - coverBlue = (p[0] * filter[4] + p[1] * filter[3] - + p[2] * filter[2] - + (j < w-1 ? p[3] * filter[1] - + p[4] * filter[0] : 0)) - >> 8; - coverRed = coverRed | ( -(coverRed >> 8)); - coverGreen = coverGreen | ( -(coverGreen >> 8)); - coverBlue = coverBlue | ( -(coverBlue >> 8)); + + coverR = ((j > 0 ? p[-2] * filter[4] + + p[-1] * filter[3] : 0) + + p[0] * filter[2] + p[1] * filter[1] + + p[2] * filter[0]) + >> 8; + coverG = ((j > 0 ? p[-1] * filter[4] : 0) + + p[0] * filter[3] + p[1] * filter[2] + + p[2] * filter[1] + + (j < w-1 ? p[3] * filter[0] : 0)) + >> 8; + coverB = (p[0] * filter[4] + p[1] * filter[3] + + p[2] * filter[2] + + (j < w-1 ? p[3] * filter[1] + + p[4] * filter[0] : 0)) + >> 8; + coverR = coverR | ( -(coverR >> 8)); + coverG = coverG | ( -(coverG >> 8)); + coverB = coverB | ( -(coverB >> 8)); } - if (coverRed || coverGreen || coverBlue) { - sl.add_cell(x + j, coverRed, coverGreen, coverBlue); - } + + if (coverR || coverG || coverB) + sl.add_cell(x + j, coverR, coverG, coverB); p += 3; } + // handle the right extra edge pixel if (w && !(p[-3] == p[-2] && p[-2] == p[-1] - && (w == 1 || (p[-6] == p[-5] && p[-5] == p[-4])))){ - coverRed = (p[-2] * filter[4] + p[-1] * filter[3]) >> 8; - coverGreen = (p[-1] * filter[4]) >> 8; - coverBlue = 0; - coverRed = coverRed | ( -(coverRed >> 8)); - coverGreen = coverGreen | ( -(coverGreen >> 8)); - if (coverRed || coverGreen || coverBlue){ - sl.add_cell(x + w, coverRed, coverGreen, coverBlue); - } + && (w == 1 || (p[-6] == p[-5] && p[-5] == p[-4])))) { + + coverR = (p[-2] * filter[4] + p[-1] * filter[3]) >> 8; + coverG = (p[-1] * filter[4]) >> 8; + coverB = 0; + coverR = coverR | ( -(coverR >> 8)); + coverG = coverG | ( -(coverG >> 8)); + + if (coverR || coverG || coverB) + sl.add_cell(x + w, coverR, coverG, coverB); } } @@ -503,6 +584,7 @@ storage.render(sl); } } +#endif } // #pragma mark - From axeld at mail.berlios.de Thu Jul 10 16:17:24 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 10 Jul 2008 16:17:24 +0200 Subject: [Haiku-commits] r26371 - haiku/trunk/src/servers/app Message-ID: <200807101417.m6AEHOhb021821@sheep.berlios.de> Author: axeld Date: 2008-07-10 16:17:23 +0200 (Thu, 10 Jul 2008) New Revision: 26371 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26371&view=rev Modified: haiku/trunk/src/servers/app/Desktop.cpp haiku/trunk/src/servers/app/Window.cpp haiku/trunk/src/servers/app/Window.h Log: * Desktop::_UpdateFloating() and Desktop::_UpdateSubsetWorkspaces() both assumed that there was only a single window that was responsible for the workspaces of a floating/subset window. Of course, any number of windows can make up the workspaces of those. This fixes bug #2506. * Added a Window::InSubsetWorkspace() method to complement SubsetWorkspaces(). * Minor cleanup. Modified: haiku/trunk/src/servers/app/Desktop.cpp =================================================================== --- haiku/trunk/src/servers/app/Desktop.cpp 2008-07-10 12:59:20 UTC (rev 26370) +++ haiku/trunk/src/servers/app/Desktop.cpp 2008-07-10 14:17:23 UTC (rev 26371) @@ -1106,14 +1106,17 @@ && floating->Feel() != B_FLOATING_APP_WINDOW_FEEL) continue; - if (fFront != NULL && fFront->IsNormal() && floating->HasInSubset(fFront)) { + if (fFront != NULL && fFront->IsNormal() + && floating->HasInSubset(fFront)) { // is now visible if (_Windows(previousWorkspace).HasWindow(floating) - && previousWorkspace != nextWorkspace) { + && previousWorkspace != nextWorkspace + && !floating->InSubsetWorkspace(previousWorkspace)) { // but no longer on the previous workspace _Windows(previousWorkspace).RemoveWindow(floating); floating->SetCurrentWorkspace(-1); } + if (!_Windows(nextWorkspace).HasWindow(floating)) { // but wasn't before _Windows(nextWorkspace).AddWindow(floating, @@ -1122,11 +1125,11 @@ if (mouseEventWindow != fFront) _ShowWindow(floating); - // TODO: - // put the floating last in the floating window list to preserve - // the on screen window order + // TODO: put the floating last in the floating window list to + // preserve the on screen window order } - } else if (_Windows(previousWorkspace).HasWindow(floating)) { + } else if (_Windows(previousWorkspace).HasWindow(floating) + && !floating->InSubsetWorkspace(previousWorkspace)) { // was visible, but is no longer _Windows(previousWorkspace).RemoveWindow(floating); @@ -1140,8 +1143,7 @@ } -/*! - Search the visible windows for a valid back window +/*! Search the visible windows for a valid back window (only desktop windows can't be back windows) */ void @@ -1160,8 +1162,7 @@ } -/*! - Search the visible windows for a valid front window +/*! Search the visible windows for a valid front window (only normal and modal windows can be front windows) The only place where you don't want to update floating windows is @@ -1915,8 +1916,7 @@ } -/*! - Updates the workspaces of all subset windows with regard to the +/*! Updates the workspaces of all subset windows with regard to the specifed window. If newIndex is not -1, it will move all subset windows that belong to the specifed window to the new workspace; this form is only called by @@ -1950,11 +1950,7 @@ if (subset->HasInSubset(window)) { // adopt the workspace change - if (newIndex != -1) { - _Windows(newIndex).AddWindow(subset); - _Windows(previousIndex).RemoveWindow(subset); - } else - SetWindowWorkspaces(subset, subset->SubsetWorkspaces()); + SetWindowWorkspaces(subset, subset->SubsetWorkspaces()); } } } @@ -1967,6 +1963,9 @@ Desktop::_ChangeWindowWorkspaces(Window* window, uint32 oldWorkspaces, uint32 newWorkspaces) { + if (oldWorkspaces == newWorkspaces) + return; + // apply changes to the workspaces' window lists LockAllWindows(); Modified: haiku/trunk/src/servers/app/Window.cpp =================================================================== --- haiku/trunk/src/servers/app/Window.cpp 2008-07-10 12:59:20 UTC (rev 26370) +++ haiku/trunk/src/servers/app/Window.cpp 2008-07-10 14:17:23 UTC (rev 26371) @@ -1606,6 +1606,17 @@ } +/*! Returns wether or not a window is in the subset workspace list with the + specified \a index. + See SubsetWorkspaces(). +*/ +bool +Window::InSubsetWorkspace(int32 index) const +{ + return (SubsetWorkspaces() & (1UL << index)) != 0; +} + + // #pragma mark - static Modified: haiku/trunk/src/servers/app/Window.h =================================================================== --- haiku/trunk/src/servers/app/Window.h 2008-07-10 12:59:20 UTC (rev 26370) +++ haiku/trunk/src/servers/app/Window.h 2008-07-10 14:17:23 UTC (rev 26371) @@ -209,6 +209,7 @@ bool HasInSubset(const Window* window) const; bool SameSubset(Window* window); uint32 SubsetWorkspaces() const; + bool InSubsetWorkspace(int32 index) const; bool HasWorkspacesViews() const { return fWorkspacesViewCount != 0; } @@ -250,7 +251,7 @@ void _ObeySizeLimits(); void _PropagatePosition(); - BString fTitle; + BString fTitle; // TODO: no fp rects anywhere BRect fFrame; @@ -259,7 +260,7 @@ // the visible region is only recalculated from the // Desktop thread, when using it, Desktop::ReadLockClipping() // has to be called - + BRegion fVisibleRegion; BRegion fVisibleContentRegion; // our part of the "global" dirty region @@ -313,15 +314,15 @@ public: UpdateSession(); virtual ~UpdateSession(); - + void Include(BRegion* additionalDirty); void Exclude(BRegion* dirtyInNextSession); - + inline BRegion& DirtyRegion() { return fDirtyRegion; } - + void MoveBy(int32 x, int32 y); - + void SetUsed(bool used); inline bool IsUsed() const { return fInUse; } @@ -331,7 +332,7 @@ { return fCause & UPDATE_EXPOSE; } inline bool IsRequest() const { return fCause & UPDATE_REQUEST; } - + private: BRegion fDirtyRegion; bool fInUse; From bonefish at mail.berlios.de Thu Jul 10 20:53:52 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 20:53:52 +0200 Subject: [Haiku-commits] r26372 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel Message-ID: <200807101853.m6AIrqRn014777@sheep.berlios.de> Author: bonefish Date: 2008-07-10 20:53:49 +0200 (Thu, 10 Jul 2008) New Revision: 26372 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26372&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/condition_variable.h haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp Log: Added ConditionVariable::Wait() that doesn't need a ConditionVariableEntry (the method itself creates one on the stack). Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/condition_variable.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/condition_variable.h 2008-07-10 14:17:23 UTC (rev 26371) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/condition_variable.h 2008-07-10 18:53:49 UTC (rev 26372) @@ -63,6 +63,10 @@ void Add(ConditionVariableEntry* entry, uint32 flags = 0); + status_t Wait(uint32 flags = 0, bigtime_t timeout = 0); + // all-in one, i.e. doesn't need a + // ConditionVariableEntry + const void* Object() const { return fObject; } static void ListAll(); Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp 2008-07-10 14:17:23 UTC (rev 26371) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp 2008-07-10 18:53:49 UTC (rev 26372) @@ -252,6 +252,15 @@ } +status_t +ConditionVariable::Wait(uint32 flags, bigtime_t timeout) +{ + ConditionVariableEntry entry; + Add(&entry, flags); + return entry.Wait(flags, timeout); +} + + /*static*/ void ConditionVariable::ListAll() { From bonefish at mail.berlios.de Thu Jul 10 20:56:38 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 20:56:38 +0200 Subject: [Haiku-commits] r26373 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel src/system/kernel/vm Message-ID: <200807101856.m6AIuc0o015066@sheep.berlios.de> Author: bonefish Date: 2008-07-10 20:56:35 +0200 (Thu, 10 Jul 2008) New Revision: 26373 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26373&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp Log: Added "bool wait" parameter to low_resource(). When true the function will wait until the low resource manager thread has finished its next iteration of calling low resource handlers. Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h 2008-07-10 18:53:49 UTC (rev 26372) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h 2008-07-10 18:56:35 UTC (rev 26373) @@ -37,7 +37,7 @@ status_t low_resource_manager_init(void); status_t low_resource_manager_init_post_thread(void); int32 low_resource_state(uint32 resources); -void low_resource(uint32 resource, uint64 requirements); +void low_resource(uint32 resource, uint64 requirements, bool wait); // these calls might get public some day status_t register_low_resource_handler(low_resource_func function, void *data, Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp 2008-07-10 18:53:49 UTC (rev 26372) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp 2008-07-10 18:56:35 UTC (rev 26373) @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -70,7 +71,9 @@ static sem_id sLowResourceWaitSem; static HandlerList sLowResourceHandlers; +static ConditionVariable sLowResourceWaiterCondition; + static int32 low_resource_state_no_update(uint32 resources) { @@ -202,6 +205,8 @@ timeout = kWarnResourceInterval; else timeout = kLowResourceInterval; + + sLowResourceWaiterCondition.NotifyAll(); } return 0; } @@ -237,8 +242,12 @@ // #pragma mark - private kernel API +/*! Notifies the low resource manager that a resource is lacking. If \a wait + is \c true, the function will wait until the low resource manager has + finished its next iteration of calling low resource handlers. +*/ void -low_resource(uint32 resource, uint64 requirements) +low_resource(uint32 resource, uint64 requirements, bool wait) { // TODO: take requirements into account @@ -247,14 +256,15 @@ vm_schedule_page_scanner(requirements); break; case B_KERNEL_RESOURCE_MEMORY: -// TODO:... break; case B_KERNEL_RESOURCE_SEMAPHORES: -// TODO:... break; } release_sem(sLowResourceWaitSem); + + if (wait) + sLowResourceWaiterCondition.Wait(); } @@ -281,6 +291,8 @@ // static initializers do not work in the kernel, // so we have to do it here, manually + sLowResourceWaiterCondition.Init(NULL, "low resource waiters"); + // compute the free memory limits off_t totalMemory = (off_t)vm_page_num_pages() * B_PAGE_SIZE; sNoteMemoryLimit = totalMemory / 16; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 18:53:49 UTC (rev 26372) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 18:56:35 UTC (rev 26373) @@ -1252,7 +1252,7 @@ freeConditionEntry.Add(&sFreePageQueue); locker.Unlock(); - low_resource(B_KERNEL_RESOURCE_PAGES, count); + low_resource(B_KERNEL_RESOURCE_PAGES, count, false); //snooze(50000); // sleep for 50ms From bonefish at mail.berlios.de Thu Jul 10 21:29:18 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 21:29:18 +0200 Subject: [Haiku-commits] r26374 - haiku/branches/developer/bonefish/vm/src/system/kernel Message-ID: <200807101929.m6AJTIbF019595@sheep.berlios.de> Author: bonefish Date: 2008-07-10 21:29:08 +0200 (Thu, 10 Jul 2008) New Revision: 26374 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26374&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp Log: Removed ASSERT that's a bit annoying for anonymous condition variables, since one doesn't need an object in this case. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp 2008-07-10 18:56:35 UTC (rev 26373) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/condition_variable.cpp 2008-07-10 19:29:08 UTC (rev 26374) @@ -295,8 +295,6 @@ void ConditionVariable::_Notify(bool all, bool threadsLocked) { - ASSERT(fObject != NULL); - InterruptsLocker _; SpinLocker threadLocker(threadsLocked ? NULL : &thread_spinlock); SpinLocker locker(sConditionVariablesLock); From bonefish at mail.berlios.de Thu Jul 10 21:50:39 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 21:50:39 +0200 Subject: [Haiku-commits] r26375 - in haiku/branches/developer/bonefish/vm: headers/private/kernel src/system/kernel src/system/kernel/vm Message-ID: <200807101950.m6AJodeL021980@sheep.berlios.de> Author: bonefish Date: 2008-07-10 21:50:34 +0200 (Thu, 10 Jul 2008) New Revision: 26375 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26375&view=rev Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h haiku/branches/developer/bonefish/vm/headers/private/kernel/vm.h haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_priv.h haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp Log: * Replaced the low_resource() "bool wait" parameter by a flags + timeout pair. Timeouts are a good idea given that it's not really clear how long the low resource handlers might take. * Added timeout parameter to vm_try_reserve_memory(). That's how long the function loops and keeps nagging the low resource manager. * Also track the amount of memory needed by threads waiting in vm_try_resource_memory(). vm_available_not_needed_memory() returns the difference of available and needed memory. * The VMAnonymous*Cache implementations use a 1s timeout for reserving memory in Commit() now. Over-committing areas still require immediate reservations, though. This might already remedy the main problem of #2046. 1s could be a little too short for freeing the 270 MB jam needs, though. Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/low_resource_manager.h 2008-07-10 19:50:34 UTC (rev 26375) @@ -37,7 +37,8 @@ status_t low_resource_manager_init(void); status_t low_resource_manager_init_post_thread(void); int32 low_resource_state(uint32 resources); -void low_resource(uint32 resource, uint64 requirements, bool wait); +void low_resource(uint32 resource, uint64 requirements, uint32 flags, + uint32 timeout); // these calls might get public some day status_t register_low_resource_handler(low_resource_func function, void *data, Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm.h 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/vm.h 2008-07-10 19:50:34 UTC (rev 26375) @@ -88,6 +88,7 @@ status_t vm_put_physical_page(addr_t vaddr); off_t vm_available_memory(void); +off_t vm_available_not_needed_memory(void); // user syscalls area_id _user_create_area(const char *name, void **address, uint32 addressSpec, Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_priv.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_priv.h 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/vm_priv.h 2008-07-10 19:50:34 UTC (rev 26375) @@ -48,7 +48,7 @@ status_t vm_page_fault(addr_t address, addr_t faultAddress, bool isWrite, bool isUser, addr_t *newip); void vm_unreserve_memory(size_t bytes); -status_t vm_try_reserve_memory(size_t bytes); +status_t vm_try_reserve_memory(size_t bytes, bigtime_t timeout); void vm_schedule_page_scanner(uint32 target); status_t vm_daemon_init(void); Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/low_resource_manager.cpp 2008-07-10 19:50:34 UTC (rev 26375) @@ -146,7 +146,7 @@ } // free memory state - off_t freeMemory = vm_available_memory(); + off_t freeMemory = vm_available_not_needed_memory(); if (freeMemory < sCriticalMemoryLimit) { sLowMemoryState = B_LOW_RESOURCE_CRITICAL; @@ -194,7 +194,8 @@ TRACE(("low_resource_manager: state = %ld, %ld free pages, %lld free " "memory, %lu free semaphores\n", state, vm_page_num_free_pages(), - vm_available_memory(), sem_max_sems() - sem_used_sems())); + vm_available_not_needed_memory(), + sem_max_sems() - sem_used_sems())); if (state < B_LOW_RESOURCE_NOTE) continue; @@ -242,12 +243,13 @@ // #pragma mark - private kernel API -/*! Notifies the low resource manager that a resource is lacking. If \a wait - is \c true, the function will wait until the low resource manager has - finished its next iteration of calling low resource handlers. +/*! Notifies the low resource manager that a resource is lacking. If \a flags + and \a timeout specify a timeout, the function will wait until the low + resource manager has finished its next iteration of calling low resource + handlers, or until the timeout occurs (whichever happens first). */ void -low_resource(uint32 resource, uint64 requirements, bool wait) +low_resource(uint32 resource, uint64 requirements, uint32 flags, uint32 timeout) { // TODO: take requirements into account @@ -263,8 +265,8 @@ release_sem(sLowResourceWaitSem); - if (wait) - sLowResourceWaiterCondition.Wait(); + if ((flags & B_RELATIVE_TIMEOUT) == 0 || timeout > 0) + sLowResourceWaiterCondition.Wait(flags, timeout); } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-10 19:50:34 UTC (rev 26375) @@ -141,7 +141,7 @@ if (size > committed_size) { // try to commit - if (vm_try_reserve_memory(size - committed_size) != B_OK) + if (vm_try_reserve_memory(size - committed_size, 1000000) != B_OK) return B_NO_MEMORY; } else { // we can release some @@ -267,7 +267,7 @@ if (fPrecommittedPages == 0) { // try to commit additional memory - if (vm_try_reserve_memory(B_PAGE_SIZE) != B_OK) + if (vm_try_reserve_memory(B_PAGE_SIZE, 0) != B_OK) return B_NO_MEMORY; committed_size += B_PAGE_SIZE; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-10 19:50:34 UTC (rev 26375) @@ -75,7 +75,7 @@ if (size > committed_size) { // try to commit - if (vm_try_reserve_memory(size - committed_size) != B_OK) + if (vm_try_reserve_memory(size - committed_size, 1000000) != B_OK) return B_NO_MEMORY; } else { // we can release some @@ -136,7 +136,7 @@ if (fPrecommittedPages == 0) { // try to commit additional memory - if (vm_try_reserve_memory(B_PAGE_SIZE) != B_OK) + if (vm_try_reserve_memory(B_PAGE_SIZE, 0) != B_OK) return B_NO_MEMORY; committed_size += B_PAGE_SIZE; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm.cpp 2008-07-10 19:50:34 UTC (rev 26375) @@ -20,31 +20,30 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include #include -#include -#include -#include #include +#include +#include #include -#include #include #include #include #include +#include +#include +#include +#include -#include -#include -#include -#include - - //#define TRACE_VM //#define TRACE_FAULTS #ifdef TRACE_VM @@ -193,6 +192,7 @@ static mutex sAreaCacheLock = MUTEX_INITIALIZER("area->cache"); static off_t sAvailableMemory; +static off_t sNeededMemory; static mutex sAvailableMemoryLock = MUTEX_INITIALIZER("available memory lock"); #if DEBUG_CACHE_LIST @@ -4613,10 +4613,19 @@ off_t vm_available_memory(void) { + MutexLocker locker(sAvailableMemoryLock); return sAvailableMemory; } +off_t +vm_available_not_needed_memory(void) +{ + MutexLocker locker(sAvailableMemoryLock); + return sAvailableMemory - sNeededMemory; +} + + status_t vm_put_physical_page(addr_t vaddr) { @@ -4636,21 +4645,42 @@ status_t -vm_try_reserve_memory(size_t amount) +vm_try_reserve_memory(size_t amount, bigtime_t timeout) { - status_t status; - mutex_lock(&sAvailableMemoryLock); + MutexLocker locker(sAvailableMemoryLock); //dprintf("try to reserve %lu bytes, %Lu left\n", amount, sAvailableMemory); if (sAvailableMemory >= amount) { sAvailableMemory -= amount; - status = B_OK; - } else - status = B_NO_MEMORY; + return B_OK; + } - mutex_unlock(&sAvailableMemoryLock); - return status; + if (timeout <= 0) + return B_NO_MEMORY; + + // turn timeout into an absolute timeout + timeout += system_time(); + + // loop until we've got the memory or the timeout occurs + do { + sNeededMemory += amount; + + // call the low resource manager + locker.Unlock(); + low_resource(B_KERNEL_RESOURCE_MEMORY, sNeededMemory - sAvailableMemory, + B_ABSOLUTE_TIMEOUT, timeout); + locker.Lock(); + + sNeededMemory -= amount; + + if (sAvailableMemory >= amount) { + sAvailableMemory -= amount; + return B_OK; + } + } while (timeout > system_time()); + + return B_NO_MEMORY; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 19:29:08 UTC (rev 26374) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/vm_page.cpp 2008-07-10 19:50:34 UTC (rev 26375) @@ -1252,7 +1252,7 @@ freeConditionEntry.Add(&sFreePageQueue); locker.Unlock(); - low_resource(B_KERNEL_RESOURCE_PAGES, count, false); + low_resource(B_KERNEL_RESOURCE_PAGES, count, B_RELATIVE_TIMEOUT, 0); //snooze(50000); // sleep for 50ms From bonefish at mail.berlios.de Thu Jul 10 22:04:38 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Thu, 10 Jul 2008 22:04:38 +0200 Subject: [Haiku-commits] r26376 - in haiku/branches/developer/bonefish/vm: headers/libs/agg headers/os/bluetooth/HCI headers/os/interface headers/posix headers/private/app headers/private/kernel headers/private/kernel/disk_device_manager headers/private/kernel/fs headers/private/kernel/util headers/private/libroot src/add-ons/kernel/drivers/audio/hda src/add-ons/kernel/drivers/bluetooth/h2/h2generic src/kits/interface src/preferences/fonts src/preferences/print src/servers/app src/servers/app/drawing/Painter src/servers/app/drawing/Painter/drawing_modes src/servers/bluetooth src/system/kernel src/system/kernel/debug src/system/kernel/device_manager src/system/kernel/disk_device_manager src/system/kernel/fs src/system/kernel/messaging src/system/libroot/os src/system/libroot/posix src/system/runtime_loader Message-ID: <200807102004.m6AK4cBd023402@sheep.berlios.de> Author: bonefish Date: 2008-07-10 22:03:36 +0200 (Thu, 10 Jul 2008) New Revision: 26376 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26376&view=rev Added: haiku/branches/developer/bonefish/vm/headers/private/libroot/dirent_private.h haiku/branches/developer/bonefish/vm/src/preferences/fonts/AdvancedSettingsView.cpp haiku/branches/developer/bonefish/vm/src/preferences/fonts/AdvancedSettingsView.h haiku/branches/developer/bonefish/vm/src/servers/app/agg_scanline_storage_subpix.h haiku/branches/developer/bonefish/vm/src/servers/app/agg_scanline_u_subpix.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/agg_renderer_scanline_subpix.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAddSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCCSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaCOSolidSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPCSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeAlphaPOSolidSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeBlendSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopySolidSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeCopyTextSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeEraseSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeInvertSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeMaxSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeMinSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeOverSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeOverSolidSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSelectSUBPIX.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingModeSubtractSUBPIX.h Modified: haiku/branches/developer/bonefish/vm/headers/libs/agg/agg_renderer_base.h haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_transport.h haiku/branches/developer/bonefish/vm/headers/os/interface/View.h haiku/branches/developer/bonefish/vm/headers/posix/dirent.h haiku/branches/developer/bonefish/vm/headers/private/app/ServerProtocol.h haiku/branches/developer/bonefish/vm/headers/private/kernel/boot_splash.h haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h haiku/branches/developer/bonefish/vm/headers/private/kernel/fs/node_monitor.h haiku/branches/developer/bonefish/vm/headers/private/kernel/util/KMessage.h haiku/branches/developer/bonefish/vm/headers/private/kernel/util/OpenHashTable.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c haiku/branches/developer/bonefish/vm/src/kits/interface/Font.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp haiku/branches/developer/bonefish/vm/src/kits/interface/Window.cpp haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.cpp haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.h haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontView.h haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontsSettings.cpp haiku/branches/developer/bonefish/vm/src/preferences/fonts/Jamfile haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.cpp haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.h haiku/branches/developer/bonefish/vm/src/preferences/print/AddPrinterDialog.cpp haiku/branches/developer/bonefish/vm/src/servers/app/Desktop.cpp haiku/branches/developer/bonefish/vm/src/servers/app/Desktop.h haiku/branches/developer/bonefish/vm/src/servers/app/DesktopSettings.cpp haiku/branches/developer/bonefish/vm/src/servers/app/DesktopSettings.h haiku/branches/developer/bonefish/vm/src/servers/app/DesktopSettingsPrivate.h haiku/branches/developer/bonefish/vm/src/servers/app/FontCacheEntry.cpp haiku/branches/developer/bonefish/vm/src/servers/app/FontCacheEntry.h haiku/branches/developer/bonefish/vm/src/servers/app/FontEngine.cpp haiku/branches/developer/bonefish/vm/src/servers/app/FontEngine.h haiku/branches/developer/bonefish/vm/src/servers/app/ProfileMessageSupport.cpp haiku/branches/developer/bonefish/vm/src/servers/app/ServerApp.cpp haiku/branches/developer/bonefish/vm/src/servers/app/ServerApp.h haiku/branches/developer/bonefish/vm/src/servers/app/Window.cpp haiku/branches/developer/bonefish/vm/src/servers/app/Window.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/AGGTextRenderer.cpp haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/AGGTextRenderer.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.cpp haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/Painter.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/agg_renderer_region.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/defines.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/DrawingMode.h haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/PixelFormat.cpp haiku/branches/developer/bonefish/vm/src/servers/app/drawing/Painter/drawing_modes/PixelFormat.h haiku/branches/developer/bonefish/vm/src/servers/bluetooth/BluetoothServer.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/HCITransportAccessor.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceHandler.cpp haiku/branches/developer/bonefish/vm/src/servers/bluetooth/LocalDeviceHandler.h haiku/branches/developer/bonefish/vm/src/system/kernel/boot_splash.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/debug/blue_screen.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/device_manager/devfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/disk_device_manager/KDiskDeviceManager.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/elf.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/node_monitor.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/rootfs.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/fs/vfs_boot.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/main.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/messaging/KMessage.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/module.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/team.cpp haiku/branches/developer/bonefish/vm/src/system/libroot/os/fs_attr.c haiku/branches/developer/bonefish/vm/src/system/libroot/os/fs_index.c haiku/branches/developer/bonefish/vm/src/system/libroot/os/fs_query.cpp haiku/branches/developer/bonefish/vm/src/system/libroot/posix/dirent.c haiku/branches/developer/bonefish/vm/src/system/runtime_loader/utility.cpp Log: Synchronized with trunk r26375. Modified: haiku/branches/developer/bonefish/vm/headers/libs/agg/agg_renderer_base.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/libs/agg/agg_renderer_base.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/libs/agg/agg_renderer_base.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -205,7 +205,23 @@ m_ren->blend_hline(x1, y, x2 - x1 + 1, c, cover); } + + //-------------------------------------------------------------------- + void blend_hline_subpix(int x1, int y, int x2, + const color_type& c, cover_type cover) + { + if(x1 > x2) { int t = x2; x2 = x1; x1 = t; } + if(y > ymax()) return; + if(y < ymin()) return; + if(x1 > xmax()) return; + if(x2 < xmin()) return; + if(x1 < xmin()) x1 = xmin(); + if(x2 > xmax()) x2 = xmax(); + + m_ren->blend_hline_subpix(x1, y, x2 - x1 + 1, c, cover); + } + //-------------------------------------------------------------------- void blend_vline(int x, int y1, int y2, const color_type& c, cover_type cover) @@ -280,7 +296,30 @@ } m_ren->blend_solid_hspan(x, y, len, c, covers); } + + //-------------------------------------------------------------------- + void blend_solid_hspan_subpix(int x, int y, int len, + const color_type& c, + const cover_type* covers) + { + if(y > ymax()) return; + if(y < ymin()) return; + if(x < xmin()) + { + len -= 3 * (xmin() - x); + if(len <= 0) return; + covers += 3*(xmin() - x); + x = xmin(); + } + if(x + len / 3 > xmax()) + { + len = 3 * (xmax() - x + 1); + if(len <= 0) return; + } + m_ren->blend_solid_hspan_subpix(x, y, len, c, covers); + } + //-------------------------------------------------------------------- void blend_solid_vspan(int x, int y, int len, const color_type& c, Modified: haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_transport.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_transport.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/os/bluetooth/HCI/btHCI_transport.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -13,11 +13,11 @@ #include #include -typedef enum { ANCILLYANT = 1, - RUNNING, - LEAVING, - SENDING, - PROCESSING +typedef enum { ANCILLYANT = (1<<0), + RUNNING = (1<<1), + LEAVING = (1<<2), + SENDING = (1<<3), + PROCESSING = (1<<4) } bt_transport_status_t; typedef uint8 bt_stat_t; @@ -84,6 +84,7 @@ enum { ISSUE_BT_COMMAND = B_DEVICE_OP_CODES_END + BT_IOCTLS_OFFSET , + BT_UP, GET_STATICS, GET_NOTIFICATION_PORT, GET_HCI_ID Modified: haiku/branches/developer/bonefish/vm/headers/os/interface/View.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/os/interface/View.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/os/interface/View.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -43,7 +43,11 @@ enum { B_LOCK_WINDOW_FOCUS = 0x00000001, B_SUSPEND_VIEW_FOCUS = 0x00000002, - B_NO_POINTER_HISTORY = 0x00000004 + B_NO_POINTER_HISTORY = 0x00000004, + // new in Haiku (unless this flag is + // specified, both BWindow and BView::GetMouse() + // will filter out older mouse moved messages) + B_FULL_POINTER_HISTORY = 0x00000008 }; enum { Modified: haiku/branches/developer/bonefish/vm/headers/posix/dirent.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/posix/dirent.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/posix/dirent.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -1,6 +1,7 @@ -/* -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Haiku Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ #ifndef _DIRENT_H #define _DIRENT_H @@ -17,10 +18,7 @@ char d_name[1]; /* name of the entry (null byte terminated) */ } dirent_t; -typedef struct { - int fd; - struct dirent ent; -} DIR; +typedef struct __DIR DIR; #ifndef MAXNAMLEN # ifdef NAME_MAX Modified: haiku/branches/developer/bonefish/vm/headers/private/app/ServerProtocol.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/app/ServerProtocol.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/app/ServerProtocol.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -6,6 +6,7 @@ * DarkWyrm * J?r?me Duval, jerome.duval at free.fr * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ #ifndef APP_SERVER_PROTOCOL_H #define APP_SERVER_PROTOCOL_H @@ -188,6 +189,11 @@ AS_GET_SHOW_ALL_DRAGGERS, AS_SET_SHOW_ALL_DRAGGERS, + AS_SET_FONT_SUBPIXEL_ANTIALIASING, + AS_GET_FONT_SUBPIXEL_ANTIALIASING, + AS_SET_HINTING, + AS_GET_HINTING, + // Graphics calls AS_SET_HIGH_COLOR, AS_SET_LOW_COLOR, Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/boot_splash.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/boot_splash.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/boot_splash.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -29,6 +29,7 @@ #endif void boot_splash_init(uint8 * boot_splash); +void boot_splash_uninit(void); void boot_splash_set_stage(int stage); #ifdef __cplusplus Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/disk_device_manager/KDiskDeviceManager.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -102,6 +102,7 @@ struct DiskSystemMap; struct PartitionMap; struct PartitionSet; + class DiskSystemWatcher; class DeviceWatcher; static status_t _CheckMediaStatusDaemon(void* self); @@ -132,6 +133,7 @@ PartitionSet *fObsoletePartitions; thread_id fMediaChecker; volatile bool fTerminating; + DiskSystemWatcher *fDiskSystemWatcher; DeviceWatcher *fDeviceWatcher; static KDiskDeviceManager *sDefaultManager; Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/fs/node_monitor.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/fs/node_monitor.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/fs/node_monitor.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -17,9 +17,9 @@ class NotificationListener; -extern status_t remove_node_listener(dev_t device, dev_t node, +extern status_t remove_node_listener(dev_t device, ino_t node, NotificationListener& listener); -extern status_t add_node_listener(dev_t device, dev_t node, uint32 flags, +extern status_t add_node_listener(dev_t device, ino_t node, uint32 flags, NotificationListener& listener); extern "C" { Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/util/KMessage.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/util/KMessage.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/util/KMessage.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -1,4 +1,4 @@ -/* +/* * Copyright 2005-2007, Ingo Weinhold, bonefish at users.sf.net. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -55,6 +55,7 @@ status_t FindField(const char *name, type_code type, KMessageField *field) const; status_t GetNextField(KMessageField *field) const; + bool IsEmpty() const; status_t AddData(const char *name, type_code type, const void *data, int32 numBytes, bool isFixedSize = true); @@ -135,7 +136,7 @@ status_t ReceiveFrom(port_id fromPort, bigtime_t timeout = -1, port_message_info* messageInfo = NULL); - void Dump(void (*printFunc)(const char*,...)); + void Dump(void (*printFunc)(const char*, ...)) const; private: friend class KMessageField; @@ -201,7 +202,7 @@ type_code TypeCode() const; bool HasFixedElementSize() const; int32 ElementSize() const; // if HasFixedElementSize() - + status_t AddElement(const void *data, int32 size = -1); status_t AddElements(const void *data, int32 count, int32 elementSize = -1); const void *ElementAt(int32 index, int32 *size = NULL) const; Modified: haiku/branches/developer/bonefish/vm/headers/private/kernel/util/OpenHashTable.h =================================================================== --- haiku/branches/developer/bonefish/vm/headers/private/kernel/util/OpenHashTable.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/headers/private/kernel/util/OpenHashTable.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -1,9 +1,6 @@ /* * Copyright 2007, Hugo Santos. All Rights Reserved. * Distributed under the terms of the MIT License. - * - * Authors: - * Hugo Santos, hugosantos at gmail.com */ #ifndef _KERNEL_UTIL_OPEN_HASH_TABLE_H #define _KERNEL_UTIL_OPEN_HASH_TABLE_H @@ -20,7 +17,7 @@ struct Foo : HashTableLink { int bar; - + HashTableLink otherLink; }; @@ -126,6 +123,8 @@ fItemCount++; } + // TODO: a ValueType* Remove(const KeyType& key) method is missing + bool Remove(ValueType *value) { if (!RemoveUnchecked(value)) Copied: haiku/branches/developer/bonefish/vm/headers/private/libroot/dirent_private.h (from rev 26375, haiku/trunk/headers/private/libroot/dirent_private.h) Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/audio/hda/driver.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -41,8 +41,7 @@ #define MAX_INPUTS 32 #define MAX_IO_WIDGETS 8 -/* FIXME: Find out why we need so much! */ -#define DEFAULT_FRAMES_PER_BUFFER 4096 +#define DEFAULT_FRAMES_PER_BUFFER 512 #define STREAM_MAX_BUFFERS 10 #define STREAM_MIN_BUFFERS 2 Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-10 20:03:36 UTC (rev 26376) @@ -429,8 +429,8 @@ } acquire_sem(bdev->lock); - // Set HCI_RUNNING - if ( TEST_AND_SET(&bdev->state, RUNNING) ) { + // Set RUNNING + if ( TEST_AND_SET(&bdev->state, ANCILLYANT) ) { flowf("dev already running! - reOpened device!\n"); return B_ERROR; } @@ -451,7 +451,7 @@ // dumping the USB frames init_room(&bdev->eventRoom); init_room(&bdev->aclRoom); - //Init_room(new_bt_dev->scoRoom); + //init_room(new_bt_dev->scoRoom); list_init(&bdev->snetBufferRecycleTrash); @@ -470,37 +470,15 @@ hdev = bdev->num; } bdev->hdev = hdev; + - // H: set the special flags - // EVENTS - err = submit_rx_event(bdev); - if (err != B_OK) - goto unrun; -#if BT_DRIVER_SUPPORTS_ACL - // ACL - for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { - err = submit_rx_acl(bdev); - if (err != B_OK && i == 0 ) - goto unrun; - } -#endif - -#if BT_DRIVER_SUPPORTS_SCO - // TODO: SCO / eSCO -#endif - *cookie = bdev; release_sem(bdev->lock); flowf(" successful\n"); return B_OK; -unrun: - CLEAR_BIT(bdev->state, RUNNING); // Set the flaq in the HCI world - flowf("Queuing failed device stops running\n"); - - return err; } @@ -617,13 +595,42 @@ snb_put(snbuf, params, size); err = submit_tx_command(bdev, snbuf); - + debugf("device launched %ld\n", err); break; + case BT_UP: + + // EVENTS + err = submit_rx_event(bdev); + if (err != B_OK) { + CLEAR_BIT(bdev->state, ANCILLYANT); + flowf("Queuing failed device stops running\n"); + break; + } + + #if BT_DRIVER_SUPPORTS_ACL // ACL + for (i = 0; i < MAX_ACL_IN_WINDOW; i++) { + err = submit_rx_acl(bdev); + if (err != B_OK && i == 0 ) { + CLEAR_BIT(bdev->state, ANCILLYANT); // Set the flaq in the HCI world + flowf("Queuing failed device stops running\n"); + break; + } + } + #endif + + SET_BIT(bdev->state, RUNNING); + + #if BT_DRIVER_SUPPORTS_SCO + // TODO: SCO / eSCO + #endif + flowf("device launched\n"); + break; + case GET_STATICS: memcpy(params, &bdev->stat, sizeof(bt_hci_statistics)); err = B_OK; - break; + break; case GET_HCI_ID: *(hci_id*)params = bdev->hdev; Modified: haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c =================================================================== --- haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2util.c 2008-07-10 20:03:36 UTC (rev 26376) @@ -62,12 +62,14 @@ void nb_destroy(net_buffer* nbuf) { + if (nbuf == NULL) + return; /* Free possible allocated */ if (nbuf->COOKIEFIELD != NULL) free((void*)nbuf->COOKIEFIELD); -// TODO check for survivers... + // TODO check for survivers... if (nb != NULL) nb->free(nbuf); Modified: haiku/branches/developer/bonefish/vm/src/kits/interface/Font.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/kits/interface/Font.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/kits/interface/Font.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -7,6 +7,7 @@ * J?r?me Duval, jerome.duval at free.fr * Axel D?rfler, axeld at pinc-software.de * Stephan A?mus + * Andrej Spielmann, */ @@ -183,7 +184,7 @@ delete family; return B_NO_MEMORY; } - + link.ReadString(style->name); link.Read(&style->face); link.Read(&style->flags); @@ -365,12 +366,12 @@ \param family the new family for the system font \param style the new style for the system font \param size the size for the system font to have - + R5 used a global area offset table to set the system fonts in the Font preferences panel. Bleah. */ void -_set_system_font_(const char *which, font_family family, font_style style, +_set_system_font_(const char *which, font_family family, font_style style, float size) { BPrivate::AppServerLink link; @@ -405,6 +406,59 @@ } +void +_set_font_subpixel_antialiasing_(bool subpix) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_SET_FONT_SUBPIXEL_ANTIALIASING); + link.Attach(subpix); + link.Flush(); +} + + +status_t +_get_font_subpixel_antialiasing_(bool* subpix) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_FONT_SUBPIXEL_ANTIALIASING); + int32 status = B_ERROR; + if (link.FlushWithReply(status) != B_OK + || status < B_OK) + return status; + link.Read(subpix); + return B_OK; +} + + +void +_set_hinting_(bool hinting) +{ + BPrivate::AppServerLink link; + + link.StartMessage(AS_SET_HINTING); + link.Attach(hinting); + link.Flush(); +} + + +status_t +_get_hinting_(bool* hinting) +{ + + BPrivate::AppServerLink link; + + link.StartMessage(AS_GET_HINTING); + int32 status = B_ERROR; + if (link.FlushWithReply(status) != B_OK + || status < B_OK) + return status; + link.Read(hinting); + return B_OK; +} + + /*! \brief Returns the number of installed font families \return The number of installed font families @@ -469,7 +523,7 @@ \param flags if non-NULL, the values of the flags IS_FIXED and B_HAS_TUNED_FONT are returned \return B_ERROR if the index does not correspond to a font style - + The face value returned by this function is not very reliable. At the same time, the value returned should be fairly reliable, returning the proper flag for 90%-99% of font names. @@ -500,7 +554,7 @@ // #pragma mark - -BFont::BFont() +BFont::BFont() : // initialise for be_plain_font (avoid circular definition) fFamilyID(0), @@ -619,7 +673,7 @@ \param family Font family to set \param face Font face to set. \return B_ERROR if family does not exists or face is an invalid value. - + To comply with the BeBook, this function will only set valid values - i.e. passing a nonexistent family will cause only the face to be set. Additionally, if a particular face does not exist in a family, the closest @@ -817,8 +871,8 @@ _GetExtraFlags(); return (font_direction)(fExtraFlags >> B_PRIVATE_FONT_DIRECTION_SHIFT); } - + bool BFont::IsFixed() const { @@ -830,7 +884,7 @@ /*! \brief Returns true if the font is fixed-width and contains both full and half-width characters - + This was left unimplemented as of R5. It was a way to work with both Kanji and Roman characters in the same fixed-width font. */ @@ -943,7 +997,7 @@ void -BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, +BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, uint32 mode, float width, BString resultArray[]) const { if (stringArray && resultArray && numStrings > 0) { @@ -967,7 +1021,7 @@ void -BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, +BFont::GetTruncatedStrings(const char *stringArray[], int32 numStrings, uint32 mode, float width, char *resultArray[]) const { if (stringArray && numStrings > 0) { @@ -1018,7 +1072,7 @@ void -BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], +BFont::GetStringWidths(const char *stringArray[], const int32 lengthArray[], int32 numStrings, float widthArray[]) const { if (!stringArray || !lengthArray || numStrings < 1 || !widthArray) @@ -1232,7 +1286,7 @@ link.Attach(fShear); link.Attach(fFalseBoldWidth); link.Attach(fSpacing); - + link.Attach(fFlags); link.Attach(mode); link.Attach(string_escapement); Modified: haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/kits/interface/View.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -1393,7 +1393,11 @@ { _CheckOwnerLockAndSwitchCurrent(); - if (checkMessageQueue) { + uint32 eventOptions = fEventOptions | fMouseEventOptions; + bool noHistory = eventOptions & B_NO_POINTER_HISTORY; + bool fullHistory = eventOptions & B_FULL_POINTER_HISTORY; + + if (checkMessageQueue && !noHistory) { Window()->UpdateIfNeeded(); BMessageQueue *queue = Window()->MessageQueue(); queue->Lock(); @@ -1410,6 +1414,30 @@ if (!Window()->_StealMouseMessage(message, deleteMessage)) continue; + if (!fullHistory && message->what == B_MOUSE_MOVED) { + // Check if the message is too old. Some applications + // check the message queue in such a way that mouse + // messages *must* pile up. This check makes them work + // as intended, although these applications could simply + // use the version of BView::GetMouse() that does not + // check the history. Also note that it isn't a problem + // to delete the message in case there is not a newer + // one. If we don't find a message in the queue, we will + // just fall back to asking the app_sever directly. So + // the imposed delay will not be a problem on slower + // computers. This check also prevents another problem, + // when the message that we use is *not* removed from + // the queue. Subsequent calls to GetMouse() would find + // this message over and over! + bigtime_t eventTime; + if (message->FindInt64("when", &eventTime) == B_OK + && system_time() - eventTime > 10000) { + // just discard the message + if (deleteMessage) + delete message; + continue; + } + } message->FindPoint("screen_where", location); message->FindInt32("buttons", (int32 *)buttons); queue->Unlock(); Modified: haiku/branches/developer/bonefish/vm/src/kits/interface/Window.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/kits/interface/Window.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/kits/interface/Window.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -1092,8 +1092,34 @@ case B_MOUSE_MOVED: { if (BView *view = dynamic_cast(target)) { - if (((view->fEventOptions | view->fMouseEventOptions) - & B_NO_POINTER_HISTORY) != 0) { + + uint32 eventOptions = view->fEventOptions + | view->fMouseEventOptions; + bool noHistory = eventOptions & B_NO_POINTER_HISTORY; + bool dropIfLate = !(eventOptions & B_FULL_POINTER_HISTORY); + + bigtime_t eventTime; + if (msg->FindInt64("when", (int64*)&eventTime) < B_OK) + eventTime = system_time(); + + uint32 transit; + msg->FindInt32("be:transit", (int32*)&transit); + // don't drop late messages with these important transit values + if (transit == B_ENTERED_VIEW || transit == B_EXITED_VIEW) + dropIfLate = false; + + // TODO: The dropping code may have the following problem: + // On slower computers, 20ms may just be to abitious a delay. + // There, we might constantly check the message queue for a + // newer message, not find any, and still use the only but + // later than 20ms message, which of course makes the whole + // thing later than need be. An adaptive delay would be + // kind of neat, but would probably use additional BWindow + // members to count the successful versus fruitless queue + // searches and the delay value itself or something similar. + + if (noHistory + || (dropIfLate && (system_time() - eventTime > 20000))) { // filter out older mouse moved messages in the queue _DequeueAll(); BMessageQueue *queue = MessageQueue(); @@ -1102,6 +1128,9 @@ BMessage *moved; for (int32 i = 0; (moved = queue->FindMessage(i)) != NULL; i++) { if (moved != msg && moved->what == B_MOUSE_MOVED) { + // there is a newer mouse moved message in the + // queue, just ignore the current one, the newer one + // will be handled here eventually queue->Unlock(); return; } @@ -1111,19 +1140,9 @@ BPoint where; uint32 buttons; - uint32 transit; msg->FindPoint("be:view_where", &where); msg->FindInt32("buttons", (int32*)&buttons); - msg->FindInt32("be:transit", (int32*)&transit); -#if 0 - bigtime_t when; - if (msg->FindInt64("when", (int64*)&when) < B_OK) - printf("BWindow B_MOUSE_MOVED no when\n"); - else if (system_time() - when > 5000) - printf("BWindow B_MOUSE_MOVED lagging behind\n"); -#endif - BMessage* dragMessage = NULL; if (msg->HasMessage("be:drag_message")) { dragMessage = new BMessage(); Copied: haiku/branches/developer/bonefish/vm/src/preferences/fonts/AdvancedSettingsView.cpp (from rev 26375, haiku/trunk/src/preferences/fonts/AdvancedSettingsView.cpp) Copied: haiku/branches/developer/bonefish/vm/src/preferences/fonts/AdvancedSettingsView.h (from rev 26375, haiku/trunk/src/preferences/fonts/AdvancedSettingsView.h) Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -114,7 +114,7 @@ // it doesn't overlap the box outline. rect = fPreviewBox->Bounds().InsetByCopy(3, 3); fPreviewText = new BStringView(rect, "preview text", - "The quick brown fox jumps over the lazy dog.", + "The quick brown fox jumps over the lazy dog.", B_FOLLOW_LEFT_RIGHT); fPreviewText->SetFont(&fCurrentFont); fPreviewBox->AddChild(fPreviewText); @@ -172,7 +172,7 @@ GetPreferredSize(&width, &height); if (width > Bounds().Width()) { - fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f, + fSizesMenuField->MoveTo(fMaxFontNameWidth + fDivider + 40.0f, fFontsMenuField->Bounds().top); ResizeTo(width, height); } @@ -424,7 +424,7 @@ void FontSelectionView::UpdateFontsMenu() { - int32 numFamilies = count_font_families(); + int32 numFamilies = count_font_families(); fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true); BFont font; @@ -434,8 +434,8 @@ font_style currentStyle; fCurrentFont.GetFamilyAndStyle(¤tFamily, ¤tStyle); - for (int32 i = 0; i < numFamilies; i++) { - font_family family; + for (int32 i = 0; i < numFamilies; i++) { + font_family family; uint32 flags; if (get_font_family(i, &family, &flags) != B_OK) continue; @@ -457,10 +457,10 @@ BMenuItem* familyItem = new BMenuItem(stylesMenu, message); fFontsMenu->AddItem(familyItem); - int32 numStyles = count_font_styles(family); + int32 numStyles = count_font_styles(family); for (int32 j = 0; j < numStyles; j++) { - font_style style; + font_style style; if (get_font_style(family, j, &style, &flags) != B_OK) continue; Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontSelectionView.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -61,5 +61,5 @@ BFont fCurrentFont; float fMaxFontNameWidth; }; - + #endif /* FONT_SELECTION_VIEW_H */ Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontView.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontView.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontView.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -12,6 +12,7 @@ #include "FontSelectionView.h" +#include "AdvancedSettingsView.h" class FontView : public BView { @@ -29,9 +30,9 @@ bool IsRevertable(); private: - FontSelectionView *fPlainView; - FontSelectionView *fBoldView; - FontSelectionView *fFixedView; + FontSelectionView *fPlainView; + FontSelectionView *fBoldView; + FontSelectionView *fFixedView; }; - + #endif /* FONT_VIEW_H */ Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontsSettings.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontsSettings.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/FontsSettings.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -32,27 +32,27 @@ path.Append(kSettingsFile); BFile file(path.Path(), B_READ_ONLY); - if (file.InitCheck() != B_OK) + if (file.InitCheck() != B_OK) SetDefaults(); else if (msg.Unflatten(&file) != B_OK) SetDefaults(); else msg.FindPoint("windowlocation", &fCorner); } -} - +} + FontsSettings::~FontsSettings() { BPath path; BMessage msg; - - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) + + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK) return; - + path.Append(kSettingsFile); BFile file(path.Path(), B_WRITE_ONLY|B_CREATE_FILE); - + if (file.InitCheck() == B_OK) { msg.AddPoint("windowlocation", fCorner); msg.Flatten(&file); Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/Jamfile =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/Jamfile 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/Jamfile 2008-07-10 20:03:36 UTC (rev 26376) @@ -5,6 +5,7 @@ Preference Fonts : FontSelectionView.cpp + AdvancedSettingsView.cpp FontsSettings.cpp FontView.cpp main.cpp Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.cpp 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.cpp 2008-07-10 20:03:36 UTC (rev 26376) @@ -6,6 +6,7 @@ * Mark Hogben * DarkWyrm * Axel D?rfler, axeld at pinc-software.de + * Andrej Spielmann, */ @@ -25,7 +26,7 @@ MainWindow::MainWindow() - : BWindow(BRect(100, 100, 445, 340), "Fonts", B_TITLED_WINDOW, + : BWindow(BRect(100, 100, 445, 410), "Fonts", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) { BRect rect = Bounds(); @@ -36,7 +37,8 @@ rect.left = 10; rect.top = rect.bottom - 10; fDefaultsButton = new BButton(rect, "defaults", "Defaults", - new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); + new BMessage(kMsgSetDefaults), B_FOLLOW_LEFT + | B_FOLLOW_BOTTOM, B_WILL_DRAW); fDefaultsButton->ResizeToPreferred(); fDefaultsButton->SetEnabled(false); float buttonHeight = fDefaultsButton->Bounds().Height(); @@ -56,11 +58,13 @@ rect.top += 5; rect.bottom -= 20 + buttonHeight; rect.left += 5; - BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); + BTabView *tabView = new BTabView(rect, "tabview", B_WIDTH_FROM_LABEL); rect = tabView->ContainerView()->Bounds().InsetByCopy(5, 8); fFontsView = new FontView(rect); + fAdvancedSettings = new AdvancedSettingsView(rect, "Advanced"); + tabView->AddTab(fFontsView); fFontsView->UpdateFonts(); @@ -83,7 +87,8 @@ tabView->ContainerView()->ResizeBy(0, heightDiff); } - ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 20 + buttonHeight); + ResizeTo(tabView->Bounds().Width() + 10, tabView->Frame().bottom + 20 + + buttonHeight); view->AddChild(tabView); fFontsView->ResizeToPreferred(); @@ -99,6 +104,23 @@ _Center(); } + tabView->AddTab(fAdvancedSettings); + + fAdvancedSettings->RelayoutIfNeeded(); + fAdvancedSettings->GetPreferredSize(&width, &height); + + widthDiff = width + 10 - tabView->ContainerView()->Bounds().Width(); + if (widthDiff > 0) { + tabView->ResizeBy(widthDiff, 0); + tabView->ContainerView()->ResizeBy(widthDiff, 0); + } + + heightDiff = height + 16 - tabView->ContainerView()->Bounds().Height(); + if (heightDiff > 0) { + tabView->ResizeBy(0, heightDiff); + tabView->ContainerView()->ResizeBy(0, heightDiff); + } + fRunner = new BMessageRunner(this, new BMessage(kMsgCheckFonts), 3000000); // every 3 seconds @@ -127,19 +149,25 @@ { switch (message->what) { case kMsgUpdate: - fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); - fRevertButton->SetEnabled(fFontsView->IsRevertable()); + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable() + || fAdvancedSettings->IsDefaultable()); + fRevertButton->SetEnabled(fFontsView->IsRevertable() + || fAdvancedSettings->IsRevertable()); break; case kMsgSetDefaults: fFontsView->SetDefaults(); + fAdvancedSettings->SetDefaults(); fDefaultsButton->SetEnabled(false); - fRevertButton->SetEnabled(fFontsView->IsRevertable()); + fRevertButton->SetEnabled(fFontsView->IsRevertable() + || fAdvancedSettings->IsRevertable()); break; case kMsgRevert: fFontsView->Revert(); - fDefaultsButton->SetEnabled(fFontsView->IsDefaultable()); + fAdvancedSettings->Revert(); + fDefaultsButton->SetEnabled(fFontsView->IsDefaultable() + || fAdvancedSettings->IsDefaultable()); fRevertButton->SetEnabled(false); break; Modified: haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.h 2008-07-10 19:50:34 UTC (rev 26375) +++ haiku/branches/developer/bonefish/vm/src/preferences/fonts/MainWindow.h 2008-07-10 20:03:36 UTC (rev 26376) @@ -12,6 +12,7 @@ #include "FontsSettings.h" [... truncated: 4472 lines follow ...] From zooey at mail.berlios.de Thu Jul 10 23:25:19 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Thu, 10 Jul 2008 23:25:19 +0200 Subject: [Haiku-commits] r26377 - in haiku/trunk: headers/private/net src/kits/network src/kits/network/libnetapi Message-ID: <200807102125.m6ALPJ8Z002212@sheep.berlios.de> Author: zooey Date: 2008-07-10 23:25:19 +0200 (Thu, 10 Jul 2008) New Revision: 26377 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26377&view=rev Modified: haiku/trunk/headers/private/net/r5_compatibility.h haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp haiku/trunk/src/kits/network/socket.cpp Log: Corrected by previous assumption, since gethostbyname() has nothing to do with struct sockaddr_in - the real culprits were BNetAddress::GetAddr(sockaddr_in&) and BNetAddress::SetTo(const sockaddr_in&): * moved check_r5_compatibility() into r5_compatibility.h to make that function available to BNetAddress, too * adjusted sockaddr_in-handling methods of BNetAddress to deal with R5-addresses if in compatibility mode * removed is_r5_sockaddr() again, since it is no longer needed With this less hacky solution, Beam, NetPositive, NetworkTime and Vision still work. So, there's hope that the R5 compatibility layer is now complete. Modified: haiku/trunk/headers/private/net/r5_compatibility.h =================================================================== --- haiku/trunk/headers/private/net/r5_compatibility.h 2008-07-10 20:03:36 UTC (rev 26376) +++ haiku/trunk/headers/private/net/r5_compatibility.h 2008-07-10 21:25:19 UTC (rev 26377) @@ -44,4 +44,31 @@ extern addr_t __gNetAPIStart; extern addr_t __gNetAPIEnd; + +static inline bool +check_r5_compatibility() +{ + if (!__gR5Compatibility) + return false; + +#ifndef __INTEL__ + return false; +#else + + struct stack_frame { + struct stack_frame* previous; + addr_t return_address; + }; + + stack_frame* frame = (stack_frame*)get_stack_frame(); + if (frame->return_address >= __gNetworkStart + && frame->return_address < __gNetworkEnd) { + return false; + } + + return true; +#endif +} + + #endif // NET_R5_COMPATIBILITY_H Modified: haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp =================================================================== --- haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-10 20:03:36 UTC (rev 26376) +++ haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-10 21:25:19 UTC (rev 26377) @@ -17,6 +17,8 @@ * No trouts were harmed during the development of this class. */ +#include + #include #include #include @@ -184,13 +186,18 @@ status_t BNetAddress::GetAddr( struct sockaddr_in& sa ) const { if ( fInit != B_OK ) - { return B_NO_INIT; - } - sa.sin_family = fFamily; sa.sin_port = fPort; sa.sin_addr.s_addr = fAddress; + if (check_r5_compatibility()) { + r5_sockaddr_in* r5Addr = (r5_sockaddr_in *)&sa; + if (fFamily == AF_INET) + r5Addr->sin_family = R5_AF_INET; + else + r5Addr->sin_family = fFamily; + } else + sa.sin_family = fFamily; return B_OK; } @@ -358,10 +365,18 @@ status_t BNetAddress::SetTo(const struct sockaddr_in& addr) { - fFamily = addr.sin_family; fPort = addr.sin_port; fAddress = addr.sin_addr.s_addr; + if (check_r5_compatibility()) { + const r5_sockaddr_in* r5Addr = (const r5_sockaddr_in *)&addr; + if (r5Addr->sin_family == R5_AF_INET) + fFamily = AF_INET; + else + fFamily = r5Addr->sin_family; + } else + fFamily = addr.sin_family; + return fInit = B_OK; } Modified: haiku/trunk/src/kits/network/socket.cpp =================================================================== --- haiku/trunk/src/kits/network/socket.cpp 2008-07-10 20:03:36 UTC (rev 26376) +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-10 21:25:19 UTC (rev 26377) @@ -22,53 +22,6 @@ #include -static inline bool -check_r5_compatibility() -{ - if (!__gR5Compatibility) - return false; - -#ifndef __INTEL__ - return false; -#else - - struct stack_frame { - struct stack_frame* previous; - addr_t return_address; - }; - - stack_frame* frame = (stack_frame*)get_stack_frame(); - if (frame->return_address >= __gNetworkStart - && frame->return_address < __gNetworkEnd) { - return false; - } - - return true; -#endif -} - - -static bool -is_r5_sockaddr(const struct sockaddr *_addr) -{ - /* r5_sockaddr_in structs do not contain sin_len, but have a larger - * sin_family instead (two bytes), so in a r5_sockaddr_in, the first two - * bytes will always be equal to R5_AF_INET, while for haiku's own - * sockaddr_in, that will never be the case, since the first byte contains - * the length which should never be zero. - * The only other case where this check could fail is when the address does - * not belong to the internet family at all. But even in that case we would - * not want to try to convert the addresses, as the conversion itself - * blindly casts the address to sockaddr_in, which would yield unpredictable - * results for other address families. - */ - const r5_sockaddr_in *addr = (r5_sockaddr_in *)_addr; - if (addr == NULL || addr->sin_family != R5_AF_INET) - return false; - - return true; -} - static void convert_from_r5_sockaddr(struct sockaddr *_to, const struct sockaddr *_from) { @@ -195,7 +148,7 @@ { struct sockaddr haikuAddr; - if (check_r5_compatibility() && is_r5_sockaddr(address)) { + if (check_r5_compatibility()) { convert_from_r5_sockaddr(&haikuAddr, address); address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); @@ -217,7 +170,7 @@ { struct sockaddr haikuAddr; - if (check_r5_compatibility() && is_r5_sockaddr(address)) { + if (check_r5_compatibility()) { convert_from_r5_sockaddr(&haikuAddr, address); address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); @@ -331,7 +284,7 @@ { struct sockaddr haikuAddr; - if (check_r5_compatibility() && is_r5_sockaddr(address)) { + if (check_r5_compatibility()) { convert_from_r5_sockaddr(&haikuAddr, address); address = &haikuAddr; addressLength = sizeof(struct sockaddr_in); From anevilyak at gmail.com Fri Jul 11 01:06:28 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Thu, 10 Jul 2008 18:06:28 -0500 Subject: [Haiku-commits] r26377 - in haiku/trunk: headers/private/net src/kits/network src/kits/network/libnetapi In-Reply-To: <200807102125.m6ALPJ8Z002212@sheep.berlios.de> References: <200807102125.m6ALPJ8Z002212@sheep.berlios.de> Message-ID: On Thu, Jul 10, 2008 at 4:25 PM, zooey at BerliOS wrote: > Author: zooey > Date: 2008-07-10 23:25:19 +0200 (Thu, 10 Jul 2008) > New Revision: 26377 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26377&view=rev > > Modified: > haiku/trunk/headers/private/net/r5_compatibility.h > haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp > haiku/trunk/src/kits/network/socket.cpp > Log: > Corrected by previous assumption, since gethostbyname() has nothing to do with > struct sockaddr_in - the real culprits were BNetAddress::GetAddr(sockaddr_in&) > and BNetAddress::SetTo(const sockaddr_in&): > * moved check_r5_compatibility() into r5_compatibility.h to make that function > available to BNetAddress, too > * adjusted sockaddr_in-handling methods of BNetAddress to deal with R5-addresses > if in compatibility mode > * removed is_r5_sockaddr() again, since it is no longer needed > > With this less hacky solution, Beam, NetPositive, NetworkTime and Vision still work. So, there's hope that the R5 compatibility layer is now complete. > Nice! :) I'm curious, what build of Vision did you use for testing? The one in Haiku's optionalpackages is native, only the bebits build uses libnet, and there it only uses socket functions directly, no BNet* classes. Regards, Rene From zooey at hirschkaefer.de Fri Jul 11 11:41:13 2008 From: zooey at hirschkaefer.de (Oliver Tappe) Date: Fri, 11 Jul 2008 11:41:13 +0200 Subject: [Haiku-commits] r26377 - in haiku/trunk: headers/private/net src/kits/network src/kits/network/libnetapi In-Reply-To: References: <200807102125.m6ALPJ8Z002212@sheep.berlios.de> Message-ID: <48772AB9.6070908@hirschkaefer.de> Hi Rene, Rene Gollent schrieb: > On Thu, Jul 10, 2008 at 4:25 PM, zooey at BerliOS wrote: >> Author: zooey >> Date: 2008-07-10 23:25:19 +0200 (Thu, 10 Jul 2008) >> New Revision: 26377 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26377&view=rev >> >> Modified: >> haiku/trunk/headers/private/net/r5_compatibility.h >> haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp >> haiku/trunk/src/kits/network/socket.cpp >> Log: >> Corrected by previous assumption, since gethostbyname() has nothing to do with >> struct sockaddr_in - the real culprits were BNetAddress::GetAddr(sockaddr_in&) >> and BNetAddress::SetTo(const sockaddr_in&): >> * moved check_r5_compatibility() into r5_compatibility.h to make that function >> available to BNetAddress, too >> * adjusted sockaddr_in-handling methods of BNetAddress to deal with R5-addresses >> if in compatibility mode >> * removed is_r5_sockaddr() again, since it is no longer needed >> >> With this less hacky solution, Beam, NetPositive, NetworkTime and Vision still work. So, there's hope that the R5 compatibility layer is now complete. >> > > Nice! :) I'm curious, what build of Vision did you use for testing? > The one in Haiku's optionalpackages is native, only the bebits build > uses libnet, and there it only uses socket functions directly, no > BNet* classes. Ah, ok - I used the one in Haiku's optional packages, but now that you told me, I will test with the one from BeBits, too. ;-) Can anyone think of any other R5 networking app that I should check? I suppose for Beam, NetworkTime and Vision we won't really *need* to be compatible anyway, since those are available in source. Is there any other closed source app apart from NetPositive worth considering? cheers, Oliver From revol at free.fr Fri Jul 11 11:50:00 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Fri, 11 Jul 2008 11:50:00 +0200 CEST Subject: [Haiku-commits] r26377 - in haiku/trunk: headers/private/net src/kits/network src/kits/network/libnetapi In-Reply-To: <48772AB9.6070908@hirschkaefer.de> Message-ID: <2102057140-BeMail@laptop> > > Nice! :) I'm curious, what build of Vision did you use for testing? > > The one in Haiku's optionalpackages is native, only the bebits > > build > > uses libnet, and there it only uses socket functions directly, no > > BNet* classes. > > Ah, ok - I used the one in Haiku's optional packages, but now that > you told > me, I will test with the one from BeBits, too. ;-) > > Can anyone think of any other R5 networking app that I should check? > I suppose > for Beam, NetworkTime and Vision we won't really *need* to be > compatible > anyway, since those are available in source. > Is there any other closed source app apart from NetPositive worth > considering? > NetPenguin maybe ? Fran?ois. From stippi at mail.berlios.de Fri Jul 11 13:32:10 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 11 Jul 2008 13:32:10 +0200 Subject: [Haiku-commits] r26378 - haiku/trunk/src/kits/support Message-ID: <200807111132.m6BBWAK0026962@sheep.berlios.de> Author: stippi Date: 2008-07-11 13:32:07 +0200 (Fri, 11 Jul 2008) New Revision: 26378 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26378&view=rev Modified: haiku/trunk/src/kits/support/String.cpp Log: * _DoAppend() no longer checks the string and the string length, which resulted in duplicate work/checks. Instead the length is checked in the calling functions. * operator=(const char*) now checks if the passed pointer is the strings own data pointer. I think it would have freed the memory before, not sure though. Modified: haiku/trunk/src/kits/support/String.cpp =================================================================== --- haiku/trunk/src/kits/support/String.cpp 2008-07-10 21:25:19 UTC (rev 26377) +++ haiku/trunk/src/kits/support/String.cpp 2008-07-11 11:32:07 UTC (rev 26378) @@ -244,7 +244,7 @@ BString& BString::operator=(const char* string) { - if (string) + if (string && string != String()) SetTo(string, strlen(string)); return *this; } @@ -375,8 +375,11 @@ BString& BString::operator+=(const char* string) { - if (string) - _DoAppend(string, strlen(string)); + if (string) { + int32 length = strlen(string); + if (length > 0) + _DoAppend(string, length); + } return *this; } @@ -392,8 +395,11 @@ BString& BString::Append(const BString& string, int32 length) { - if (&string != this) - _DoAppend(string.fPrivateData, min_clamp0(length, string.Length())); + if (&string != this) { + int32 length = min_clamp0(length, string.Length()); + if (length > 0) + _DoAppend(string.fPrivateData, length); + } return *this; } @@ -401,8 +407,11 @@ BString& BString::Append(const char* string, int32 length) { - if (string) - _DoAppend(string, strlen_clamp(string, length)); + if (string) { + int32 length = strlen_clamp(string, length); + if (length > 0) + _DoAppend(string, length); + } return *this; } @@ -410,9 +419,9 @@ BString& BString::Append(char c, int32 count) { - int32 len = Length(); + int32 oldLength = Length(); if (count > 0 && _DoAppend("", count)) - memset(fPrivateData + len, c, count); + memset(fPrivateData + oldLength, c, count); return *this; } @@ -1557,8 +1566,11 @@ BString& BString::operator<<(const char* string) { - if (string != NULL) - _DoAppend(string, strlen(string)); + if (string != NULL) { + int32 length = strlen(string); + if (length > 0) + _DoAppend(string, length); + } return *this; } @@ -1853,8 +1865,7 @@ { int32 oldLength = Length(); if (_DetachWith(fPrivateData, oldLength + length) == B_OK) { - if (string && length) - strncpy(fPrivateData + oldLength, string, length); + strncpy(fPrivateData + oldLength, string, length); return true; } return false; From stippi at mail.berlios.de Fri Jul 11 13:38:54 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 11 Jul 2008 13:38:54 +0200 Subject: [Haiku-commits] r26379 - haiku/trunk/src/kits/interface Message-ID: <200807111138.m6BBcsli027494@sheep.berlios.de> Author: stippi Date: 2008-07-11 13:38:51 +0200 (Fri, 11 Jul 2008) New Revision: 26379 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26379&view=rev Modified: haiku/trunk/src/kits/interface/StatusBar.cpp Log: Calling BStatusBar::Update() with NULL as either string argument should keep the current string. (Untested) Modified: haiku/trunk/src/kits/interface/StatusBar.cpp =================================================================== --- haiku/trunk/src/kits/interface/StatusBar.cpp 2008-07-11 11:32:07 UTC (rev 26378) +++ haiku/trunk/src/kits/interface/StatusBar.cpp 2008-07-11 11:38:51 UTC (rev 26379) @@ -361,6 +361,11 @@ void BStatusBar::Update(float delta, const char* text, const char* trailingText) { + // If any of these are NULL, the existing text remains (BeBook) + if (text == NULL) + text = fText.String(); + if (trailingText == NULL) + trailingText = fTrailingText.String(); BStatusBar::SetTo(fCurrent + delta, text, trailingText); } From stippi at mail.berlios.de Fri Jul 11 16:13:13 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Fri, 11 Jul 2008 16:13:13 +0200 Subject: [Haiku-commits] r26380 - haiku/trunk/src/apps/mediaplayer/playlist Message-ID: <200807111413.m6BEDDDc014196@sheep.berlios.de> Author: stippi Date: 2008-07-11 16:13:10 +0200 (Fri, 11 Jul 2008) New Revision: 26380 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26380&view=rev Modified: haiku/trunk/src/apps/mediaplayer/playlist/Playlist.cpp haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h Log: Added methods for (un)archiving. (yet unused and untested.) Modified: haiku/trunk/src/apps/mediaplayer/playlist/Playlist.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/Playlist.cpp 2008-07-11 11:38:51 UTC (rev 26379) +++ haiku/trunk/src/apps/mediaplayer/playlist/Playlist.cpp 2008-07-11 14:13:10 UTC (rev 26380) @@ -24,15 +24,15 @@ #include #include #include -#include -#include -#include -#include #include #include +#include #include +#include +#include #include +#include #include "FileReadWrite.h" @@ -68,6 +68,59 @@ } +// #pragma mark - archiving + + +static const char* kPathKey = "path"; + + +status_t +Playlist::UnArchive(const BMessage* archive) +{ + if (archive == NULL) + return B_BAD_VALUE; + + MakeEmpty(); + + BString path; + for (int32 i = 0; archive->FindString(kPathKey, i, &path) == B_OK; i++) { + BEntry entry(path.String(), false); + // don't follow links, we want to do that when opening files only + entry_ref ref; + if (entry.GetRef(&ref) != B_OK) + continue; + if (!AddRef(ref)) + return B_NO_MEMORY; + } + + return B_OK; +} + + +status_t +Playlist::Archive(BMessage* into) const +{ + if (into == NULL) + return B_BAD_VALUE; + + int32 count = fRefs.CountItems(); + for (int32 i = 0; i < count; i++) { + const entry_ref* ref = (entry_ref*)fRefs.ItemAtFast(i); + BPath path(ref); + if (path.InitCheck() != B_OK) + continue; + status_t ret = into->AddString(kPathKey, path.Path()); + if (ret != B_OK) + return ret; + } + + return B_OK; +} + + +// #pragma mark - list access + + void Playlist::MakeEmpty() { Modified: haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h 2008-07-11 11:38:51 UTC (rev 26379) +++ haiku/trunk/src/apps/mediaplayer/playlist/Playlist.h 2008-07-11 14:13:10 UTC (rev 26380) @@ -48,25 +48,29 @@ public: Playlist(); ~Playlist(); - + // archiving + status_t UnArchive(const BMessage* archive); + status_t Archive(BMessage* into) const; + + // list functionality void MakeEmpty(); int32 CountItems() const; void Sort(); - + bool AddRef(const entry_ref& ref); bool AddRef(const entry_ref& ref, int32 index); entry_ref RemoveRef(int32 index, bool careAboutCurrentIndex = true); - + bool AdoptPlaylist(Playlist& other); bool AdoptPlaylist(Playlist& other, int32 index); - + int32 IndexOf(const entry_ref& ref) const; status_t GetRefAt(int32 index, entry_ref* ref) const; // bool HasRef(const entry_ref& ref) const; - + // navigating current ref void SetCurrentRefIndex(int32 index); int32 CurrentRefIndex() const; From stippi at mail.berlios.de Fri Jul 11 17:00:59 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Fri, 11 Jul 2008 17:00:59 +0200 Subject: [Haiku-commits] r26381 - haiku/trunk/src/apps/mediaplayer/playlist Message-ID: <200807111500.m6BF0xkK025373@sheep.berlios.de> Author: stippi Date: 2008-07-11 17:00:58 +0200 (Fri, 11 Jul 2008) New Revision: 26381 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26381&view=rev Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp Log: The scrollbar down-button was hidden behind the window resize handle in the Playlist window. Modified: haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp 2008-07-11 14:13:10 UTC (rev 26380) +++ haiku/trunk/src/apps/mediaplayer/playlist/PlaylistWindow.cpp 2008-07-11 15:00:58 UTC (rev 26381) @@ -71,7 +71,7 @@ // make it so the frame of the menubar is also the frame of // the scroll bar (appears to be) scrollBar->MoveBy(0, -1); - scrollBar->ResizeBy(0, 1); + scrollBar->ResizeBy(0, -(B_H_SCROLL_BAR_HEIGHT - 2)); } fCommandStack->AddListener(&fCommandStackListener); From oruizdorantes at mail.berlios.de Fri Jul 11 20:18:46 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Fri, 11 Jul 2008 20:18:46 +0200 Subject: [Haiku-commits] r26382 - haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic Message-ID: <200807111818.m6BIIkXG028456@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-11 20:18:43 +0200 (Fri, 11 Jul 2008) New Revision: 26382 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26382&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c Log: - Reorder and fix the uninitialization of a device. - Fix some null pointer bugs - Mark the removed device to avoid killing it twice in the uninit hook (Mika Lindqvist) * More things might be still missing in the uninit context Modified: haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-11 15:00:58 UTC (rev 26381) +++ haiku/trunk/src/add-ons/kernel/drivers/bluetooth/h2/h2generic/h2generic.c 2008-07-11 18:18:43 UTC (rev 26382) @@ -22,6 +22,11 @@ #include #define BT_DEBUG_THIS_MODULE + +#define MODULE_NAME "BT" +#define SUBMODULE_NAME BLUETOOTH_DEVICE_DEVFS_NAME +#define SUBMODULE_COLOR 31 + #include #include "h2generic.h" @@ -147,15 +152,20 @@ /* remove a device from the list of connected devices */ static void -kill_device(bt_usb_dev* dev) +kill_device(bt_usb_dev* bdev) { - debugf("remove_device(%p)\n", dev); + if (bdev != NULL) { + debugf("(%p)\n", bdev); - delete_sem(dev->lock); - delete_sem(dev->cmd_complete); - - free(dev); - dev_count--; + delete_sem(bdev->lock); + delete_sem(bdev->cmd_complete); + + // mark it free + bt_usb_devices[bdev->num] = NULL; + + free(bdev); + dev_count--; + } } @@ -347,46 +357,37 @@ static status_t device_removed(void* cookie) { - int32 i; - void* item; bt_usb_dev* bdev = (bt_usb_dev*) fetch_device(cookie, 0); debugf("device_removed(%p)\n", bdev); if (bdev == NULL) { - flowf("Weird condition...\n"); + flowf(" not present in driver??\n"); return B_ERROR; } - // TODO: Consider some other place - // TX - for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { - if (i == BT_COMMAND) - while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { - snb_free(item); - } - else - while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { - nb_destroy(item); - } + + if (!TEST_AND_CLEAR(&bdev->state, RUNNING) ) { + flowf(" wasnt running??\n"); + } + + + flowf("Cancelling queues...\n"); + if ( bdev->intr_in_ep != NULL ) { + usb->cancel_queued_transfers(bdev->intr_in_ep->handle); + flowf("Cancelling impossible EVENTS\n"); + } + if (bdev->bulk_in_ep!=NULL) { + usb->cancel_queued_transfers(bdev->bulk_in_ep->handle); + flowf("Cancelling impossible ACL in\n"); } - // RX - for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) { - nb_destroy(bdev->nbufferRx[i]); + + if (bdev->bulk_out_ep!=NULL) { + usb->cancel_queued_transfers(bdev->bulk_out_ep->handle); + flowf("Cancelling impossible ACL out\n"); } - snb_free(bdev->eventRx); - purge_room(&bdev->eventRoom); - purge_room(&bdev->aclRoom); - // TODO: Consider some other place - - if (hci != NULL) - hci->UnregisterDriver(bdev->hdev); - bdev->connected = false; - - /* TODO: maybe we still need this struct for close and free hooks */ - kill_device(bdev); return B_OK; } @@ -487,41 +488,48 @@ static status_t device_close(void *cookie) { + int32 i; + void* item; bt_usb_dev* bdev = (bt_usb_dev*)cookie; - + if (bdev == NULL) panic("bad cookie"); debugf("device_close() called on %ld\n", bdev->hdev ); + // Clean queues - if (!TEST_AND_CLEAR(&bdev->state, RUNNING) ) { - flowf("Device wasnt running!!!\n"); - } + // TX + for (i = 0; i < BT_DRIVER_TXCOVERAGE; i++) { + if (i == BT_COMMAND) + while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { + snb_free(item); + } + else + while ((item = list_remove_head_item(&bdev->nbuffersTx[i])) != NULL) { + nb_destroy(item); + } - flowf("Stopping device and cancelling queues...\n"); - - if ( bdev->intr_in_ep != NULL ) { - usb->cancel_queued_transfers(bdev->intr_in_ep->handle); - - } else { - flowf("Cancelling impossible EVENTS\n"); } - - if (bdev->bulk_in_ep!=NULL) { - usb->cancel_queued_transfers(bdev->bulk_in_ep->handle); - } else { - flowf("Cancelling impossible ACL in\n"); + // RX + for (i = 0; i < BT_DRIVER_RXCOVERAGE; i++) { + nb_destroy(bdev->nbufferRx[i]); } + snb_free(bdev->eventRx); - if (bdev->bulk_out_ep!=NULL) { - usb->cancel_queued_transfers(bdev->bulk_out_ep->handle); - } else { - flowf("Cancelling impossible ACL out\n"); - } + purge_room(&bdev->eventRoom); + purge_room(&bdev->aclRoom); - // TODO: Kill if its not connected? + /* Device no longer in our Stack*/ + if (hci != NULL) + hci->UnregisterDriver(bdev->hdev); + // unSet RUNNING + if (TEST_AND_CLEAR(&bdev->state, RUNNING)) { + debugf(" %s not running??\n",bdev->name); + return B_ERROR; + } + return B_OK; } @@ -532,23 +540,22 @@ device_free (void *cookie) { status_t err = B_OK; - bt_usb_dev* dev = (bt_usb_dev*)cookie; + bt_usb_dev* bdev = (bt_usb_dev*)cookie; debugf("device_free() called on %s \n",BLUETOOTH_DEVICE_PATH); - if (--dev->open_count == 0) { + if (--bdev->open_count == 0) { /* GotoLowPower */ // interesting ..... } else { /* The last client has closed, and the device is no longer - connected, so remove it from the list. */ - + connected, so remove it from the list. */ } - // TODO: Kill if its not connected? + kill_device(bdev); return err; } @@ -747,10 +754,9 @@ // if (connected_dev != NULL) { // debugf("Device %p still exists.\n", connected_dev); // } + debugf("%s still present??\n",bt_usb_devices[j]->name); kill_device(bt_usb_devices[j]); - bt_usb_devices[j] = NULL; } - } usb->uninstall_notify(BLUETOOTH_DEVICE_DEVFS_NAME); From zooey at hirschkaefer.de Fri Jul 11 20:02:39 2008 From: zooey at hirschkaefer.de (Oliver Tappe) Date: Fri, 11 Jul 2008 20:02:39 +0200 Subject: [Haiku-commits] r26377 - in haiku/trunk: headers/private/net src/kits/network src/kits/network/libnetapi In-Reply-To: <2102057140-BeMail@laptop> References: <2102057140-BeMail@laptop> Message-ID: <20080711200239.1374.2@bee.hirschkaefer.site> On 2008-07-11 at 11:50:00 [+0200], Fran?ois Revol wrote: > > > Nice! :) I'm curious, what build of Vision did you use for testing? > > > The one in Haiku's optionalpackages is native, only the bebits > > > build > > > uses libnet, and there it only uses socket functions directly, no > > > BNet* classes. > > > > Ah, ok - I used the one in Haiku's optional packages, but now that > > you told > > me, I will test with the one from BeBits, too. ;-) I have tried the R5 versions of Vision and BeShare and they both work, too. > > Can anyone think of any other R5 networking app that I should check? > > I suppose > > for Beam, NetworkTime and Vision we won't really *need* to be > > compatible > > anyway, since those are available in source. > > Is there any other closed source app apart from NetPositive worth > > considering? > > > > NetPenguin maybe ? Ah, right. When I tried that just now, it failed without ever showing anything in wireshark (running on the VMware host). So there must be still some problem in the code ... back to debugging. cheers, Oliver From julun at mail.berlios.de Fri Jul 11 22:07:00 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Fri, 11 Jul 2008 22:07:00 +0200 Subject: [Haiku-commits] r26383 - haiku/trunk/src/kits/app Message-ID: <200807112007.m6BK70ek011580@sheep.berlios.de> Author: julun Date: 2008-07-11 22:07:00 +0200 (Fri, 11 Jul 2008) New Revision: 26383 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26383&view=rev Modified: haiku/trunk/src/kits/app/Handler.cpp Log: * If a handler goes away that has an looper, we should remove us from the loppers fHandlers list, otherwise we might end up with a dangeling pointer. This should fix the crashes seen in Cortex and Icon-O-Matic on app close. Modified: haiku/trunk/src/kits/app/Handler.cpp =================================================================== --- haiku/trunk/src/kits/app/Handler.cpp 2008-07-11 18:18:43 UTC (rev 26382) +++ haiku/trunk/src/kits/app/Handler.cpp 2008-07-11 20:07:00 UTC (rev 26383) @@ -131,6 +131,11 @@ BHandler::~BHandler() { + if (LockLooper()) { + Looper()->RemoveHandler(this); + UnlockLooper(); + } + // remove all filters if (fFilters) { int32 count = fFilters->CountItems(); From anevilyak at gmail.com Fri Jul 11 22:10:47 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Fri, 11 Jul 2008 15:10:47 -0500 Subject: [Haiku-commits] r26383 - haiku/trunk/src/kits/app In-Reply-To: <200807112007.m6BK70ek011580@sheep.berlios.de> References: <200807112007.m6BK70ek011580@sheep.berlios.de> Message-ID: On Fri, Jul 11, 2008 at 3:07 PM, julun at BerliOS wrote: > Author: julun > Date: 2008-07-11 22:07:00 +0200 (Fri, 11 Jul 2008) > New Revision: 26383 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26383&view=rev > > Modified: > haiku/trunk/src/kits/app/Handler.cpp > Log: > * If a handler goes away that has an looper, we should remove us from the > loppers fHandlers list, otherwise we might end up with a dangeling pointer. > > This should fix the crashes seen in Cortex and Icon-O-Matic on app close. > Nice catch! It somewhat surprises me that this wasn't more noticeable though. Regards, Rene From host.haiku at gmx.de Fri Jul 11 22:33:12 2008 From: host.haiku at gmx.de (julun) Date: Fri, 11 Jul 2008 22:33:12 +0200 Subject: [Haiku-commits] r26383 - haiku/trunk/src/kits/app In-Reply-To: References: <200807112007.m6BK70ek011580@sheep.berlios.de> Message-ID: <4877C388.6060104@gmx.de> Hi Rene, > On Fri, Jul 11, 2008 at 3:07 PM, julun at BerliOS wrote: >> Author: julun >> Date: 2008-07-11 22:07:00 +0200 (Fri, 11 Jul 2008) >> New Revision: 26383 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26383&view=rev >> >> Modified: >> haiku/trunk/src/kits/app/Handler.cpp >> Log: >> * If a handler goes away that has an looper, we should remove us from the >> loppers fHandlers list, otherwise we might end up with a dangeling pointer. >> >> This should fix the crashes seen in Cortex and Icon-O-Matic on app close. >> > > Nice catch! It somewhat surprises me that this wasn't more noticeable though. > True, even more it seems only to happen on gcc 4 builds? I noticed it while debugging the BLooper destructor exit crash whatever thing. Regards, Karsten From umccullough at gmail.com Sat Jul 12 00:31:02 2008 From: umccullough at gmail.com (Urias McCullough) Date: Fri, 11 Jul 2008 15:31:02 -0700 Subject: [Haiku-commits] r26383 - haiku/trunk/src/kits/app In-Reply-To: <4877C388.6060104@gmx.de> References: <200807112007.m6BK70ek011580@sheep.berlios.de> <4877C388.6060104@gmx.de> Message-ID: <1e80d8750807111531s3c616d18n51f7db39e95b4b34@mail.gmail.com> 2008/7/11 julun : > True, even more it seems only to happen on gcc 4 builds? I noticed it while > debugging the BLooper destructor exit crash whatever thing. Oh? I wonder if this was causing the Tracker crash on quit/shutdown on gcc4 builds. It was mentioned here: http://dev.haiku-os.org/ticket/973 (that ticket probably needed to be re-opened, or at least a separate ticket opened for the gcc4 issue i saw). I'll re-test it tonight if I can. - Urias From bonefish at mail.berlios.de Sat Jul 12 01:59:51 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 01:59:51 +0200 Subject: [Haiku-commits] r26384 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807112359.m6BNxpFs003645@sheep.berlios.de> Author: bonefish Date: 2008-07-12 01:59:50 +0200 (Sat, 12 Jul 2008) New Revision: 26384 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26384&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h Log: Patch by Zhao Shuai: * Removed the swap_file_address structure, which was used to refer to an address in the swap space. We do now use a kind of virtual swap address space and assign swap files disjoint ranges of it, so that a swap location can be identified by a single number. * Implemented the swapping related part of MergeStore(), i.e. the swapped out pages of the source cache are taken over, respectively freed if shadowed. * Some coding style improvements. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-11 20:07:00 UTC (rev 26383) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-11 23:59:50 UTC (rev 26384) @@ -28,53 +28,57 @@ # define TRACE(x) ; #endif - #define SWAP_HASH_SIZE 128 -#define SWAP_HASH_MASK (SWAP_HASH_SIZE - 1) -#define SWAP_BLOCK_SHIFT 5 -#define SWAP_BLOCK_PAGES (1 << SWAP_BLOCK_SHIFT) +#define SWAP_BLOCK_PAGES 32 +#define SWAP_BLOCK_MASK (SWAP_BLOCK_PAGES - 1) -#define SWAP_BLOCK_NONE -1 +#define SWAP_PAGE_NONE -1 +// bitmap allocation macros +#define MAP_SHIFT 5 +#define NUM_BITS_PER_WORD 32 // number of bits per word +#define TESTBIT(map, i) \ + (((map)[(i) >> MAP_SHIFT] & (1 << (i) % NUM_BITS_PER_WORD))) +#define SETBIT(map, i) \ + (((map)[(i) >> MAP_SHIFT] |= (1 << (i) % NUM_BITS_PER_WORD))) +#define CLEARBIT(map, i) \ + (((map)[(i) >> MAP_SHIFT] &= ~(1 << (i) % NUM_BITS_PER_WORD))) + + // The stack functionality looks like a good candidate to put into its own // store. I have not done this because once we have a swap file backing up // the memory, it would probably not be a good idea to separate this // anymore. - struct swap_file { mutex lock; struct vnode *vnode; dev_t device; ino_t inode; - int page_count; - int used; // # of pages used - struct swap_file *next; + int32 first_page; + int32 last_page; + int32 used; // # of pages used + struct swap_file *next; // next swap file in the list int *maps; // bitmap for the pages - int hint; // next free page + int32 hint; // next free page }; -struct swap_file_address { - struct swap_file *swapfile; - int page_index; -}; - - // Each swap block contains SWAP_BLOCK_PAGES pages struct swap_block { struct swap_block *hash_next; - VMAnonymousCache *store; + VMAnonymousCache *cache; addr_t cache_offset; -// int used; - struct swap_file_address swap_pages[SWAP_BLOCK_PAGES]; + int used; + int swap_pages[SWAP_BLOCK_PAGES]; }; -static status_t swap_space_alloc(int, struct swap_file_address *); -static void swap_space_dealloc(struct swap_file_address, int); +static int32 swap_space_alloc(int32); +static void swap_space_dealloc(int32, int32); +static struct swap_file *find_swap_file(int32); static object_cache * sSwapBlockCache; @@ -88,14 +92,6 @@ static struct swap_file *sSwapFileAlloc = NULL; //allocate from here -// bitmap allocation macros -#define MAP_SHIFT 5 -#define NUM_BITS_PER_WORD 32 // number of bits per word -#define TESTBIT(map, i) (((map)[(i) >> MAP_SHIFT] & (1 << (i) % NUM_BITS_PER_WORD))) -#define SETBIT(map, i) (((map)[(i) >> MAP_SHIFT] |= (1 << (i) % NUM_BITS_PER_WORD))) -#define CLEARBIT(map, i) (((map)[(i) >> MAP_SHIFT] &= ~(1 << (i) % NUM_BITS_PER_WORD))) - - VMAnonymousCache::~VMAnonymousCache() { vm_unreserve_memory(committed_size); @@ -164,39 +160,38 @@ VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - status_t status = B_OK; - off_t cache_offset; iovec iov; - off_t pos; - struct swap_file_address start_address, address; - int i, j; + int32 i, j; - cache_offset = offset >> PAGE_SHIFT; + off_t cacheOffset = offset >> PAGE_SHIFT; - start_address.swapfile = NULL; - start_address.page_index = SWAP_BLOCK_NONE; - address.swapfile = NULL; - address.page_index = SWAP_BLOCK_NONE; - - for (i = 0; i < count; i = j) { - _SwapBlockGetAddress(cache_offset + i, &start_address); - for (j = i+1; j < count; j++) { - _SwapBlockGetAddress(cache_offset + j, &address); - if (address.swapfile != start_address.swapfile || - address.page_index != start_address.page_index + j - i) + for (i = 0; i < (int)count; i = j) { + int32 startPageIndex = _SwapBlockGetAddress(cacheOffset + i); + for (j = i + 1; j <(int)count; j++) { + int32 pageIndex = _SwapBlockGetAddress(cacheOffset + j); + if (pageIndex != startPageIndex + j - i) break; } - pos = start_address.page_index * PAGE_SIZE; + struct swap_file *swapFile = find_swap_file(startPageIndex); + if (swapFile == NULL) { + panic("can't find swap file for page index %ld\n", startPageIndex); + return B_ERROR; + } + + off_t pos = (startPageIndex - swapFile->first_page) * PAGE_SIZE; iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); - iov.iov_len = (j-i) * PAGE_SIZE; + iov.iov_len = (j - i) * PAGE_SIZE; - status = vfs_read_pages(start_address.swapfile->vnode, NULL, pos, &iov, j-i, + status_t status = vfs_read_pages(swapFile->vnode, NULL, pos, &iov, j - i, _numBytes, fsReenter); if(status != B_OK) return status; - swap_space_dealloc(start_address, j-i); + for (int32 k = i; k < j - i; k++) + _SwapBlockFree(cacheOffset + k); + + swap_space_dealloc(startPageIndex, j - i); } return B_OK; @@ -207,39 +202,42 @@ VMAnonymousCache::Write(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - status_t status = B_OK; - off_t pos; iovec iov; - int i, j, n; - struct swap_file_address address; - int page_index; + int32 pageIndex; offset >>= PAGE_SHIFT; iov.iov_base = vecs->iov_base; iov.iov_len = vecs->iov_len; - n = count; - for (i = 0; i < count; i += n) { + int32 n = count; + for (int32 i = 0; i < (int)count; i += n) { //try to allocate n pages, if fail, try to allocate n/2 - while ((status = swap_space_alloc(n, &address)) == B_ERROR + while ((pageIndex = swap_space_alloc(n)) == SWAP_PAGE_NONE && n >= 2) n >>= 1; - if (status == B_ERROR) + if (pageIndex == SWAP_PAGE_NONE) return B_ERROR; - for (j = 0; j < n; j++) - _SwapBlockBuild(offset + i + j, address); + for (int32 j = 0; j < n; j++) + _SwapBlockBuild(offset + i + j, pageIndex + j); - pos = address.page_index * PAGE_SIZE; + struct swap_file *swapFile = find_swap_file(pageIndex); + if (swapFile == NULL) { + panic("can't find swap file for page index %ld\n", pageIndex); + return B_ERROR; + } + + off_t pos = (pageIndex - swapFile->first_page) * PAGE_SIZE; iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); iov.iov_len = n * PAGE_SIZE; - if ((status = vfs_write_pages(address.swapfile->vnode, NULL, pos, - &iov, n, _numBytes, fsReenter)) != B_OK) - return B_ERROR; + status_t status = vfs_write_pages(swapFile->vnode, NULL, pos, &iov, n, + _numBytes, fsReenter); + if (status != B_OK) + return status; } - return status; + return B_OK; } @@ -282,6 +280,7 @@ void VMAnonymousCache::MergeStore(VMCache* source) +//VMAnonymousCache::MergeStore(VMAnonymousCache *source) { if (source->type != CACHE_TYPE_RAM) { panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache %p " @@ -298,19 +297,45 @@ vm_unreserve_memory(committed_size - actualSize); committed_size = actualSize; } + + int32 sourceSwapIndex = SWAP_PAGE_NONE; // page index in the swap file + + for (off_t offset = source->virtual_base; offset < source->virtual_end; + offset += PAGE_SIZE) { + sourceSwapIndex = ((VMAnonymousCache *)source)-> + _SwapBlockGetAddress(offset); + if (sourceSwapIndex == SWAP_PAGE_NONE) // this page is not swapped out + continue; + else if (LookupPage(offset)) { + // this page is shadowed and we can find it in the new cache, + // free the swap block and swap space + ((VMAnonymousCache *)source)->_SwapBlockFree(offset); + swap_space_dealloc(sourceSwapIndex, 1); + } + else { + int32 swapIndex = _SwapBlockGetAddress(offset); + if (swapIndex == SWAP_PAGE_NONE) + // the page is not shadowed, assign the swap address to the new cache + _SwapBlockBuild(offset, sourceSwapIndex); + else // the page is shadowed but is also swapped out + swap_space_dealloc(sourceSwapIndex, 1); + ((VMAnonymousCache *)source)->_SwapBlockFree(offset); + } + } } swap_block** -VMAnonymousCache::_SwapHash(off_t cache_offset) +VMAnonymousCache::_SwapHash(off_t cacheOffset) { - struct swap_block **pswap; - struct swap_block *swap; + cacheOffset &= ~(off_t)(SWAP_BLOCK_MASK); - cache_offset &= ~(off_t)(SWAP_HASH_MASK); - pswap = &sSwapHash[(cache_offset ^ (int)(int *)this) & sSwapHashMask]; - while ((swap = *pswap) != NULL) { - if (swap->store == this && swap->cache_offset == cache_offset) + struct swap_block **pswap = + &sSwapHash[(cacheOffset ^ (int)(int *)this) & sSwapHashMask]; + struct swap_block *swap = *pswap; + + while (swap != NULL) { + if (swap->cache == this && swap->cache_offset == cacheOffset) break; pswap = &swap->hash_next; } @@ -320,17 +345,13 @@ void -VMAnonymousCache::_SwapBlockBuild(off_t cache_offset, - swap_file_address& address) +VMAnonymousCache::_SwapBlockBuild(off_t cacheOffset, int32 pageIndex) { - struct swap_block *swap; - struct swap_block **pswap; - int index, i; - mutex_lock(&sSwapHashLock); - pswap = _SwapHash(cache_offset); - if ((swap = *pswap) == NULL) { + struct swap_block **pswap = _SwapHash(cacheOffset); + struct swap_block *swap = *pswap; + if (swap == NULL) { swap = *pswap = (struct swap_block *)object_cache_alloc(sSwapBlockCache, CACHE_DONT_SLEEP); if (swap == NULL) { mutex_unlock(&sSwapHashLock); @@ -338,63 +359,101 @@ } swap->hash_next = NULL; - swap->store = this; - swap->cache_offset = cache_offset & ~(off_t)(SWAP_BLOCK_PAGES - 1); -// swap->used = 0; + swap->cache = this; + swap->cache_offset = cacheOffset & ~(off_t)SWAP_BLOCK_MASK; + swap->used = 0; - for (i = 0; i < SWAP_BLOCK_PAGES; i++) - swap->swap_pages[i].swapfile = NULL; - swap->swap_pages[i].page_index = SWAP_BLOCK_NONE; + for (int32 i = 0; i < SWAP_BLOCK_PAGES; i++) + swap->swap_pages[i] = SWAP_PAGE_NONE; } - index = cache_offset & (SWAP_BLOCK_PAGES - 1); - swap->swap_pages[index].swapfile = address.swapfile; - swap->swap_pages[index].page_index = address.page_index; + int32 blockIndex = cacheOffset & SWAP_BLOCK_MASK; + swap->swap_pages[blockIndex] = pageIndex; -// swap->used++; + swap->used++; mutex_unlock(&sSwapHashLock); } void -VMAnonymousCache::_SwapBlockGetAddress(off_t cache_offset, - swap_file_address *address) +VMAnonymousCache::_SwapBlockFree(off_t cacheOffset) { - struct swap_block *swap; - struct swap_block **pswap; - int index; + mutex_lock(&sSwapHashLock); + struct swap_block **pswap = _SwapHash(cacheOffset); + struct swap_block *swap = *pswap; + if (swap != NULL) { + int32 pageIndex = swap->swap_pages[cacheOffset & SWAP_BLOCK_MASK]; + if (pageIndex != SWAP_PAGE_NONE) { + swap->swap_pages[cacheOffset & SWAP_BLOCK_MASK] = SWAP_PAGE_NONE; + swap->used--; + if (swap->used == 0) { + *pswap = swap->hash_next; + object_cache_free(sSwapBlockCache, swap); + } + } + } + + mutex_unlock(&sSwapHashLock); +} + + +int32 +VMAnonymousCache::_SwapBlockGetAddress(off_t cacheOffset) +{ + int32 pageIndex = SWAP_PAGE_NONE; + mutex_lock(&sSwapHashLock); - pswap = _SwapHash(cache_offset); - if ((swap = *pswap) != NULL) { - index = cache_offset & (off_t)SWAP_HASH_MASK; - address->swapfile = swap->swap_pages[index].swapfile; - address->page_index = swap->swap_pages[index].page_index; + struct swap_block **pswap = _SwapHash(cacheOffset); + struct swap_block *swap = *pswap; + if (swap != NULL) { + int32 blockIndex = cacheOffset & SWAP_BLOCK_MASK; + pageIndex = swap->swap_pages[blockIndex]; } mutex_unlock(&sSwapHashLock); + + return pageIndex; } -static status_t -swap_space_alloc(int npages, struct swap_file_address *address) +static struct swap_file * +find_swap_file(int32 pageIndex) { - int hint, i, j; + struct swap_file *swapFile = sSwapFileList; + while (swapFile != NULL) { + if (pageIndex >= swapFile->first_page && + pageIndex < swapFile->last_page) + break; + else + swapFile = swapFile->next; + } + + return swapFile; +} + + +static int32 +swap_space_alloc(int32 npages) +{ + int32 hint, j; + for (j = 0; j < sSwapFileCount; j++) { if (sSwapFileAlloc == NULL) { sSwapFileAlloc = sSwapFileList->next; if (sSwapFileAlloc == NULL) // there is no swap_file - return B_ERROR; + return SWAP_PAGE_NONE; } mutex_lock(&sSwapFileAlloc->lock); hint = sSwapFileAlloc->hint; + int32 pageCount = sSwapFileAlloc->last_page - sSwapFileAlloc->first_page; - i = 0; - while (i < npages && (hint + npages) < sSwapFileAlloc->page_count) { + int32 i = 0; + while (i < npages && (hint + npages) < pageCount) { if (TESTBIT(sSwapFileAlloc->maps, hint+i)) { hint++; @@ -413,61 +472,68 @@ if (j == sSwapFileCount) { panic("swap space exhausted\n"); - return B_ERROR; + return SWAP_PAGE_NONE; } - address->swapfile = sSwapFileAlloc; - address->page_index = hint; + int32 pageIndex = sSwapFileAlloc->first_page + hint; - for (i = 0; i < npages; i++) + for (int32 i = 0; i < npages; i++) SETBIT(sSwapFileAlloc->maps, hint + i); if (hint == sSwapFileAlloc->hint) - sSwapFileAlloc->hint += i; + sSwapFileAlloc->hint += npages; sSwapFileAlloc->used += npages; - if (sSwapFileAlloc->used > 9 * sSwapFileAlloc->page_count / 10) + + // if this swap file has used more than 90% percent of its pages + // switch to another + if (sSwapFileAlloc->used > + 9 * (sSwapFileAlloc->last_page - sSwapFileAlloc->first_page) / 10) sSwapFileAlloc = sSwapFileAlloc->next; mutex_unlock(&sSwapFileAlloc->lock); - return B_OK; + return pageIndex; } static void -swap_space_dealloc(struct swap_file_address address, int npages) +swap_space_dealloc(int32 pageIndex, int32 npages) { - mutex_lock(&address.swapfile->lock); + struct swap_file *swapFile = find_swap_file(pageIndex); + + mutex_lock(&swapFile->lock); + + pageIndex -= swapFile->first_page; - for (int i = 0; i < npages; i++) - CLEARBIT(address.swapfile->maps, address.page_index + i); - if (address.swapfile->hint > address.page_index) - address.swapfile->hint = address.page_index; + for (int32 i = 0; i < npages; i++) + CLEARBIT(swapFile->maps, pageIndex + i); - address.swapfile->used -= npages; + if (swapFile->hint > pageIndex) + swapFile->hint = pageIndex; - mutex_unlock(&address.swapfile->lock); + swapFile->used -= npages; + + mutex_unlock(&swapFile->lock); } -static status_t +status_t swap_file_add(char *path) { vnode *vp = NULL; - status_t status = B_OK; - struct swap_file *swap, *sw; - struct stat st; - - if ((status = vfs_get_vnode_from_path(path, true, &vp)) != B_OK) + status_t status = vfs_get_vnode_from_path(path, true, &vp); + if (status != B_OK) return status; - swap = (struct swap_file *)malloc(sizeof(struct swap_file)); + struct swap_file *swap = (struct swap_file *)malloc(sizeof(struct swap_file)); if (swap == NULL) return B_NO_MEMORY; mutex_init(&swap->lock, "swap_file"); - if ((status = vfs_stat_vnode(vp, &st)) != B_OK) { + struct stat st; + status = vfs_stat_vnode(vp, &st); + if (status != B_OK) { free(swap); return status; } @@ -475,43 +541,101 @@ swap->device = st.st_dev; swap->inode = st.st_ino; - swap->page_count = st.st_size >> PAGE_SHIFT; + int32 pageCount = st.st_size >> PAGE_SHIFT; swap->used = 0; - swap->maps = (int *)malloc(swap->page_count / NUM_BITS_PER_WORD + 1); + swap->next = NULL; + + swap->maps = (int *)malloc(pageCount / NUM_BITS_PER_WORD + 1); if (swap->maps == NULL) { free(swap); return B_NO_MEMORY; } - memset(swap->maps, 0, swap->page_count % 8 + 1); + memset(swap->maps, 0, pageCount % 8 + 1); swap->hint = 0; - // add this file to swap file list + // set start page index and add this file to swap file list mutex_lock(&sSwapFileListLock); - sw = sSwapFileList; - while (sw != NULL) - sw = sw->next; - sw->next = swap; - swap->next = NULL; + struct swap_file *sw = sSwapFileList; + if (sw == NULL) { + swap->first_page = 0; + swap->last_page = pageCount; + sw = swap; + } else { + while (sw->next != NULL) + sw = sw->next; + swap->first_page = sw->last_page + 1; + swap->last_page = swap->first_page + pageCount; + sw->next = swap; + } + + sSwapFileCount++; + mutex_unlock(&sSwapFileListLock); + + return B_OK; +} + + +status_t +swap_file_delete(char *path) +{ + vnode *vp = NULL; + status_t status = vfs_get_vnode_from_path(path, true, &vp); + if (status != B_OK) + return status; + + mutex_lock(&sSwapFileListLock); - sSwapFileCount++; + struct swap_file *swapFile = sSwapFileList; + while (swapFile != NULL) { + if (swapFile->vnode == vp) + break; + else + swapFile = swapFile->next; + } + if (swapFile == NULL) + return B_ERROR; + + for (int32 i = 0; i < swapFile->last_page - swapFile->first_page; i++) + if (TESTBIT(swapFile->maps, i)) + // this swap file is in use, can't delete + return B_ERROR; - return status; + // remove this swap file from swap file list + if (swapFile == sSwapFileList) + sSwapFileList = swapFile->next; + else { + struct swap_file *swapFilePre = sSwapFileList; + while (swapFilePre->next != swapFile) + swapFilePre = swapFilePre->next; + swapFilePre->next = swapFile->next; + } + + sSwapFileCount--; + + mutex_unlock(&sSwapFileListLock); + + mutex_destroy(&swapFile->lock); + free(swapFile->maps); + free(swapFile); + + return B_OK; } + - -static void +void swap_init(void) { // create swap block cache sSwapBlockCache = create_object_cache("swapblock", - sizeof(struct swap_block), sizeof(void*), NULL, NULL, NULL); + sizeof(struct swap_block), sizeof(void*), NULL, NULL, NULL); if (sSwapBlockCache == NULL) panic("can't create object cache for swap blocks\n"); // init swap hash table - sSwapHash = (struct swap_block **)malloc(sizeof(struct swap_block *) * SWAP_HASH_SIZE); + sSwapHash = (struct swap_block **)malloc(sizeof(struct swap_block *) * + SWAP_HASH_SIZE); if (sSwapHash == NULL) panic("swap hash table allocation error\n"); sSwapHashMask = SWAP_HASH_SIZE - 1; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-11 20:07:00 UTC (rev 26383) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-11 23:59:50 UTC (rev 26384) @@ -13,9 +13,7 @@ struct swap_block; -struct swap_file_address; - class VMAnonymousCache : public VMCache { public: virtual ~VMAnonymousCache(); @@ -36,11 +34,10 @@ virtual void MergeStore(VMCache* source); private: - swap_block** _SwapHash(off_t cache_offset); - void _SwapBlockBuild(off_t cache_offset, - swap_file_address& address); - void _SwapBlockGetAddress(off_t cache_offset, - swap_file_address *address); + swap_block** _SwapHash(off_t cacheOffset); + void _SwapBlockBuild(off_t cacheOffset, int32 pageIndex); + void _SwapBlockFree(off_t cacheOffset); + int32 _SwapBlockGetAddress(off_t cacheOffset); private: bool fCanOvercommit; From bonefish at mail.berlios.de Sat Jul 12 02:05:22 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 02:05:22 +0200 Subject: [Haiku-commits] r26385 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807120005.m6C05Maw005076@sheep.berlios.de> Author: bonefish Date: 2008-07-12 02:05:20 +0200 (Sat, 12 Jul 2008) New Revision: 26385 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26385&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp Log: Use dynamic_cast<>() in MergeStore() instead of checking VMCache::type, which is not exact enough. Also saves later casts. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-11 23:59:50 UTC (rev 26384) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-12 00:05:20 UTC (rev 26385) @@ -279,12 +279,12 @@ void -VMAnonymousCache::MergeStore(VMCache* source) -//VMAnonymousCache::MergeStore(VMAnonymousCache *source) +VMAnonymousCache::MergeStore(VMCache* _source) { - if (source->type != CACHE_TYPE_RAM) { - panic("VMAnonymousCache::MergeStore(): merge with non-RAM cache %p " - "requested", source); + VMAnonymousCache* source = dynamic_cast(_source); + if (source) { + panic("VMAnonymousCache::MergeStore(): merge with incompatible cache " + "%p requested", _source); return; } @@ -302,14 +302,13 @@ for (off_t offset = source->virtual_base; offset < source->virtual_end; offset += PAGE_SIZE) { - sourceSwapIndex = ((VMAnonymousCache *)source)-> - _SwapBlockGetAddress(offset); + sourceSwapIndex = source->_SwapBlockGetAddress(offset); if (sourceSwapIndex == SWAP_PAGE_NONE) // this page is not swapped out continue; else if (LookupPage(offset)) { // this page is shadowed and we can find it in the new cache, // free the swap block and swap space - ((VMAnonymousCache *)source)->_SwapBlockFree(offset); + source->_SwapBlockFree(offset); swap_space_dealloc(sourceSwapIndex, 1); } else { @@ -319,7 +318,7 @@ _SwapBlockBuild(offset, sourceSwapIndex); else // the page is shadowed but is also swapped out swap_space_dealloc(sourceSwapIndex, 1); - ((VMAnonymousCache *)source)->_SwapBlockFree(offset); + source->_SwapBlockFree(offset); } } } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-11 23:59:50 UTC (rev 26384) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-12 00:05:20 UTC (rev 26385) @@ -150,11 +150,13 @@ void -VMAnonymousNoSwapCache::MergeStore(VMCache* source) +VMAnonymousNoSwapCache::MergeStore(VMCache* _source) { - if (source->type != CACHE_TYPE_RAM) { - panic("VMAnonymousNoSwapCache::MergeStore(): merge with non-RAM cache %p " - "requested", source); + VMAnonymousNoSwapCache* source + = dynamic_cast(_source); + if (source) { + panic("VMAnonymousNoSwapCache::MergeStore(): merge with incompatible " + "cache %p requested", _source); return; } From anevilyak at gmail.com Sat Jul 12 02:08:13 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Fri, 11 Jul 2008 19:08:13 -0500 Subject: [Haiku-commits] r26385 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm In-Reply-To: <200807120005.m6C05Maw005076@sheep.berlios.de> References: <200807120005.m6C05Maw005076@sheep.berlios.de> Message-ID: On Fri, Jul 11, 2008 at 7:05 PM, wrote: > Author: bonefish > Date: 2008-07-12 02:05:20 +0200 (Sat, 12 Jul 2008) > New Revision: 26385 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26385&view=rev > > Modified: > haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp > haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp > Log: > Use dynamic_cast<>() in MergeStore() instead of checking VMCache::type, > which is not exact enough. Also saves later casts. > Just curiosity, I thought RTTI wasn't allowed when using C++ in the kernel? Regards, Rene From ingo_weinhold at gmx.de Sat Jul 12 03:03:44 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sat, 12 Jul 2008 03:03:44 +0200 Subject: [Haiku-commits] r26385 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm In-Reply-To: References: <200807120005.m6C05Maw005076@sheep.berlios.de> Message-ID: <20080712030344.915.2@knochen-vm.nameserver> On 2008-07-12 at 02:08:13 [+0200], Rene Gollent wrote: > On Fri, Jul 11, 2008 at 7:05 PM, wrote: > > Author: bonefish > > Date: 2008-07-12 02:05:20 +0200 (Sat, 12 Jul 2008) > > New Revision: 26385 > > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26385&view=rev > > > > Modified: > > haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCac > > he.cpp > > haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoS > > wapCache.cpp > > Log: > > Use dynamic_cast<>() in MergeStore() instead of checking VMCache::type, > > which is not exact enough. Also saves later casts. > > > > Just curiosity, I thought RTTI wasn't allowed when using C++ in the kernel? RTTI is fine in the kernel -- we dropped "-fno-rtti" ages ago and link against libgcc. Technically exceptions would work, too, but the general sentiment was, that exceptions probably introduce more danger than benefits (though, admittedly I was wavering when writing the KDL parser), hence we still explicitly forbid them via "-fno-exceptions". CU, Ingo From bonefish at mail.berlios.de Sat Jul 12 03:28:59 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 03:28:59 +0200 Subject: [Haiku-commits] r26387 - haiku/trunk/src/apps/terminal Message-ID: <200807120128.m6C1SxTf013031@sheep.berlios.de> Author: bonefish Date: 2008-07-12 03:28:57 +0200 (Sat, 12 Jul 2008) New Revision: 26387 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26387&view=rev Modified: haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h Log: Changed GetStringFromRegion() to not insert '\n' for soft line breaks. Fixes bug #2515. Modified: haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp =================================================================== --- haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp 2008-07-12 00:54:53 UTC (rev 26386) +++ haiku/trunk/src/apps/terminal/BasicTerminalBuffer.cpp 2008-07-12 01:28:57 UTC (rev 26387) @@ -320,7 +320,9 @@ // get all but the last line while (pos.y < end.y) { - if (_GetPartialLineString(string, pos.y, pos.x, fWidth)) + TerminalLine* line = _GetPartialLineString(string, pos.y, pos.x, + fWidth); + if (line != NULL && !line->softBreak) string.Append('\n', 1); pos.x = 0; pos.y++; @@ -1347,14 +1349,14 @@ /*! \a endColumn is not inclusive. */ -bool +TerminalLine* BasicTerminalBuffer::_GetPartialLineString(BString& string, int32 row, int32 startColumn, int32 endColumn) const { TerminalLine* lineBuffer = ALLOC_LINE_ON_STACK(fWidth); TerminalLine* line = _HistoryLineAt(row, lineBuffer); if (line == NULL) - return false; + return NULL; if (endColumn > line->length) endColumn = line->length; @@ -1367,7 +1369,7 @@ x++; } - return true; + return line; } Modified: haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h =================================================================== --- haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h 2008-07-12 00:54:53 UTC (rev 26386) +++ haiku/trunk/src/apps/terminal/BasicTerminalBuffer.h 2008-07-12 01:28:57 UTC (rev 26387) @@ -160,7 +160,7 @@ void _PadLineToCursor(); static void _TruncateLine(TerminalLine* line, int32 length); void _InsertGap(int32 width); - bool _GetPartialLineString(BString& string, + TerminalLine* _GetPartialLineString(BString& string, int32 row, int32 startColumn, int32 endColumn) const; bool _PreviousChar(TermPos& pos, UTF8Char& c) const; From bonefish at mail.berlios.de Sat Jul 12 02:54:55 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 02:54:55 +0200 Subject: [Haiku-commits] r26386 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807120054.m6C0stW2011095@sheep.berlios.de> Author: bonefish Date: 2008-07-12 02:54:53 +0200 (Sat, 12 Jul 2008) New Revision: 26386 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26386&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp Log: The check was incorrect. Even for simple changes testing is a good idea. :-) Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-12 00:05:20 UTC (rev 26385) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-12 00:54:53 UTC (rev 26386) @@ -282,7 +282,7 @@ VMAnonymousCache::MergeStore(VMCache* _source) { VMAnonymousCache* source = dynamic_cast(_source); - if (source) { + if (source == NULL) { panic("VMAnonymousCache::MergeStore(): merge with incompatible cache " "%p requested", _source); return; Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-12 00:05:20 UTC (rev 26385) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousNoSwapCache.cpp 2008-07-12 00:54:53 UTC (rev 26386) @@ -154,7 +154,7 @@ { VMAnonymousNoSwapCache* source = dynamic_cast(_source); - if (source) { + if (source == NULL) { panic("VMAnonymousNoSwapCache::MergeStore(): merge with incompatible " "cache %p requested", _source); return; From bonefish at mail.berlios.de Sat Jul 12 03:39:47 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 03:39:47 +0200 Subject: [Haiku-commits] r26388 - haiku/trunk/src/apps/terminal Message-ID: <200807120139.m6C1dlQW013650@sheep.berlios.de> Author: bonefish Date: 2008-07-12 03:39:45 +0200 (Sat, 12 Jul 2008) New Revision: 26388 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26388&view=rev Modified: haiku/trunk/src/apps/terminal/TermView.cpp Log: Incorrect selection line end enforcement -- the selection end is exclusive. Fixes bug #2516. Modified: haiku/trunk/src/apps/terminal/TermView.cpp =================================================================== --- haiku/trunk/src/apps/terminal/TermView.cpp 2008-07-12 01:28:57 UTC (rev 26387) +++ haiku/trunk/src/apps/terminal/TermView.cpp 2008-07-12 01:39:45 UTC (rev 26388) @@ -1990,7 +1990,7 @@ if (start.x < 0) start.x = 0; if (end.x >= fTermColumns) - end.x = fTermColumns - 1; + end.x = fTermColumns; TermPos minPos(0, -fTextBuffer->HistorySize()); TermPos maxPos(0, fTextBuffer->Height()); From bonefish at mail.berlios.de Sat Jul 12 04:36:29 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sat, 12 Jul 2008 04:36:29 +0200 Subject: [Haiku-commits] r26389 - haiku/trunk/src/apps/terminal Message-ID: <200807120236.m6C2aT70018446@sheep.berlios.de> Author: bonefish Date: 2008-07-12 04:36:26 +0200 (Sat, 12 Jul 2008) New Revision: 26389 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26389&view=rev Modified: haiku/trunk/src/apps/terminal/TermView.cpp Log: Fixed small selection problems: * When selecting character-wise backwards the initially selected char was deselected. * When first extending a selection and then moving the mouse back into the initial selection region (char, word, or line), the previously selected additional char/word/line would not be deselected (only when moving the mouse in the other direction out of the initial selection). Modified: haiku/trunk/src/apps/terminal/TermView.cpp =================================================================== --- haiku/trunk/src/apps/terminal/TermView.cpp 2008-07-12 01:39:45 UTC (rev 26388) +++ haiku/trunk/src/apps/terminal/TermView.cpp 2008-07-12 02:36:26 UTC (rev 26389) @@ -1933,8 +1933,19 @@ switch (fSelectGranularity) { case SELECT_CHARS: + { + // If we just start selecting, we first select the initially + // hit char, so that we get a proper initial selection -- the char + // in question, which will thus always be selected, regardless of + // whether selecting forward or backward. + if (fInitialSelectionStart == fInitialSelectionEnd) { + _Select(fInitialSelectionStart, fInitialSelectionEnd, true, + true); + } + _ExtendSelection(_ConvertToTerminal(where), true, true); break; + } case SELECT_WORDS: _SelectWord(where, true, true); break; @@ -2056,6 +2067,8 @@ _Select(pos, end, false, !useInitialSelection); else if (pos > end) _Select(start, pos, false, !useInitialSelection); + else if (useInitialSelection) + _Select(start, end, false, false); } @@ -2098,6 +2111,8 @@ _ExtendSelection(start, false, useInitialSelection); else if (end > (useInitialSelection ? fInitialSelectionEnd : fSelEnd)) _ExtendSelection(end, false, useInitialSelection); + else if (useInitialSelection) + _Select(start, end, false, false); } else _Select(start, end, false, !useInitialSelection); } @@ -2114,7 +2129,8 @@ _ExtendSelection(start, false, useInitialSelection); else if (end > (useInitialSelection ? fInitialSelectionEnd : fSelEnd)) _ExtendSelection(end, false, useInitialSelection); - + else if (useInitialSelection) + _Select(start, end, false, false); } else _Select(start, end, false, !useInitialSelection); } From modeenf at mail.berlios.de Sat Jul 12 12:31:43 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Sat, 12 Jul 2008 12:31:43 +0200 Subject: [Haiku-commits] r26390 - in haiku/trunk/src/add-ons/kernel/drivers: . joystick joystick/emuxkigameport joystick/usb_joy Message-ID: <200807121031.m6CAVh6c018662@sheep.berlios.de> Author: modeenf Date: 2008-07-12 12:31:24 +0200 (Sat, 12 Jul 2008) New Revision: 26390 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26390&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/ haiku/trunk/src/add-ons/kernel/drivers/joystick/Jamfile haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/ haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/Jamfile haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.cpp haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.h haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/joystick_driver.h haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/ haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/Jamfile haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devlist.c haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/driver.c haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/driver.h haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/hidparse.c haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/hidparse.h haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/joystick_driver.h Log: Driver for USB Joystick SBLive and audigy. Work in progress. Right now the USB driver don't work. Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/Jamfile 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/Jamfile 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,4 @@ +SubDir HAIKU_TOP src add-ons kernel drivers joystick ; + +SubInclude HAIKU_TOP src add-ons kernel drivers joystick emuxkigameport ; +SubInclude HAIKU_TOP src add-ons kernel drivers joystick usb_joy ; \ No newline at end of file Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/Jamfile 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/Jamfile 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,7 @@ +SubDir HAIKU_TOP src add-ons kernel drivers joystick emuxkigameport ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +KernelAddon emuxkigameport : + driver.cpp +; Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.cpp 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.cpp 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,279 @@ +/* + * Copyright 2008 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander Coers Alexander.Coers at gmx.de + * Fredrik Mod?en fredrik at modeen.se + * Axel D?rfler axeld at pinc-software.de + */ + +#include "driver.h" + +#include +#include + +#include +#include + +#define TRACE_DRIVER +#ifdef TRACE_DRIVER +# define TRACE(x) dprintf x +#else +# define TRACE(x) ; +#endif + +int32 api_version = B_CUR_DRIVER_API_VERSION; + +int num_names = 0; +int num_cards = 0; + +char *gDeviceNames[MAX_CARDS + 1]; +gameport_info cards[MAX_CARDS]; + +/* setup_card used to initialize cards, structures or hardware */ +static status_t +setup_card (gameport_info* card) +{ + char * name = card->name; + uint32 command_reg = 0; + area_id area; + int32 base,size; + + dprintf (DRIVER_NAME ": setup_card() trying to init structures \n"); + /* enable PCI i/o */ + command_reg = PCI_command_io || PCI_command_master ; + + (*pci->write_pci_config)(card->info.bus,card->info.device, + card->info.function, PCI_command, 2, 0); + + /* disable all i/o -regs and bus_mastering */ + base = card->info.u.h0.base_registers[0]; + size = card->info.u.h0.base_register_sizes[0]; + + (*pci->write_pci_config) (card->info.bus,card->info.device, + card->info.function, 0x10, 2, base); + + (*pci->write_pci_config) (card->info.bus,card->info.device, + card->info.function, PCI_command, 2, command_reg); + + /* enable i/o- regs and possible bus_mastering */ + dprintf (DRIVER_NAME ": setup_card() enabled card with i/o regs from " + "0x%04x to 0x%04x \n",base,base+size-1); + + if ((*gameport->create_device)((int32)base, &card->joy.driver) < B_OK) { + dprintf (DRIVER_NAME ": setup_card() Gameport setup failed! Failed to " + "load Generic Gameport Module \n"); + return B_ERROR; + } + + sprintf(card->joy.name1, "joystick/"DRIVER_NAME "/%x", base); + gDeviceNames[num_names++] = card->joy.name1; + gDeviceNames[num_names] = NULL; + return B_OK; +} + + +extern "C" status_t +init_hardware (void) +{ + status_t err = ENODEV; + pci_info info; + int ix = 0; + uint32 buffer; + + /* probe PCI bus */ + if (get_module (pci_name, (module_info **)&pci)) + return ENOSYS; + while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { + /* look for HARDWARE */ + if (info.vendor_id == VENDOR_ID_CREATIVE && + info.device_id == DEVICE_ID_CREATIVE_EMU10K1) { + err = B_OK; + + dprintf (DRIVER_NAME ": init_hardware() found one, Revision %02x\n" + ,info.revision); + + if (!(info.u.h0.subsystem_id == 0x20 || + info.u.h0.subsystem_id == 0xc400 || + (info.u.h0.subsystem_id == 0x21 && info.revision < 6))) { + buffer = (*pci->read_io_32)(info.u.h0.base_registers[0] + HCFG); + buffer |= HCFG_JOYENABLE; + (*pci->write_io_32)(info.u.h0.base_registers[0] + HCFG, buffer); + } + /* Some SB-Live cards need to the Joyenable Bit in the config + Register, others don?t */ + } + ix++; + } + put_module (B_PCI_MODULE_NAME); + return err; +} + + +extern "C" status_t +init_driver (void) +{ + area_id area; + area_info ainfo; + pci_info info; + int ix = 0; + dprintf (DRIVER_NAME ": init_driver() " __DATE__ " " __TIME__ "\n"); + + /* probe PCI bus */ + if (get_module (pci_name, (module_info **)&pci)) + return ENOSYS; + + if (get_module (gameport_name, (module_info **)&gameport)) { + dprintf (DRIVER_NAME ": Failed to load Generic Gameport Module \n"); + put_module (pci_name); + return ENOSYS; + } + + while ((*pci->get_nth_pci_info)(ix, &info) == B_OK) { + if (info.vendor_id == VENDOR_ID_CREATIVE && ( + info.device_id == SBLIVE_ID || + info.device_id == AUDIGY_ID || + info.device_id == SBLIVE_DELL_ID)) { + + if (num_cards == MAX_CARDS) { + dprintf(DRIVER_NAME ": Too many cards installed!\n"); + break; + } + + memset(&cards[num_cards], 0, sizeof(gameport_info)); + cards[num_cards].info = info; + if (setup_card(&cards[num_cards])) + dprintf(DRIVER_NAME ": Setup of card %ld failed \n", + num_cards + 1); + else + num_cards++; + } + ix++; + } + + if (!num_cards) { + dprintf(DRIVER_NAME ": no cards \n"); + put_module(pci_name); + return ENODEV; + } + return B_OK; +} + + +void +uninit_driver (void) +{ + int ix = 0; + area_id area; + dprintf (DRIVER_NAME ": uninit_driver()\n"); + for (ix = 0; ix < num_cards; ix++) { + area = find_area (AREA_NAME); + if (area >= 0) + delete_area (area); + (*gameport->delete_device)(cards[ix].joy.driver); + } + memset(&cards, 0, sizeof(cards)); + put_module (gameport_name); + put_module (pci_name); + num_cards = 0; +} + + +extern "C" const char** +publish_devices() +{ + return (const char **)gDeviceNames; +} + + +static int +lookup_device_name (const char *name) +{ + int i; + for (i = 0; gDeviceNames[i]; i++) + if (!strcmp (gDeviceNames[i], name)) + return i; + return -1; +} + + +static status_t +device_open(const char* name, uint32 flags, void** cookie) +{ + int ix; + int offset = -1; + + *cookie = NULL; + for (ix = 0; ix < num_cards; ix++) { + if (!strcmp(name, cards[ix].joy.name1)) { + offset = 0; + break; + } + } + + if (offset < 0) { + return ENODEV; + } + + return (*gameport->open_hook)(cards[ix].joy.driver, flags, cookie); +} + + +static status_t +device_close(void * cookie) +{ + return (*gameport->close_hook)(cookie); +} + + +static status_t +device_free(void * cookie) +{ + return (*gameport->free_hook)(cookie); +} + + +static status_t +device_control(void * cookie, uint32 iop, void * data, size_t len) +{ + return (*gameport->control_hook)(cookie, iop, data, len); +} + + +static status_t +device_read(void * cookie, off_t pos, void * data, size_t * nread) +{ + return (*gameport->read_hook)(cookie, pos, data, nread); +} + + +static status_t +device_write(void * cookie, off_t pos, const void * data, size_t * nwritten) +{ + (*pci->write_io_32) ((int)vaddr,0); + return (*gameport->write_hook)(cookie, pos, data, nwritten); +} + +device_hooks gDeviceHooks = { + device_open, + device_close, + device_free, + device_control, + device_read, + device_write, + NULL, /* select */ + NULL, /* deselect */ + NULL, /* readv */ + NULL /* writev */ +}; + + +device_hooks* +find_device(const char* name) +{ + if (lookup_device_name (name) >= 0) { + return &gDeviceHooks; + } + return NULL; +} Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.h 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/driver.h 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,52 @@ +/* + * Copyright 2008 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander Coers Alexander.Coers at gmx.de + * Fredrik Mod?en fredrik at modeen.se + */ + +#ifndef DRIVER_H +#define DRIVER_H + +#include +#include + +#include "joystick_driver.h" + +#define VENDOR_ID_CREATIVE 0x1102 +#define DEVICE_ID_CREATIVE_EMU10K1 0x0002 +#define SBLIVE_ID 0x7002 /*EMU10000*/ +#define AUDIGY_ID 0x7003 /*EMU10K2*/ +#define SBLIVE_DELL_ID 0x7004 /* Game port for SB Live!, Dell OEM gameport*/ +#define DRIVER_NAME "emuxkigameport" +#define AREA_NAME "SB_GAME" +#define MAX_CARDS 2 + +/* NB global variables are valid only while driver is loaded */ +static volatile ulong vaddr; /* PCI */ + +// use pci manager +static char pci_name[] = B_PCI_MODULE_NAME; +static pci_module_info *pci; + +// use generic_gameport_module... +static char gameport_name [] = "generic/gameport/v2"; +static generic_gameport_module *gameport; + +#define HCFG 0x14 /* Hardware Configuration Register of SB-Live */ +#define HCFG_JOYENABLE 0x00000200 /* Mask for enabling Joystick */ + +struct joystick_dev { + void * driver; + char name1[64]; +}; + +struct gameport_info { + char name[60]; /* used for resources */ + pci_info info; + joystick_dev joy; +}; + +#endif /* DRIVER_H */ Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/joystick_driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/joystick_driver.h 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/emuxkigameport/joystick_driver.h 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,120 @@ +/* ++++++++++ + FILE: joystick_driver.h + REVS: $Revision: 1.1 $ + NAME: herold + DATE: Tue Jun 4 14:57:25 PDT 1996 ++++++ */ + +/* + Copyright 1999, Be Incorporated. All Rights Reserved. + This file may be used under the terms of the Be Sample Code License. +*/ + +#ifndef _JOYSTICK_DRIVER_H +#define _JOYSTICK_DRIVER_H + +#include +#include +#include + +typedef struct _joystick { + bigtime_t timestamp; + uint32 horizontal; + uint32 vertical; + bool button1; + bool button2; +} joystick; + +/* maximum number of axes on one controller (pads count as 2 axes each) */ +#define MAX_AXES 12 +/* maximum number of hats on one controller -- PADS SHOULD BE RETURNED AS AXES! */ +#define MAX_HATS 8 +/* maximum number of buttons on one controller */ +#define MAX_BUTTONS 32 +/* maximum number of controllers on one port */ +#define MAX_STICKS 4 + +typedef struct _extended_joystick { + bigtime_t timestamp; /* system_time when it was read */ + uint32 buttons; /* lsb to msb, 1 == on */ + int16 axes[MAX_AXES]; /* -32768 to 32767, X, Y, Z, U, V, W */ + uint8 hats[MAX_HATS]; /* 0 through 8 (1 == N, 3 == E, 5 == S, 7 == W) */ +} extended_joystick; + +#define MAX_CONFIG_SIZE 100 + +enum { /* flags for joystick module info */ + js_flag_force_feedback = 0x1, + js_flag_force_feedback_directional = 0x2 +}; + +typedef struct _joystick_module_info { + char module_name[64]; + char device_name[64]; + int16 num_axes; + int16 num_buttons; + int16 num_hats; + uint16 _reserved[7]; + uint32 flags; + uint16 num_sticks; + int16 config_size; + char device_config[MAX_CONFIG_SIZE]; /* device specific */ +} joystick_module_info; + +/* Note that joystick_module is something used by the game port driver */ +/* to talk to digital joysticks; if you're writing a sound card driver */ +/* and want to add support for a /dev/joystick device, use the generic_gameport */ +/* module. */ + +typedef struct _joystick_module { + module_info minfo; + /** "configure" might change the "info" if it auto-detects a device */ + int (*configure)(int port, joystick_module_info * info, size_t size, void ** out_cookie); + /** "read" actual data from device into "data" */ + int (*read)(void * cookie, int port, extended_joystick * data, size_t size); + /** "crumble" the cookie (deallocate) when done */ + int (*crumble)(void * cookie, int port); + /** "force" tells the joystick to exert force on the same axes as input for the specified duration */ + int (*force)(void * cookie, int port, bigtime_t duration, extended_joystick * force, size_t size); + int _reserved_; +} joystick_module; + +/** Doing force feedback means writing an extended_joystick to the device with force values. + The "timestamp" should be the duration of the feedback. Successive writes will be queued + by the device module. */ +enum { /* Joystick driver ioctl() opcodes */ + B_JOYSTICK_GET_SPEED_COMPENSATION = B_JOYSTICK_DRIVER_BASE, + /* arg -> ptr to int32 */ + B_JOYSTICK_SET_SPEED_COMPENSATION, /* arg -> ptr to int32 */ + B_JOYSTICK_GET_MAX_LATENCY, /* arg -> ptr to long long */ + B_JOYSTICK_SET_MAX_LATENCY, /* arg -> ptr to long long */ + B_JOYSTICK_SET_DEVICE_MODULE, /* arg -> ptr to joystick_module; also enters enhanced mode */ + B_JOYSTICK_GET_DEVICE_MODULE, /* arg -> ptr to joystick_module */ + B_JOYSTICK_SET_RAW_MODE /* arg -> ptr to bool (true or false) */ +}; + +/* Speed compensation is not generally necessary, because the joystick */ +/* driver is measuring using real time, not just # cycles. "0" means the */ +/* default, center value. + typically returns higher values; - returns lower */ +/* A typical range might be from -10 to +10, but it varies by driver */ + +/* Lower latency will make for more overhead in reading the joystick */ +/* ideally, you set this value to just short of how long it takes you */ +/* to calculate and render a frame. 30 fps -> latency 33000 */ + + +typedef struct _generic_gameport_module { + module_info minfo; + status_t (*create_device)(int port, void ** out_storage); + status_t (*delete_device)(void * storage); + status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie); + status_t (*close_hook)(void * cookie); + status_t (*free_hook)(void * cookie); + status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len); + status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len); + status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len); + int _reserved_; +} generic_gameport_module; + + +#endif Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/Jamfile 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/Jamfile 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,12 @@ +SubDir HAIKU_TOP src add-ons kernel drivers joystick usb_joy ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +SubDirSysHdrs $(HAIKU_TOP) src add-ons kernel bus_managers usb ; + +KernelAddon usb_joy : + devlist.c + devmgmt.c + driver.c + hidparse.c +; Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devlist.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devlist.c 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devlist.c 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,110 @@ +/* + USB joystick driver for BeOS R5 + Copyright 2000 (C) ITO, Takayuki + All rights reserved +*/ + +#include "driver.h" + +#define DPRINTF_INFO(x) dprintf x +#define DPRINTF_ERR(x) dprintf x + +sem_id my_device_list_lock = -1; +bool my_device_list_changed = true; /* added or removed */ + +static my_device_info *my_device_list = NULL; +static int my_device_count = 0; + +void add_device_info (my_device_info *my_dev) +{ + assert (my_dev != NULL); + acquire_sem (my_device_list_lock); + my_dev->next = my_device_list; + my_device_list = my_dev; + my_device_count++; + my_device_list_changed = true; + release_sem (my_device_list_lock); +} + +void remove_device_info (my_device_info *my_dev) +{ + assert (my_dev != NULL); + acquire_sem (my_device_list_lock); + if (my_device_list == my_dev) + my_device_list = my_dev->next; + else + { + my_device_info *d; + for (d = my_device_list; d != NULL; d = d->next) + { + if (d->next == my_dev) + { + d->next = my_dev->next; + --my_device_count; + my_device_list_changed = true; + break; + } + } + assert (d != NULL); + } + release_sem (my_device_list_lock); +} + +my_device_info *search_device_info (int number) +{ + my_device_info *my_dev; + + acquire_sem (my_device_list_lock); + for (my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next) + { + if (my_dev->number == number) + break; + } + release_sem (my_device_list_lock); + return my_dev; +} + +/* + device names +*/ + +/* dynamically generated */ +char **my_device_names = NULL; + +void alloc_device_names (void) +{ + assert (my_device_names == NULL); + my_device_names = malloc (sizeof (char *) * (my_device_count + 1)); +} + +void free_device_names (void) +{ + if (my_device_names != NULL) + { + int i; + for (i = 0; my_device_names [i] != NULL; i++) + free (my_device_names [i]); + free (my_device_names); + my_device_names = NULL; + } +} + +void rebuild_device_names (void) +{ + int i; + my_device_info *my_dev; + + assert (my_device_names != NULL); + acquire_sem (my_device_list_lock); + for (i = 0, my_dev = my_device_list; my_dev != NULL; my_dev = my_dev->next) + { + char *p = malloc (strlen (my_base_name) + 4); + assert (p != NULL); + sprintf (p, "%s%d", my_base_name, my_dev->number); + DPRINTF_INFO ((MY_ID "publishing %s\n", p)); + my_device_names [i++] = p; + } + my_device_names [i] = NULL; + release_sem (my_device_list_lock); +} + Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/devmgmt.c 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,82 @@ +/* + USB joystick driver for BeOS R5 + Copyright 2000 (C) ITO, Takayuki + All rights reserved +*/ + +#include "driver.h" + +#define DPRINTF_INFO(x) dprintf x +#define DPRINTF_ERR(x) dprintf x + +static int device_number = 0; + +my_device_info *create_device ( + const usb_device *dev, + const usb_interface_info *ii) +{ + my_device_info *my_dev = NULL; + int number; + area_id area; + sem_id sem; + char area_name [32]; + + assert (usb != NULL && dev != NULL); + + number = device_number++; + + my_dev = malloc (sizeof (my_device_info)); + if (my_dev == NULL) + return NULL; + + my_dev->sem_cb = sem = create_sem (0, DRIVER_NAME "_cb"); + if (sem < 0) + { + DPRINTF_ERR ((MY_ID "create_sem() failed %d\n", (int) sem)); + free (my_dev); + return NULL; + } + + my_dev->sem_lock = sem = create_sem (1, DRIVER_NAME "_lock"); + if (sem < 0) + { + DPRINTF_ERR ((MY_ID "create_sem() failed %d\n", (int) sem)); + delete_sem (my_dev->sem_cb); + free (my_dev); + return NULL; + } + + sprintf (area_name, DRIVER_NAME "_buffer%d", number); + my_dev->buffer_area = area = create_area (area_name, + (void **) &my_dev->buffer, B_ANY_KERNEL_ADDRESS, + B_PAGE_SIZE, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); + if (area < 0) + { + DPRINTF_ERR ((MY_ID "create_area() failed %d\n", (int) area)); + delete_sem (my_dev->sem_cb); + delete_sem (my_dev->sem_lock); + free (my_dev); + return NULL; + } + + my_dev->buffer_valid = false; + my_dev->dev = dev; + my_dev->number = number; + my_dev->open = 0; + my_dev->open_fds = NULL; + my_dev->active = true; + my_dev->insns = NULL; + my_dev->num_insns = 0; + my_dev->flags = 0; + + return my_dev; +} + +void remove_device (my_device_info *my_dev) +{ + assert (my_dev != NULL); + delete_area (my_dev->buffer_area); + delete_sem (my_dev->sem_cb); + delete_sem (my_dev->sem_lock); + free (my_dev); +} Added: haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/driver.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/driver.c 2008-07-12 02:36:26 UTC (rev 26389) +++ haiku/trunk/src/add-ons/kernel/drivers/joystick/usb_joy/driver.c 2008-07-12 10:31:24 UTC (rev 26390) @@ -0,0 +1,949 @@ +/* + USB Joystick driver for BeOS R5 + Copyright 2000 (C) ITO, Takayuki + All rights reserved +*/ + +#include +#include +#include +#include +#include "driver.h" + +#define AXIS_VALUE_MIN (-32768) +#define AXIS_VALUE_MAX 32767 + +#define USB_VID_MICROSOFT 0x045e + +#define DPRINTF_INFO(x) dprintf x +#define DPRINTF_ERR(x) dprintf x + +/* gameport driver cookie (per open) */ + +typedef struct driver_cookie +{ + struct driver_cookie *next; + + my_device_info *my_dev; + bool enhanced; + + /* below are valid under enhanced mode */ + joystick_module_info joy_mod_info; +} driver_cookie; + +/* NB global variables are valid only while driver is loaded */ + +_EXPORT int32 api_version = B_CUR_DRIVER_API_VERSION; + +const char *my_driver_name = "usb_joy"; +const char *my_base_name = "joystick/usb/"; + +usb_module_info *usb; + +/* + driver settings +*/ + +static product_info *prod_info = NULL; +static int num_prod_info = 0; + +#define atoi2(s) (int)strtol((s),NULL,0) + +static void load_settings_file (void) +{ + void *handle; + int entry_idx, param_idx, i; + static product_info null_prod_info; + const driver_settings *settings; + + /* make default mapping */ + null_prod_info.vendor_id = null_prod_info.product_id = 0; + for (i = 0; i < MAX_AXES; i++) + null_prod_info.axis_tbl [i] = i; + for (i = 0; i < MAX_HATS; i++) + null_prod_info.hat_tbl [i] = i; + for (i = 0; i < MAX_BUTTONS; i++) + null_prod_info.button_tbl [i] = i; + + handle = load_driver_settings (my_driver_name); + if (handle == NULL) + { + DPRINTF_ERR ((MY_ID "settings file open error\n")); + prod_info = &null_prod_info; + num_prod_info = 0; + return; + } + + settings = get_driver_settings (handle); + /* FIXME: num_prod_info may not be equal to parameter_count */ + num_prod_info = settings->parameter_count; + if (num_prod_info == 0) + { + prod_info = &null_prod_info; + return; + } + prod_info = malloc (sizeof (product_info) * (num_prod_info + 1)); + if (prod_info == NULL) + { + DPRINTF_ERR ((MY_ID "no memory\n")); + prod_info = &null_prod_info; + num_prod_info = 0; + return; + } + + prod_info [0] = null_prod_info; + for (entry_idx = 0; entry_idx < num_prod_info; entry_idx++) + { + product_info *prod; + const driver_parameter *entry; + + entry = &settings->parameters [entry_idx]; + if (strcmp (entry->name, "version") == 0) + { + /* XXX */ + } + else if (strcmp (entry->name, "product") == 0) + { + prod = &prod_info [entry_idx + 1]; + *prod = null_prod_info; + assert (entry->value_count == 2); + prod->vendor_id = atoi2 (entry->values [0]); + prod->product_id = atoi2 (entry->values [1]); + + for (param_idx = 0; param_idx < entry->parameter_count; param_idx++) + { + const driver_parameter *param; + + param = &entry->parameters [param_idx]; + if (strcmp (param->name, "button") == 0) + { + int src, dst; + assert (param->value_count >= 2); + src = atoi2 (param->values [0]) - 1; + dst = atoi2 (param->values [1]) - 1; + if (src < MAX_BUTTONS && dst < MAX_BUTTONS) + prod->button_tbl [src] = dst; + } + else if (strcmp (param->name, "axis") == 0) + { + int src, dst; + assert (param->value_count >= 2); + src = atoi2 (param->values [0]) - 1; + dst = atoi2 (param->values [1]) - 1; + if (src < MAX_AXES && dst < MAX_AXES) + prod->axis_tbl [src] = dst; + } + else if (strcmp (param->name, "hat") == 0) + { + int src, dst; + assert (param->value_count >= 2); + src = atoi2 (param->values [0]) - 1; + dst = atoi2 (param->values [1]) - 1; + if (src < MAX_HATS && dst < MAX_HATS) + prod->hat_tbl [src] = dst; + } + } + } + } + unload_driver_settings (handle); +} + +/* + callback: got a report, issue next request +*/ + +static void usb_callback ( + void *cookie, + uint32 status, + void *data, + uint32 actual_len) +{ + status_t st; + my_device_info *my_dev = cookie; + + assert (cookie != NULL); + + acquire_sem (my_dev->sem_lock); + my_dev->actual_length = actual_len; + my_dev->bus_status = status; /* B_USB_STATUS_* */ + if (status != B_OK) + { + /* request failed */ + release_sem (my_dev->sem_lock); + DPRINTF_ERR ((MY_ID "bus status %d\n", (int)status)); + //if (status == B_USB_STATUS_IRP_CANCELLED_BY_REQUEST) + //{ + /* cancelled: device is unplugged */ + return; + //} +#if 1 + //st = usb->clear_feature (my_dev->ept->handle, USB_FEATURE_ENDPOINT_HALT); + //if (st != B_OK) + // DPRINTF_ERR ((MY_ID "clear_feature() error %d\n", (int)st)); +#endif + } + else + { + /* got a report */ +#if 0 + int i; + char linbuf [256]; + uint8 *buffer = my_dev->buffer; + + for (i = 0; i < my_dev->total_report_size; i++) + sprintf (&linbuf[i*3], "%02X ", buffer [i]); + DPRINTF_INFO ((MY_ID "input report: %s\n", linbuf)); +#endif + my_dev->buffer_valid = true; + my_dev->timestamp = system_time (); + release_sem (my_dev->sem_lock); + } + + /* issue next request */ + + st = usb->queue_interrupt (my_dev->ept->handle, my_dev->buffer, + my_dev->total_report_size, usb_callback, my_dev); + if (st != B_OK) + { + /* XXX probably endpoint stall */ + DPRINTF_ERR ((MY_ID "queue_interrupt() error %d\n", (int)st)); + } +} + +/* + USB specific device hooks +*/ + +static status_t my_device_added ( + const usb_device *dev, + void **cookie) +{ + my_device_info *my_dev; + const usb_device_descriptor *dev_desc; + const usb_configuration_info *conf; + const usb_interface_info *intf; + status_t st; + usb_hid_descriptor *hid_desc; + uint8 *rep_desc = NULL; + size_t desc_len, actual; + decomp_item *items; + size_t num_items; + int i, ifno, fd, report_id; + + assert (dev != NULL && cookie != NULL); + DPRINTF_INFO ((MY_ID "device_added()\n")); + + dev_desc = usb->get_device_descriptor (dev); + DPRINTF_INFO ((MY_ID "vendor ID 0x%04X, product ID 0x%04X\n", + dev_desc->vendor_id, dev_desc->product_id)); + + /* check interface class */ + + if ((conf = usb->get_nth_configuration + (dev, DEFAULT_CONFIGURATION)) == NULL) + { + DPRINTF_ERR ((MY_ID "cannot get default configuration\n")); + return B_ERROR; + } + + for (ifno = 0; ifno < conf->interface_count; ifno++) + { + /* This is C; I can use "class" :-> */ + int class, subclass, protocol; + + intf = conf->interface [ifno].active; + class = intf->descr->interface_class; + subclass = intf->descr->interface_subclass; + protocol = intf->descr->interface_protocol; + DPRINTF_INFO ((MY_ID "interface %d: class %d, subclass %d, protocol %d\n", + ifno, class, subclass, protocol)); + if (class == USB_CLASS_HID && subclass == 0) + break; + } + + if (ifno >= conf->interface_count) + { + DPRINTF_INFO ((MY_ID "Non-boot HID interface not found\n")); + return B_ERROR; + } + + /* read HID descriptor */ + + desc_len = sizeof (usb_hid_descriptor); + hid_desc = malloc (desc_len); + st = usb->send_request (dev, + USB_REQTYPE_INTERFACE_IN | USB_REQTYPE_STANDARD, + USB_REQUEST_GET_DESCRIPTOR, + USB_DESCRIPTOR_HID << 8, ifno, desc_len, + hid_desc, &desc_len); + DPRINTF_INFO ((MY_ID "get_hid_desc: st=%d, len=%d\n", + (int) st, (int)desc_len)); [... truncated: 1649 lines follow ...] From modeenf at mail.berlios.de Sat Jul 12 12:56:02 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Sat, 12 Jul 2008 12:56:02 +0200 Subject: [Haiku-commits] r26391 - haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki Message-ID: <200807121056.m6CAu287019126@sheep.berlios.de> Author: modeenf Date: 2008-07-12 12:55:44 +0200 (Sat, 12 Jul 2008) New Revision: 26391 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26391&view=rev Added: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joy.c haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joystick_driver.h Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h Log: unsuccessfully effort to move emuxkigamport to the emuxki audio driver where it belongs. The sound got distorted when the joystick was used. Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile 2008-07-12 10:31:24 UTC (rev 26390) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/Jamfile 2008-07-12 10:55:44 UTC (rev 26391) @@ -12,6 +12,7 @@ midi.c multi.c util.c +# joy.c ; SEARCH on emuxki.settings = $(SUBDIR) ; Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-12 10:31:24 UTC (rev 26390) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.c 2008-07-12 10:55:44 UTC (rev 26391) @@ -3,6 +3,10 @@ * * Copyright (c) 2002, Jerome Duval (jerome.duval at free.fr) * + * Authors: + * Alexander Coers Alexander.Coers at gmx.de + * Fredrik Mod?en fredrik at modeen.se + * */ /* This code is derived from the NetBSD driver for Creative Labs SBLive! series * @@ -69,8 +73,9 @@ pci_module_info *pci; generic_mpu401_module * mpu401; +//static char gameport_name[] = "generic/gameport/v2"; +//generic_gameport_module * gameport; - int32 num_cards; emuxki_dev cards[NUM_CARDS]; int32 num_names; @@ -88,6 +93,7 @@ extern device_hooks multi_hooks; extern device_hooks midi_hooks; +//extern device_hooks joy_hooks; /* Hardware Dump */ @@ -2007,8 +2013,9 @@ status_t init_hardware(void) { - int ix=0; + int ix = 0; pci_info info; +// uint32 buffer; status_t err = ENODEV; LOG_CREATE(); @@ -2027,6 +2034,16 @@ #endif )) { err = B_OK; + +/* + Joystick suport + if (!(info.u.h0.subsystem_id == 0x20 || + info.u.h0.subsystem_id == 0xc400 || + (info.u.h0.subsystem_id == 0x21 && info.revision < 6))) { + buffer = (*pci->read_io_32)(info.u.h0.base_registers[0] + HCFG); + buffer |= HCFG_JOYENABLE; + (*pci->write_io_32)(info.u.h0.base_registers[0] + HCFG, buffer); + }*/ } ix++; } @@ -2040,11 +2057,13 @@ make_device_names( emuxki_dev * card) { - #if MIDI sprintf(card->midi.name, "midi/emuxki/%ld", card-cards+1); names[num_names++] = card->midi.name; #endif + +// sprintf(card->joy.name1, "joystick/"DRIVER_NAME "/%x", card-cards+1); +// names[num_names++] = card->joy.name1; sprintf(card->name, "audio/hmulti/emuxki/%ld", card-cards+1); names[num_names++] = card->name; @@ -2058,6 +2077,7 @@ { status_t err = B_OK; unsigned char cmd; + int32 base; PRINT(("setup_emuxki(%p)\n", card)); @@ -2092,11 +2112,22 @@ //SBLIVE : EMU_MUDATA, workaround 0, AUDIGY, AUDIGY2: 0, workaround 0x11020004 if ((err = (*mpu401->create_device)((card->config.nabmbar + !IS_AUDIGY(&card->config) ? EMU_MUDATA : 0), &card->midi.driver, !IS_AUDIGY(&card->config) ? 0 : 0x11020004, midi_interrupt_op, &card->midi)) < B_OK) - return (err); + return (err); card->midi.card = card; #endif - + + // begin Joystick part +/* base = card->info.u.h0.base_registers[0]; + (*pci->write_pci_config) (card->info.bus,card->info.device, + card->info.function, 0x10, 2, base); + + if ((*gameport->create_device)(base, &card->joy.driver) < B_OK) { + dprintf("Audigy joystick - Error creating device\n"); + (*gameport->delete_device)(card->joy.driver); + }*/ + // end Joystick part + /* reset the codec */ PRINT(("codec reset\n")); emuxki_codec_write(&card->config, 0x00, 0x0000); @@ -2816,7 +2847,13 @@ if (get_module(B_PCI_MODULE_NAME, (module_info **) &pci)) return ENOSYS; +// if (get_module (gameport_name, (module_info **)&gameport)) { +// put_module (B_PCI_MODULE_NAME); +// return ENOSYS; +// } + if (get_module(B_MPU_401_MODULE_NAME, (module_info **) &mpu401)) { + //put_module(gameport_name); put_module(B_PCI_MODULE_NAME); return ENOSYS; } @@ -2846,6 +2883,7 @@ } if (!num_cards) { put_module(B_MPU_401_MODULE_NAME); +// put_module(gameport_name); put_module(B_PCI_MODULE_NAME); PRINT(("emuxki: no suitable cards found\n")); return ENODEV; @@ -2919,6 +2957,8 @@ PRINT(("freeing silentpage_area\n")); if (card->silentpage_area > B_OK) delete_area(card->silentpage_area); + +// (*gameport->delete_device)(card->joy.driver); } @@ -2934,6 +2974,7 @@ } memset(&cards, 0, sizeof(cards)); put_module(B_MPU_401_MODULE_NAME); +// put_module(gameport_name); put_module(B_PCI_MODULE_NAME); num_cards = 0; } @@ -2965,6 +3006,10 @@ return &midi_hooks; } #endif +// if (!strcmp(cards[ix].joy.name1, name)) { +// return &joy_hooks; +// } + if (!strcmp(cards[ix].name, name)) { return &multi_hooks; } Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h 2008-07-12 10:31:24 UTC (rev 26390) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/emuxki.h 2008-07-12 10:55:44 UTC (rev 26391) @@ -3,6 +3,10 @@ * * Copyright (c) 2002, Jerome Duval (jerome.duval at free.fr) * + * Authors: + * Alexander Coers Alexander.Coers at gmx.de + * Fredrik Mod?en fredrik at modeen.se + * * Copyright (c) 2001 The NetBSD Foundation, Inc. * All rights reserved. * @@ -48,6 +52,7 @@ #include "queue.h" #include "hmulti_audio.h" #include "multi.h" +#include "joystick_driver.h" #define CREATIVELABS_VENDOR_ID 0x1102 /* Creative Labs */ @@ -87,6 +92,22 @@ extern emuxki_settings current_settings; /* + * Gameport stuff + */ + +#define HCFG 0x14 /* Hardware Configuration Register of SB-Live */ +#define HCFG_JOYENABLE 0x00000200 /* Mask for enabling Joystick */ + +extern generic_gameport_module * gameport; + +typedef struct _joy_dev +{ + void * driver; + char name1[64]; +} joy_dev; +/* End Gameport stuff*/ + +/* * Emu10k1 midi */ @@ -321,6 +342,7 @@ EMU_AUDIO_MODE = 1 << 1 } emuxki_parameter_type; + /* * Devices */ @@ -357,6 +379,7 @@ sem_id buffer_ready_sem; + joy_dev joy; midi_dev midi; /* mixer controls */ @@ -364,7 +387,7 @@ uint32 gpr_count; /* multi_audio */ - multi_dev multi; + multi_dev multi; } emuxki_dev; extern int32 num_cards; Added: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joy.c =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joy.c 2008-07-12 10:31:24 UTC (rev 26390) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joy.c 2008-07-12 10:55:44 UTC (rev 26391) @@ -0,0 +1,95 @@ +/* + * Copyright 2008 Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander Coers Alexander.Coers at gmx.de + * Fredrik Mod?en fredrik at modeen.se + */ + +#include "emuxki.h" +#include "debug.h" + +#if !defined(_KERNEL_EXPORT_H) +#include +#endif /* _KERNEL_EXPORT_H */ + +static status_t joy_open(const char *name, uint32 flags, void **cookie); +static status_t joy_close(void *cookie); +static status_t joy_free(void *cookie); +static status_t joy_control(void *cookie, uint32 op, void *data, size_t len); +static status_t joy_read(void *cookie, off_t pos, void *data, size_t *len); +static status_t joy_write(void *cookie, off_t pos, const void *data, size_t *len); + +#define MIN_COMP -7 +#define MAX_COMP 8 + +device_hooks joy_hooks = { + &joy_open, + &joy_close, + &joy_free, + &joy_control, + &joy_read, + &joy_write, + NULL, /* select */ + NULL, /* deselect */ + NULL, /* readv */ + NULL /* writev */ +}; + + +static status_t +joy_open(const char * name, uint32 flags, void ** cookie) +{ + int ix; + int offset = -1; + + LOG(("GamePort: joy_open()\n")); + + *cookie = NULL; + for (ix = 0; ix < num_cards; ix++) { + if (!strcmp(name, cards[ix].joy.name1)) { + offset = 0; + break; + } + } + if (offset < 0) { + return ENODEV; + } + return (*gameport->open_hook)(cards[ix].joy.driver, flags, cookie); +} + + +static status_t +joy_close(void * cookie) +{ + return (*gameport->close_hook)(cookie); +} + + +static status_t +joy_free(void * cookie) +{ + return (*gameport->free_hook)(cookie); +} + + +static status_t +joy_control(void * cookie, uint32 iop, void * data, size_t len) +{ + return (*gameport->control_hook)(cookie, iop, data, len); +} + + +static status_t +joy_read(void * cookie, off_t pos, void * data, size_t * nread) +{ + return (*gameport->read_hook)(cookie, pos, data, nread); +} + + +static status_t +joy_write(void * cookie, off_t pos, const void * data, size_t * nwritten) +{ + return (*gameport->write_hook)(cookie, pos, data, nwritten); +} Added: haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joystick_driver.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joystick_driver.h 2008-07-12 10:31:24 UTC (rev 26390) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/emuxki/joystick_driver.h 2008-07-12 10:55:44 UTC (rev 26391) @@ -0,0 +1,113 @@ +/* + Copyright 1999, Be Incorporated. All Rights Reserved. + This file may be used under the terms of the Be Sample Code License. +*/ + +#ifndef _JOYSTICK_DRIVER_H +#define _JOYSTICK_DRIVER_H + +#include +#include +#include + +typedef struct _joystick { + bigtime_t timestamp; + uint32 horizontal; + uint32 vertical; + bool button1; + bool button2; +} joystick; + +/* maximum number of axes on one controller (pads count as 2 axes each) */ +#define MAX_AXES 12 +/* maximum number of hats on one controller -- PADS SHOULD BE RETURNED AS AXES! */ +#define MAX_HATS 8 +/* maximum number of buttons on one controller */ +#define MAX_BUTTONS 32 +/* maximum number of controllers on one port */ +#define MAX_STICKS 4 + +typedef struct _extended_joystick { + bigtime_t timestamp; /* system_time when it was read */ + uint32 buttons; /* lsb to msb, 1 == on */ + int16 axes[MAX_AXES]; /* -32768 to 32767, X, Y, Z, U, V, W */ + uint8 hats[MAX_HATS]; /* 0 through 8 (1 == N, 3 == E, 5 == S, 7 == W) */ +} extended_joystick; + +#define MAX_CONFIG_SIZE 100 + +enum { /* flags for joystick module info */ + js_flag_force_feedback = 0x1, + js_flag_force_feedback_directional = 0x2 +}; + +typedef struct _joystick_module_info { + char module_name[64]; + char device_name[64]; + int16 num_axes; + int16 num_buttons; + int16 num_hats; + uint16 _reserved[7]; + uint32 flags; + uint16 num_sticks; + int16 config_size; + char device_config[MAX_CONFIG_SIZE]; /* device specific */ +} joystick_module_info; + +/* Note that joystick_module is something used by the game port driver */ +/* to talk to digital joysticks; if you're writing a sound card driver */ +/* and want to add support for a /dev/joystick device, use the generic_gameport */ +/* module. */ + +typedef struct _joystick_module { + module_info minfo; + /** "configure" might change the "info" if it auto-detects a device */ + int (*configure)(int port, joystick_module_info * info, size_t size, void ** out_cookie); + /** "read" actual data from device into "data" */ + int (*read)(void * cookie, int port, extended_joystick * data, size_t size); + /** "crumble" the cookie (deallocate) when done */ + int (*crumble)(void * cookie, int port); + /** "force" tells the joystick to exert force on the same axes as input for the specified duration */ + int (*force)(void * cookie, int port, bigtime_t duration, extended_joystick * force, size_t size); + int _reserved_; +} joystick_module; + +/** Doing force feedback means writing an extended_joystick to the device with force values. + The "timestamp" should be the duration of the feedback. Successive writes will be queued + by the device module. */ +enum { /* Joystick driver ioctl() opcodes */ + B_JOYSTICK_GET_SPEED_COMPENSATION = B_JOYSTICK_DRIVER_BASE, + /* arg -> ptr to int32 */ + B_JOYSTICK_SET_SPEED_COMPENSATION, /* arg -> ptr to int32 */ + B_JOYSTICK_GET_MAX_LATENCY, /* arg -> ptr to long long */ + B_JOYSTICK_SET_MAX_LATENCY, /* arg -> ptr to long long */ + B_JOYSTICK_SET_DEVICE_MODULE, /* arg -> ptr to joystick_module; also enters enhanced mode */ + B_JOYSTICK_GET_DEVICE_MODULE, /* arg -> ptr to joystick_module */ + B_JOYSTICK_SET_RAW_MODE /* arg -> ptr to bool (true or false) */ +}; + +/* Speed compensation is not generally necessary, because the joystick */ +/* driver is measuring using real time, not just # cycles. "0" means the */ +/* default, center value. + typically returns higher values; - returns lower */ +/* A typical range might be from -10 to +10, but it varies by driver */ + +/* Lower latency will make for more overhead in reading the joystick */ +/* ideally, you set this value to just short of how long it takes you */ +/* to calculate and render a frame. 30 fps -> latency 33000 */ + + +typedef struct _generic_gameport_module { + module_info minfo; + status_t (*create_device)(int port, void ** out_storage); + status_t (*delete_device)(void * storage); + status_t (*open_hook)(void * storage, uint32 flags, void ** out_cookie); + status_t (*close_hook)(void * cookie); + status_t (*free_hook)(void * cookie); + status_t (*control_hook)(void * cookie, uint32 op, void * data, size_t len); + status_t (*read_hook)(void * cookie, off_t pos, void * data, size_t * len); + status_t (*write_hook)(void * cookie, off_t pos, const void * data, size_t * len); + int _reserved_; +} generic_gameport_module; + + +#endif From modeenf at mail.berlios.de Sat Jul 12 13:01:41 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Sat, 12 Jul 2008 13:01:41 +0200 Subject: [Haiku-commits] r26392 - haiku/trunk/src/preferences/joysticks Message-ID: <200807121101.m6CB1ft7025675@sheep.berlios.de> Author: modeenf Date: 2008-07-12 13:01:38 +0200 (Sat, 12 Jul 2008) New Revision: 26392 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26392&view=rev Modified: haiku/trunk/src/preferences/joysticks/Jamfile Log: cleanup Modified: haiku/trunk/src/preferences/joysticks/Jamfile =================================================================== --- haiku/trunk/src/preferences/joysticks/Jamfile 2008-07-12 10:55:44 UTC (rev 26391) +++ haiku/trunk/src/preferences/joysticks/Jamfile 2008-07-12 11:01:38 UTC (rev 26392) @@ -1,7 +1,6 @@ SubDir HAIKU_TOP src preferences joysticks ; SetSubDirSupportedPlatformsBeOSCompatible ; -AddSubDirSupportedPlatforms libbe_test ; Preference Joysticks : CalibWin.cpp From mmlr at mlotz.ch Sat Jul 12 13:08:29 2008 From: mmlr at mlotz.ch (Michael Lotz) Date: Sat, 12 Jul 2008 13:08:29 +0200 Subject: [Haiku-commits] =?windows-1252?q?r26390_-_in_haiku/trunk/src/add-?= =?windows-1252?q?ons/kernel/drivers=3A_=2E_joystick_joystick/emuxkigamepo?= =?windows-1252?q?rt_joystick/usb=5Fjoy?= In-Reply-To: <200807121031.m6CAVh6c018662@sheep.berlios.de> Message-ID: <2297495615-BeMail@primary> > Author: modeenf > Date: 2008-07-12 12:31:24 +0200 (Sat, 12 Jul 2008) > New Revision: 26390 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26390&view=rev > > Log: > Driver for USB Joystick SBLive and audigy. Work in progress. Right > now the USB driver don't work. Ehm, didn't we agree that this belongs to usb_hid and not in its own driver? It duplicates the HID parsing code and device management for absolutely no reason. Regards Michael From modeenf at mail.berlios.de Sat Jul 12 14:37:51 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Sat, 12 Jul 2008 14:37:51 +0200 Subject: [Haiku-commits] r26393 - in haiku/trunk/data/etc: . joysticks Message-ID: <200807121237.m6CCbpaa017272@sheep.berlios.de> Author: modeenf Date: 2008-07-12 14:37:45 +0200 (Sat, 12 Jul 2008) New Revision: 26393 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26393&view=rev Added: haiku/trunk/data/etc/joysticks/ haiku/trunk/data/etc/joysticks/Analog_2_Axes haiku/trunk/data/etc/joysticks/Analog_3_Axes haiku/trunk/data/etc/joysticks/Analog_4_Axes haiku/trunk/data/etc/joysticks/Analog_Dual_2_Axes haiku/trunk/data/etc/joysticks/Generic_USB_Joystick haiku/trunk/data/etc/joysticks/Gravis_GamePad_Pro haiku/trunk/data/etc/joysticks/Gravis_Xterminator haiku/trunk/data/etc/joysticks/Logitech_CyberMan_2 haiku/trunk/data/etc/joysticks/Logitech_Precision_GamePad haiku/trunk/data/etc/joysticks/Logitech_ThunderPad_Digital haiku/trunk/data/etc/joysticks/Logitech_WingMan_Extreme_Digital haiku/trunk/data/etc/joysticks/Logitech_WingMan_Interceptor haiku/trunk/data/etc/joysticks/Microsoft_SideWinder_GamePad haiku/trunk/data/etc/joysticks/Microsoft_SideWinder_PrecisionPro haiku/trunk/data/etc/joysticks/ThrustMaster_Inceptor_Millennium_3D_Digital haiku/trunk/data/etc/joysticks/ThrustMaster_Rage_3D_Digital Log: Beginning of joystick definition files Added: haiku/trunk/data/etc/joysticks/Analog_2_Axes =================================================================== Added: haiku/trunk/data/etc/joysticks/Analog_3_Axes =================================================================== Added: haiku/trunk/data/etc/joysticks/Analog_4_Axes =================================================================== Added: haiku/trunk/data/etc/joysticks/Analog_Dual_2_Axes =================================================================== Added: haiku/trunk/data/etc/joysticks/Generic_USB_Joystick =================================================================== --- haiku/trunk/data/etc/joysticks/Generic_USB_Joystick 2008-07-12 11:01:38 UTC (rev 26392) +++ haiku/trunk/data/etc/joysticks/Generic_USB_Joystick 2008-07-12 12:37:45 UTC (rev 26393) @@ -0,0 +1,63 @@ +# Description for generic USB joysticks, full spec + +module = "media/joy/dummy/v0" +gadget = "Generic USB Joystick" +num_axes = 12 +num_hats = 8 +num_buttons = 32 +num_sticks = 1 + +axis 0 = "Left-Right" +axis 1 = "Front-Back" +axis 2 = "Axis 3" +axis 3 = "Axis 4" +axis 4 = "Axis 5" +axis 5 = "Axis 6" +axis 6 = "Axis 7" +axis 7 = "Axis 8" +axis 8 = "Axis 9" +axis 9 = "Axis 10" +axis 10 = "Axis 11" +axis 11 = "Axis 12" + +hat 0 = "Hat 1" +hat 1 = "Hat 2" +hat 2 = "Hat 3" +hat 3 = "Hat 4" +hat 4 = "Hat 5" +hat 5 = "Hat 6" +hat 6 = "Hat 7" +hat 7 = "Hat 8" + +button 0 = "Button 1" +button 1 = "Button 2" +button 2 = "Button 3" +button 3 = "Button 4" +button 4 = "Button 5" +button 5 = "Button 6" +button 6 = "Button 7" +button 7 = "Button 8" +button 8 = "Button 9" +button 9 = "Button 10" +button 10 = "Button 11" +button 11 = "Button 12" +button 12 = "Button 13" +button 13 = "Button 14" +button 14 = "Button 15" +button 15 = "Button 16" +button 16 = "Button 17" +button 17 = "Button 18" +button 18 = "Button 19" +button 19 = "Button 20" +button 20 = "button 21" +button 21 = "button 22" +button 22 = "button 23" +button 23 = "button 24" +button 24 = "button 25" +button 25 = "button 26" +button 26 = "button 27" +button 27 = "button 28" +button 28 = "button 29" +button 29 = "Button 30" +button 30 = "button 31" +button 31 = "button 32" Added: haiku/trunk/data/etc/joysticks/Gravis_GamePad_Pro =================================================================== Added: haiku/trunk/data/etc/joysticks/Gravis_Xterminator =================================================================== Added: haiku/trunk/data/etc/joysticks/Logitech_CyberMan_2 =================================================================== Added: haiku/trunk/data/etc/joysticks/Logitech_Precision_GamePad =================================================================== Added: haiku/trunk/data/etc/joysticks/Logitech_ThunderPad_Digital =================================================================== Added: haiku/trunk/data/etc/joysticks/Logitech_WingMan_Extreme_Digital =================================================================== Added: haiku/trunk/data/etc/joysticks/Logitech_WingMan_Interceptor =================================================================== Added: haiku/trunk/data/etc/joysticks/Microsoft_SideWinder_GamePad =================================================================== Added: haiku/trunk/data/etc/joysticks/Microsoft_SideWinder_PrecisionPro =================================================================== Added: haiku/trunk/data/etc/joysticks/ThrustMaster_Inceptor_Millennium_3D_Digital =================================================================== Added: haiku/trunk/data/etc/joysticks/ThrustMaster_Rage_3D_Digital =================================================================== From stippi at mail.berlios.de Sat Jul 12 19:50:08 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 12 Jul 2008 19:50:08 +0200 Subject: [Haiku-commits] r26394 - haiku/trunk/src/apps/mediaplayer Message-ID: <200807121750.m6CHo8tx025077@sheep.berlios.de> Author: stippi Date: 2008-07-12 19:50:05 +0200 (Sat, 12 Jul 2008) New Revision: 26394 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26394&view=rev Modified: haiku/trunk/src/apps/mediaplayer/InfoWin.cpp Log: The info window is not zoomable. (Fixes #2436.) Modified: haiku/trunk/src/apps/mediaplayer/InfoWin.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/InfoWin.cpp 2008-07-12 12:37:45 UTC (rev 26393) +++ haiku/trunk/src/apps/mediaplayer/InfoWin.cpp 2008-07-12 17:50:05 UTC (rev 26394) @@ -79,7 +79,7 @@ InfoWin::InfoWin(BPoint leftTop, Controller* controller) : BWindow(BRect(leftTop.x, leftTop.y, leftTop.x + MIN_WIDTH - 1, leftTop.y + 300), NAME, B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE) + B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE) , fController(controller) , fControllerObserver(new ControllerObserver(this, OBSERVE_FILE_CHANGES | OBSERVE_TRACK_CHANGES | OBSERVE_STAT_CHANGES)) From stippi at mail.berlios.de Sat Jul 12 21:33:05 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Sat, 12 Jul 2008 21:33:05 +0200 Subject: [Haiku-commits] r26395 - haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa Message-ID: <200807121933.m6CJX5R1007096@sheep.berlios.de> Author: stippi Date: 2008-07-12 21:33:03 +0200 (Sat, 12 Jul 2008) New Revision: 26395 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26395&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/Jamfile haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp Log: * On some systems, switching the resolution in VESA mode during runtime did not work and gave a "General System Error". Jan Kloetzke provided a temporary work around, the area which the BIOS can access is enlarged, although according to specs, this should not be needed. * After switching modes in the VESA driver, turn on write combining for the frame buffer area. This gives a huge speed boost for all graphics drawing. Only people for which mode changes did not work were using the full speed since the VESA mode switching support was added. * Cleanup in the Jamfile, some header directories were included multiple times. Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/Jamfile =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/Jamfile 2008-07-12 17:50:05 UTC (rev 26394) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/Jamfile 2008-07-12 19:33:03 UTC (rev 26395) @@ -1,7 +1,8 @@ SubDir HAIKU_TOP src add-ons kernel drivers graphics vesa ; -UsePrivateHeaders kernel graphics [ FDirName graphics common ] ; -UsePrivateHeaders kernel graphics [ FDirName graphics vesa ] ; +UsePrivateHeaders [ FDirName graphics common ] ; +UsePrivateHeaders [ FDirName graphics vesa ] ; +UsePrivateKernelHeaders ; KernelAddon vesa : device.cpp Modified: haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp 2008-07-12 17:50:05 UTC (rev 26394) +++ haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa/vesa.cpp 2008-07-12 19:33:03 UTC (rev 26395) @@ -13,6 +13,7 @@ #include #include #include +#include #include "driver.h" #include "utility.h" @@ -174,7 +175,7 @@ // Prepare vm86 mode environment struct vm86_state vmState; - status_t status = vm86_prepare(&vmState, 0x2000); + status_t status = vm86_prepare(&vmState, 0x20000); if (status != B_OK) { dprintf(DEVICE_NAME": vesa_set_display_mode(): vm86_prepare failed\n"); return status; @@ -210,6 +211,9 @@ } delete_area(info.shared_info->frame_buffer_area); + // Turn on write combining for the area + vm_set_area_memory_type(newFBArea, modeInfo.physical_base, B_MTR_WC); + // Update shared frame buffer information info.shared_info->frame_buffer_area = newFBArea; info.shared_info->frame_buffer = (uint8 *)frameBuffer; From julun at mail.berlios.de Sat Jul 12 23:09:52 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sat, 12 Jul 2008 23:09:52 +0200 Subject: [Haiku-commits] r26396 - in haiku/trunk: headers/private/print/utils src/add-ons/print/drivers/pdf/source src/add-ons/print/drivers/preview src/add-ons/print/drivers/shared/libprint src/add-ons/print/drivers/shared/utils Message-ID: <200807122109.m6CL9qAu019820@sheep.berlios.de> Author: julun Date: 2008-07-12 23:09:49 +0200 (Sat, 12 Jul 2008) New Revision: 26396 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26396&view=rev Modified: haiku/trunk/headers/private/print/utils/MarginView.h haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp haiku/trunk/src/add-ons/print/drivers/preview/PageSetupWindow.cpp haiku/trunk/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp haiku/trunk/src/add-ons/print/drivers/shared/utils/MarginView.cpp Log: * reordered MarinView.h, MarginView.cpp * rename private functions to use underscore * rename some public functions to match the usual style * adjust pdf/ preview driver to use the renamed functions * we where leaking a single message in _ConstructGui, otherwise no functional change Modified: haiku/trunk/headers/private/print/utils/MarginView.h =================================================================== --- haiku/trunk/headers/private/print/utils/MarginView.h 2008-07-12 19:33:03 UTC (rev 26395) +++ haiku/trunk/headers/private/print/utils/MarginView.h 2008-07-12 21:09:49 UTC (rev 26396) @@ -4,9 +4,9 @@ Copyright (c) 2002 OpenBeOS. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin Michael Pfeiffer Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -28,40 +28,40 @@ THE SOFTWARE. Documentation: - + The MarginView is designed to be a self contained component that manages the display of a BBox control that shows a graphic of a page and its' margings. The component also includes text fields that are used to mofify the margin values and a popup to change the units used for the margins. There are two interfaces for the MarginView component: - + 1) Set methods: - page size - orientation - + Get methods to retrieve: - margins - page size - - The method interface is available for the parent Component to call on + + The method interface is available for the parent Component to call on the MarginView in response to the Window receiveing messages from other BControls that it contains, such as a Page Size popup. The - Get methods are used to extract the page size and margins so that + Get methods are used to extract the page size and margins so that the printer driver may put these values into a BMessage for printing. - + 2) 'Optional' Message interface: - Set Page Size - Flip Orientation - - The message interface is available for GUI Controls, BPopupMenu to send + + The message interface is available for GUI Controls, BPopupMenu to send messages to the MarginView if the parent Window is not used to handle - the messages. + the messages. General Use of MarginView component: - - 1) Simply construct a new MarginView object with the margins - you want as defaults and add this view to the parent view + + 1) Simply construct a new MarginView object with the margins + you want as defaults and add this view to the parent view of the dialog. MarginView *mv; @@ -69,17 +69,17 @@ parentView->AddChild(mv); * you can also set the margins in the constructor, and the units: - + mv = new MarginView(viewSizeRect, pageWidth, pageHeight marginRect, kUnitPointS); ! but remeber to have the marginRect values match the UNITS :-) - + 2) Set Page Size with methods: mv-SetPageSize( pageWidth, pageHeight ); mv->UpdateView(); - + 3) Set Page Size with BMessage: BMessage* msg = new BMessage(CHANGE_PAGE_SIZE); @@ -88,12 +88,12 @@ mv->PostMessage(msg); 4) Flip Page with methods: - + mv-SetPageSize( pageHeight, pageWidth ); mv->UpdateView(); - - 5) Flip Page with BMessage: - + + 5) Flip Page with BMessage: + BMessage* msg = new BMessage(FLIP_PAGE); mv->Looper()->PostMessage(msg); @@ -103,16 +103,16 @@ 6) Get Page Size BPoint pageSize = mv->GetPageSize(); - + 7) Get Margins BRect margins = mv->GetMargins(); - + 8) Get Units - + uint32 units = mv->GetUnits(); - where units is one of: + where units is one of: kUnitInch, 72 points/in kUnitCM, 28.346 points/cm kUnitPoint, 1 point/point @@ -124,6 +124,7 @@ #include #include +class BTextControl; class MarginManager; // Messages that the MarginManager accepts @@ -145,81 +146,77 @@ /** * Class MarginView */ -class MarginView : public BBox +class MarginView : public BBox { friend class MarginManager; -private: +public: + MarginView(BRect rect, int32 pageWidth = 0, + int32 pageHeight = 0, + BRect margins = BRect(1, 1, 1, 1), // 1 inch + MarginUnit unit = kUnitInch); - // GUI components - BTextControl *fTop, *fBottom, *fLeft, *fRight; + virtual ~MarginView(); - // rect that holds the margins for the page as a set of point offsets - BRect fMargins; + virtual void AttachedToWindow(); + virtual void Draw(BRect rect); + virtual void FrameResized(float width, float height); + virtual void MessageReceived(BMessage *msg); - // the maximum size of the page view calculated from the view size - float fMaxPageWidth; - float fMaxPageHeight; + // point.x = width, point.y = height + BPoint PageSize() const; + void SetPageSize(float pageWidth, float pageHeight); - // the actual size of the page in points - float fPageHeight; - float fPageWidth; + // margin + BRect Margin() const; - // the units used to calculate the page size - MarginUnit fMarginUnit; - float fUnitValue; + // units + MarginUnit Unit() const; - // the size of the drawing area we have to draw the view in pixels - float fViewHeight; - float fViewWidth; + // will cause a recalc and redraw + void UpdateView(uint32 msg); - // Calculate the view size for the margins - void CalculateViewSize(uint32 msg); +private: + // all the GUI construction code + void _ConstructGUI(); - // performed internally using the supplied popup - void SetMarginUnit(MarginUnit unit); + // utility method + void _AllowOnlyNumbers(BTextControl *textControl, + int32 maxNum); - // performed internally using text fields - void SetMargin(BRect margin); + // performed internally using text fields + void _SetMargin(BRect margin); - // utility method - void AllowOnlyNumbers(BTextControl *textControl, int maxNum); - -public: - MarginView(BRect rect, - int32 pageWidth = 0, - int32 pageHeight = 0, - BRect margins = BRect(1, 1, 1, 1), // default to 1 inch - MarginUnit unit = kUnitInch); + // performed internally using the supplied popup + void _SetMarginUnit(MarginUnit unit); - ~MarginView(); + // Calculate the view size for the margins + void _CalculateViewSize(uint32 msg); - /// all the GUI construction code - void ConstructGUI(); - - // page size - void SetPageSize(float pageWidth, float pageHeight); - // point.x = width, point.y = height - BPoint GetPageSize(void); +private: + BTextControl* fTop; + BTextControl* fBottom; + BTextControl* fLeft; + BTextControl* fRight; - // margin - BRect GetMargin(void); + // rect that holds the margins for the page as a set of point offsets + BRect fMargins; - // orientation - // None, this state should be saved elsewhere in the page setup code - // and not here. See the FLIP_PAGE message to perform this function. - - // units - MarginUnit GetMarginUnit(void); + // the maximum size of the page view calculated from the view size + float fMaxPageWidth; + float fMaxPageHeight; - // will cause a recalc and redraw - void UpdateView(uint32 msg); + // the actual size of the page in points + float fPageHeight; + float fPageWidth; - // BeOS Hook methods - virtual void AttachedToWindow(void); - void Draw(BRect rect); - void FrameResized(float width, float height); - void MessageReceived(BMessage *msg); + // the units used to calculate the page size + MarginUnit fMarginUnit; + float fUnitValue; + + // the size of the drawing area we have to draw the view in pixels + float fViewHeight; + float fViewWidth; }; #endif // _MARGIN_VIEW_H Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp 2008-07-12 19:33:03 UTC (rev 26395) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp 2008-07-12 21:09:49 UTC (rev 26396) @@ -4,11 +4,11 @@ Version: 12.19.2000 -Copyright (c) 2001 OpenBeOS. +Copyright (c) 2001 OpenBeOS. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin Michael Pfeiffer Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -33,7 +33,7 @@ #include #include -#include "pdflib.h" // for pageFormat constants +#include "pdflib.h" // for pageFormat constants #include "PrinterDriver.h" #include "PageSetupWindow.h" @@ -42,12 +42,12 @@ #include "AdvancedSettingsWindow.h" // static global variables -static struct +static struct { char *label; float width; float height; -} pageFormat[] = +} pageFormat[] = { {"Letter", letter_width, letter_height }, {"Legal", legal_width, legal_height }, @@ -65,11 +65,11 @@ }; -static struct +static struct { char *label; int32 orientation; -} orientation[] = +} orientation[] = { {"Portrait", PrinterDriver::PORTRAIT_ORIENTATION}, {"Landscape", PrinterDriver::LANDSCAPE_ORIENTATION}, @@ -82,7 +82,7 @@ /** * Constuctor * - * @param + * @param * @return */ PageSetupWindow::PageSetupWindow(BMessage *msg, const char *printerName) @@ -94,10 +94,10 @@ fExitSem = create_sem(0, "PageSetup"); fResult = B_ERROR; fAdvancedSettings = *msg; - + if ( printerName ) { BString title; - + title << printerName << " Page Setup"; SetTitle( title.String() ); @@ -122,23 +122,23 @@ // load orientation fSetupMsg->FindInt32("orientation", &orient); -// (new BAlert("", "orientation not in msg", "Shit"))->Go(); +// (new BAlert("", "orientation not in msg", "Shit"))->Go(); // load page rect fSetupMsg->FindRect("paper_rect", &r); width = r.Width(); height = r.Height(); page = r; - + // Load compression fSetupMsg->FindInt32("pdf_compression", &compression); - + // Load units fSetupMsg->FindInt32("units", &units); // Load printable rect fSetupMsg->FindRect("printable_rect", &margin); - + // Load pdf compatability fSetupMsg->FindString("pdf_compatibility", &setting_value); @@ -149,15 +149,15 @@ if (fSetupMsg->FindMessage("fonts", &fonts) == B_OK) { fFonts->SetTo(&fonts); } - + // add a *dialog* background r = Bounds(); - panel = new BBox(r, "top_panel", B_FOLLOW_ALL, + panel = new BBox(r, "top_panel", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); ////////////// Create the margin view ////////////////////// - + // re-calculate the margin from the printable rect in points margin.top -= page.top; margin.left -= page.left; @@ -167,7 +167,7 @@ fMarginView = new MarginView(BRect(20,20,200,160), (int32)width, (int32)height, margin, (MarginUnit)units); panel->AddChild(fMarginView); - + // add page format menu // Simon Changed to OFFSET popups x = r.left + kMargin * 2 + kOffset; y = r.top + kMargin * 2; @@ -176,7 +176,7 @@ m->SetRadioMode(true); // Simon changed width 200->140 - BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size", + BMenuField *mf = new BMenuField(BRect(x, y, x + 140, y + 20), "page_size", "Page Size:", m); fPageSizeMenu = mf; mf->ResizeToPreferred(); @@ -188,19 +188,19 @@ panel->AddChild(mf); item = NULL; - for (i = 0; pageFormat[i].label != NULL; i++) + for (i = 0; pageFormat[i].label != NULL; i++) { BMessage* msg = new BMessage('pgsz'); msg->AddFloat("width", pageFormat[i].width); msg->AddFloat("height", pageFormat[i].height); BMenuItem* mi = new BMenuItem(pageFormat[i].label, msg); m->AddItem(mi); - + if (width == pageFormat[i].width && height == pageFormat[i].height) { - item = mi; + item = mi; } if (height == pageFormat[i].width && width == pageFormat[i].height) { - item = mi; + item = mi; } } mf->Menu()->SetLabelFromMarked(true); @@ -212,28 +212,28 @@ // add orientation menu y += h + kMargin; - + m = new BPopUpMenu("orientation"); m->SetRadioMode(true); - + // Simon changed 200->140 mf = new BMenuField(BRect(x, y, x + 140, y + 20), "orientation", "Orientation:", m); - + // Simon added: SetDivider mf->SetDivider(be_plain_font->StringWidth("Orientation#")); - + fOrientationMenu = mf; mf->ResizeToPreferred(); panel->AddChild(mf); r.top += h; item = NULL; - for (int i = 0; orientation[i].label != NULL; i++) + for (int i = 0; orientation[i].label != NULL; i++) { - BMessage* msg = new BMessage('ornt'); + BMessage* msg = new BMessage('ornt'); msg->AddInt32("orientation", orientation[i].orientation); BMenuItem* mi = new BMenuItem(orientation[i].label, msg); m->AddItem(mi); - + if (orient == orientation[i].orientation) { item = mi; } @@ -249,7 +249,7 @@ // add PDF comptibility menu y += h + kMargin; - + m = new BPopUpMenu("pdf_compatibility"); m->SetRadioMode(true); mf = new BMenuField(BRect(x, y, x + 200, y + 20), "pdf_compatibility", "PDF Compatibility:", m); @@ -259,12 +259,12 @@ r.top += h; item = NULL; - for (int i = 0; pdf_compatibility[i] != NULL; i++) - { + for (int i = 0; pdf_compatibility[i] != NULL; i++) + { BMenuItem* mi = new BMenuItem(pdf_compatibility[i], NULL); m->AddItem(mi); - -//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go(); + +//(new BAlert("", setting_value.String(), pdf_compatibility[i]))->Go(); if (setting_value == pdf_compatibility[i]) { item = mi; } @@ -290,16 +290,16 @@ fPDFCompressionSlider = slider; panel->AddChild(slider); - + slider->SetLimitLabels("None", "Best"); slider->SetHashMarks(B_HASH_MARKS_BOTTOM); slider->ResizeToPreferred(); slider->GetPreferredSize(&w, &h); - + slider->SetValue(compression); - + // add a "OK" button, and make it default - button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), + button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->ResizeToPreferred(); button->GetPreferredSize(&w, &h); @@ -309,25 +309,25 @@ panel->AddChild(button); button->MakeDefault(true); - // add a "Cancel button - button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG), + // add a "Cancel button + button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(x - w - 8, y); panel->AddChild(button); - // add a "Fonts" button - button = new BButton(r, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG), + // add a "Fonts" button + button = new BButton(r, NULL, "Fonts" B_UTF8_ELLIPSIS, new BMessage(FONTS_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); button->MoveTo(r.left + 8, y); panel->AddChild(button); - // add a "Fonts" button + // add a "Fonts" button BButton* font = button; - button = new BButton(r, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG), + button = new BButton(r, NULL, "Advanced" B_UTF8_ELLIPSIS, new BMessage(ADVANCED_MSG), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->GetPreferredSize(&w, &h); button->ResizeToPreferred(); @@ -353,7 +353,7 @@ // -------------------------------------------------- -bool +bool PageSetupWindow::QuitRequested() { release_sem(fExitSem); @@ -362,8 +362,8 @@ // -------------------------------------------------- -void -PageSetupWindow::UpdateSetupMessage() +void +PageSetupWindow::UpdateSetupMessage() { BMenuItem *item; int32 orientation = 0; @@ -382,7 +382,7 @@ else fSetupMsg->AddString("pdf_compatibility", item->Label()); } - + if (fSetupMsg->HasInt32("pdf_compression")) { fSetupMsg->ReplaceInt32("pdf_compression", fPDFCompressionSlider->Value()); } else { @@ -396,14 +396,14 @@ msg->FindFloat("width", &w); msg->FindFloat("height", &h); BRect r; - if (orientation == 0) + if (orientation == 0) r.Set(0, 0, w, h); else r.Set(0, 0, h, w); fSetupMsg->ReplaceRect("paper_rect", r); - - // Save the printable_rect - BRect margin = fMarginView->GetMargin(); + + // Save the printable_rect + BRect margin = fMarginView->Margin(); if (orientation == 0) { margin.right = w - margin.right; margin.bottom = h - margin.bottom; @@ -414,12 +414,12 @@ fSetupMsg->ReplaceRect("printable_rect", margin); // save the units used - int32 units = fMarginView->GetMarginUnit(); + int32 units = fMarginView->Unit(); if (fSetupMsg->HasInt32("units")) { fSetupMsg->ReplaceInt32("units", units); } else { fSetupMsg->AddInt32("units", units); - } + } } BMessage fonts; @@ -436,8 +436,8 @@ float f; BString s; int32 i; - - + + if (fAdvancedSettings.FindString("pdflib_license_key", &s) == B_OK) { if (fSetupMsg->HasString("pdflib_license_key")) { fSetupMsg->ReplaceString("pdflib_license_key", s.String()); @@ -505,7 +505,7 @@ // -------------------------------------------------- -void +void PageSetupWindow::MessageReceived(BMessage *msg) { switch (msg->what){ @@ -514,7 +514,7 @@ fResult = B_OK; release_sem(fExitSem); break; - + case CANCEL_MSG: fResult = B_ERROR; release_sem(fExitSem); @@ -543,12 +543,12 @@ // Simon added case 'ornt': - { - BPoint p = fMarginView->GetPageSize(); + { + BPoint p = fMarginView->PageSize(); int32 orientation; msg->FindInt32("orientation", &orientation); if (orientation == PrinterDriver::LANDSCAPE_ORIENTATION - && p.y > p.x) { + && p.y > p.x) { fMarginView->SetPageSize(p.y, p.x); fMarginView->UpdateView(MARGIN_CHANGED); } @@ -563,20 +563,20 @@ case FONTS_MSG: (new FontsWindow(fFonts))->Show(); break; - + case ADVANCED_MSG: (new AdvancedSettingsWindow(&fAdvancedSettings))->Show(); break; - + default: inherited::MessageReceived(msg); break; } } - + // -------------------------------------------------- -status_t +status_t PageSetupWindow::Go() { MoveTo(300,300); Modified: haiku/trunk/src/add-ons/print/drivers/preview/PageSetupWindow.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/preview/PageSetupWindow.cpp 2008-07-12 19:33:03 UTC (rev 26395) +++ haiku/trunk/src/add-ons/print/drivers/preview/PageSetupWindow.cpp 2008-07-12 21:09:49 UTC (rev 26396) @@ -276,7 +276,7 @@ AddString(fSetupMsg, "preview:paper_size", item->Label()); // Save the printable_rect - BRect margin = fMarginView->GetMargin(); + BRect margin = fMarginView->Margin(); if (fCurrentOrientation == PrinterDriver::PORTRAIT_ORIENTATION) { margin.right = w - margin.right; margin.bottom = h - margin.bottom; @@ -287,7 +287,7 @@ SetRect(fSetupMsg, "preview:printable_rect", margin); SetRect(fSetupMsg, "printable_rect", ScaleRect(margin, scaleR)); - SetInt32(fSetupMsg, "units", fMarginView->GetMarginUnit()); + SetInt32(fSetupMsg, "units", fMarginView->Unit()); } } @@ -323,7 +323,7 @@ if (fCurrentOrientation != orientation) { fCurrentOrientation = orientation; - BPoint p = fMarginView->GetPageSize(); + BPoint p = fMarginView->PageSize(); fMarginView->SetPageSize(p.y, p.x); fMarginView->UpdateView(MARGIN_CHANGED); } Modified: haiku/trunk/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp 2008-07-12 19:33:03 UTC (rev 26395) +++ haiku/trunk/src/add-ons/print/drivers/shared/libprint/PageSetupDlg.cpp 2008-07-12 21:09:49 UTC (rev 26396) @@ -2,11 +2,11 @@ * PageSetupDlg.cpp * Copyright 1999-2000 Y.Takagi. All Rights Reserved. */ - + #include #include #include -#include +#include #include #include @@ -40,7 +40,7 @@ #if (!__MWERKS__ || defined(MSIPL_USING_NAMESPACE)) using namespace std; -#else +#else #define std #endif @@ -159,7 +159,7 @@ BMessage *msg = new BMessage(kMsgOrientationChanged); msg->AddInt32("orientation", orientation); BMenuItem *item = new BMenuItem(name, msg); - + fOrientation->AddItem(item); item->SetTarget(this); if (fJobData->getOrientation() == orientation) { @@ -169,7 +169,7 @@ } } -void +void PageSetupView::AttachedToWindow() { BMenuItem *item = NULL; @@ -189,8 +189,8 @@ margin.right = paper.right - margin.right; margin.bottom = paper.bottom - margin.bottom; - fMarginView = new MarginView(MARGIN_RECT, - paper.IntegerWidth(), + fMarginView = new MarginView(MARGIN_RECT, + paper.IntegerWidth(), paper.IntegerHeight(), margin, units); AddChild(fMarginView); @@ -224,10 +224,10 @@ /* orientaion */ fOrientation = new BPopUpMenu("orientation"); fOrientation->SetRadioMode(true); - + menuField = new BMenuField(ORIENTATION_RECT, "orientation", ORIENTATION_TEXT, fOrientation); menuField->SetDivider(width); - + count = fPrinterCap->countCap(PrinterCap::kOrientation); if (count == 0) { AddOrientationItem(PORTRAIT_TEXT, JobData::kPortrait); @@ -240,7 +240,7 @@ orientation_cap++; } } - + AddChild(menuField); /* resolution */ @@ -269,7 +269,7 @@ /* scale */ BString scale; scale << (int)fJobData->getScaling(); - fScaling = new BTextControl(SCALE_RECT, "scale", "Scale [%]:", + fScaling = new BTextControl(SCALE_RECT, "scale", "Scale [%]:", scale.String(), NULL, B_FOLLOW_RIGHT); int num; @@ -282,7 +282,7 @@ fScaling->TextView()->SetMaxBytes(3); fScaling->SetDivider(width); - AddChild(fScaling); + AddChild(fScaling); /* cancel */ @@ -296,7 +296,7 @@ button->MakeDefault(true); } -inline void +inline void swap(float *e1, float *e2) { float e = *e1; @@ -304,7 +304,7 @@ *e2 = e; } -JobData::Orientation +JobData::Orientation PageSetupView::GetOrientation() { BMenuItem *item = fOrientation->FindMarked(); @@ -330,12 +330,12 @@ } } -bool +bool PageSetupView::UpdateJobData() { fJobData->setOrientation(GetOrientation()); - PaperCap *paperCap = GetPaperCap(); + PaperCap *paperCap = GetPaperCap(); BRect paper_rect = paperCap->paper_rect; BRect physical_rect = paperCap->physical_rect; fJobData->setPaper(paperCap->paper); @@ -363,8 +363,8 @@ } // adjust printable rect by margin - fJobData->setMarginUnit(fMarginView->GetMarginUnit()); - BRect margin = fMarginView->GetMargin(); + fJobData->setMarginUnit(fMarginView->Unit()); + BRect margin = fMarginView->Margin(); BRect printable_rect; printable_rect.left = paper_rect.left + margin.left; printable_rect.top = paper_rect.top + margin.top; @@ -392,13 +392,13 @@ fJobData->setPrintableRect(printable_rect); fJobData->setScaledPrintableRect(ScaleRect(printable_rect, scalingR)); fJobData->setPhysicalRect(physical_rect); - fJobData->setScaledPhysicalRect(ScaleRect(physical_rect, scalingR)); + fJobData->setScaledPhysicalRect(ScaleRect(physical_rect, scalingR)); fJobData->save(); return true; } -void +void PageSetupView::MessageReceived(BMessage *msg) { switch (msg->what) { @@ -414,7 +414,7 @@ } fMarginView->SetPageSize(width, height); fMarginView->UpdateView(MARGIN_CHANGED); - + } break; } @@ -431,11 +431,11 @@ PageSetupView *view = new PageSetupView(Bounds(), job_data, printer_data, printer_cap); AddChild(view); - + SetResult(B_ERROR); } -void +void PageSetupDlg::MessageReceived(BMessage *msg) { switch (msg->what) { Modified: haiku/trunk/src/add-ons/print/drivers/shared/utils/MarginView.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/shared/utils/MarginView.cpp 2008-07-12 19:33:03 UTC (rev 26395) +++ haiku/trunk/src/add-ons/print/drivers/shared/utils/MarginView.cpp 2008-07-12 21:09:49 UTC (rev 26396) @@ -4,9 +4,9 @@ Copyright (c) 2002 OpenBeOS. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin Michael Pfeiffer Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -30,17 +30,21 @@ Todo: 2 Make Strings constants or UI resources - + */ #include "MarginView.h" + #include #include +#include + #include #include + /*----------------- MarginView Private Constants --------------------*/ const int kOffsetY = 20; @@ -49,18 +53,16 @@ const int kWidth = 50; const int kNumCount = 10; -const static float kPointUnits = 1; // 1 point = 1 point +const static float kPointUnits = 1; // 1 point = 1 point const static float kInchUnits = 72; // 1" = 72 points const static float kCMUnits = 28.346; // 72/2.54 1cm = 28.346 points const static float kMinFieldWidth = 100; // pixels const static float kMinUnitHeight = 30; // pixels - -const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits }; + +const static float kUnitFormat[] = { kInchUnits, kCMUnits, kPointUnits }; const static char *kUnitNames[] = { "Inch", "cm", "Points", NULL }; -const static MarginUnit kUnitMsg[] = { kUnitInch, - kUnitCM, - kUnitPoint }; +const static MarginUnit kUnitMsg[] = { kUnitInch, kUnitCM, kUnitPoint }; const pattern kDots = {{ 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55 }}; @@ -69,7 +71,6 @@ const rgb_color kWhite = { 255,255,255,0 }; const rgb_color kGray = { 220,220,220,0 }; -/*----------------- MarginView Public Methods --------------------*/ /** * Constructor @@ -81,46 +82,59 @@ * @param units, unit32 enum for units used in view * @return void */ -MarginView::MarginView(BRect frame, - int32 pageWidth, - int32 pageHeight, - BRect margins, - MarginUnit units) - - :BBox(frame, NULL, B_FOLLOW_ALL) +MarginView::MarginView(BRect frame, int32 pageWidth, int32 pageHeight, + BRect margins, MarginUnit units) + : BBox(frame, NULL, B_FOLLOW_ALL) { fMarginUnit = units; fUnitValue = kUnitFormat[units]; - + SetLabel("Margins"); - + fMaxPageHeight = frame.Height() - kMinUnitHeight - kOffsetY; fMaxPageWidth = frame.Width() - kMinFieldWidth - kOffsetX; fMargins = margins; - + fPageWidth = pageWidth; [... truncated: 740 lines follow ...] From bonefish at mail.berlios.de Sun Jul 13 00:28:11 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 13 Jul 2008 00:28:11 +0200 Subject: [Haiku-commits] r26397 - haiku/trunk/src/kits/storage/disk_device Message-ID: <200807122228.m6CMSBaJ028279@sheep.berlios.de> Author: bonefish Date: 2008-07-13 00:28:04 +0200 (Sun, 13 Jul 2008) New Revision: 26397 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26397&view=rev Modified: haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp Log: Don't fail, when no userland add-on could be found for partition. We won't be able to edit the partition in any way, but we shouldn't cause the whole BDiskDevice::PrepareModifications() to fail. Should fix bug #2470 -- haven't tested this, though. Modified: haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp =================================================================== --- haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp 2008-07-12 21:09:49 UTC (rev 26396) +++ haiku/trunk/src/kits/storage/disk_device/PartitionDelegate.cpp 2008-07-12 22:28:04 UTC (rev 26397) @@ -71,7 +71,7 @@ if (!addOn) { TRACE("BPartition::Delegate::InitAfterHierarchy(): add-on for disk " "system \"%s\" not found\n", fMutablePartition.ContentType()); - return B_ENTRY_NOT_FOUND; + return B_OK; } BPartitionHandle* handle; From julun at mail.berlios.de Sun Jul 13 13:11:52 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 13 Jul 2008 13:11:52 +0200 Subject: [Haiku-commits] r26398 - in haiku/trunk: headers/private/print/utils src/add-ons/print/drivers/pdf/source src/add-ons/print/drivers/preview src/add-ons/print/drivers/shared/utils Message-ID: <200807131111.m6DBBq6W030535@sheep.berlios.de> Author: julun Date: 2008-07-13 13:11:43 +0200 (Sun, 13 Jul 2008) New Revision: 26398 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26398&view=rev Modified: haiku/trunk/headers/private/print/utils/Utils.h haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.cpp haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.h haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.cpp haiku/trunk/src/add-ons/print/drivers/pdf/source/PageSetupWindow.h haiku/trunk/src/add-ons/print/drivers/preview/PageSetupWindow.cpp haiku/trunk/src/add-ons/print/drivers/shared/utils/Utils.cpp Log: * fixes for ticket #2378 * adjust ui code to be more font sensitive * add/ rename some of the utils message manipulation functions * use ReadAttrString instead of ReadAttr to get the printer name Modified: haiku/trunk/headers/private/print/utils/Utils.h =================================================================== --- haiku/trunk/headers/private/print/utils/Utils.h 2008-07-12 22:28:04 UTC (rev 26397) +++ haiku/trunk/headers/private/print/utils/Utils.h 2008-07-13 11:11:43 UTC (rev 26398) @@ -2,14 +2,14 @@ PDF Writer printer driver. -Copyright (c) 2001, 2002 OpenBeOS. -Copyright (c) 2005 Haiku. +Copyright (c) 2001, 2002 OpenBeOS. +Copyright (c) 2005 - 2008 Haiku. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin Michael Pfeiffer - + 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 the rights to @@ -33,24 +33,34 @@ #ifndef _UTILS_H #define _UTILS_H -#include -#include + +#include #include +#include +#include -void AddString(BMessage* m, const char* name, const char* value); +class BHandler; +class BMessage; +class BWindow; + // set or replace a value in a BMessage -void SetRect(BMessage* msg, const char* name, BRect rect); +void SetBool(BMessage* msg, const char* name, bool value); void SetFloat(BMessage* msg, const char* name, float value); void SetInt32(BMessage* msg, const char* name, int32 value); +void SetString(BMessage* msg, const char* name, const char* value); -class EscapeMessageFilter : public BMessageFilter +void SetRect(BMessage* msg, const char* name, const BRect& rect); +void SetString(BMessage* msg, const char* name, const BString& value); + + +class EscapeMessageFilter : public BMessageFilter { private: BWindow *fWindow; int32 fWhat; - + public: EscapeMessageFilter(BWindow *window, int32 what); filter_result Filter(BMessage *msg, BHandler **target); @@ -65,7 +75,7 @@ private: BList fList; typedef int (*sort_func)(const void*, const void*); - + public: virtual ~TList(); void MakeEmpty(); Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp 2008-07-12 22:28:04 UTC (rev 26397) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp 2008-07-13 11:11:43 UTC (rev 26398) @@ -2,9 +2,9 @@ AdvancedSettingsWindow.cpp -Copyright (c) 2002 OpenBeOS. +Copyright (c) 2002 OpenBeOS. -Author: +Author: Michael Pfeiffer Permission is hereby granted, free of charge, to any person obtaining a copy of @@ -27,16 +27,22 @@ */ -#include -#include -#include #include "AdvancedSettingsWindow.h" +#include "Utils.h" -#define SETTINGS_PATH "/boot/home/config/settings/PDF Writer/" -#define BOOKMARKS_PATH SETTINGS_PATH "bookmarks/" -#define XREFS_PATH SETTINGS_PATH "xrefs/" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + static BMessage* BorderWidthMessage(uint32 what, float width) { BMessage* m = new BMessage(what); @@ -44,314 +50,332 @@ return m; } -// -------------------------------------------------- + AdvancedSettingsWindow::AdvancedSettingsWindow(BMessage *settings) - : HWindow(BRect(0,0,400,180), "Advanced Settings", B_TITLED_WINDOW_LOOK, - B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | - B_NOT_ZOOMABLE) + : HWindow(BRect(0, 0, 400, 180), "Advanced Settings", B_TITLED_WINDOW_LOOK, + B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | + B_NOT_ZOOMABLE), + fSettings(settings) { - // ---- Ok, build a default page setup user interface - BRect r; - BBox *panel; - BButton *button; - // BCheckBox *cb; - BMenuField *mf; - float x, y, w, h; - fSettings = settings; - - AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); - - // add a *dialog* background - r = Bounds(); - panel = new BBox(r, "top_panel", B_FOLLOW_ALL, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER); + AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); - x = 5; y = 5; w = r.Width(); h = r.Height(); + BString licenseKey; + if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK) + licenseKey = "Not supported."; - // PDFlib license key -#if 0 - BString licenseKey; - if (settings->FindString("pdflib_license_key", &licenseKey) != B_OK) licenseKey = ""; - fLicenseKey = new BTextControl(BRect(x, y, x+2-10, y+14), "pdflib_license_key", "PDFlib License Key", "", NULL); - fLicenseKey->TextView()->HideTyping(true); - fLicenseKey->TextView()->SetText(licenseKey.String()); + if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK) + fCreateLinks = false; + + if (settings->FindFloat("link_border_width", &fLinkBorderWidth)) + fLinkBorderWidth = 1; + + if (settings->FindBool("create_bookmarks", &fCreateBookmarks) != B_OK) + fCreateBookmarks = false; + + if (settings->FindString("xrefs_file", &fXRefs) != B_OK) + fXRefs = ""; + + if (settings->FindString("bookmark_definition_file", &fBookmarkDefinition) != B_OK) + fBookmarkDefinition = ""; + + if (settings->FindBool("create_xrefs", &fCreateXRefs) != B_OK) + fCreateXRefs = false; + + if (settings->FindInt32("close_option", (int32)&fCloseOption) != B_OK) + fCloseOption = kNever; + + BRect bounds(Bounds()); + BBox *panel = new BBox(bounds, "background", B_FOLLOW_ALL, + B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_PLAIN_BORDER); + AddChild(panel); + + bounds.InsetBy(10.0, 10.0); + float divider = be_plain_font->StringWidth("Close status window when done: "); + fLicenseKey = new BTextControl(bounds, "pdflib_license_key", + "PDFlib License Key: ", "", NULL); panel->AddChild(fLicenseKey); + fLicenseKey->SetEnabled(false); fLicenseKey->ResizeToPreferred(); - y += fLicenseKey->Bounds().Height()+5; -#endif + fLicenseKey->SetDivider(divider); + //fLicenseKey->TextView()->HideTyping(true); + fLicenseKey->TextView()->SetText(licenseKey.String()); - // web links - if (settings->FindBool("create_web_links", &fCreateLinks) != B_OK) fCreateLinks = false; + // border link + bounds.OffsetBy(0.0, fLicenseKey->Bounds().Height() + 10.0); + BPopUpMenu* m = new BPopUpMenu("Link Border"); + m->SetRadioMode(true); + + BMenuField *mf = new BMenuField(bounds, "link_border_width_menu", + "Link Border: ", m); + panel->AddChild(mf); + mf->ResizeToPreferred(); + mf->SetDivider(divider); + mf->Menu()->SetLabelFromMarked(true); + BMenuItem* item; - if (settings->FindFloat("link_border_width", &fLinkBorderWidth)) fLinkBorderWidth = 1; - BPopUpMenu* m = new BPopUpMenu("link_border_width"); - m->SetRadioMode(true); m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_LINKS_MSG))); item->SetMarked(!fCreateLinks); m->AddSeparatorItem(); - + m->AddItem(item = new BMenuItem("No Border", BorderWidthMessage(LINK_BORDER_MSG, 0.0))); - if (fCreateLinks && fLinkBorderWidth == 0) item->SetMarked(true); - m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0))); - if (fCreateLinks && fLinkBorderWidth == 1) item->SetMarked(true); - m->AddItem(item = new BMenuItem("Bold Border", BorderWidthMessage(LINK_BORDER_MSG, 2.0))); - if (fCreateLinks && fLinkBorderWidth == 2) item->SetMarked(true); + if (fCreateLinks && fLinkBorderWidth == 0) + item->SetMarked(true); - mf = new BMenuField(BRect(x, y, x+w-10, y+14), "link_border_width_menu", "Link:", m); - mf->ResizeToPreferred(); - panel->AddChild(mf); - y += mf->Bounds().Height() + 15; - + m->AddItem(item = new BMenuItem("Normal Border", BorderWidthMessage(LINK_BORDER_MSG, 1.0))); + if (fCreateLinks && fLinkBorderWidth == 1) + item->SetMarked(true); + + m->AddItem(item = new BMenuItem("Bold Border", BorderWidthMessage(LINK_BORDER_MSG, 2.0))); + if (fCreateLinks && fLinkBorderWidth == 2) + item->SetMarked(true); + + // bookmarks - if (settings->FindBool("create_bookmarks", &fCreateBookmarks) != B_OK) fCreateBookmarks = false; + m = new BPopUpMenu("Bookmark Definition File"); + m->SetRadioMode(true); - m = new BPopUpMenu("definition"); - m->SetRadioMode(true); - mf = new BMenuField(BRect(x, y, x+w-10, y+14), "definition_menu", "Bookmark Definition File:", m); + bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0); + mf = new BMenuField(bounds, "definition_menu", "Bookmark Definition File: ", m); panel->AddChild(mf); - y += mf->Bounds().Height() + 15; + mf->ResizeToPreferred(); + mf->SetDivider(divider); + mf->Menu()->SetLabelFromMarked(true); - if (settings->FindString("bookmark_definition_file", &fBookmarkDefinition) != B_OK) fBookmarkDefinition = ""; - m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_BOOKMARKS_MSG))); item->SetMarked(!fCreateBookmarks); m->AddSeparatorItem(); - BDirectory folder; - BEntry entry; - - // XXX: B_USER_SETTINGS_DIRECTORY - folder.SetTo (BOOKMARKS_PATH); - if (folder.InitCheck() == B_OK) { - while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { + BDirectory bookmarks(_SetupDirectory("bookmarks")); + if (bookmarks.InitCheck() == B_OK) { + BEntry entry; + while (bookmarks.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { char name[B_FILE_NAME_LENGTH]; - if (entry.GetName(name) == B_NO_ERROR) - m->AddItem (item = new BMenuItem(name, new BMessage(DEFINITION_MSG))); - if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0) item->SetMarked(true); + if (entry.GetName(name) == B_OK) { + m->AddItem(item = new BMenuItem(name, new BMessage(DEFINITION_MSG))); + if (fCreateBookmarks && strcmp(name, fBookmarkDefinition.String()) == 0) + item->SetMarked(true); + } } - } + } // cross references - if (settings->FindBool("create_xrefs", &fCreateXRefs) != B_OK) fCreateXRefs = false; - m = new BPopUpMenu("cross references"); + m = new BPopUpMenu("Cross References File"); m->SetRadioMode(true); - mf = new BMenuField(BRect(x, y, x+w-10, y+14), "xrefs_menu", "Cross References File:", m); + + bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0); + mf = new BMenuField(bounds, "xrefs_menu", "Cross References File: ", m); panel->AddChild(mf); - y += mf->Bounds().Height() + 15; + mf->ResizeToPreferred(); + mf->SetDivider(divider); + mf->Menu()->SetLabelFromMarked(true); - if (settings->FindString("xrefs_file", &fXRefs) != B_OK) fXRefs = ""; - m->AddItem(item = new BMenuItem("None", new BMessage(CREATE_XREFS_MSG))); item->SetMarked(!fCreateXRefs); m->AddSeparatorItem(); - - // XXX: B_USER_SETTINGS_DIRECTORY - folder.SetTo (XREFS_PATH); - if (folder.InitCheck() == B_OK) { - while (folder.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { + + BDirectory xrefs(_SetupDirectory("xrefs")); + if (xrefs.InitCheck() == B_OK) { + BEntry entry; + while (xrefs.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { char name[B_FILE_NAME_LENGTH]; - if (entry.GetName(name) == B_NO_ERROR) + if (entry.GetName(name) == B_OK) { m->AddItem (item = new BMenuItem(name, new BMessage(XREFS_MSG))); - if (fCreateXRefs && strcmp(name, fXRefs.String()) == 0) item->SetMarked(true); + if (fCreateXRefs && strcmp(name, fXRefs.String()) == 0) + item->SetMarked(true); + } } - } + } - // close automatically status window after pdf generation - // - Never - // - No Errors - // - No Errors and Warnings - // - Always - m = new BPopUpMenu("close option"); + m = new BPopUpMenu("Close status window when done"); m->SetRadioMode(true); - mf = new BMenuField(BRect(x, y, x+w-10, y+14), "close_option_menu", "Close status window when done:", m); + + bounds.OffsetBy(0.0, mf->Bounds().Height() + 10.0); + mf = new BMenuField(bounds, "close_option_menu", "Close status window when done: ", m); panel->AddChild(mf); + mf->ResizeToPreferred(); + mf->SetDivider(divider); + mf->Menu()->SetLabelFromMarked(true); - int32 closeOption; - if (settings->FindInt32("close_option", &closeOption) != B_OK) closeOption = kNever; - fCloseOption = (CloseOption)closeOption; - AddMenuItem(m, "Never", kNever); - AddMenuItem(m, "No Errors", kNoErrors); - AddMenuItem(m, "No Errors or Warnings", kNoErrorsOrWarnings); - AddMenuItem(m, "No Errors, Warnings or Info", kNoErrorsWarningsOrInfo); - AddMenuItem(m, "Always", kAlways); + _AddMenuItem(m, "Never", kNever); + _AddMenuItem(m, "No Errors", kNoErrors); + _AddMenuItem(m, "No Errors or Warnings", kNoErrorsOrWarnings); + _AddMenuItem(m, "No Errors, Warnings or Info", kNoErrorsWarningsOrInfo); + _AddMenuItem(m, "Always", kAlways); - // add a "OK" button, and make it default - button = new BButton(r, NULL, "OK", new BMessage(OK_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->GetPreferredSize(&w, &h); - button->MakeDefault(true); - x = r.right - w - 8; - y = r.bottom - h - 8; - button->MoveTo(x, y); - panel->AddChild(button); - - // add a "Cancel button - button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->GetPreferredSize(&w, &h); - button->ResizeToPreferred(); - x -= w + 8; - button->MoveTo(x, y); - panel->AddChild(button); - - // add a "Open Settings Folder" button - button = new BButton(r, NULL, "Open Settings Folder?", new BMessage(OPEN_SETTINGS_FOLDER_MSG), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->GetPreferredSize(&w, &h); - button->ResizeToPreferred(); - x = r.left + 8; - button->MoveTo(x, y); - panel->AddChild(button); - - - // add a separator line... - BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM ); + bounds = Bounds(); + bounds.InsetBy(5.0, 0.0); + bounds.top = mf->Frame().bottom + 10.0; + BBox *line = new BBox(BRect(bounds.left, bounds.top, bounds.right, + bounds.top + 1.0), NULL, B_FOLLOW_LEFT_RIGHT); panel->AddChild(line); - // Finally, add our panel to window - AddChild(panel); - - MoveTo(320, 320); -} + bounds.InsetBy(5.0, 0.0); + bounds.OffsetBy(0.0, 11.0); + BButton *cancel = new BButton(bounds, NULL, "Cancel", new BMessage(CANCEL_MSG)); + panel->AddChild(cancel); + cancel->ResizeToPreferred(); -void -AdvancedSettingsWindow::UpdateSettings() -{ -#if 0 - if (fSettings->HasString("pdflib_license_key")) { - fSettings->ReplaceString("pdflib_license_key", fLicenseKey->Text()); - } else { - fSettings->AddString("pdflib_license_key", fLicenseKey->Text()); - } -#endif + BButton *ok = new BButton(bounds, NULL, "OK", new BMessage(OK_MSG)); + panel->AddChild(ok, cancel); + ok->ResizeToPreferred(); - if (fSettings->HasBool("create_web_links")) { - fSettings->ReplaceBool("create_web_links", fCreateLinks); - } else { - fSettings->AddBool("create_web_links", fCreateLinks); - } + bounds.right = fLicenseKey->Frame().right; + ok->MoveTo(bounds.right - ok->Bounds().Width(), ok->Frame().top); - if (fSettings->HasFloat("link_border_width")) { - fSettings->ReplaceFloat("link_border_width", fLinkBorderWidth); - } else { - fSettings->AddFloat("link_border_width", fLinkBorderWidth); - } + bounds = ok->Frame(); + cancel->MoveTo(bounds.left - cancel->Bounds().Width() - 10.0, bounds.top); - if (fSettings->HasBool("create_bookmarks")) { - fSettings->ReplaceBool("create_bookmarks", fCreateBookmarks); - } else { - fSettings->AddBool("create_bookmarks", fCreateBookmarks); - } + ok->MakeDefault(true); + ResizeTo(bounds.right + 10.0, bounds.bottom + 10.0); - if (fSettings->HasString("bookmark_definition_file")) { - fSettings->ReplaceString("bookmark_definition_file", fBookmarkDefinition.String()); - } else { - fSettings->AddString("bookmark_definition_file", fBookmarkDefinition.String()); - } + BButton *button = new BButton(bounds, NULL, "Open Settings Folder" B_UTF8_ELLIPSIS, + new BMessage(OPEN_SETTINGS_FOLDER_MSG)); + panel->AddChild(button); + button->ResizeToPreferred(); + button->MoveTo(fLicenseKey->Frame().left, bounds.top); - if (fSettings->HasBool("create_xrefs")) { - fSettings->ReplaceBool("create_xrefs", fCreateXRefs); - } else { - fSettings->AddBool("create_xrefs", fCreateXRefs); - } - - if (fSettings->HasString("xrefs_file")) { - fSettings->ReplaceString("xrefs_file", fXRefs.String()); - } else { - fSettings->AddString("xrefs_file", fXRefs.String()); - } - - if (fSettings->HasInt32("close_option")) { - fSettings->ReplaceInt32("close_option", fCloseOption); - } else { - fSettings->AddInt32("close_option", fCloseOption); - } + BRect winFrame(Frame()); + BRect screenFrame(BScreen().Frame()); + MoveTo((screenFrame.right - winFrame.right) / 2, + (screenFrame.bottom - winFrame.bottom) / 2); } -// -------------------------------------------------- -void AdvancedSettingsWindow::AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option) { - BMessage* msg = new BMessage(AUTO_CLOSE_MSG); - msg->AddInt32("close_option", option); - BMenuItem* item = new BMenuItem(label, msg); - menu->AddItem(item); - if (fCloseOption == option) item->SetMarked(true); -} - -// -------------------------------------------------- -void +void AdvancedSettingsWindow::MessageReceived(BMessage *msg) { - float w; void *source; - int32 closeOption; + BMenuItem *item = NULL; + if (msg->FindPointer("source", &source) == B_OK) + item = static_cast (source); - if (msg->FindPointer("source", &source) != B_OK) source = NULL; - switch (msg->what){ - case OK_MSG: UpdateSettings(); Quit(); - break; - - case CANCEL_MSG: Quit(); - break; + case OK_MSG: { + _UpdateSettings(); + Quit(); + } break; - case CREATE_LINKS_MSG: + case CANCEL_MSG: { + Quit(); + } break; + + case CREATE_LINKS_MSG: { fCreateLinks = false; - break; - - case LINK_BORDER_MSG: + } break; + + case LINK_BORDER_MSG: { + float w; if (msg->FindFloat("width", &w) == B_OK) { fLinkBorderWidth = w; fCreateLinks = true; } - break; - - case CREATE_BOOKMARKS_MSG: + } break; + + case CREATE_BOOKMARKS_MSG: { fCreateBookmarks = false; - break; - - case DEFINITION_MSG: - if (source) { - BMenuItem* item = (BMenuItem*)source; + } break; + + case DEFINITION_MSG: { + if (item) { fBookmarkDefinition = item->Label(); fCreateBookmarks = true; } - break; - - case CREATE_XREFS_MSG: + } break; + + case CREATE_XREFS_MSG: { fCreateXRefs = false; - break; - - case XREFS_MSG: - if (source) { - BMenuItem* item = (BMenuItem*)source; + } break; + + case XREFS_MSG: { + if (item) { fXRefs = item->Label(); fCreateXRefs = true; } - break; - - case AUTO_CLOSE_MSG: - if (msg->FindInt32("close_option", &closeOption) == B_OK) { + } break; + + case AUTO_CLOSE_MSG: { + int32 closeOption; + if (msg->FindInt32("close_option", &closeOption) == B_OK) fCloseOption = (CloseOption)closeOption; + } break; + + case OPEN_SETTINGS_FOLDER_MSG: { + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY, &path, false); + path.Append("PDF Writer"); + + entry_ref ref; + get_ref_for_path(path.Path(), &ref); + + BMessenger tracker("application/x-vnd.Be-TRAK"); + if (tracker.IsValid()) { + BMessage message(B_REFS_RECEIVED); + message.AddRef("refs", &ref); + tracker.SendMessage(&message); } - break; - - case OPEN_SETTINGS_FOLDER_MSG: - { - char* argv[] = { SETTINGS_PATH }; - be_roster->Launch("application/x-vnd.Be-TRAK", 1, argv); - } - break; - + } break; + default: inherited::MessageReceived(msg); break; } } + +void +AdvancedSettingsWindow::_UpdateSettings() +{ +#if 0 + AddString(fSettings, "pdflib_license_key", fLicenseKey); +#endif + + SetInt32(fSettings, "close_option", fCloseOption); + + SetBool(fSettings, "create_web_links", fCreateLinks); + SetFloat(fSettings, "link_border_width", fLinkBorderWidth); + + SetString(fSettings, "xrefs_file", fXRefs); + SetBool(fSettings, "create_xrefs", fCreateXRefs); + + SetBool(fSettings, "create_bookmarks", fCreateBookmarks); + SetString(fSettings, "bookmark_definition_file", fBookmarkDefinition); +} + + +BDirectory +AdvancedSettingsWindow::_SetupDirectory(const char* dirName) +{ + BPath path; + find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); + + BDirectory dir(path.Path()); + if (dir.Contains("PDF Writer")) { + path.Append("PDF Writer"); + dir.SetTo(path.Path()); + } else { + dir.CreateDirectory("PDF Writer", &dir); + } + + if (dir.Contains(dirName)) { + path.Append(dirName); + dir.SetTo(path.Path()); + } else { + dir.CreateDirectory(dirName, &dir); + } + return dir; +} + + +void AdvancedSettingsWindow::_AddMenuItem(BPopUpMenu* menu, const char* label, + CloseOption option) +{ + BMessage* msg = new BMessage(AUTO_CLOSE_MSG); + msg->AddInt32("close_option", option); + BMenuItem* item = new BMenuItem(label, msg); + menu->AddItem(item); + if (fCloseOption == option) + item->SetMarked(true); +} Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h 2008-07-12 22:28:04 UTC (rev 26397) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.h 2008-07-13 11:11:43 UTC (rev 26398) @@ -2,9 +2,9 @@ PDF Writer printer driver. -Copyright (c) 2002 OpenBeOS. +Copyright (c) 2002 OpenBeOS. -Authors: +Authors: Philippe Houdoin Simon Gauvin Michael Pfeiffer @@ -32,59 +32,58 @@ #ifndef ADVANCED_SETTINGS_WINDOW_H #define ADVANCED_SETTINGS_WINDOW_H -#include -#include -#include -#include -#include -#include -#include + #include "InterfaceUtils.h" -#include "Utils.h" #include "PrinterDriver.h" -class AdvancedSettingsWindow : public HWindow + +#include +#include + + +class BMessage; +class BPopUpMenu; +class BTextControl; + + +class AdvancedSettingsWindow : public HWindow { + typedef HWindow inherited; public: // Constructors, destructors, operators... - AdvancedSettingsWindow(BMessage *doc_info); + AdvancedSettingsWindow(BMessage *doc_info); - typedef HWindow inherited; + virtual void MessageReceived(BMessage *msg); - // public constantes enum { - OK_MSG = 'ok__', - CANCEL_MSG = 'cncl', - CREATE_LINKS_MSG = 'clnk', - LINK_BORDER_MSG = 'lnkb', - CREATE_BOOKMARKS_MSG = 'cbmk', - DEFINITION_MSG = 'defi', - CREATE_XREFS_MSG = 'cxrf', - XREFS_MSG = 'xref', - AUTO_CLOSE_MSG = 'acls', - OPEN_SETTINGS_FOLDER_MSG = 'opsf', + OK_MSG = 'ok__', + CANCEL_MSG = 'cncl', + CREATE_LINKS_MSG = 'clnk', + LINK_BORDER_MSG = 'lnkb', + CREATE_BOOKMARKS_MSG = 'cbmk', + DEFINITION_MSG = 'defi', + CREATE_XREFS_MSG = 'cxrf', + XREFS_MSG = 'xref', + AUTO_CLOSE_MSG = 'acls', + OPEN_SETTINGS_FOLDER_MSG = 'opsf', }; - - // Virtual function overrides -public: - virtual void MessageReceived(BMessage *msg); private: + void _UpdateSettings(); + BDirectory _SetupDirectory(const char* dirName); + void _AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option); - BMessage* fSettings; - - BTextControl* fLicenseKey; - bool fCreateLinks; - float fLinkBorderWidth; - bool fCreateBookmarks; - BString fBookmarkDefinition; - bool fCreateXRefs; - BString fXRefs; - CloseOption fCloseOption; - - void UpdateSettings(); - void AddMenuItem(BPopUpMenu* menu, const char* label, CloseOption option); +private: + BMessage* fSettings; + BTextControl* fLicenseKey; + bool fCreateLinks; + float fLinkBorderWidth; + bool fCreateBookmarks; + BString fBookmarkDefinition; + bool fCreateXRefs; + BString fXRefs; + CloseOption fCloseOption; }; #endif Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.cpp 2008-07-12 22:28:04 UTC (rev 26397) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.cpp 2008-07-13 11:11:43 UTC (rev 26398) @@ -2,13 +2,13 @@ PDF Writer printer driver. -Copyright (c) 2001 OpenBeOS. +Copyright (c) 2001 OpenBeOS. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin Michael Pfeiffer - + 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 the rights to @@ -37,124 +37,100 @@ #include "Driver.h" #include "PDFWriter.h" +#include "PrinterDriver.h" #include "PrinterSettings.h" + static PrinterDriver *instanciate_driver(BNode *spoolDir); // ======== For testing only ================== -BMessage* -take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg) +BMessage* +take_job(BFile *spoolFile, BNode *spoolDir, BMessage *msg) { - PrinterDriver *driver; - - driver = instanciate_driver(spoolDir); - if (driver->PrintJob(spoolFile, spoolDir, msg) == B_OK) { - msg = new BMessage('okok'); - } else { - msg = new BMessage('baad'); - } + PrinterDriver *driver = instanciate_driver(spoolDir); + status_t status = driver->PrintJob(spoolFile, spoolDir, msg); delete driver; - + + msg = new BMessage('okok'); + if (status != B_OK) + msg->what = 'baad'; + return msg; } -// -------------------------------------------------- -BMessage* -config_page(BNode *spoolDir, BMessage *msg) +BMessage* +config_page(BNode *spoolDir, BMessage *msg) { - BMessage *pagesetupMsg; - PrinterDriver *driver; - const char *printerName; - char buffer[B_ATTR_NAME_LENGTH+1]; - - pagesetupMsg = new BMessage(*msg); - + BMessage *pagesetupMsg = new BMessage(*msg); PrinterSettings::Read(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings); - // retrieve the printer (spool) name. - printerName = NULL; - if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) { - printerName = buffer; - } + BString printerName; + spoolDir->ReadAttrString("Printer Name", &printerName); - driver = instanciate_driver(spoolDir); - if (driver->PageSetup(pagesetupMsg, printerName) == B_OK) { + PrinterDriver *driver = instanciate_driver(spoolDir); + if (driver->PageSetup(pagesetupMsg, printerName.String()) == B_OK) { pagesetupMsg->what = 'okok'; - PrinterSettings::Update(spoolDir, pagesetupMsg, PrinterSettings::kPageSettings); + PrinterSettings::Update(spoolDir, pagesetupMsg, + PrinterSettings::kPageSettings); } else { delete pagesetupMsg; pagesetupMsg = NULL; } - delete driver; - return pagesetupMsg; } -// -------------------------------------------------- -BMessage* +BMessage* config_job(BNode *spoolDir, BMessage *msg) { - BMessage *jobsetupMsg; - PrinterDriver *driver; - const char *printerName; - char buffer[B_ATTR_NAME_LENGTH+1]; - - jobsetupMsg = new BMessage(*msg); - + BMessage *jobsetupMsg = new BMessage(*msg); PrinterSettings::Read(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings); - // retrieve the printer (spool) name. - printerName = NULL; - if (spoolDir->ReadAttr("Printer Name", B_STRING_TYPE, 1, buffer, B_ATTR_NAME_LENGTH+1) > 0) { - printerName = buffer; - } - driver = instanciate_driver(spoolDir); - if (driver->JobSetup(jobsetupMsg, printerName) == B_OK) { + BString printerName; + spoolDir->ReadAttrString("Printer Name", &printerName); + + PrinterDriver *driver = instanciate_driver(spoolDir); + if (driver->JobSetup(jobsetupMsg, printerName.String()) == B_OK) { jobsetupMsg->what = 'okok'; - PrinterSettings::Update(spoolDir, jobsetupMsg, PrinterSettings::kJobSettings); + PrinterSettings::Update(spoolDir, jobsetupMsg, + PrinterSettings::kJobSettings); } else { delete jobsetupMsg; jobsetupMsg = NULL; } - delete driver; - return jobsetupMsg; } -// -------------------------------------------------- -char* +char* add_printer(char *printerName) { - return printerName; + return printerName; } -// -------------------------------------------------- -static PrinterDriver* +static PrinterDriver* instanciate_driver(BNode *spoolDir) { return new PDFWriter(); } + /** - * default_settings + * default_settings * * @param BNode* printer spool directory * @return BMessage* the settings */ -BMessage* +BMessage* default_settings(BNode* printer) { BMessage *msg = new BMessage(); - PrinterSettings::Read(printer, msg, PrinterSettings::kPageSettings); - + return msg; } - Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.h =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.h 2008-07-12 22:28:04 UTC (rev 26397) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/Driver.h 2008-07-13 11:11:43 UTC (rev 26398) @@ -2,13 +2,13 @@ PDF Writer printer driver. -Copyright (c) 2002 OpenBeOS. +Copyright (c) 2002 OpenBeOS. -Authors: +Authors: Philippe Houdoin - Simon Gauvin + Simon Gauvin [... truncated: 1149 lines follow ...] From julun at mail.berlios.de Sun Jul 13 13:13:51 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 13 Jul 2008 13:13:51 +0200 Subject: [Haiku-commits] r26399 - haiku/trunk/src/add-ons/print/drivers/pdf/source Message-ID: <200807131113.m6DBDp9J000926@sheep.berlios.de> Author: julun Date: 2008-07-13 13:13:50 +0200 (Sun, 13 Jul 2008) New Revision: 26399 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26399&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/Image.cpp Log: * missing include, remove some whitespaces Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/Image.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/Image.cpp 2008-07-13 11:11:43 UTC (rev 26398) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/Image.cpp 2008-07-13 11:13:50 UTC (rev 26399) @@ -2,11 +2,11 @@ Image Cache Item. -Copyright (c) 2003 OpenBeOS. +Copyright (c) 2003 OpenBeOS. -Author: +Author: Michael Pfeiffer - + 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 the rights to @@ -35,6 +35,7 @@ #include #include #include +#include #include "Report.h" #include "Image.h" @@ -72,7 +73,7 @@ fileName << id; pdfFileName = fileName; pdfFileName << ".png"; - + bitmap->Lock(); w = bitmap->Bounds().IntegerWidth()+1; h = bitmap->Bounds().IntegerHeight()+1; @@ -94,9 +95,9 @@ unlink(pdfFileName.String()); return NULL; } - + int image; - image = PDF_open_image_file(pdf, "png", pdfFileName.String(), + image = PDF_open_image_file(pdf, "png", pdfFileName.String(), mask == -1 ? "" : "masked", mask == -1 ? 0 : mask); #if STORE_AS_BBITMAP @@ -178,11 +179,11 @@ if (bm) { bm->Lock(); bitmap->Lock(); - + equals = bm->BitsLength() == bitmap->BitsLength() && bm->ColorSpace() == bitmap->ColorSpace() && memcmp(bm->Bits(), bitmap->Bits(), bm->BitsLength()) == 0; - + bitmap->Unlock(); bm->Unlock(); delete bm; From julun at mail.berlios.de Sun Jul 13 13:16:23 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 13 Jul 2008 13:16:23 +0200 Subject: [Haiku-commits] r26400 - haiku/trunk/src/add-ons/print/drivers/pdf/source Message-ID: <200807131116.m6DBGNC6005063@sheep.berlios.de> Author: julun Date: 2008-07-13 13:16:15 +0200 (Sun, 13 Jul 2008) New Revision: 26400 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26400&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp Log: * fix some longjump warnings Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp 2008-07-13 11:13:50 UTC (rev 26399) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/PDFWriter.cpp 2008-07-13 11:16:15 UTC (rev 26400) @@ -602,7 +602,7 @@ float a = (float)alpha/255.0; sprintf(trans, "opacitystroke=%f opacityfill=%f", a, a); - int handle = -1; + volatile int handle = -1; PDF_TRY(fPdf) { handle = PDF_create_gstate(fPdf, trans); } PDF_CATCH(fPdf) { @@ -621,30 +621,34 @@ } // -------------------------------------------------- -void -PDFWriter::BeginTransparency() +void +PDFWriter::BeginTransparency() { - if (!SupportsOpacity() || !MakesPDF() || !IsDrawing()) return; + if (!SupportsOpacity() || !MakesPDF() || !IsDrawing()) + return; + REPORT(kDebug, fPage, ">>> BeginTransparency"); - REPORT(kDebug, fPage, "current_color(%d, %d, %d, %d)", fState->currentColor.red, fState->currentColor.green, fState->currentColor.blue, fState->currentColor.alpha); - REPORT(kDebug, fPage, "drawing_mode %d alpha %d", (int)fState->drawingMode, (int)fState->currentColor.alpha); - - Transparency* t = NULL; - + REPORT(kDebug, fPage, "current_color(%d, %d, %d, %d)", fState->currentColor.red, + fState->currentColor.green, fState->currentColor.blue, fState->currentColor.alpha); + REPORT(kDebug, fPage, "drawing_mode %d alpha %d", (int)fState->drawingMode, + (int)fState->currentColor.alpha); + uint8 alpha = fState->currentColor.alpha; if (fState->drawingMode == B_OP_ALPHA && alpha < 255) { PDF_save(fPdf); - t = FindTransparency(alpha); + Transparency* t = FindTransparency(alpha); if (t != NULL) { PDF_TRY(fPdf) { PDF_set_gstate(fPdf, t->Handle()); } PDF_CATCH(fPdf) { - REPORT(kError, 0, PDF_get_errmsg(fPdf)); + REPORT(kError, 0, PDF_get_errmsg(fPdf)); } - } + fTransparencyStack.AddItem(t); + return; + } } - // if transparency is not set then push NULL to transparency stack - fTransparencyStack.AddItem(t); + // if transparency is not set then push NULL to transparency stack + fTransparencyStack.AddItem(NULL); } // -------------------------------------------------- From bonefish at mail.berlios.de Sun Jul 13 14:47:15 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 13 Jul 2008 14:47:15 +0200 Subject: [Haiku-commits] r26401 - in haiku/trunk: headers/os/drivers src/system/kernel/fs Message-ID: <200807131247.m6DClFrA021016@sheep.berlios.de> Author: bonefish Date: 2008-07-13 14:47:08 +0200 (Sun, 13 Jul 2008) New Revision: 26401 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26401&view=rev Modified: haiku/trunk/headers/os/drivers/fs_interface.h haiku/trunk/src/system/kernel/fs/vfs.cpp Log: * Added "partition_id partition" field to fs_volume, so that file systems can get the partition they reside on easily. * Updated TODO. Modified: haiku/trunk/headers/os/drivers/fs_interface.h =================================================================== --- haiku/trunk/headers/os/drivers/fs_interface.h 2008-07-13 11:16:15 UTC (rev 26400) +++ haiku/trunk/headers/os/drivers/fs_interface.h 2008-07-13 12:47:08 UTC (rev 26401) @@ -54,6 +54,7 @@ struct fs_volume { dev_t id; + partition_id partition; int32 layer; void* private_volume; fs_volume_ops* ops; Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-13 11:16:15 UTC (rev 26400) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2008-07-13 12:47:08 UTC (rev 26401) @@ -6284,7 +6284,7 @@ // Write lock the partition's device. For the time being, we keep the lock // until we're done mounting -- not nice, but ensure, that no-one is // interfering. - // TODO: Find a better solution. + // TODO: Just mark the partition busy while mounting! KDiskDevice *diskDevice = NULL; if (partition) { diskDevice = ddm->WriteLockDevice(partition->Device()->ID()); @@ -6364,6 +6364,7 @@ mount->owns_file_device = false; mount->volume->id = mount->id; + mount->volume->partition = partition != NULL ? partition->ID() : -1; mount->volume->layer = 0; mount->volume->private_volume = NULL; mount->volume->ops = NULL; From bonefish at mail.berlios.de Sun Jul 13 14:47:38 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 13 Jul 2008 14:47:38 +0200 Subject: [Haiku-commits] r26402 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200807131247.m6DClcHA021043@sheep.berlios.de> Author: bonefish Date: 2008-07-13 14:47:36 +0200 (Sun, 13 Jul 2008) New Revision: 26402 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26402&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp Log: Calmed down some debug output. Modified: haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp 2008-07-13 12:47:08 UTC (rev 26401) +++ haiku/trunk/src/system/kernel/disk_device_manager/KDiskSystem.cpp 2008-07-13 12:47:36 UTC (rev 26402) @@ -13,9 +13,12 @@ // debugging -//#define DBG(x) -#define DBG(x) x -#define OUT dprintf +//#define TRACE_KDISK_SYSTEM +#ifdef TRACE_KDISK_SYSTEM +# define TRACE(x...) dprintf(x) +#else +# define TRACE(x...) do { } while (false) +#endif // constructor @@ -131,7 +134,7 @@ KDiskSystem::Load() { ManagerLocker locker(KDiskDeviceManager::Default()); -dprintf("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter + 1); +TRACE("KDiskSystem::Load(): %s -> %ld\n", Name(), fLoadCounter + 1); status_t error = B_OK; if (fLoadCounter == 0) error = LoadModule(); @@ -146,7 +149,7 @@ KDiskSystem::Unload() { ManagerLocker locker(KDiskDeviceManager::Default()); -dprintf("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1); +TRACE("KDiskSystem::Unload(): %s -> %ld\n", Name(), fLoadCounter - 1); if (fLoadCounter > 0 && --fLoadCounter == 0) UnloadModule(); } From bonefish at mail.berlios.de Sun Jul 13 14:50:39 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 13 Jul 2008 14:50:39 +0200 Subject: [Haiku-commits] r26403 - in haiku/trunk: headers/os/drivers src/system/kernel/disk_device_manager Message-ID: <200807131250.m6DCodbI021289@sheep.berlios.de> Author: bonefish Date: 2008-07-13 14:50:35 +0200 (Sun, 13 Jul 2008) New Revision: 26403 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26403&view=rev Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp Log: Added helper function get_default_partition_content_name() that can be used by file systems to get a useful name, if the file system (or just that specific volume) doesn't have one. Modified: haiku/trunk/headers/os/drivers/disk_device_manager.h =================================================================== --- haiku/trunk/headers/os/drivers/disk_device_manager.h 2008-07-13 12:47:36 UTC (rev 26402) +++ haiku/trunk/headers/os/drivers/disk_device_manager.h 2008-07-13 12:50:35 UTC (rev 26403) @@ -114,6 +114,12 @@ // Service method for disks systems: Synchronously scans the partition. // Device must not be locked. +// partition support functions +// (no lock required) +status_t get_default_partition_content_name(partition_id partitionID, + const char* fileSystemName, char* buffer, size_t bufferSize); + // The partition_data::content_size field must already be initialized. + // disk systems disk_system_id find_disk_system(const char *name); Modified: haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2008-07-13 12:47:36 UTC (rev 26402) +++ haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2008-07-13 12:50:35 UTC (rev 26403) @@ -224,6 +224,38 @@ } +// get_default_partition_content_name +status_t +get_default_partition_content_name(partition_id partitionID, + const char* fileSystemName, char* buffer, size_t bufferSize) +{ + KDiskDeviceManager *manager = KDiskDeviceManager::Default(); + KPartition *partition = manager->RegisterPartition(partitionID); + if (partition == NULL) + return B_ENTRY_NOT_FOUND; + + off_t size = partition->ContentSize(); + partition->Unregister(); + + const char* const suffixes[] = { + "", "K", "M", "G", "T", "P", "E", NULL + }; + + size *= 10; + // We want one digit precision. + int index = 0; + while (size >= 1024 * 10 && suffixes[index + 1]) { + size /= 1024; + index++; + } + + snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, + int32(size / 10), int32(size % 10), suffixes[index]); + + return B_OK; +} + + // find_disk_system disk_system_id find_disk_system(const char *name) From bonefish at mail.berlios.de Sun Jul 13 14:52:07 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Sun, 13 Jul 2008 14:52:07 +0200 Subject: [Haiku-commits] r26404 - haiku/trunk/src/add-ons/kernel/file_systems/reiserfs Message-ID: <200807131252.m6DCq74k021438@sheep.berlios.de> Author: bonefish Date: 2008-07-13 14:52:05 +0200 (Sun, 13 Jul 2008) New Revision: 26404 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26404&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp Log: Use the new get_default_partition_content_name() to construct a useful volume name -- ReiserFS volumes don't support names. Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-13 12:50:35 UTC (rev 26403) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.cpp 2008-07-13 12:52:05 UTC (rev 26404) @@ -78,6 +78,7 @@ fSettings(NULL), fNegativeEntries() { + fVolumeName[0] = '\0'; } // destructor @@ -86,6 +87,7 @@ Unmount(); } + // Identify status_t Volume::Identify(int fd, partition_data *partition) @@ -131,6 +133,10 @@ // read and analyze super block if (error == B_OK) error = _ReadSuperBlock(); + + if (error == B_OK) + UpdateName(fsVolume->partition); + // create and init block cache if (error == B_OK) { fBlockCache = new(nothrow) BlockCache; @@ -248,9 +254,21 @@ const char * Volume::GetName() const { - return fSettings->GetVolumeName(); + return fVolumeName; } + +// UpdateName +void +Volume::UpdateName(partition_id partitionID) +{ + if (get_default_partition_content_name(partitionID, "ReiserFS", + fVolumeName, sizeof(fVolumeName)) != B_OK) { + strlcpy(fVolumeName, "ReiserFS Volume", sizeof(fVolumeName)); + } +} + + // GetDeviceName const char * Volume::GetDeviceName() const @@ -658,4 +676,3 @@ } } } - Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-13 12:50:35 UTC (rev 26403) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/Volume.h 2008-07-13 12:52:05 UTC (rev 26404) @@ -53,6 +53,7 @@ off_t CountBlocks() const; off_t CountFreeBlocks() const; const char *GetName() const; + void UpdateName(partition_id partitionID); const char *GetDeviceName() const; BlockCache *GetBlockCache() const { return fBlockCache; } @@ -102,6 +103,7 @@ char *fDeviceName; Settings *fSettings; List fNegativeEntries; + char fVolumeName[B_OS_NAME_LENGTH]; }; #endif // VOLUME_H Modified: haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-13 12:50:35 UTC (rev 26403) +++ haiku/trunk/src/add-ons/kernel/file_systems/reiserfs/kernel_interface.cpp 2008-07-13 12:52:05 UTC (rev 26404) @@ -1,6 +1,6 @@ // kernel_interface.cpp // -// Copyright (c) 2003-2004, Ingo Weinhold (bonefish at cs.tu-berlin.de) +// Copyright (c) 2003-2008, Ingo Weinhold (bonefish at cs.tu-berlin.de) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -88,8 +88,10 @@ partition->content_size = volume->CountBlocks() * volume->GetBlockSize(); partition->block_size = volume->GetBlockSize(); - // TODO: Construct name from partition layout? - partition->content_name = strdup("Untitled ReiserFS"); + + volume->UpdateName(partition->id); + // must be done after setting the content size + partition->content_name = strdup(volume->GetName()); if (partition->content_name == NULL) return B_NO_MEMORY; @@ -163,9 +165,9 @@ info->io_size = kOptimalIOSize; info->total_blocks = volume->CountBlocks(); info->free_blocks = volume->CountFreeBlocks(); - strncpy(info->device_name, volume->GetDeviceName(), + strlcpy(info->device_name, volume->GetDeviceName(), sizeof(info->device_name)); - strncpy(info->volume_name, volume->GetName(), sizeof(info->volume_name)); + strlcpy(info->volume_name, volume->GetName(), sizeof(info->volume_name)); return B_OK; } From axeld at pinc-software.de Sun Jul 13 18:28:38 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Sun, 13 Jul 2008 18:28:38 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26395_-_haiku/trunk/src/add-ons/kernel?= =?utf-8?q?/drivers/graphics/vesa?= In-Reply-To: <200807121933.m6CJX5R1007096@sheep.berlios.de> Message-ID: <1099236319-BeMail@zon> stippi at mail.berlios.de wrote: > + // Turn on write combining for the area > + vm_set_area_memory_type(newFBArea, modeInfo.physical_base, > B_MTR_WC); While this is not part of the public API, it's definitely easier to use than the historical approach (ie. trying write combining first, and, if that fails, try to create the same area without WC again). Anyway, did you change the resolution from a lower one to a higher one or vice versa? In the second case, the current area should be reused, and not recreated -- maybe that doesn't work correctly? Bye, Axel. From axeld at pinc-software.de Sun Jul 13 18:29:39 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Sun, 13 Jul 2008 18:29:39 +0200 CEST Subject: [Haiku-commits] r26390 - in haiku/trunk/src/add-ons/kernel/drivers: . joystick joystick/emuxkigameport joystick/usb_joy In-Reply-To: <2297495615-BeMail@primary> Message-ID: <1160038869-BeMail@zon> "Michael Lotz" wrote: > > Author: modeenf > > Log: > > Driver for USB Joystick SBLive and audigy. Work in progress. Right > > now the USB driver don't work. > Ehm, didn't we agree that this belongs to usb_hid and not in its own > driver? It duplicates the HID parsing code and device management for > absolutely no reason. We definitely did. Bye, Axel. From axeld at pinc-software.de Sun Jul 13 18:47:29 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Sun, 13 Jul 2008 18:47:29 +0200 CEST Subject: [Haiku-commits] =?utf-8?q?r26403_-_in_haiku/trunk=3A_headers/os/d?= =?utf-8?q?rivers_src/system/kernel/disk=5Fdevice=5Fmanager?= In-Reply-To: <200807131250.m6DCodbI021289@sheep.berlios.de> Message-ID: <2230629549-BeMail@zon> bonefish at mail.berlios.de wrote: > + int index = 0; > + while (size >= 1024 * 10 && suffixes[index + 1]) { > + size /= 1024; > + index++; > + } What about rounding? :-) Bye, Axel. From superstippi at gmx.de Sun Jul 13 19:44:13 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Sun, 13 Jul 2008 19:44:13 +0200 Subject: [Haiku-commits] r26395 - haiku/trunk/src/add-ons/kernel/drivers/graphics/vesa In-Reply-To: <1099236319-BeMail@zon> References: <1099236319-BeMail@zon> Message-ID: <20080713194413.707.1@stippis2.1215970573.fake> Axel D?rfler wrote: > stippi at mail.berlios.de wrote: > > + // Turn on write combining for the area > > + vm_set_area_memory_type(newFBArea, modeInfo.physical_base, > > B_MTR_WC); > > While this is not part of the public API, it's definitely easier to use > than the historical approach (ie. trying write combining first, and, if > that fails, try to create the same area without WC again). > > Anyway, did you change the resolution from a lower one to a higher one or > vice versa? In the second case, the current area should be reused, and > not recreated -- maybe that doesn't work correctly? I always used the native resolution. In another words, when the change Jan suggested was effective, there was appearantly another mode change to the same resolution as soon as app_server started. Hence the slowness. Since I have it working, I only switched to lower resolutions and back to the native one. Drawing had the correct speed now in all cases. I was also wondering if the area needed to be recreated at all, but I figured the code is working anyways. I guess I was lazy and just wanted the speed back... :-) Best regards, -Stephan From zooey at mail.berlios.de Sun Jul 13 21:58:36 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Sun, 13 Jul 2008 21:58:36 +0200 Subject: [Haiku-commits] r26405 - in haiku/trunk: headers/os/net src/kits/network src/kits/network/libnetapi src/tests/kits/net Message-ID: <200807131958.m6DJwaEn031820@sheep.berlios.de> Author: zooey Date: 2008-07-13 21:58:35 +0200 (Sun, 13 Jul 2008) New Revision: 26405 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26405&view=rev Added: haiku/trunk/src/tests/kits/net/NetEndpointTest.cpp Modified: haiku/trunk/headers/os/net/NetAddress.h haiku/trunk/headers/os/net/NetEndpoint.h haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp haiku/trunk/src/kits/network/libnetapi/NetEndpoint.cpp haiku/trunk/src/kits/network/socket.cpp haiku/trunk/src/tests/kits/net/Jamfile Log: Overhauled BNetEndpoint implementation (and BNetAddress, too): * added NetEndpointTest that exposed a couple of bugs * fixed several bugs in the implementation of BNetEndpoint, some of which kept NetPenguin from working * fixed a couple of constness issues in BNetEndpoint and BNetAddress Modified: haiku/trunk/headers/os/net/NetAddress.h =================================================================== --- haiku/trunk/headers/os/net/NetAddress.h 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/headers/os/net/NetAddress.h 2008-07-13 19:58:35 UTC (rev 26405) @@ -27,22 +27,28 @@ BNetAddress(in_addr addr, int port = 0); BNetAddress(uint32 addr, int port = 0); BNetAddress(const BNetAddress& other); - BNetAddress(const char* hostname, const char* protocol, const char* service); + BNetAddress(const char* hostname, const char* protocol, + const char* service); BNetAddress& operator=(const BNetAddress&); - status_t InitCheck(); + status_t InitCheck() const; - status_t SetTo(const char* hostname, const char* protocol, const char* service); + status_t SetTo(const char* hostname, const char* protocol, + const char* service); status_t SetTo(const char* hostname = NULL, unsigned short port = 0); status_t SetTo(const struct sockaddr_in& addr); status_t SetTo(in_addr addr, int port = 0); status_t SetTo(uint32 addr = INADDR_ANY, int port = 0); - status_t GetAddr(char* hostname = NULL, unsigned short* port = NULL) const; + status_t GetAddr(char* hostname = NULL, + unsigned short* port = NULL) const; status_t GetAddr(struct sockaddr_in& addr) const; status_t GetAddr(in_addr& addr, unsigned short* port = NULL) const; + // TODO: drop this compatibility cruft method after R1 + status_t InitCheck(); + private: virtual void _ReservedBNetAddressFBCCruft1(); virtual void _ReservedBNetAddressFBCCruft2(); Modified: haiku/trunk/headers/os/net/NetEndpoint.h =================================================================== --- haiku/trunk/headers/os/net/NetEndpoint.h 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/headers/os/net/NetEndpoint.h 2008-07-13 19:58:35 UTC (rev 26405) @@ -25,18 +25,19 @@ BNetEndpoint& operator=(const BNetEndpoint& other); - status_t InitCheck(); + status_t InitCheck() const; virtual status_t Archive(BMessage* into, bool deep = true) const; static BArchivable* Instantiate(BMessage* archive); status_t SetProtocol(int protocol); - int SetOption(int32 option, int32 level, const void* data, unsigned int dataSize); + int SetOption(int32 option, int32 level, const void* data, + unsigned int dataSize); int SetNonBlocking(bool on = true); int SetReuseAddr(bool on = true); - const BNetAddress& LocalAddr(); - const BNetAddress& RemoteAddr(); + const BNetAddress& LocalAddr() const; + const BNetAddress& RemoteAddr() const; int Socket() const; @@ -71,7 +72,14 @@ virtual bool IsDataPending(bigtime_t timeout = 0); + // TODO: drop these compatibility cruft methods after R1 + status_t InitCheck(); + const BNetAddress& LocalAddr(); + const BNetAddress& RemoteAddr(); + private: + status_t _SetupSocket(); + virtual void _ReservedBNetEndpointFBCCruft1(); virtual void _ReservedBNetEndpointFBCCruft2(); virtual void _ReservedBNetEndpointFBCCruft3(); @@ -79,14 +87,17 @@ virtual void _ReservedBNetEndpointFBCCruft5(); virtual void _ReservedBNetEndpointFBCCruft6(); - status_t fInit; + status_t fStatus; + int fFamily; + int fType; + int fProtocol; int fSocket; bigtime_t fTimeout; - int fLastError; BNetAddress fAddr; BNetAddress fPeer; - int32 _reserved[18]; + int32 _reserved[16]; }; + #endif // H_NETENDPOINT Modified: haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp =================================================================== --- haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/src/kits/network/libnetapi/NetAddress.cpp 2008-07-13 19:58:35 UTC (rev 26405) @@ -241,12 +241,18 @@ * Returns: * B_OK if this instance is initialized, B_ERROR if not. */ -status_t BNetAddress::InitCheck( void ) +status_t BNetAddress::InitCheck( void ) const { return ( fInit == B_OK ) ? B_OK : B_ERROR; } +status_t BNetAddress::InitCheck() +{ + return const_cast(this)->InitCheck(); +} + + /* Archive *=--------------------------------------------------------------------------=* * Purpose: Modified: haiku/trunk/src/kits/network/libnetapi/NetEndpoint.cpp =================================================================== --- haiku/trunk/src/kits/network/libnetapi/NetEndpoint.cpp 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/src/kits/network/libnetapi/NetEndpoint.cpp 2008-07-13 19:58:35 UTC (rev 26405) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ @@ -20,71 +20,87 @@ BNetEndpoint::BNetEndpoint(int type) : - fInit(B_NO_INIT), + fStatus(B_NO_INIT), + fFamily(AF_INET), + fType(type), + fProtocol(0), fSocket(-1), - fTimeout(B_INFINITE_TIMEOUT), - fLastError(0) + fTimeout(B_INFINITE_TIMEOUT) { - if ((fSocket = socket(AF_INET, type, 0)) < 0) - fLastError = errno; - else - fInit = B_OK; + _SetupSocket(); } BNetEndpoint::BNetEndpoint(int family, int type, int protocol) : - fInit(B_NO_INIT), + fStatus(B_NO_INIT), + fFamily(family), + fType(type), + fProtocol(protocol), fSocket(-1), - fTimeout(B_INFINITE_TIMEOUT), - fLastError(0) + fTimeout(B_INFINITE_TIMEOUT) { - if ((fSocket = socket(family, type, protocol)) < 0) - fLastError = errno; - else - fInit = B_OK; + _SetupSocket(); } BNetEndpoint::BNetEndpoint(BMessage* archive) : - fInit(B_NO_INIT), + fStatus(B_NO_INIT), + fFamily(AF_INET), + fProtocol(0), fSocket(-1), - fTimeout(B_INFINITE_TIMEOUT), - fLastError(0) + fTimeout(B_INFINITE_TIMEOUT) { - // TODO - if (! archive) + if (!archive) return; - BMessage msg; - if (archive->FindMessage("bnendp_peer", &msg) != B_OK) - return; - fPeer = BNetAddress(&msg); + in_addr addr, peer; + unsigned short addrPort = 0, peerPort = 0; + + fStatus = archive->FindInt32("_BNetEndpoint_addr_addr", + (int32 *)&addr.s_addr); + if (fStatus == B_OK) { + fStatus = archive->FindInt16("_BNetEndpoint_addr_port", + (int16 *)&addrPort); + if (fStatus == B_OK) + fStatus = fAddr.SetTo(addr, addrPort); + } + + fStatus = archive->FindInt32("_BNetEndpoint_peer_addr", + (int32 *)&peer.s_addr); + if (fStatus == B_OK) { + fStatus = archive->FindInt16("_BNetEndpoint_peer_port", + (int16 *)&peerPort); + if (fStatus == B_OK) + fStatus = fPeer.SetTo(peer, peerPort); + } - if (archive->FindMessage("bnendp_addr", &msg) != B_OK) - return; - fAddr = BNetAddress(&msg); + fStatus = archive->FindInt64("_BNetEndpoint_timeout", (int64 *)&fTimeout); + if (fStatus == B_OK) + fStatus = archive->FindInt32("_BNetEndpoint_proto", (int32 *)&fType); - fInit = B_OK; + if (fStatus == B_OK) + _SetupSocket(); } BNetEndpoint::BNetEndpoint(const BNetEndpoint& endpoint) : - fInit(endpoint.fInit), + fStatus(endpoint.fStatus), + fFamily(endpoint.fFamily), + fType(endpoint.fType), + fProtocol(endpoint.fProtocol), + fSocket(-1), fTimeout(endpoint.fTimeout), - fLastError(endpoint.fLastError), fAddr(endpoint.fAddr), fPeer(endpoint.fPeer) + { - fSocket = -1; if (endpoint.fSocket >= 0) { fSocket = dup(endpoint.fSocket); - if (fSocket < 0) { - fLastError = errno; - fInit = B_NO_INIT; - } + if (fSocket < 0) + fStatus = errno; } } @@ -92,21 +108,24 @@ BNetEndpoint& BNetEndpoint::operator=(const BNetEndpoint& endpoint) { + if (this == &endpoint) + return *this; + Close(); - fInit = endpoint.fInit; + fStatus = endpoint.fStatus; + fFamily = endpoint.fFamily; + fType = endpoint.fType; + fProtocol = endpoint.fProtocol; fTimeout = endpoint.fTimeout; - fLastError = endpoint.fLastError; fAddr = endpoint.fAddr; fPeer = endpoint.fPeer; fSocket = -1; if (endpoint.fSocket >= 0) { fSocket = dup(endpoint.fSocket); - if (fSocket < 0) { - fLastError = errno; - fInit = B_NO_INIT; - } + if (fSocket < 0) + fStatus = errno; } return *this; @@ -115,7 +134,8 @@ BNetEndpoint::~BNetEndpoint() { - Close(); + if (fSocket >= 0) + Close(); } @@ -125,25 +145,38 @@ status_t BNetEndpoint::Archive(BMessage* into, bool deep) const { - // TODO - if (into == 0) + if (!into) return B_ERROR; - if (fInit != B_OK) - return B_NO_INIT; + status_t status = BArchivable::Archive(into, deep); + if (status != B_OK) + return status; - BMessage msg; - if (fPeer.Archive(&msg) != B_OK) - return B_ERROR; - if (into->AddMessage("bnendp_peer", &msg) != B_OK) - return B_ERROR; + in_addr addr, peer; + unsigned short addrPort, peerPort; - if (fAddr.Archive(&msg) != B_OK) - return B_ERROR; - if (into->AddMessage("bnendp_addr", &msg) != B_OK) - return B_ERROR; + status = fAddr.GetAddr(addr, &addrPort); + if (status == B_OK) { + status = into->AddInt32("_BNetEndpoint_addr_addr", addr.s_addr); + if (status == B_OK) + status = into->AddInt16("_BNetEndpoint_addr_port", addrPort); + if (status != B_OK) + return status; + } + status = fPeer.GetAddr(peer, &peerPort); + if (status == B_OK) { + status = into->AddInt32("_BNetEndpoint_peer_addr", peer.s_addr); + if (status == B_OK) + status = into->AddInt16("_BNetEndpoint_peer_port", peerPort); + if (status != B_OK) + return status; + } - return B_OK; + status = into->AddInt64("_BNetEndpoint_timeout", fTimeout); + if (status == B_OK) + status = into->AddInt32("_BNetEndpoint_proto", fType); + + return status; } @@ -153,7 +186,7 @@ if (!archive) return NULL; - if (!validate_instantiation(archive, "BNetAddress")) + if (!validate_instantiation(archive, "BNetEndpoint")) return NULL; BNetEndpoint* endpoint = new BNetEndpoint(archive); @@ -169,9 +202,9 @@ status_t -BNetEndpoint::InitCheck() +BNetEndpoint::InitCheck() const { - return fInit; + return fSocket == -1 ? B_NO_INIT : B_OK; } @@ -183,14 +216,14 @@ const BNetAddress& -BNetEndpoint::LocalAddr() +BNetEndpoint::LocalAddr() const { return fAddr; } const BNetAddress& -BNetEndpoint::RemoteAddr() +BNetEndpoint::RemoteAddr() const { return fPeer; } @@ -200,12 +233,8 @@ BNetEndpoint::SetProtocol(int protocol) { Close(); - if ((fSocket = socket(AF_INET, protocol, 0)) < 0) { - fLastError = errno; - return fLastError; - } - fInit = B_OK; - return fInit; + fType = protocol; // sic (protocol is SOCK_DGRAM or SOCK_STREAM) + return _SetupSocket(); } @@ -213,11 +242,11 @@ BNetEndpoint::SetOption(int32 option, int32 level, const void* data, unsigned int length) { - if (fInit < B_OK) - return fInit; + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; if (setsockopt(fSocket, level, option, data, length) < 0) { - fLastError = errno; + fStatus = errno; return B_ERROR; } @@ -228,9 +257,12 @@ int BNetEndpoint::SetNonBlocking(bool enable) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + int flags = fcntl(fSocket, F_GETFL); if (flags < 0) { - fLastError = errno; + fStatus = errno; return B_ERROR; } @@ -240,7 +272,7 @@ flags &= ~O_NONBLOCK; if (fcntl(fSocket, F_SETFL, flags) < 0) { - fLastError = errno; + fStatus = errno; return B_ERROR; } @@ -251,6 +283,9 @@ int BNetEndpoint::SetReuseAddr(bool enable) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + int onoff = (int) enable; return SetOption(SO_REUSEADDR, SOL_SOCKET, &onoff, sizeof(onoff)); } @@ -266,14 +301,14 @@ int BNetEndpoint::Error() const { - return fLastError; + return (int)fStatus; } char* BNetEndpoint::ErrorStr() const { - return strerror(fLastError); + return strerror(fStatus); } @@ -287,15 +322,15 @@ close(fSocket); fSocket = -1; - fInit = B_NO_INIT; + fStatus = B_NO_INIT; } status_t BNetEndpoint::Bind(const BNetAddress& address) { - if (fInit < B_OK) - return fInit; + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; struct sockaddr_in addr; status_t status = address.GetAddr(addr); @@ -303,28 +338,18 @@ return status; if (bind(fSocket, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - fLastError = errno; + fStatus = errno; Close(); return B_ERROR; } socklen_t addrSize = sizeof(addr); if (getsockname(fSocket, (struct sockaddr *)&addr, &addrSize) < 0) { - fLastError = errno; + fStatus = errno; Close(); return B_ERROR; } - if (addr.sin_addr.s_addr == 0) { - // TODO: does this still apply? - // Grrr, buggy getsockname! - char hostname[MAXHOSTNAMELEN]; - gethostname(hostname, sizeof(hostname)); - struct hostent *host = gethostbyname(hostname); - if (host != NULL) - memcpy(&addr.sin_addr.s_addr, host->h_addr, sizeof(addr.sin_addr.s_addr)); - } - fAddr.SetTo(addr); return B_OK; } @@ -341,8 +366,8 @@ status_t BNetEndpoint::Connect(const BNetAddress& address) { - if (fInit < B_OK) - return fInit; + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; sockaddr_in addr; if (address.GetAddr(addr) != B_OK) @@ -350,17 +375,16 @@ if (connect(fSocket, (sockaddr *) &addr, sizeof(addr)) < 0) { Close(); - fLastError = errno; + fStatus = errno; return B_ERROR; } socklen_t addrSize = sizeof(addr); if (getpeername(fSocket, (sockaddr *) &addr, &addrSize) < 0) { Close(); - fLastError = errno; + fStatus = errno; return B_ERROR; } - fPeer.SetTo(addr); return B_OK; } @@ -377,12 +401,12 @@ status_t BNetEndpoint::Listen(int backlog) { - if (fInit < B_OK) - return fInit; + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; if (listen(fSocket, backlog) < 0) { Close(); - fLastError = errno; + fStatus = errno; return B_ERROR; } return B_OK; @@ -401,14 +425,14 @@ int socket = accept(fSocket, (struct sockaddr *) &addr, &addrSize); if (socket < 0) { Close(); - fLastError = errno; + fStatus = errno; return NULL; } BNetEndpoint* endpoint = new (std::nothrow) BNetEndpoint(*this); if (endpoint == NULL) { close(socket); - fLastError = B_NO_MEMORY; + fStatus = B_NO_MEMORY; return NULL; } @@ -417,7 +441,7 @@ if (getsockname(socket, (struct sockaddr *)&addr, &addrSize) < 0) { delete endpoint; - fLastError = errno; + fStatus = errno; return NULL; } @@ -444,7 +468,7 @@ } if (select(fSocket + 1, &fds, NULL, NULL, timeout > 0 ? &tv : NULL) < 0) { - fLastError = errno; + fStatus = errno; return false; } @@ -455,12 +479,15 @@ int32 BNetEndpoint::Receive(void* buffer, size_t length, int flags) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + if (fTimeout >= 0 && IsDataPending(fTimeout) == false) return 0; ssize_t bytesReceived = recv(fSocket, buffer, length, flags); if (bytesReceived < 0) - fLastError = errno; + fStatus = errno; return bytesReceived; } @@ -480,6 +507,9 @@ BNetEndpoint::ReceiveFrom(void* buffer, size_t length, BNetAddress& address, int flags) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + if (fTimeout >= 0 && IsDataPending(fTimeout) == false) return 0; @@ -489,7 +519,7 @@ length = recvfrom(fSocket, buffer, length, flags, (struct sockaddr *)&addr, &addrSize); if (length < 0) - fLastError = errno; + fStatus = errno; else address.SetTo(addr); @@ -511,9 +541,12 @@ int32 BNetEndpoint::Send(const void* buffer, size_t length, int flags) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + ssize_t bytesSent = send(fSocket, (const char *) buffer, length, flags); if (bytesSent < 0) - fLastError = errno; + fStatus = errno; return bytesSent; } @@ -530,6 +563,9 @@ BNetEndpoint::SendTo(const void* buffer, size_t length, const BNetAddress& address, int flags) { + if (fSocket < 0 && _SetupSocket() != B_OK) + return fStatus; + struct sockaddr_in addr; if (address.GetAddr(addr) != B_OK) return B_ERROR; @@ -537,7 +573,7 @@ ssize_t bytesSent = sendto(fSocket, buffer, length, flags, (struct sockaddr *) &addr, sizeof(addr)); if (bytesSent < 0) - fLastError = errno; + fStatus = errno; return bytesSent; } @@ -554,6 +590,40 @@ // #pragma mark - +status_t +BNetEndpoint::_SetupSocket() +{ + if ((fSocket = socket(fFamily, fType, fProtocol)) < 0) + fStatus = errno; + else + fStatus = B_OK; + return fStatus; +} + + +// #pragma mark - + +status_t BNetEndpoint::InitCheck() +{ + return const_cast(this)->InitCheck(); +} + + +const BNetAddress& BNetEndpoint::LocalAddr() +{ + return const_cast(this)->LocalAddr(); +} + + +const BNetAddress& BNetEndpoint::RemoteAddr() +{ + return const_cast(this)->RemoteAddr(); +} + + +// #pragma mark - + + // These are virtuals, implemented for binary compatibility purpose void BNetEndpoint::_ReservedBNetEndpointFBCCruft1() {} void BNetEndpoint::_ReservedBNetEndpointFBCCruft2() {} Modified: haiku/trunk/src/kits/network/socket.cpp =================================================================== --- haiku/trunk/src/kits/network/socket.cpp 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/src/kits/network/socket.cpp 2008-07-13 19:58:35 UTC (rev 26405) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2002-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ Modified: haiku/trunk/src/tests/kits/net/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/net/Jamfile 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/src/tests/kits/net/Jamfile 2008-07-13 19:58:35 UTC (rev 26405) @@ -17,6 +17,9 @@ SimpleTest NetAddressTest : NetAddressTest.cpp : $(TARGET_NETWORK_LIBS) $(HAIKU_NETAPI_LIB) ; +SimpleTest NetEndpointTest : NetEndpointTest.cpp + : $(TARGET_NETWORK_LIBS) $(HAIKU_NETAPI_LIB) be ; + SubInclude HAIKU_TOP src tests kits net DialUpPreflet ; SubInclude HAIKU_TOP src tests kits net multicast ; SubInclude HAIKU_TOP src tests kits net netperf ; Added: haiku/trunk/src/tests/kits/net/NetEndpointTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/net/NetEndpointTest.cpp 2008-07-13 12:52:05 UTC (rev 26404) +++ haiku/trunk/src/tests/kits/net/NetEndpointTest.cpp 2008-07-13 19:58:35 UTC (rev 26405) @@ -0,0 +1,352 @@ +/* + * Copyright 2008, Oliver Tappe, zooey at hirschkaefer.de. + * Distributed under the terms of the MIT license. + */ + + +#include +#include + +#include +#include +#include +#include +#include +#include + + +static BNetAddress serverAddr("127.0.0.1", 1234); +static BNetAddress clientAddr("127.0.0.1", 51234); + + +static int problemCount = 0; + + +void +checkAddrsAreEqual(const BNetAddress& na1, const BNetAddress& na2, + const char* fmt) +{ + in_addr addr1, addr2; + unsigned short port1, port2; + na1.GetAddr(addr1, &port1); + na2.GetAddr(addr2, &port2); + if (addr1.s_addr == addr2.s_addr && port1 == port2) + return; + fprintf(stderr, fmt, addr1.s_addr, port1, addr2.s_addr, port2); + exit(1); +} + + +void +checkArchive(const BNetEndpoint ne, int32 protocol, + const BNetAddress& localNetAddress, const BNetAddress& remoteNetAddress) +{ + in_addr localAddr, remoteAddr; + unsigned short localPort, remotePort; + localNetAddress.GetAddr(localAddr, &localPort); + remoteNetAddress.GetAddr(remoteAddr, &remotePort); + + BMessage archive(0UL); + status_t status = ne.Archive(&archive); + if (status != B_OK) { + fprintf(stderr, "Archive() failed - %lx:%s\n", status, + strerror(status)); + problemCount++; + exit(1); + } + const char* arcClass; + if (archive.FindString("class", &arcClass) != B_OK) { + fprintf(stderr, "'class' not found in archive\n"); + problemCount++; + exit(1); + } + if (strcmp(arcClass, "BNetEndpoint") != 0) { + fprintf(stderr, "expected 'class' to be 'BNetEndpoint' - is '%s'\n", + arcClass); + problemCount++; + exit(1); + } + + if (ne.LocalAddr().InitCheck() == B_OK) { + int32 arcAddr; + if (archive.FindInt32("_BNetEndpoint_addr_addr", &arcAddr) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_addr_addr' not found in archive\n"); + problemCount++; + exit(1); + } + if ((uint32)localAddr.s_addr != (uint32)arcAddr) { + fprintf(stderr, + "expected '_BNetEndpoint_addr_addr' to be %x - is %x\n", + localAddr.s_addr, (unsigned int)arcAddr); + problemCount++; + exit(1); + } + int16 arcPort; + if (archive.FindInt16("_BNetEndpoint_addr_port", &arcPort) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_addr_port' not found in archive\n"); + problemCount++; + exit(1); + } + if ((uint16)localPort != (uint16)arcPort) { + fprintf(stderr, + "expected '_BNetEndpoint_addr_port' to be %d - is %d\n", + localPort, (int)arcPort); + problemCount++; + exit(1); + } + } + + if (ne.RemoteAddr().InitCheck() == B_OK) { + int32 arcAddr; + if (archive.FindInt32("_BNetEndpoint_peer_addr", &arcAddr) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_peer_addr' not found in archive\n"); + problemCount++; + exit(1); + } + if ((uint32)remoteAddr.s_addr != (uint32)arcAddr) { + fprintf(stderr, + "expected '_BNetEndpoint_peer_addr' to be %x - is %x\n", + remoteAddr.s_addr, (unsigned int)arcAddr); + problemCount++; + exit(1); + } + int16 arcPort; + if (archive.FindInt16("_BNetEndpoint_peer_port", &arcPort) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_peer_port' not found in archive\n"); + problemCount++; + exit(1); + } + if ((uint16)remotePort != (uint16)arcPort) { + fprintf(stderr, + "expected '_BNetEndpoint_peer_port' to be %u - is %u\n", + remotePort, (unsigned short)arcPort); + problemCount++; + exit(1); + } + } + + int64 arcTimeout; + if (archive.FindInt64("_BNetEndpoint_timeout", &arcTimeout) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_timeout' not found in archive\n"); + problemCount++; + exit(1); + } + if (arcTimeout != B_INFINITE_TIMEOUT) { + fprintf(stderr, + "expected '_BNetEndpoint_timeout' to be %llu - is %llu\n", + B_INFINITE_TIMEOUT, (uint64)arcTimeout); + problemCount++; + exit(1); + } + + int32 arcProtocol; + if (archive.FindInt32("_BNetEndpoint_proto", &arcProtocol) != B_OK) { + fprintf(stderr, "'_BNetEndpoint_proto' not found in archive\n"); + problemCount++; + exit(1); + } + if (arcProtocol != protocol) { + fprintf(stderr, "expected '_BNetEndpoint_proto' to be %d - is %d\n", + (int)protocol, (int)arcProtocol); + problemCount++; + exit(1); + } + + BNetEndpoint* clone + = dynamic_cast(BNetEndpoint::Instantiate(&archive)); + if (!clone) { + fprintf(stderr, "unable to instantiate endpoint from archive\n"); + problemCount++; + exit(1); + } + delete clone; +} + +void testServer(thread_id clientThread) +{ + char buf[1]; + + // check simple UDP "connection" + BNetEndpoint server(SOCK_DGRAM); + for(int i=0; i < 2; ++i) { + status_t status = server.Bind(serverAddr); + if (status != B_OK) { + fprintf(stderr, "Bind() failed in testServer - %s\n", + strerror(status)); + problemCount++; + exit(1); + } + + checkAddrsAreEqual(server.LocalAddr(), serverAddr, + "LocalAddr() doesn't match serverAddr\n"); + + if (i == 0) + resume_thread(clientThread); + + BNetAddress remoteAddr; + status = server.ReceiveFrom(buf, 1, remoteAddr, 0); + if (status < B_OK) { + fprintf(stderr, "ReceiveFrom() failed in testServer - %s\n", + strerror(status)); + problemCount++; + exit(1); + } + + if (buf[0] != 'U') { + fprintf(stderr, "expected to receive %c but got %c\n", 'U', buf[0]); + problemCount++; + exit(1); + } + + checkAddrsAreEqual(remoteAddr, clientAddr, + "remoteAddr(%x:%d) doesn't match clientAddr(%x:%d)\n"); + + checkArchive(server, SOCK_DGRAM, serverAddr, clientAddr); + + server.Close(); + } + + // now switch to TCP and try again + server.SetProtocol(SOCK_STREAM); + status_t status = server.Bind(serverAddr); + if (status != B_OK) { + fprintf(stderr, "Bind() failed in testServer - %s\n", + strerror(status)); + problemCount++; + exit(1); + } + + checkAddrsAreEqual(server.LocalAddr(), serverAddr, + "LocalAddr() doesn't match serverAddr\n"); + + status = server.Listen(); + BNetEndpoint* acceptedConn = server.Accept(); + if (acceptedConn == NULL) { + fprintf(stderr, "Accept() failed in testServer\n"); + problemCount++; + exit(1); + } + + const BNetAddress& remoteAddr = acceptedConn->RemoteAddr(); + checkAddrsAreEqual(remoteAddr, clientAddr, + "remoteAddr(%x:%d) doesn't match clientAddr(%x:%d)\n"); + + status = acceptedConn->Receive(buf, 1); + if (status < B_OK) { + fprintf(stderr, "Receive() failed in testServer - %s\n", + strerror(status)); + problemCount++; + exit(1); + } + delete acceptedConn; + + if (buf[0] != 'T') { + fprintf(stderr, "expected to receive %c but got %c\n", 'T', buf[0]); + problemCount++; + exit(1); + } + + checkArchive(server, SOCK_STREAM, serverAddr, clientAddr); + + server.Close(); +} [... truncated: 101 lines follow ...] From julun at mail.berlios.de Sun Jul 13 22:42:15 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 13 Jul 2008 22:42:15 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface Message-ID: <200807132042.m6DKgFeP006540@sheep.berlios.de> Author: julun Date: 2008-07-13 22:42:14 +0200 (Sun, 13 Jul 2008) New Revision: 26406 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26406&view=rev Modified: haiku/trunk/src/kits/interface/PopUpMenu.cpp Log: * only delete the popupmenu if we running the async version of BPopUpMenu This fixes part 3 of task #1987, TaskManager was using the syncronous version of of BPopUpMenu wrapped in it's own class to run asyncronous. It did set SetAsyncAutoDestruct to true and afterwards calling delete an the already deleted menu. Modified: haiku/trunk/src/kits/interface/PopUpMenu.cpp =================================================================== --- haiku/trunk/src/kits/interface/PopUpMenu.cpp 2008-07-13 19:58:35 UTC (rev 26405) +++ haiku/trunk/src/kits/interface/PopUpMenu.cpp 2008-07-13 20:42:14 UTC (rev 26406) @@ -63,7 +63,7 @@ if (fTrackThread >= 0) { status_t status; while (wait_for_thread(fTrackThread, &status) == B_INTERRUPTED) - ; + ; } } @@ -273,7 +273,7 @@ sem_id sem = create_sem(0, "window close lock"); if (sem < B_OK) { delete data; - return NULL; + return NULL; } // Get a pointer to the window from which Go() was called @@ -284,7 +284,7 @@ // and let BWindow block when needed if (async && window != NULL) { _set_menu_sem_(window, sem); - } + } data->object = this; data->autoInvoke = autoInvoke; @@ -298,7 +298,7 @@ data->lock = sem; // Spawn the tracking thread - fTrackThread = spawn_thread(_thread_entry, "popup", B_DISPLAY_PRIORITY, data); + fTrackThread = spawn_thread(_thread_entry, "popup", B_DISPLAY_PRIORITY, data); if (fTrackThread < B_OK) { // Something went wrong. Cleanup and return NULL delete_sem(sem); @@ -322,22 +322,22 @@ BPopUpMenu::_thread_entry(void *arg) { popup_menu_data *data = static_cast(arg); - BPopUpMenu *menu = data->object; + BPopUpMenu *menu = data->object; BRect *rect = NULL; - + if (data->useRect) rect = &data->rect; data->selected = menu->_StartTrack(data->where, data->autoInvoke, data->startOpened, rect); - // Reset the window menu semaphore + // Reset the window menu semaphore if (data->async && data->window) _set_menu_sem_(data->window, B_BAD_SEM_ID); delete_sem(data->lock); - // Commit suicide if needed - if (menu->fAutoDestruct) { + // Commit suicide if needed + if (data->async && menu->fAutoDestruct) { menu->fTrackThread = -1; delete menu; } @@ -388,13 +388,13 @@ status_t unused; while (wait_for_thread(fTrackThread, &unused) == B_INTERRUPTED) ; - + fTrackThread = -1; - + BMenuItem *selected = data->selected; // data->selected is filled by the tracking thread - + delete data; - + return selected; } From revol at free.fr Sun Jul 13 23:36:30 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Sun, 13 Jul 2008 23:36:30 +0200 CEST Subject: [Haiku-commits] r26394 - haiku/trunk/src/apps/mediaplayer In-Reply-To: <200807121750.m6CHo8tx025077@sheep.berlios.de> Message-ID: <8896457040-BeMail@laptop> > Author: stippi > Date: 2008-07-12 19:50:05 +0200 (Sat, 12 Jul 2008) > New Revision: 26394 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26394&view=rev > > Modified: > haiku/trunk/src/apps/mediaplayer/InfoWin.cpp > Log: > The info window is not zoomable. (Fixes #2436.) Btw I'm still not happy with the way I wrote it. I wanted to try using a ListView to make sure stuff would stay aligned with their labels... feel free to do. Fran?ois. From julun at mail.berlios.de Sun Jul 13 23:47:20 2008 From: julun at mail.berlios.de (julun at BerliOS) Date: Sun, 13 Jul 2008 23:47:20 +0200 Subject: [Haiku-commits] r26407 - haiku/trunk/src/add-ons/print/drivers/pdf/source Message-ID: <200807132147.m6DLlKsB012221@sheep.berlios.de> Author: julun Date: 2008-07-13 23:47:20 +0200 (Sun, 13 Jul 2008) New Revision: 26407 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26407&view=rev Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp Log: * hide the license key field as it is only supported in the commercial pdflib version Modified: haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp =================================================================== --- haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp 2008-07-13 20:42:14 UTC (rev 26406) +++ haiku/trunk/src/add-ons/print/drivers/pdf/source/AdvancedSettingsWindow.cpp 2008-07-13 21:47:20 UTC (rev 26407) @@ -97,12 +97,15 @@ fLicenseKey->SetEnabled(false); fLicenseKey->ResizeToPreferred(); fLicenseKey->SetDivider(divider); - //fLicenseKey->TextView()->HideTyping(true); + fLicenseKey->TextView()->HideTyping(true); fLicenseKey->TextView()->SetText(licenseKey.String()); + // Hide the license key field as it is only supported in the commercial + // version of of pdflib. Leave it here for layout atm. + fLicenseKey->Hide(); // border link - bounds.OffsetBy(0.0, fLicenseKey->Bounds().Height() + 10.0); + // bounds.OffsetBy(0.0, fLicenseKey->Bounds().Height() + 10.0); BPopUpMenu* m = new BPopUpMenu("Link Border"); m->SetRadioMode(true); @@ -329,7 +332,7 @@ AdvancedSettingsWindow::_UpdateSettings() { #if 0 - AddString(fSettings, "pdflib_license_key", fLicenseKey); + SetString(fSettings, "pdflib_license_key", fLicenseKey); #endif SetInt32(fSettings, "close_option", fCloseOption); From ingo_weinhold at gmx.de Sun Jul 13 23:48:36 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Sun, 13 Jul 2008 23:48:36 +0200 Subject: [Haiku-commits] r26403 - in haiku/trunk: headers/os/drivers src/system/kernel/disk_device_manager In-Reply-To: <2230629549-BeMail@zon> References: <2230629549-BeMail@zon> Message-ID: <20080713234836.847.8@knochen-vm.nameserver> On 2008-07-13 at 18:47:29 [+0200], Axel D?rfler wrote: > bonefish at mail.berlios.de wrote: > > + int index = 0; > > + while (size >= 1024 * 10 && suffixes[index + 1]) { > > + size /= 1024; > > + index++; > > + } > > What about rounding? :-) Could be done, but unless I miss an obvious solution it makes things quite a bit more complicated to do it correctly. CU, Ingo From stefano.ceccherini at gmail.com Mon Jul 14 08:45:31 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Mon, 14 Jul 2008 08:45:31 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <200807132042.m6DKgFeP006540@sheep.berlios.de> References: <200807132042.m6DKgFeP006540@sheep.berlios.de> Message-ID: <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> 2008/7/13 julun at BerliOS : > Author: julun > Date: 2008-07-13 22:42:14 +0200 (Sun, 13 Jul 2008) > New Revision: 26406 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26406&view=rev > > Modified: > haiku/trunk/src/kits/interface/PopUpMenu.cpp > Log: > * only delete the popupmenu if we running the async version of BPopUpMenu > > This fixes part 3 of task #1987, TaskManager was using the syncronous version of > of BPopUpMenu wrapped in it's own class to run asyncronous. It did set SetAsyncAutoDestruct > to true and afterwards calling delete an the already deleted menu. Who does this ? If it's TaskManager, it's a bug, and should be fixed there. Please revert this, otherwise we'll leak the PopUpMenu if used synchronously. From axeld at pinc-software.de Mon Jul 14 08:46:23 2008 From: axeld at pinc-software.de (Axel =?utf-8?q?D=C3=B6rfler?=) Date: Mon, 14 Jul 2008 08:46:23 +0200 CEST Subject: [Haiku-commits] r26403 - in haiku/trunk: headers/os/drivers src/system/kernel/disk_device_manager In-Reply-To: <20080713234836.847.8@knochen-vm.nameserver> Message-ID: <1723939622-BeMail@zon> Ingo Weinhold wrote: > On 2008-07-13 at 18:47:29 [+0200], Axel D?rfler > > wrote: > > bonefish at mail.berlios.de wrote: > > > + int index = 0; > > > + while (size >= 1024 * 10 && suffixes[index + 1]) { > > > + size /= 1024; > > > + index++; > > > + } > > What about rounding? :-) > Could be done, but unless I miss an obvious solution it makes things > quite > a bit more complicated to do it correctly. It's just because Tracker uses rounding when creating the labels -- so the entry in the mount menu could differ from the volume label once mounted. Bye, Axel. From HOST.HAIKU at gmx.de Mon Jul 14 10:46:03 2008 From: HOST.HAIKU at gmx.de (Julun) Date: Mon, 14 Jul 2008 10:46:03 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> References: <200807132042.m6DKgFeP006540@sheep.berlios.de> <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> Message-ID: <487B124B.9090400@gmx.de> Hi Stefano, Stefano Ceccherini schrieb: > 2008/7/13 julun at BerliOS : >> Author: julun >> Date: 2008-07-13 22:42:14 +0200 (Sun, 13 Jul 2008) >> New Revision: 26406 >> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26406&view=rev >> >> Modified: >> haiku/trunk/src/kits/interface/PopUpMenu.cpp >> Log: >> * only delete the popupmenu if we running the async version of BPopUpMenu >> >> This fixes part 3 of task #1987, TaskManager was using the syncronous version of >> of BPopUpMenu wrapped in it's own class to run asyncronous. It did set SetAsyncAutoDestruct >> to true and afterwards calling delete an the already deleted menu. > > Who does this ? If it's TaskManager, it's a bug, and should be fixed there. > Please revert this, otherwise we'll leak the PopUpMenu if used synchronously. i did it as well on R5, to be sure the behavior i introduce is the right one. I know the Be-Book does not state that calling SetAsyncAutoDestruct on the synchronous version of BPopUpMenu doesn't do anything, but my test app and BeTaskManager work properly doing this on R5 and fail on Haiku. I would even go that far and claim the name SetAsyncAutoDestruct(...) implies that it sets auto destruction mode for the async version, otherwise they would have called it SetAutoDestruct(...). Anyway, if you think we should go with the previous behavior, feel free to revert the change. :) Regards, Karsten From stefano.ceccherini at gmail.com Mon Jul 14 12:08:03 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Mon, 14 Jul 2008 12:08:03 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <487B124B.9090400@gmx.de> References: <200807132042.m6DKgFeP006540@sheep.berlios.de> <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> <487B124B.9090400@gmx.de> Message-ID: <894b9700807140308l5c0742cbq3b5c8ddd4dd277ca@mail.gmail.com> 2008/7/14 Julun : > Hi Stefano, > > Stefano Ceccherini schrieb: >> 2008/7/13 julun at BerliOS : >>> Author: julun >>> Date: 2008-07-13 22:42:14 +0200 (Sun, 13 Jul 2008) >>> New Revision: 26406 >>> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26406&view=rev >>> >>> Modified: >>> haiku/trunk/src/kits/interface/PopUpMenu.cpp >>> Log: >>> * only delete the popupmenu if we running the async version of BPopUpMenu >>> >>> This fixes part 3 of task #1987, TaskManager was using the syncronous version of >>> of BPopUpMenu wrapped in it's own class to run asyncronous. It did set SetAsyncAutoDestruct >>> to true and afterwards calling delete an the already deleted menu. >> >> Who does this ? If it's TaskManager, it's a bug, and should be fixed there. >> Please revert this, otherwise we'll leak the PopUpMenu if used synchronously. > > i did it as well on R5, to be sure the behavior i introduce is the right > one. I know the Be-Book does not state that calling SetAsyncAutoDestruct > on the synchronous version of BPopUpMenu doesn't do anything, but my > test app and BeTaskManager work properly doing this on R5 and fail on Haiku. Yes, but that could be because in certain cases, deleting an already deleted item does not fail on R5. It does on haiku, though. If BeTaskManager sets that flag, why does it call delete on the menu afterwards ? > > I would even go that far and claim the name SetAsyncAutoDestruct(...) > implies that it sets auto destruction mode for the async version, > otherwise they would have called it SetAutoDestruct(...). Indeed, but that could mean it autodestructs asynchronously, not it does autodestruct only if asynchronously, no ? :) > Anyway, if you > think we should go with the previous behavior, feel free to revert the > change. :) From HOST.HAIKU at gmx.de Mon Jul 14 13:56:03 2008 From: HOST.HAIKU at gmx.de (Julun) Date: Mon, 14 Jul 2008 13:56:03 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <894b9700807140308l5c0742cbq3b5c8ddd4dd277ca@mail.gmail.com> References: <200807132042.m6DKgFeP006540@sheep.berlios.de> <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> <487B124B.9090400@gmx.de> <894b9700807140308l5c0742cbq3b5c8ddd4dd277ca@mail.gmail.com> Message-ID: <487B3ED3.8030002@gmx.de> Hi Stefano, Stefano Ceccherini schrieb: > 2008/7/14 Julun : >> Hi Stefano, >> >> Stefano Ceccherini schrieb: >>> 2008/7/13 julun at BerliOS : >>>> Author: julun >>>> Date: 2008-07-13 22:42:14 +0200 (Sun, 13 Jul 2008) >>>> New Revision: 26406 >>>> ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26406&view=rev >>>> >>>> Modified: >>>> haiku/trunk/src/kits/interface/PopUpMenu.cpp >>>> Log: >>>> * only delete the popupmenu if we running the async version of BPopUpMenu >>>> >>>> This fixes part 3 of task #1987, TaskManager was using the syncronous version of >>>> of BPopUpMenu wrapped in it's own class to run asyncronous. It did set SetAsyncAutoDestruct >>>> to true and afterwards calling delete an the already deleted menu. >>> Who does this ? If it's TaskManager, it's a bug, and should be fixed there. >>> Please revert this, otherwise we'll leak the PopUpMenu if used synchronously. >> i did it as well on R5, to be sure the behavior i introduce is the right >> one. I know the Be-Book does not state that calling SetAsyncAutoDestruct >> on the synchronous version of BPopUpMenu doesn't do anything, but my >> test app and BeTaskManager work properly doing this on R5 and fail on Haiku. > > Yes, but that could be because in certain cases, deleting an already > deleted item does not fail on R5. It does on haiku, though. > If BeTaskManager sets that flag, why does it call delete on the menu > afterwards ? Well, i don't know why it's implemented like this. We propably have to ask him. :) If you like you can get the source from: http://www.3rd-evolution.de/BeOS/TaskMgr/index.html The interesting parts are AsynchronousPopUpMenu.h/cpp, DeskbarLedView.h/cpp starting at line 254 and GraphView.h/cpp starting at line 1361. Regards, Karsten From leavengood at mail.berlios.de Mon Jul 14 18:41:24 2008 From: leavengood at mail.berlios.de (leavengood at BerliOS) Date: Mon, 14 Jul 2008 18:41:24 +0200 Subject: [Haiku-commits] r26408 - haiku/trunk/src/apps/midiplayer Message-ID: <200807141641.m6EGfOIx020371@sheep.berlios.de> Author: leavengood Date: 2008-07-14 18:41:21 +0200 (Mon, 14 Jul 2008) New Revision: 26408 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26408&view=rev Modified: haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp haiku/trunk/src/apps/midiplayer/ScopeView.cpp Log: CHANGED the MidiPlayer GUI to use the layout system, mostly for the purposes of the article I am writing, though it really did need this change. Modified: haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp =================================================================== --- haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp 2008-07-13 21:47:20 UTC (rev 26407) +++ haiku/trunk/src/apps/midiplayer/MidiPlayerWindow.cpp 2008-07-14 16:41:21 UTC (rev 26408) @@ -20,9 +20,13 @@ * DEALINGS IN THE SOFTWARE. */ +#include +#include +#include #include #include #include +#include #include "MidiPlayerApp.h" #include "MidiPlayerWindow.h" @@ -36,7 +40,7 @@ MidiPlayerWindow::MidiPlayerWindow() : BWindow(BRect(0, 0, 1, 1), "MidiPlayer", B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE) + B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { playing = false; scopeEnabled = true; @@ -188,12 +192,7 @@ inputPopUp->AddItem(inputOff); - inputMenu = new BMenuField( - BRect(0, 0, 128, 17), "inputMenu", "Live Input:", inputPopUp, - B_FOLLOW_LEFT | B_FOLLOW_TOP); - - inputMenu->SetDivider(55); - inputMenu->ResizeToPreferred(); + inputMenu = new BMenuField("Live Input:", inputPopUp, NULL); } //------------------------------------------------------------------------------ @@ -227,26 +226,20 @@ reverbPopUp->AddItem(reverbCavern); reverbPopUp->AddItem(reverbDungeon); - reverbMenu = new BMenuField( - BRect(0, 0, 128, 17), "reverbMenu", "Reverb:", reverbPopUp, - B_FOLLOW_LEFT | B_FOLLOW_TOP); - - reverbMenu->SetDivider(55); - reverbMenu->ResizeToPreferred(); + reverbMenu = new BMenuField("Reverb:", reverbPopUp, NULL); } //------------------------------------------------------------------------------ void MidiPlayerWindow::CreateViews() { + // Set up needed views scopeView = new ScopeView; showScope = new BCheckBox( BRect(0, 0, 1, 1), "showScope", "Scope", new BMessage(MSG_SHOW_SCOPE), B_FOLLOW_LEFT); - showScope->SetValue(B_CONTROL_ON); - showScope->ResizeToPreferred(); CreateInputMenu(); CreateReverbMenu(); @@ -254,83 +247,52 @@ volumeSlider = new BSlider( BRect(0, 0, 1, 1), "volumeSlider", NULL, NULL, 0, 100, B_TRIANGLE_THUMB); - rgb_color col = { 152, 152, 255 }; volumeSlider->UseFillColor(true, &col); volumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME)); - volumeSlider->ResizeToPreferred(); - volumeSlider->ResizeTo(_W(scopeView) - 42, _H(volumeSlider)); playButton = new BButton( BRect(0, 1, 80, 1), "playButton", "Play", new BMessage(MSG_PLAY_STOP), B_FOLLOW_RIGHT); - - //playButton->MakeDefault(true); - playButton->ResizeToPreferred(); playButton->SetEnabled(false); - BBox* background = new BBox( - BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, - B_PLAIN_BORDER); - BBox* divider = new BBox( BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); + divider->SetExplicitMaxSize( + BSize(B_SIZE_UNLIMITED, 1)); - divider->ResizeTo(_W(scopeView), 1); - BStringView* volumeLabel = new BStringView( BRect(0, 0, 1, 1), NULL, "Volume:"); - - volumeLabel->ResizeToPreferred(); + volumeLabel->SetAlignment(B_ALIGN_LEFT); + volumeLabel->SetExplicitMaxSize( + BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); - float width = 8 + _W(scopeView) + 8; + // Build the layout + SetLayout(new BGroupLayout(B_HORIZONTAL)); - float height = - 8 + _H(scopeView) - + 8 + _H(showScope) - + 4 + _H(inputMenu) - + _H(reverbMenu) - + 2 + _H(volumeSlider) - + 10 + _H(divider) - + 6 + _H(playButton) - + 16; + AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) + .Add(scopeView) + .Add(BGridLayoutBuilder(10, 10) + .Add(BSpaceLayoutItem::CreateGlue(), 0, 0) + .Add(showScope, 1, 0) - ResizeTo(width, height); + .Add(reverbMenu->CreateLabelLayoutItem(), 0, 1) + .Add(reverbMenu->CreateMenuBarLayoutItem(), 1, 1) - AddChild(background); - background->ResizeTo(width, height); - background->AddChild(scopeView); - background->AddChild(showScope); - background->AddChild(reverbMenu); - background->AddChild(inputMenu); - background->AddChild(volumeLabel); - background->AddChild(volumeSlider); - background->AddChild(divider); - background->AddChild(playButton); + .Add(inputMenu->CreateLabelLayoutItem(), 0, 2) + .Add(inputMenu->CreateMenuBarLayoutItem(), 1, 2) - float y = 8; - scopeView->MoveTo(8, y); - - y += _H(scopeView) + 8; - showScope->MoveTo(8 + 55, y); - - y += _H(showScope) + 4; - inputMenu->MoveTo(8, y); - - y += _H(inputMenu); - reverbMenu->MoveTo(8, y); - - y += _H(reverbMenu) + 2; - volumeLabel->MoveTo(8, y); - volumeSlider->MoveTo(8 + 49, y); - - y += _H(volumeSlider) + 10; - divider->MoveTo(8, y); - - y += _H(divider) + 6; - playButton->MoveTo((width - _W(playButton)) / 2, y); + .Add(volumeLabel, 0, 3) + .Add(volumeSlider, 1, 3) + ) + .AddGlue() + .Add(divider) + .AddGlue() + .Add(playButton) + .AddGlue() + .SetInsets(5, 5, 5, 5) + ); } //------------------------------------------------------------------------------ Modified: haiku/trunk/src/apps/midiplayer/ScopeView.cpp =================================================================== --- haiku/trunk/src/apps/midiplayer/ScopeView.cpp 2008-07-13 21:47:20 UTC (rev 26407) +++ haiku/trunk/src/apps/midiplayer/ScopeView.cpp 2008-07-14 16:41:21 UTC (rev 26408) @@ -28,7 +28,7 @@ //------------------------------------------------------------------------------ ScopeView::ScopeView() - : BView(BRect(0, 0, 127, 63), NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, + : BView(BRect(0, 0, 180, 63), NULL, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW) { SetViewColor(0, 0, 0); From axeld at mail.berlios.de Mon Jul 14 19:29:04 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 14 Jul 2008 19:29:04 +0200 Subject: [Haiku-commits] r26409 - haiku/trunk/src/apps/activitymonitor Message-ID: <200807141729.m6EHT4NA029032@sheep.berlios.de> Author: axeld Date: 2008-07-14 19:29:02 +0200 (Mon, 14 Jul 2008) New Revision: 26409 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26409&view=rev Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp haiku/trunk/src/apps/activitymonitor/ActivityView.h haiku/trunk/src/apps/activitymonitor/ActivityWindow.cpp haiku/trunk/src/apps/activitymonitor/ActivityWindow.h haiku/trunk/src/apps/activitymonitor/DataSource.cpp haiku/trunk/src/apps/activitymonitor/DataSource.h Log: * Now use two views when starting (one memory, one CPU usage). The third view that is added to the window is a networking monitor, all later views default to CPU usage again. * DataSources can now share a single adaptive scale, so that they become comparable in a single view. * The networking in/out sources are now using this feature. * DataHistory::ValueAt() now uses binary search to find the right data_item; this also fixes bug #2140, and makes it possible to change the refresh rate (which is not yet implemented, though). * Zooming the timeline now also works by clicking the first mouse button and dragging the mouse around (instead of only via the scroll wheel, in case you hadn't noticed yet :-)). Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-14 17:29:02 UTC (rev 26409) @@ -11,7 +11,7 @@ #include #ifdef __HAIKU__ -#include +# include #endif #include #include @@ -23,11 +23,26 @@ #include "ActivityMonitor.h" #include "ActivityWindow.h" -#include "DataSource.h" #include "SystemInfo.h" #include "SystemInfoHandler.h" +class Scale { +public: + Scale(scale_type type); + + int64 MinimumValue() const { return fMinimumValue; } + int64 MaximumValue() const { return fMaximumValue; } + + void Update(int64 value); + +private: + scale_type fType; + int64 fMinimumValue; + int64 fMaximumValue; + bool fInitialized; +}; + struct data_item { bigtime_t time; int64 value; @@ -85,13 +100,39 @@ extern const char* kSignature; +Scale::Scale(scale_type type) + : + fType(type), + fMinimumValue(0), + fMaximumValue(0), + fInitialized(false) +{ +} + + +void +Scale::Update(int64 value) +{ + if (!fInitialized || fMinimumValue > value) + fMinimumValue = value; + if (!fInitialized || fMaximumValue > value) + fMaximumValue = value; + + fInitialized = true; +} + + +// #pragma mark - + + DataHistory::DataHistory(bigtime_t memorize, bigtime_t interval) : fBuffer(10000), fMinimumValue(0), fMaximumValue(0), fRefreshInterval(interval), - fLastIndex(-1) + fLastIndex(-1), + fScale(NULL) { } @@ -108,6 +149,8 @@ fMaximumValue = value; if (fBuffer.IsEmpty() || fMinimumValue > value) fMinimumValue = value; + if (fScale != NULL) + fScale->Update(value); data_item item = {time, value}; fBuffer.AddItem(item); @@ -117,12 +160,29 @@ int64 DataHistory::ValueAt(bigtime_t time) { - // TODO: if the refresh rate changes, this computation won't work anymore! - int32 index = (time - Start()) / fRefreshInterval; - data_item* item = fBuffer.ItemAt(index); - if (item != NULL) - return item->value; + int32 left = 0; + int32 right = fBuffer.CountItems() - 1; + data_item* item = NULL; + while (left <= right) { + int32 index = (left + right) / 2; + item = fBuffer.ItemAt(index); + + if (item->time > time) { + // search in left part + right = index - 1; + } else { + if (index + 1 >= fBuffer.CountItems() + || fBuffer.ItemAt(index + 1)->time > time) { + // found item + return item->value; + } + + // search in right part + left = index + 1; + } + } + return 0; } @@ -130,6 +190,9 @@ int64 DataHistory::MaximumValue() const { + if (fScale != NULL) + return fScale->MaximumValue(); + return fMaximumValue; } @@ -137,6 +200,9 @@ int64 DataHistory::MinimumValue() const { + if (fScale != NULL) + return fScale->MinimumValue(); + return fMinimumValue; } @@ -168,6 +234,13 @@ } +void +DataHistory::SetScale(Scale* scale) +{ + fScale = scale; +} + + // #pragma mark - @@ -378,6 +451,7 @@ fDrawInterval = kInitialRefreshInterval * 2; fLastRefresh = 0; fDrawResolution = 1; + fZooming = false; fSystemInfoHandler = new SystemInfoHandler; @@ -385,11 +459,8 @@ || settings->FindBool("show legend", &fShowLegend) != B_OK) fShowLegend = true; - if (settings == NULL) { - AddDataSource(new UsedMemoryDataSource()); - AddDataSource(new CachedMemoryDataSource()); + if (settings == NULL) return; - } ssize_t colorLength; rgb_color *color; @@ -466,6 +537,24 @@ } +Scale* +ActivityView::_ScaleFor(scale_type type) +{ + if (type == kNoScale) + return NULL; + + std::map::iterator iterator = fScales.find(type); + if (iterator != fScales.end()) + return iterator->second; + + // add new scale + ::Scale* scale = new ::Scale(type); + fScales[type] = scale; + + return scale; +} + + #ifdef __HAIKU__ BLayoutItem* ActivityView::CreateHistoryLayoutItem() @@ -535,6 +624,8 @@ return B_NO_MEMORY; } + values->SetScale(_ScaleFor(source->ScaleType())); + DataSource* copy; if (source->PerCPU()) copy = source->CopyForCPU(i); @@ -688,14 +779,16 @@ void ActivityView::MouseDown(BPoint where) { -#if 0 - int32 buttons = B_PRIMARY_MOUSE_BUTTON; - int32 clicks = 1; - if (Looper() != NULL && Looper()->CurrentMessage() != NULL) { + int32 buttons = B_SECONDARY_MOUSE_BUTTON; + if (Looper() != NULL && Looper()->CurrentMessage() != NULL) Looper()->CurrentMessage()->FindInt32("buttons", &buttons); - Looper()->CurrentMessage()->FindInt32("clicks", &clicks); + + if (buttons == B_PRIMARY_MOUSE_BUTTON) { + fZoomPoint = where; + fOriginalResolution = fDrawResolution; + fZooming = true; + return; } -#endif BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); menu->SetFont(be_plain_font); @@ -749,9 +842,34 @@ void +ActivityView::MouseUp(BPoint where) +{ + fZooming = false; +} + + +void ActivityView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { + if (!fZooming) + return; + + int32 previousResolution = fDrawResolution; + + int32 shift = int32(where.x - fZoomPoint.x) / 25; + if (shift > 0) + fDrawResolution = fOriginalResolution << shift; + else + fDrawResolution = fOriginalResolution >> -shift; + + if (fDrawResolution < 1) + fDrawResolution = 1; + if (fDrawResolution > 128) + fDrawResolution = 128; + + if (previousResolution != fDrawResolution) + Invalidate(); } Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.h =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityView.h 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/ActivityView.h 2008-07-14 17:29:02 UTC (rev 26409) @@ -6,14 +6,18 @@ #define ACTIVITY_VIEW_H +#include + #include #include #include "CircularBuffer.h" +#include "DataSource.h" class BBitmap; class BMessageRunner; class DataSource; +class Scale; class SystemInfoHandler; struct data_item; @@ -32,6 +36,7 @@ bigtime_t End() const; void SetRefreshInterval(bigtime_t interval); + void SetScale(Scale* scale); private: CircularBuffer fBuffer; @@ -39,6 +44,7 @@ int64 fMaximumValue; bigtime_t fRefreshInterval; int32 fLastIndex; + Scale* fScale; }; @@ -77,6 +83,7 @@ virtual void FrameResized(float width, float height); virtual void MouseDown(BPoint where); + virtual void MouseUp(BPoint where); virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); @@ -86,6 +93,7 @@ private: void _Init(const BMessage* settings); + ::Scale* _ScaleFor(scale_type type); void _Refresh(); void _UpdateOffscreenBitmap(); BView* _OffscreenView(); @@ -99,6 +107,7 @@ DataHistory* values, int64 value); void _DrawHistory(); +private: class HistoryLayoutItem; class LegendLayoutItem; @@ -120,7 +129,11 @@ bigtime_t fDrawInterval; int32 fDrawResolution; bool fShowLegend; + bool fZooming; + BPoint fZoomPoint; + int32 fOriginalResolution; SystemInfoHandler* fSystemInfoHandler; + std::map fScales; }; #endif // ACTIVITY_VIEW_H Modified: haiku/trunk/src/apps/activitymonitor/ActivityWindow.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityWindow.cpp 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/ActivityWindow.cpp 2008-07-14 17:29:02 UTC (rev 26409) @@ -22,13 +22,14 @@ #include "ActivityMonitor.h" #include "ActivityView.h" +#include "DataSource.h" static const uint32 kMsgAddView = 'advw'; ActivityWindow::ActivityWindow() - : BWindow(BRect(100, 100, 500, 250), "ActivityMonitor", B_TITLED_WINDOW, + : BWindow(BRect(100, 100, 500, 350), "ActivityMonitor", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { BMessage settings; @@ -68,12 +69,11 @@ count++; } if (count == 0) { - ActivityView* view = new ActivityView("ActivityMonitor", NULL); - fLayout->AddItem(view->CreateHistoryLayoutItem()); - fLayout->AddItem(view->CreateLegendLayoutItem()); + // Add default views (memory & CPU usage) + _AddDefaultView(); + _AddDefaultView(); } - -#else +#else // !__HAIKU__ BView *layout = new BView(Bounds(), "topmost", B_FOLLOW_NONE, 0); AddChild(layout); @@ -222,6 +222,34 @@ void +ActivityWindow::_AddDefaultView() +{ + ActivityView* view = new ActivityView("ActivityMonitor", NULL); + + switch (ActivityViewCount()) { + case 0: + // The first view defaults to memory usage + view->AddDataSource(new UsedMemoryDataSource()); + view->AddDataSource(new CachedMemoryDataSource()); + break; + case 2: + // The third view defaults to network in/out + view->AddDataSource(new NetworkUsageDataSource(true)); + view->AddDataSource(new NetworkUsageDataSource(false)); + break; + case 1: + default: + // Everything beyond that defaults to a CPU usage view + view->AddDataSource(new CPUUsageDataSource()); + break; + } + + fLayout->AddItem(view->CreateHistoryLayoutItem()); + fLayout->AddItem(view->CreateLegendLayoutItem()); +} + + +void ActivityWindow::MessageReceived(BMessage* message) { if (message->WasDropped()) { @@ -240,9 +268,7 @@ #ifdef __HAIKU__ BView* firstView = fLayout->View()->ChildAt(0); - ActivityView* view = new ActivityView("ActivityMonitor", NULL); - fLayout->AddItem(view->CreateHistoryLayoutItem()); - fLayout->AddItem(view->CreateLegendLayoutItem()); + _AddDefaultView(); if (firstView != NULL) ResizeBy(0, firstView->Bounds().Height() + fLayout->Spacing()); Modified: haiku/trunk/src/apps/activitymonitor/ActivityWindow.h =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityWindow.h 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/ActivityWindow.h 2008-07-14 17:29:02 UTC (rev 26409) @@ -29,6 +29,7 @@ status_t _LoadSettings(BMessage& settings); status_t _SaveSettings(); + void _AddDefaultView(); void _UpdateRemoveItem(); void _MessageDropped(BMessage *message); Modified: haiku/trunk/src/apps/activitymonitor/DataSource.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/DataSource.cpp 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/DataSource.cpp 2008-07-14 17:29:02 UTC (rev 26409) @@ -176,6 +176,13 @@ } +scale_type +DataSource::ScaleType() const +{ + return kNoScale; +} + + int32 DataSource::CPU() const { Modified: haiku/trunk/src/apps/activitymonitor/DataSource.h =================================================================== --- haiku/trunk/src/apps/activitymonitor/DataSource.h 2008-07-14 16:41:21 UTC (rev 26408) +++ haiku/trunk/src/apps/activitymonitor/DataSource.h 2008-07-14 17:29:02 UTC (rev 26409) @@ -12,6 +12,11 @@ class SystemInfo; +enum scale_type { + kNoScale, + kBytePerSecondScale, +}; + class DataSource { public: DataSource(int64 initialMin, int64 initialMax); @@ -38,6 +43,7 @@ virtual const char* Unit() const; virtual rgb_color Color() const; virtual bool AdaptiveScale() const; + virtual scale_type ScaleType() const; virtual int32 CPU() const; virtual bool PerCPU() const; virtual bool MultiCPUOnly() const; From axeld at mail.berlios.de Mon Jul 14 19:31:00 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 14 Jul 2008 19:31:00 +0200 Subject: [Haiku-commits] r26410 - haiku/trunk/headers/os/interface Message-ID: <200807141731.m6EHV0OB001580@sheep.berlios.de> Author: axeld Date: 2008-07-14 19:30:59 +0200 (Mon, 14 Jul 2008) New Revision: 26410 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26410&view=rev Modified: haiku/trunk/headers/os/interface/PopUpMenu.h Log: * Cleaned up odd indentation. Modified: haiku/trunk/headers/os/interface/PopUpMenu.h =================================================================== --- haiku/trunk/headers/os/interface/PopUpMenu.h 2008-07-14 17:29:02 UTC (rev 26409) +++ haiku/trunk/headers/os/interface/PopUpMenu.h 2008-07-14 17:30:59 UTC (rev 26410) @@ -1,84 +1,82 @@ /* - * Copyright 2007, Haiku, Inc. All Rights Reserved. + * Copyright 2007-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _POP_UP_MENU_H #define _POP_UP_MENU_H + #include #include + class BPopUpMenu : public BMenu { - public: - BPopUpMenu(const char *title, bool radioMode = true, - bool autoRename = true, - menu_layout layout = B_ITEMS_IN_COLUMN); - BPopUpMenu(BMessage *data); - virtual ~BPopUpMenu(); - - virtual status_t Archive(BMessage *data, bool deep = true) const; - static BArchivable* Instantiate(BMessage *data); +public: + BPopUpMenu(const char* title, bool radioMode = true, + bool autoRename = true, + menu_layout layout = B_ITEMS_IN_COLUMN); + BPopUpMenu(BMessage* data); + virtual ~BPopUpMenu(); - BMenuItem* Go(BPoint where, bool autoInvoke = false, - bool keepOpen = false, - bool async = false); - BMenuItem* Go(BPoint where, bool autoInvoke, - bool keepOpen, - BRect openRect, - bool async = false); + virtual status_t Archive(BMessage* data, bool deep = true) const; + static BArchivable* Instantiate(BMessage* data); - virtual void MessageReceived(BMessage *message); - virtual void MouseDown(BPoint point); - virtual void MouseUp(BPoint point); - virtual void MouseMoved(BPoint point, uint32 code, - const BMessage *message); - virtual void AttachedToWindow(); - virtual void DetachedFromWindow(); - virtual void FrameMoved(BPoint newPosition); - virtual void FrameResized(float newWidth, float newHeight); + BMenuItem* Go(BPoint where, bool autoInvoke = false, + bool keepOpen = false, bool async = false); + BMenuItem* Go(BPoint where, bool autoInvoke, bool keepOpen, + BRect openRect, bool async = false); - virtual BHandler* ResolveSpecifier(BMessage *message, int32 index, - BMessage *specifier, int32 form, - const char *property); - virtual status_t GetSupportedSuites(BMessage *data); + virtual void MessageReceived(BMessage* message); + virtual void MouseDown(BPoint point); + virtual void MouseUp(BPoint point); + virtual void MouseMoved(BPoint point, uint32 code, + const BMessage* message); + virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); + virtual void FrameMoved(BPoint newPosition); + virtual void FrameResized(float newWidth, float newHeight); - virtual status_t Perform(perform_code code, void *arg); + virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, + BMessage* specifier, int32 form, + const char* property); + virtual status_t GetSupportedSuites(BMessage* data); - virtual void ResizeToPreferred(); - virtual void GetPreferredSize(float *width, float *height); - virtual void MakeFocus(bool state = true); - virtual void AllAttached(); - virtual void AllDetached(); + virtual status_t Perform(perform_code code, void* arg); - void SetAsyncAutoDestruct(bool state); - bool AsyncAutoDestruct() const; + virtual void ResizeToPreferred(); + virtual void GetPreferredSize(float* _width, float* _height); + virtual void MakeFocus(bool state = true); + virtual void AllAttached(); + virtual void AllDetached(); - protected: - virtual BPoint ScreenLocation(); + void SetAsyncAutoDestruct(bool state); + bool AsyncAutoDestruct() const; - virtual void _ReservedPopUpMenu1(); - virtual void _ReservedPopUpMenu2(); - virtual void _ReservedPopUpMenu3(); +protected: + virtual BPoint ScreenLocation(); - BPopUpMenu &operator=(const BPopUpMenu &); + virtual void _ReservedPopUpMenu1(); + virtual void _ReservedPopUpMenu2(); + virtual void _ReservedPopUpMenu3(); - private: - BMenuItem *_Go(BPoint where, bool autoInvoke, bool startOpened, - BRect *specialRect, bool async); - BMenuItem *_StartTrack(BPoint where, bool autoInvoke, - bool startOpened, BRect *specialRect); - BMenuItem *_WaitMenu(void *data); + BPopUpMenu& operator=(const BPopUpMenu& other); - static int32 _thread_entry(void *); +private: + BMenuItem* _Go(BPoint where, bool autoInvoke, bool startOpened, + BRect* specialRect, bool async); + BMenuItem* _StartTrack(BPoint where, bool autoInvoke, + bool startOpened, BRect* specialRect); + BMenuItem* _WaitMenu(void* data); - BPoint fWhere; - bool fUseWhere; - bool fAutoDestruct; - bool _fUnusedBool1; - bool _fUnusedBool2; - thread_id fTrackThread; - uint32 _reserved[3]; + static int32 _thread_entry(void* data); + + BPoint fWhere; + bool fUseWhere; + bool fAutoDestruct; + bool _fUnusedBool1; + bool _fUnusedBool2; + thread_id fTrackThread; + uint32 _reserved[3]; }; - -#endif /* _POP_UP_MENU_H */ +#endif // _POP_UP_MENU_H From axeld at mail.berlios.de Mon Jul 14 19:33:11 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Mon, 14 Jul 2008 19:33:11 +0200 Subject: [Haiku-commits] r26411 - haiku/trunk/src/apps/workspaces Message-ID: <200807141733.m6EHXBEF001775@sheep.berlios.de> Author: axeld Date: 2008-07-14 19:33:10 +0200 (Mon, 14 Jul 2008) New Revision: 26411 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26411&view=rev Modified: haiku/trunk/src/apps/workspaces/Workspaces.cpp Log: * Popup menu is now sticky - this should probably be the default of all menus when "sticky menus" is selected in the menu preferences (just in case we still have that setting...). Oh, this also fixes bug #2315. Modified: haiku/trunk/src/apps/workspaces/Workspaces.cpp =================================================================== --- haiku/trunk/src/apps/workspaces/Workspaces.cpp 2008-07-14 17:30:59 UTC (rev 26410) +++ haiku/trunk/src/apps/workspaces/Workspaces.cpp 2008-07-14 17:33:10 UTC (rev 26411) @@ -449,7 +449,7 @@ changeItem->SetTarget(this); ConvertToScreen(&where); - menu->Go(where, true, false, true); + menu->Go(where, true, true, true); } From host.haiku at gmx.de Mon Jul 14 20:00:15 2008 From: host.haiku at gmx.de (julun) Date: Mon, 14 Jul 2008 20:00:15 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <487B3ED3.8030002@gmx.de> References: <200807132042.m6DKgFeP006540@sheep.berlios.de> <894b9700807132345t2034fc55x3487e3c7320cef95@mail.gmail.com> <487B124B.9090400@gmx.de> <894b9700807140308l5c0742cbq3b5c8ddd4dd277ca@mail.gmail.com> <487B3ED3.8030002@gmx.de> Message-ID: <487B942F.508@gmx.de> Hi, > > If you like you can get the source from: > > http://www.3rd-evolution.de/BeOS/TaskMgr/index.html > > The interesting parts are AsynchronousPopUpMenu.h/cpp, > DeskbarLedView.h/cpp starting at line 254 and GraphView.h/cpp starting > at line 1361. > one can get a HAIKU jam'able version here: www.julun.de/haiku/taskmanager.zip Simply unzip into 3rdparty, go into the taskmanager folder which will contain a UserBuildConfig.taskmanager and add the content to your real UserBuildConfig. Regards, Karsten From revol at free.fr Mon Jul 14 20:10:04 2008 From: revol at free.fr (=?windows-1252?q?Fran=E7ois?= Revol) Date: Mon, 14 Jul 2008 20:10:04 +0200 CEST Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <487B942F.508@gmx.de> Message-ID: <8766186401-BeMail@laptop> > Simply unzip into 3rdparty, go into the taskmanager folder which will > contain a UserBuildConfig.taskmanager and add the content to your > real > UserBuildConfig. Maybe we should just enable 3rdparty by default... Did you use the <3rdparty> grist ? I talked about that already, we should probably use that to avoid conflicts with src/ Fran?ois. From host.haiku at gmx.de Mon Jul 14 20:24:59 2008 From: host.haiku at gmx.de (julun) Date: Mon, 14 Jul 2008 20:24:59 +0200 Subject: [Haiku-commits] r26406 - haiku/trunk/src/kits/interface In-Reply-To: <8766186401-BeMail@laptop> References: <8766186401-BeMail@laptop> Message-ID: <487B99FB.6060500@gmx.de> Hi Fran?ois, Fran?ois Revol schrieb: >> Simply unzip into 3rdparty, go into the taskmanager folder which will >> contain a UserBuildConfig.taskmanager and add the content to your >> real >> UserBuildConfig. > > Maybe we should just enable 3rdparty by default... > > Did you use the <3rdparty> grist ? > I talked about that already, we should probably use that to avoid > conflicts with src/ eahm, no? I have no idea :) Karsten From mmu_man at mail.berlios.de Mon Jul 14 20:47:04 2008 From: mmu_man at mail.berlios.de (mmu_man at mail.berlios.de) Date: Mon, 14 Jul 2008 20:47:04 +0200 Subject: [Haiku-commits] r26412 - haiku/trunk/headers/private/net Message-ID: <200807141847.m6EIl4VJ011411@sheep.berlios.de> Author: mmu_man Date: 2008-07-14 20:47:02 +0200 (Mon, 14 Jul 2008) New Revision: 26412 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26412&view=rev Modified: haiku/trunk/headers/private/net/net_device.h Log: This weren't typedefed, using them without struct is invalid in C. Modified: haiku/trunk/headers/private/net/net_device.h =================================================================== --- haiku/trunk/headers/private/net/net_device.h 2008-07-14 17:33:10 UTC (rev 26411) +++ haiku/trunk/headers/private/net/net_device.h 2008-07-14 18:47:02 UTC (rev 26412) @@ -31,7 +31,7 @@ struct net_hardware_address address; - ifreq_stats stats; + struct ifreq_stats stats; }; struct net_device_module_info { @@ -56,9 +56,9 @@ status_t (*set_media)(struct net_device *device, uint32 media); status_t (*add_multicast)(struct net_device *device, - const sockaddr *address); + const struct sockaddr *address); status_t (*remove_multicast)(struct net_device *device, - const sockaddr *address); + const struct sockaddr *address); }; #endif // NET_DEVICE_H From modeenf at mail.berlios.de Mon Jul 14 21:14:27 2008 From: modeenf at mail.berlios.de (modeenf at mail.berlios.de) Date: Mon, 14 Jul 2008 21:14:27 +0200 Subject: [Haiku-commits] r26413 - in haiku/trunk/src/tests/kits: . device device/stickit_BJoystick Message-ID: <200807141914.m6EJERqd014270@sheep.berlios.de> Author: modeenf Date: 2008-07-14 21:14:23 +0200 (Mon, 14 Jul 2008) New Revision: 26413 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26413&view=rev Added: haiku/trunk/src/tests/kits/device/ haiku/trunk/src/tests/kits/device/stickit_BJoystick/ haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.cpp haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.h haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.h haiku/trunk/src/tests/kits/device/stickit_BJoystick/Stick_it.txt haiku/trunk/src/tests/kits/device/stickit_BJoystick/article.txt haiku/trunk/src/tests/kits/device/stickit_BJoystick/stickit_x86.proj Log: BJoystick test app. A updated Stickit demo app the original article included Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.cpp 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,244 @@ +// +// StickIt +// File: JoystickWindow.cpp +// Joystick window. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "JoystickWindow.h" + +rgb_color rgb_black = {0, 0, 0, 255}; +rgb_color rgb_red = {255, 0, 0, 255}; +rgb_color rgb_grey = {216, 216, 216}; + +int32 hatX[9] = {10, 10, 20, 20, 20, 10, 0, 0, 0}; +int32 hatY[9] = {10, 0, 0, 10, 20, 20, 20, 10, 0}; + +JoystickWindow::JoystickWindow(BJoystick *stick, BRect rect) + : BWindow(rect, "StickIt", B_TITLED_WINDOW, + B_NOT_RESIZABLE|B_NOT_ZOOMABLE) +{ + fView = new JoystickView(Bounds(), stick); + fView->SetViewColor(rgb_grey); + fView->SetLowColor(rgb_grey); + ResizeTo(fView->Bounds().Width(), fView->Bounds().Height()); + AddChild(fView); + SetPulseRate(100000.0); +} + + +bool +JoystickWindow::QuitRequested(void) { + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +JoystickView::JoystickView(BRect frame, BJoystick *stick) + :BView(frame, "jview", B_FOLLOW_ALL_SIDES, B_WILL_DRAW|B_PULSE_NEEDED), + fStick(stick) +{ + // Set up the controls + BString name; + fStick->GetControllerName(&name); + BRect rect(5, 5, 350, 25); + BStringView *stickName = new BStringView(rect, "stickname", name.String()); + stickName->SetFontSize(18); + AddChild(stickName); + + rect = _BuildButtons(stick); + rect.top += 15; + rect.bottom += 15; + rect = _BuildHats(stick, rect); + _BuildAxes(stick, rect); +} + + +void +JoystickView::Pulse(void) { + Window()->Lock(); + Draw(Bounds()); + Window()->Unlock(); +} + + +void +JoystickView::Draw(BRect updateRect) +{ + int32 numButtons = fStick->CountButtons(); + int32 numHats = fStick->CountHats(); + int32 numAxes = fStick->CountAxes(); + int16 *axes = (int16 *) malloc(sizeof(int16) * numAxes); + uint8 *hats = (uint8 *) malloc(numHats); + fStick->Update(); + + // Buttons first + BRect r(105, 50, 115, 60); + uint32 buttons = fStick->ButtonValues(); + for (int32 i = 0; i < numButtons; i++) { + if (buttons & (1 << i)) { + FillRect(r, B_SOLID_HIGH); + } else { + r.InsetBy(1, 1); + FillRect(r, B_SOLID_LOW); + r.InsetBy(-1, -1); + StrokeRect(r, B_SOLID_HIGH); + } + r.top += 18; + r.bottom += 18; + } + + // Now hats + fStick->GetHatValues(hats); + r.top += 15; + r.bottom = r.top + 30; + r.left = 105; + r.right = r.left + 30; + BRect curHatRect; + for (int32 i = 0; i < numHats; i++) { + BeginLineArray(8); + AddLine(r.LeftTop(), r.RightTop(), rgb_black); + AddLine(r.LeftTop(), r.LeftBottom(), rgb_black); + AddLine(r.RightTop(), r.RightBottom(), rgb_black); + AddLine(r.LeftBottom(), r.RightBottom(), rgb_black); + AddLine(BPoint(r.left+10, r.top), BPoint(r.left+10, r.bottom), + rgb_black); + AddLine(BPoint(r.left+20, r.top), BPoint(r.left+20, r.bottom), + rgb_black); + AddLine(BPoint(r.left, r.top+10), BPoint(r.right, r.top+10), + rgb_black); + AddLine(BPoint(r.left, r.top+20), BPoint(r.right, r.top+20), + rgb_black); + EndLineArray(); + curHatRect.Set(r.left, r.top, r.left+10, r.top+10); + curHatRect.OffsetBy(hatX[hats[i]], hatY[hats[i]]); + fLastHatRect.InsetBy(1, 1); + FillRect(fLastHatRect, B_SOLID_LOW); + fLastHatRect = curHatRect; + fLastHatRect.InsetBy(1, 1); + FillRect(fLastHatRect, B_SOLID_HIGH); + fLastHatRect.InsetBy(-1, -1); + r.top += 20; + r.bottom += 20; + } + + // Now the joystick + r.Set(200, 50, 350, 200); + FillRect(r, B_SOLID_HIGH); + fStick->GetAxisValues(axes); + float x = axes[0]; + float y = axes[1]; + SetHighColor(rgb_red); + x += 32768; + y -= 32768; + x *= 0.0021362304; + y *= 0.0021362304; + x += 205; + y += 195; + FillEllipse(BPoint(x,y), 5, 5); + SetHighColor(rgb_black); + + // Finally, other axes + r.Set(200, 220, 350, 234); + for (int32 i = 2; i < numAxes; i++) { + FillRect(r, B_SOLID_HIGH); + x = axes[i]; + x += 32768; + x *= 0.0021362304; + x += 205; + BRect thumbRect(x - 3, r.top, x + 3, r.bottom); + SetHighColor(rgb_red); + FillRoundRect(thumbRect, 3, 3); + SetHighColor(rgb_black); + r.top += 20; + r.bottom += 20; + } + free(axes); + free(hats); +} + +//----------------------- Pragma mark ------------------------------------// + +BRect +JoystickView::_BuildButtons(BJoystick *stick) +{ + BString name; + int32 numButtons = stick->CountButtons(); + BRect rect(5, 50, 100, 64); + for (int32 i = 0; i < numButtons; i++) { + stick->GetButtonNameAt(i, &name); + rect = _BuildString(name, "buttonlabel", 18, rect); + } + return rect; +} + + +BRect +JoystickView::_BuildHats(BJoystick *stick, BRect rect) +{ + BString name; + int32 numHats = stick->CountHats(); + for (int32 i = 0; i < numHats; i++) { + stick->GetHatNameAt(i, &name); + rect = _BuildString(name, "hatlabel", 40, rect); + } + return rect; +} + + +BRect +JoystickView::_BuildString(BString name, const char* strName, int number, + BRect rect) +{ + name.Append(":"); + BStringView *sview = new BStringView(rect, strName, name.String()); + sview->SetAlignment(B_ALIGN_RIGHT); + sview->SetFont(be_bold_font); + AddChild(sview); + rect.top += number; + rect.bottom += number; + return rect; +} + + +void +JoystickView::_BuildAxes(BJoystick *stick, BRect rect) +{ + float col1bot = rect.bottom - 30; + int32 numAxes = stick->CountAxes(); + // We assume that the first two axes are the x and y axes. + rect.Set(130, 50, 195, 64); + BStringView *sview = new BStringView(rect, "sticklabel", "Stick:"); + sview->SetFont(be_bold_font); + sview->SetAlignment(B_ALIGN_RIGHT); + AddChild(sview); + + BString name; + int32 i; + // Now make labels for all the solitary axes + rect.Set(130, 200, 195, 234); + for (i = 2; i < numAxes; i++) { + stick->GetAxisNameAt(i, &name); + rect = _BuildString(name, "hatlabel", 20, rect); + } + + fLastHatRect.Set(0, 0, 0, 0); + if (rect.bottom-10 > col1bot) { + if (i == 2) { + col1bot = 205; + } else { + col1bot = rect.bottom - 10; + } + } + ResizeTo(355, col1bot); +} Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/JoystickWindow.h 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,37 @@ +// +// StickIt +// File: JoystickWindow.h +// Joystick window definitions. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include +#include + +class BJoystick; + +class JoystickView : public BView { + public: + JoystickView(BRect bounds, BJoystick *stick); + virtual void Draw(BRect updateRect); + virtual void Pulse(void); + + private: + BRect _BuildButtons(BJoystick *stick); + BRect _BuildHats(BJoystick *stick, BRect rect); + void _BuildAxes(BJoystick *stick, BRect rect); + BRect _BuildString(BString name, const char* strName, + int number, BRect rect); + + BJoystick *fStick; + BRect fLastHatRect; +}; + +class JoystickWindow : public BWindow { + public: + JoystickWindow(BJoystick *stick, BRect rect); + virtual bool QuitRequested(void); + + private: + JoystickView *fView; +}; Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.cpp =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.cpp 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.cpp 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,22 @@ +// +// StickIt +// File: StickItApp.c +// Joystick application. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include "StickItWindow.h" +#include "StickItApp.h" + +StickItApp::StickItApp() + :BApplication("application/x-vnd.Be-JoyDemoOne") +{ + fStickItWindow = new StickItWindow(BRect(50, 50, 500, 500)); + fStickItWindow->Show(); +} + +int main(void) { + StickItApp app; + app.Run(); + return 0; +} Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.h =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.h 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItApp.h 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,16 @@ +// +// StickIt +// File: StickItApp.h +// Joystick application definitions. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include +#include + +class StickItApp : public BApplication { + public: + StickItApp(); + private: + StickItWindow *fStickItWindow; +}; Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,221 @@ +// +// StickIt +// File: jwindow.cpp +// Joystick window. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPACE 10 + +#include "JoystickWindow.h" + +#define SELECTED 'sele' +#define INVOKE 'invo' + +#include "StickItWindow.h" + +StickItWindow::StickItWindow(BRect frame) + : BWindow(frame, "StickIt", B_TITLED_WINDOW, NULL) +{ + frame = Bounds(); + frame.InsetBy(5, 5); + BBox* box = new BBox(frame, NULL, B_FOLLOW_ALL_SIDES); + + + // Allocate object + BView* view = new BView(Bounds(), "", B_FOLLOW_ALL_SIDES, NULL); + view->SetViewColor(216, 216, 216); + view->SetLowColor(216, 216, 216); + + BRect rectString = BRect(frame.left, frame.top-10, frame.right -30, 30); + BStringView* stringview1 = new BStringView(rectString,"StringView1", + "This list, lists action that StickIt makes."); + + BRect rect = BRect(rectString.left, rectString.bottom + SPACE, + rectString.right, rectString.bottom + SPACE + 200); + fListView1 = new BListView(rect,"ListView1"); + + rectString = BRect(rect.left, rect.bottom + SPACE, rect.right, + rect.bottom + SPACE + 15); + BStringView* stringview2 = new BStringView(rectString,"StringView2", + "Choose Joystick below if any exists"); + + rect = BRect(rectString.left, rectString.bottom + SPACE, rectString.right, + Bounds().bottom -20); + fListView2 = new BListView(rect,"ListView2"); + fListView2->SetSelectionMessage(new BMessage(SELECTED)); + fListView2->SetInvocationMessage(new BMessage(INVOKE)); + + + // Adding object + box->AddChild(new BScrollView("fListView1", fListView1, + B_FOLLOW_LEFT_RIGHT, NULL, false, true)); + + box->AddChild(new BScrollView("fListView2", fListView2, + B_FOLLOW_ALL_SIDES, NULL, false, true)); + + box->AddChild(stringview1); + box->AddChild(stringview2); + view->AddChild(box); + AddChild(view); + + fJoystick = new BJoystick; + PickJoystick(fJoystick); +} + + +bool +StickItWindow::QuitRequested(void) { + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + + +void +StickItWindow::MessageReceived(BMessage *message) +{ +// message->PrintToStream(); + switch(message->what) + { + case INVOKE: + case SELECTED: + { + int32 id = fListView2->CurrentSelection(); + BString temp1; + if (id > -1) { + char devName[B_OS_NAME_LENGTH]; + status_t err = fJoystick->GetDeviceName(id, devName); + if (err == B_OK) { + temp1 << "BJoystick::GetDeviceName(), id = " << id + << ", name = " << devName; + temp1 = AddToList(fListView1, temp1.String()); + err = fJoystick->Open(devName); + if (err != B_ERROR) { + temp1 = AddToList(fListView1, "BJoystick::Open()"); + temp1 = AddToList(fListView1, "BJoystick::Open()"); + if(fJoystick->IsCalibrationEnabled()) + temp1 = AddToList(fListView1, + "BJoystick::IsCalibrationEnabled() - True"); + else + temp1 = AddToList(fListView1, + "BJoystick::IsCalibrationEnabled() - False"); + fJoystickWindow = new JoystickWindow(fJoystick, + BRect(50, 50, 405, 350)); + fJoystickWindow->Show(); + } else + AddToList(fListView1, + "No controller connected on that port. Try again."); + } else + AddToList(fListView1, "Can't use that stick. Try again."); + } + break; + } + default: + BWindow::MessageReceived(message); + break; + } +} + + +BString +StickItWindow::AddToList(BListView *bl, const char * str) +{ + bl->AddItem(new BStringItem(str)); + return BString (""); +} + + +// PickJoystick +// Present a list of all game controllers and let the user choose the one to +// use. This will configure the "stick" object for that controller. +void +StickItWindow::PickJoystick(BJoystick *stick) +{ + int32 numDevices = stick->CountDevices(); + BString temp1("BJoystick::CountDevices()"); + temp1 << ", Num = " << numDevices; + temp1 = AddToList(fListView1, temp1.String()); + status_t err = B_ERROR; + if (numDevices) { + temp1 << "There are " << numDevices + << " Joysticks device types available"; + temp1 = AddToList(fListView1, temp1.String()); + for (int32 i = 0; i < numDevices; i++) { + char devName[B_OS_NAME_LENGTH]; + err = stick->GetDeviceName(i, devName); + temp1 << "BJoystick::GetDeviceName(), id = " << i << ", name = " + << devName; + temp1 = AddToList(fListView1, temp1.String()); + if (err == B_OK) { + err = stick->Open(devName); + temp1 = AddToList(fListView1, "BJoystick::Open()"); + int32 sticks = stick->CountSticks(); + temp1 << "BJoystick::CountSticks(), number of sticks = " + << sticks; + temp1 = AddToList(fListView1, temp1.String()); + if (err != B_ERROR) { + BString name; + err = stick->GetControllerModule(&name); + temp1 << "BJoystick::GetControllerModule(), name = " + << name; + temp1 = AddToList(fListView1, temp1.String()); + + if (name == "Legacy") { + bool b = stick->EnterEnhancedMode(); + if (b) { + temp1 << "BJoystick::EnterEnhancedMode(), OK"; + temp1 = AddToList(fListView1, temp1.String()); + } else { + temp1 << "BJoystick::EnterEnhancedMode(), Not OK"; + temp1 = AddToList(fListView1, temp1.String()); + } + } + + err = stick->GetControllerName(&name); + temp1 << "BJoystick::GetControllerName(), name = " << name; + temp1 = AddToList(fListView1, temp1.String()); + if (err == B_OK) { + stick->Close(); + temp1 = AddToList(fListView1, "BJoystick::Close()"); + temp1 << i+1 << " " << name.String(); + temp1 = AddToList(fListView2, temp1.String()); + } else { + temp1 << "Error = " << strerror(err); + temp1 = AddToList(fListView1, temp1.String()); + temp1 << "*** Can't get name of controller " + << devName; + temp1 = AddToList(fListView1, temp1.String()); + } + } else { + temp1 << "Error = " << strerror(err) << "err nr = " << err; + temp1 = AddToList(fListView1, temp1.String()); + temp1 << "No controller on " << devName; + temp1 = AddToList(fListView1, temp1.String()); + } + } else { + temp1 << "Error = " << strerror(err); + temp1 = AddToList(fListView1, temp1.String()); + temp1 << "*** Error while reading controller list."; + temp1 = AddToList(fListView1, temp1.String()); + } + } + } else { + temp1 << "Error = " << strerror(err); + temp1 = AddToList(fListView1, temp1.String()); + temp1 = AddToList(fListView1, "*** No game ports detected."); + } +} Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.h =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.h 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.h 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,30 @@ +// +// StickIt +// File: jwindow.h +// Joystick window definitions. +// Sampel code used in "Getting a Grip on BJoystick" by Eric Shepherd +// + +#include +#include + +class JoystickWindow; +class BJoystick; +class BBox; +class BStringView; +class BListView; + +class StickItWindow : public BWindow { + public: + StickItWindow(BRect rect); + void PickJoystick(BJoystick *stick); + virtual bool QuitRequested(void); + virtual void MessageReceived(BMessage *message); + BString AddToList(BListView *bl, const char * str); + + private: + BListView* fListView1; + BListView* fListView2; + BJoystick* fJoystick; + JoystickWindow* fJoystickWindow; +}; Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/Stick_it.txt =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/Stick_it.txt 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/Stick_it.txt 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,3 @@ +Not used in stickit +EnableCalibration() +SetMaxLatency() \ No newline at end of file Added: haiku/trunk/src/tests/kits/device/stickit_BJoystick/article.txt =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/article.txt 2008-07-14 18:47:02 UTC (rev 26412) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/article.txt 2008-07-14 19:14:23 UTC (rev 26413) @@ -0,0 +1,150 @@ +Getting a Grip on BJoystick +by Eric Shepherd + +The BJoystick class is getting a major overhaul for BeOS Release 4. In earlier versions of BeOS, BJoystick was limited to supporting a simple two-axis, two-button analog stick. But in this age of games with complicated moves, high-realism flight simulations, and the like, this just isn't enough. The new, improved BJoystick class gives you access to modern digital game controllers (such as the Logitech Wingman Extreme Digital, the Microsoft Sidewinder, and others). As always, the warning goes (come on, you can say it along with me): "BeOS R4 isn't final, and this is all subject to change." + +These sticks often have a half-dozen buttons or more, thumb hats (those little direction knobs on top of the main stick), and additional axes, such as rotational controls or throttles. Game players want to use these controls to their maximum potential, and the new BJoystick class lets you do just that. + +The old BJoystick mechanism still works, but I'm not going to talk about it, because the old API doesn't support these advanced features. Note, however, that enhanced joysticks don't work on the BeBox's built-in game port hardware -- all you can get are two-axis, two-button joysticks. + +This article will be based on the sample project StickIt. StickIt lets you pick a joystick (previously configured using the new Joysticks preference application), then presents a window showing all the buttons, hats, and axes provided by that joystick, providing instant feedback as the joystick is manipulated. Only key portions of the code will be shown here; you can download the complete source code at <>. + +On R4 Intel, you can use the following command in a Terminal window to compile and link the program: + +cc -o StickIt main.cpp japplication.cpp jwindow.cpp -lbe -ldevice + +On R4 PowerPC, the following command will compile and link the program: + +cc -o StickIt main.cpp japplication.cpp jwindow.cpp + +Note that I use the term "joystick," but I mean "any BeOS-compatible game controller." There are supported game pads as well. + +Let's begin by looking at how to figure out what joysticks are available, and how to open them. Take a look at the PickJoystick() function in StickIt's main.cpp file. This function presents, in the Terminal from which StickIt was launched, a list of joysticks, and lets the user pick the one they want to play with. + +It begins by calling BJoystick->CountDevices(), which returns the number of devices connected (this isn't technically the same thing as the number of joysticks connected, since "devices" really refers to game ports, and it's possible for multiple devices to be chained to one game port, although none of the drivers provided in R4 support this). If there aren't any devices available, an error message is printed, and PickJoystick() returns false. + +Otherwise, a loop prints out the names of the joysticks the user has configured for each game port: + +for (i=0; iGetDeviceName(i, devName) != B_OK) { + printf("*** Error while reading controller list.\n"); + return false; + } + if (stick->Open(devName, true) < B_OK) { + printf("%4d. No controller on %s.\n", i+1, devPath); + } + else { + if (stick->GetControllerName(&name) != B_OK) { + printf("*** Can't get name of controller %s.\n", devPath); + return false; + } + printf("%4d. %s\n", i+1, name.String()); + stick->Close(); + } +} + +This begins by obtaining the device name of the joystick that's configured for the port (calling GetDeviceName() with an index number indicating which port to check). BJoystick::Open() is then called to open the joystick device. If this fails, an error message is displayed and the loop continues (in case there are empty or unconfigured game ports, but others may be valid). + +Once the device is open, GetControllerName() is called to get the name of the joystick. The returned name will be the same as the name indicated by the Joysticks preference application. This name is then displayed as the option for the user to select, and the joystick is closed. This loop continues until the entire menu is displayed on the terminal. + +PickJoystick() then lets the user select the joystick they want to use, and then the device is opened, using code very similar to the code above: first the device name is obtained by calling GetDeviceName(), then the Open() function is used to actually open the device. Open() returns the file descriptor of the joystick's device driver (which you don't really need to know), or a negative number if an error occurred while opening the device). + +PickJoystick() returns with the BJoystick object open and ready to use. + +StickIt's main() function is fairly simple. It calls PickJoystick() to get a joystick to use, then instantiates a JWindow, in which the instant joystick feedback is presented. + +JWindow is a very simple class and we won't dwell on it -- it just sets up the JView, which does all the real work, and sets the pulse rate to 100,000 microseconds. + +Let's just skim on to the JView class, where all the cool stuff is done. The constructor creates labels for the various displays in the view, and resizes the view and the window, vertically, so it's the right size for the controls provided by the joystick it's displaying). + +At the top of the window, in a nice large font, the joystick's name is displayed: + +stick->GetControllerName(&name); +stickName = new BStringView(BRect(5,5,350, 25), "stickname", name.String()); +stickName->SetFontSize(18); +AddChild(stickName); + +We've seen how GetControllerName() works already, in PickJoystick(), so we skip on to the labels for the buttons. + + numButtons = stick->CountButtons(); + r.Set(5,50,100, 64); + for (i=0; iGetButtonNameAt(i, &name); + name.Append(":"); + sview = new BStringView(r, "buttonlabel", name.String()); + sview->SetAlignment(B_ALIGN_RIGHT); + sview->SetFont(be_bold_font); + AddChild(sview); + r.top += 18; + r.bottom += 18; + } + +CountButtons() returns the number of buttons the joystick provides. The buttons are numbered from 0 to numButtons-1. The BRect, r, is initialized to the rectangle of the first button's label, and then we enter the for loop. + +In the loop, each button's name is retrieved by calling GetButtonNameAt(), which returns the name (as specified by the joystick's driver) for the specified button number. The name is returned in a BString object. We append a colon to the name (which makes it look like a label, instead of just random text displayed in a window), then we create a BStringView using the name as the label. Alignment and font settings are tweaked as appropriate, and the rectangle is adjusted so that the next button will be created 18 pixels further down in the window. + +A similar procedure is done to create the labels for the hats, which are displayed in the same column as the buttons. CountHats() is called to get the number of hats, and the labels are generated in the same way (except that the hat displays are larger, so each hat is displayed 40 pixels below the previous one, instead of just 18 pixels). + +The right-hand column is dedicated to displays for the axes. The topmost display is a two-dimensional display for the X and Y axes, and a "Stick:" label is displayed there, under the assumption that all joysticks have an X/Y axis pair. + +Below this are created labels for any other axes, such as throttles, twist controls, and the like. This is done just like the button labels (except that CountAxes() is called to get the number of axes available). Note that axes 0 and 1 are the X and Y axes (this is standard), and all axes above that are treated as one-dimensional axes. + +Finally, the view and window are resized so the height of the view and window is just a bit higher than needed to display the taller of the two columns. This makes the window look nice, without a lot of wasted space on the screen. + +The Pulse() function just locks the window and calls Draw() to refresh the display. + +The Draw() function actually handles drawing the joystick's movements interactively. It begins by getting the numbers of buttons, hats, and axes, and by allocating buffers for the axis and hat values: + +numButtons = stick->CountButtons(); +numHats = stick->CountHats(); +numAxes = stick->CountAxes(); +axes = (int16 *) malloc(sizeof(int16) * numAxes); +hats = (uint8 *) malloc(numHats); + +The axes and hats arrays will be used when we call GetAxisValues() and GetHatValues(); these functions fill these arrays with the values of each of the axes and hats on the joystick. + +Then, BJoystick::Update() is called. This tells the joystick driver to look at the state of the joystick and record the current values. Now we can actually retrieve the values and do something with them. + +We begin by drawing the state of the buttons. Each button is represented by a box next to the corresponding label. If the button is pressed, a solid black box is drawn. If the button isn't pressed, a hollow box is drawn. This is done in a loop, as follows: + +r.Set(105,50,115,60); +buttons = stick->ButtonValues(); +for (i=0; i Author: modeenf Date: 2008-07-14 21:53:39 +0200 (Mon, 14 Jul 2008) New Revision: 26414 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26414&view=rev Modified: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp haiku/trunk/src/tests/kits/device/stickit_BJoystick/stickit_x86.proj Log: small updates Modified: haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp =================================================================== --- haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp 2008-07-14 19:14:23 UTC (rev 26413) +++ haiku/trunk/src/tests/kits/device/stickit_BJoystick/StickItWindow.cpp 2008-07-14 19:53:39 UTC (rev 26414) @@ -163,10 +163,31 @@ if (err == B_OK) { err = stick->Open(devName); temp1 = AddToList(fListView1, "BJoystick::Open()"); - int32 sticks = stick->CountSticks(); + int32 count = stick->CountSticks(); temp1 << "BJoystick::CountSticks(), number of sticks = " - << sticks; + << count; temp1 = AddToList(fListView1, temp1.String()); + + count = stick->CountAxes(); + temp1 << "BJoystick::CountAxes(), number of Axes = " + << count; + temp1 = AddToList(fListView1, temp1.String()); + + count = stick->CountButtons(); + temp1 << "BJoystick::CountButtons(), number of Buttons = " + << count; + temp1 = AddToList(fListView1, temp1.String()); + + count = stick->CountHats(); + temp1 << "BJoystick::CountHats(), number of Hats = " + << count; + temp1 = AddToList(fListView1, temp1.String()); + + count = stick->CountDevices(); + temp1 << "BJoystick::CountDevices(), number of Devices = " + << count; + temp1 = AddToList(fListView1, temp1.String()); + if (err != B_ERROR) { BString name; err = stick->GetControllerModule(&name); Modified: haiku/trunk/src/tests/kits/device/stickit_BJoystick/stickit_x86.proj =================================================================== (Binary files differ) From stippi at mail.berlios.de Mon Jul 14 23:58:08 2008 From: stippi at mail.berlios.de (stippi at BerliOS) Date: Mon, 14 Jul 2008 23:58:08 +0200 Subject: [Haiku-commits] r26415 - in haiku/trunk/src/apps/mediaplayer: . media_node_framework Message-ID: <200807142158.m6ELw8QA001505@sheep.berlios.de> Author: stippi Date: 2008-07-14 23:58:07 +0200 (Mon, 14 Jul 2008) New Revision: 26415 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26415&view=rev Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp haiku/trunk/src/apps/mediaplayer/Controller.h haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.h haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.cpp haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.h Log: * Whether an audio and/or video node is used is now more explicit. The audio node can now also be turned off for videos that don't have audio. * The PlaybackManager currently has the "no audio" support added in a not quite so nice way, will have to think about something, this is just quick and dirty to get it going. There is just two places where the audio time needs to be ignored, because it remains at zero. -> Especially when using OSS, the seeking latency will be much reduced when playing videos that have no sound. * The Controller now maintains the frame it wanted to seek to and does not forward "position changed" to other listeners as long as the seek frame has not been reached. This fixes the slider jumping back to the old position for a bit until jumping back to the seek frame. It also fixes another problem when switching to the next file. Because the total duration is already adopted while the old clip is still playing within the seek latency, the current position jumped to the new relative position, while it is still refering to the position within the old clip. So both seeking and switching clips looks much smoother now. Modified: haiku/trunk/src/apps/mediaplayer/Controller.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.cpp 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/Controller.cpp 2008-07-14 21:58:07 UTC (rev 26415) @@ -100,6 +100,7 @@ , fPosition(0) , fDuration(0) , fVideoFrameRate(25.0) + , fSeekFrame(-1) , fAutoplay(true) , fPauseAtEndOfStream(false) @@ -164,7 +165,7 @@ if (fRef == ref) { if (InitCheck() == B_OK) { - SetCurrentFrame(0); + SetPosition(0.0); StartPlaying(); } return B_OK; @@ -269,17 +270,25 @@ preferredVideoFormat = format.u.raw_video.display.format; } + uint32 enabledNodes; + if (!fVideoTrackSupplier) + enabledNodes = AUDIO_ONLY; + else if (!fAudioTrackSupplier) + enabledNodes = VIDEO_ONLY; + else + enabledNodes = AUDIO_AND_VIDEO; + if (InitCheck() != B_OK) { Init(BRect(0, 0, width - 1, height - 1), fVideoFrameRate, - preferredVideoFormat, LOOPING_ALL, false); + preferredVideoFormat, LOOPING_ALL, false, 1.0, enabledNodes); } else { FormatChanged(BRect(0, 0, width - 1, height - 1), fVideoFrameRate, - preferredVideoFormat); + preferredVideoFormat, enabledNodes); } _NotifyFileChanged(); - SetCurrentFrame(0); + SetPosition(0.0); if (fAutoplay) StartPlaying(true); @@ -420,7 +429,7 @@ BAutolock _(this); StopPlaying(); - SetCurrentFrame(0); + SetPosition(0.0); } @@ -559,8 +568,14 @@ { BAutolock _(this); - SetCurrentFrame(Duration() * value); + fSeekFrame = (int32)(Duration() * value); + int32 currentFrame = CurrentFrame(); + if (fSeekFrame != currentFrame) + SetCurrentFrame(fSeekFrame); + else + fSeekFrame = -1; + // TODO: What was this used for in the old framework? fSeekToStartAfterPause = false; } @@ -891,6 +906,12 @@ void Controller::NotifyCurrentFrameChanged(int32 frame) const { + // check if we are still waiting to reach the seekframe, + // don't pass the event on to the listeners in that case + if (fSeekFrame >= 0 && frame != fSeekFrame) + return; + fSeekFrame = -1; + float position = 0.0; double duration = (double)fDuration * fVideoFrameRate / 1000000.0; if (duration > 0) Modified: haiku/trunk/src/apps/mediaplayer/Controller.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/Controller.h 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/Controller.h 2008-07-14 21:58:07 UTC (rev 26415) @@ -174,6 +174,7 @@ mutable bigtime_t fPosition; bigtime_t fDuration; float fVideoFrameRate; + mutable int32 fSeekFrame; bool fAutoplay; volatile bool fPauseAtEndOfStream; Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.cpp 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.cpp 2008-07-14 21:58:07 UTC (rev 26415) @@ -67,7 +67,7 @@ status_t NodeManager::Init(BRect videoBounds, float videoFrameRate, color_space preferredVideoFormat, int32 loopingMode, - bool loopingEnabled, float speed) + bool loopingEnabled, float speed, uint32 enabledNodes) { // init base class PlaybackManager::Init(videoFrameRate, loopingMode, loopingEnabled, speed); @@ -83,7 +83,7 @@ fAudioSupplier = CreateAudioSupplier(); return FormatChanged(videoBounds, videoFrameRate, preferredVideoFormat, - true); + enabledNodes, true); } // InitCheck @@ -118,13 +118,16 @@ // FormatChanged status_t NodeManager::FormatChanged(BRect videoBounds, float videoFrameRate, - color_space preferredVideoFormat, bool force) + color_space preferredVideoFormat, uint32 enabledNodes, bool force) { TRACE("NodeManager::FormatChanged()\n"); if (!force && videoBounds == VideoBounds() && videoFrameRate == FramesPerSecond()) { TRACE(" -> reusing existing nodes\n"); + // TODO: if enabledNodes would indicate that audio or video + // is no longer needed, or, worse yet, suddenly needed when + // it wasn't before, then we should not return here! return B_OK; } @@ -139,7 +142,7 @@ SetVideoBounds(videoBounds); - status_t ret = _SetUpNodes(preferredVideoFormat); + status_t ret = _SetUpNodes(preferredVideoFormat, enabledNodes); if (ret == B_OK) _StartNodes(); else @@ -247,7 +250,7 @@ // _SetUpNodes status_t -NodeManager::_SetUpNodes(color_space preferredVideoFormat) +NodeManager::_SetUpNodes(color_space preferredVideoFormat, uint32 enabledNodes) { TRACE("NodeManager::_SetUpNodes()\n"); @@ -271,7 +274,7 @@ } // setup the video nodes - if (fVideoBounds.IsValid()) { + if (enabledNodes != AUDIO_ONLY) { fStatus = _SetUpVideoNodes(preferredVideoFormat); if (fStatus != B_OK) { print_error("Error setting up video nodes", fStatus); @@ -282,11 +285,17 @@ printf("running without video node\n"); // setup the audio nodes - fStatus = _SetUpAudioNodes(); - if (fStatus != B_OK) { - print_error("Error setting up audio nodes", fStatus); - fMediaRoster->Unlock(); - return fStatus; + if (enabledNodes != VIDEO_ONLY) { + fStatus = _SetUpAudioNodes(); + if (fStatus != B_OK) { + print_error("Error setting up audio nodes", fStatus); + fMediaRoster->Unlock(); + return fStatus; + } +fNoAudio = false; + } else { +fNoAudio = true; + printf("running without audio node\n"); } // we're done mocking with the media roster @@ -589,7 +598,7 @@ NodeManager::_StartNodes() { status_t status = B_NO_INIT; - if (!fMediaRoster || !fAudioProducer) + if (!fMediaRoster) return status; // begin mucking with the media roster if (!fMediaRoster->Lock()) @@ -623,10 +632,13 @@ } initLatency += estimate_max_scheduling_latency(); - bigtime_t audioLatency = 0; - status = fMediaRoster->GetLatencyFor(fAudioConnection.producer, - &audioLatency); - TRACE("audio latency: %Ld\n", audioLatency); + if (fAudioProducer) { + // TODO: was this supposed to be added to initLatency?!? + bigtime_t audioLatency = 0; + status = fMediaRoster->GetLatencyFor(fAudioConnection.producer, + &audioLatency); + TRACE("audio latency: %Ld\n", audioLatency); + } BTimeSource* timeSource; if (fVideoProducer) { @@ -677,11 +689,13 @@ } } - fAudioProducer->SetRunning(true); - status = fMediaRoster->StartNode(fAudioConnection.producer, perf); - if (status != B_OK) { - print_error("Can't start the audio producer", status); - return status; + if (fAudioProducer) { + fAudioProducer->SetRunning(true); + status = fMediaRoster->StartNode(fAudioConnection.producer, perf); + if (status != B_OK) { + print_error("Can't start the audio producer", status); + return status; + } } fPerformanceTimeBase = perf; Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.h 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/NodeManager.h 2008-07-14 21:58:07 UTC (rev 26415) @@ -32,11 +32,18 @@ virtual AudioSupplier* CreateAudioSupplier() = 0; // NodeManager + enum { + AUDIO_AND_VIDEO = 0, + VIDEO_ONLY, + AUDIO_ONLY + }; + status_t Init(BRect videoBounds, float videoFrameRate, color_space preferredVideoFormat, int32 loopingMode = LOOPING_ALL, bool loopingEnabled = true, - float speed = 1.0); + float speed = 1.0, + uint32 enabledNodes = AUDIO_AND_VIDEO); status_t InitCheck(); // only call this if the // media_server has died! @@ -45,6 +52,7 @@ status_t FormatChanged(BRect videoBounds, float videoFrameRate, color_space preferredVideoFormat, + uint32 enabledNodes = AUDIO_AND_VIDEO, bool force = false); virtual void SetPlayMode(int32 mode, bool continuePlaying = true); @@ -65,7 +73,8 @@ void SetPeakListener(BHandler* handler); private: - status_t _SetUpNodes(color_space preferredVideoFormat); + status_t _SetUpNodes(color_space preferredVideoFormat, + uint32 enabledNodes); status_t _SetUpVideoNodes( color_space preferredVideoFormat); status_t _SetUpAudioNodes(); Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.cpp =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.cpp 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.cpp 2008-07-14 21:58:07 UTC (rev 26415) @@ -67,7 +67,8 @@ fPerformanceTime(0), fFrameRate(1.0), fStopPlayingFrame(-1), - fListeners() + fListeners(), + fNoAudio(false) { Run(); } @@ -452,8 +453,11 @@ int64 PlaybackManager::NextFrame() const { + if (fNoAudio) + return FrameForTime(fCurrentVideoTime - 1) + 1; + return FrameForTime(max((bigtime_t)fCurrentAudioTime, - (bigtime_t)fCurrentVideoTime) - 1) + 1; + (bigtime_t)fCurrentVideoTime) - 1) + 1; } @@ -1549,6 +1553,9 @@ bigtime_t PlaybackManager::_TimeForLastFrame() const { + if (fNoAudio) + return TimeForFrame(FrameForTime(fCurrentVideoTime)); + return TimeForFrame(FrameForTime(min((bigtime_t)fCurrentAudioTime, (bigtime_t)fCurrentVideoTime))); } Modified: haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.h =================================================================== --- haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.h 2008-07-14 19:53:39 UTC (rev 26414) +++ haiku/trunk/src/apps/mediaplayer/media_node_framework/PlaybackManager.h 2008-07-14 21:58:07 UTC (rev 26415) @@ -228,6 +228,8 @@ // disabled: -1 BList fListeners; + protected: + bool fNoAudio; }; From axeld at mail.berlios.de Tue Jul 15 01:23:17 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 01:23:17 +0200 Subject: [Haiku-commits] r26416 - haiku/trunk/src/add-ons/kernel/file_systems/bfs Message-ID: <200807142323.m6ENNHOZ027697@sheep.berlios.de> Author: axeld Date: 2008-07-15 01:23:16 +0200 (Tue, 15 Jul 2008) New Revision: 26416 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26416&view=rev Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp Log: * Fixed the bug described by Salvatore: since we let BFS open directories with read/write access, we shouldn't let it truncate the directory B+tree... * Also fixed allowing truncation in read-only mode. Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-14 21:58:07 UTC (rev 26415) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp 2008-07-14 23:23:16 UTC (rev 26416) @@ -1147,7 +1147,14 @@ cookie->last_notification = system_time(); // Should we truncate the file? - if (openMode & O_TRUNC) { + if ((openMode & O_TRUNC) != 0) { + if ((openMode & O_RWMASK) == O_RDONLY) + return B_NOT_ALLOWED; + // TODO: this check is only necessary as long as we allow directories + // to be opened r/w, see above. + if (inode->IsDirectory()) + return B_IS_A_DIRECTORY; + Transaction transaction(volume, inode->BlockNumber()); WriteLocker locker(inode->Lock()); From stefano.ceccherini at gmail.com Tue Jul 15 09:19:26 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Tue, 15 Jul 2008 09:19:26 +0200 Subject: [Haiku-commits] r26411 - haiku/trunk/src/apps/workspaces In-Reply-To: <200807141733.m6EHXBEF001775@sheep.berlios.de> References: <200807141733.m6EHXBEF001775@sheep.berlios.de> Message-ID: <894b9700807150019gf1a0935me03257ff44193783@mail.gmail.com> 2008/7/14 axeld at BerliOS : > * Popup menu is now sticky - this should probably be the default of all menus > when "sticky menus" is selected in the menu preferences (just in case we still > have that setting...). We don't :) From superstippi at gmx.de Tue Jul 15 13:21:40 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 15 Jul 2008 13:21:40 +0200 Subject: [Haiku-commits] r26408 - haiku/trunk/src/apps/midiplayer In-Reply-To: <200807141641.m6EGfOIx020371@sheep.berlios.de> References: <200807141641.m6EGfOIx020371@sheep.berlios.de> Message-ID: <20080715132140.761.1@stippis2.1216119101.fake> Hi Ryan, nice patch (and article, although I would prefer to use the dark on light scheme for the code sections)! My only comment is that you could change some of the constructors to use the new layout friendly versions: Index: MidiPlayerWindow.cpp =================================================================== --- MidiPlayerWindow.cpp (revision 26416) +++ MidiPlayerWindow.cpp (working copy) @@ -236,34 +236,31 @@ // Set up needed views scopeView = new ScopeView; - showScope = new BCheckBox( - BRect(0, 0, 1, 1), "showScope", "Scope", - new BMessage(MSG_SHOW_SCOPE), B_FOLLOW_LEFT); + showScope = new BCheckBox("showScope", "Scope", + new BMessage(MSG_SHOW_SCOPE)); showScope->SetValue(B_CONTROL_ON); CreateInputMenu(); CreateReverbMenu(); - volumeSlider = new BSlider( - BRect(0, 0, 1, 1), "volumeSlider", NULL, NULL, + volumeSlider = new BSlider(BRect(0, 0, 1, 1), "volumeSlider", NULL, NULL, 0, 100, B_TRIANGLE_THUMB); + // TODO: use layout version of constructor once available rgb_color col = { 152, 152, 255 }; volumeSlider->UseFillColor(true, &col); volumeSlider->SetModificationMessage(new BMessage(MSG_VOLUME)); - playButton = new BButton( - BRect(0, 1, 80, 1), "playButton", "Play", new BMessage(MSG_PLAY_STOP), - B_FOLLOW_RIGHT); + playButton = new BButton("playButton", "Play", new BMessage(MSG_PLAY_STOP)); playButton->SetEnabled(false); - BBox* divider = new BBox( - BRect(0, 0, 1, 1), B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, - B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); + BBox* divider = new BBox(B_EMPTY_STRING, B_WILL_DRAW | B_FRAME_EVENTS, + B_FANCY_BORDER); divider->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, 1)); - BStringView* volumeLabel = new BStringView( - BRect(0, 0, 1, 1), NULL, "Volume:"); + BStringView* volumeLabel = new BStringView(BRect(0, 0, 1, 1), NULL, + "Volume:"); + // TODO: use layout version of constructor once available volumeLabel->SetAlignment(B_ALIGN_LEFT); volumeLabel->SetExplicitMaxSize( BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); --- Maybe I get around to add layout friendly constructors to the classes missing them, then the rest could be changed as well. Best regards, -Stephan From bonefish at mail.berlios.de Tue Jul 15 13:28:20 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 15 Jul 2008 13:28:20 +0200 Subject: [Haiku-commits] r26417 - haiku/trunk/src/system/kernel/disk_device_manager Message-ID: <200807151128.m6FBSKxF005014@sheep.berlios.de> Author: bonefish Date: 2008-07-15 13:28:18 +0200 (Tue, 15 Jul 2008) New Revision: 26417 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26417&view=rev Modified: haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp Log: Properly round the partition size in get_default_partition_content_name(). Modified: haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp =================================================================== --- haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2008-07-14 23:23:16 UTC (rev 26416) +++ haiku/trunk/src/system/kernel/disk_device_manager/disk_device_manager.cpp 2008-07-15 11:28:18 UTC (rev 26417) @@ -234,24 +234,26 @@ if (partition == NULL) return B_ENTRY_NOT_FOUND; - off_t size = partition->ContentSize(); + double size = partition->ContentSize(); partition->Unregister(); - const char* const suffixes[] = { - "", "K", "M", "G", "T", "P", "E", NULL - }; + const char* const suffixes[] = { + "", "K", "M", "G", "T", "P", "E", NULL + }; - size *= 10; - // We want one digit precision. - int index = 0; - while (size >= 1024 * 10 && suffixes[index + 1]) { - size /= 1024; - index++; - } + int index = 0; + while (size >= 1024 && suffixes[index + 1]) { + size /= 1024; + index++; + } - snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, - int32(size / 10), int32(size % 10), suffixes[index]); + // Our kernel snprintf() ignores the precision argument, so we manually + // do one digit precision. + uint64 result = uint64(size * 10 + 0.5); + snprintf(buffer, bufferSize, "%s Volume (%ld.%ld %sB)", fileSystemName, + int32(result / 10), int32(result % 10), suffixes[index]); + return B_OK; } From mmlr at mail.berlios.de Tue Jul 15 13:52:12 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Tue, 15 Jul 2008 13:52:12 +0200 Subject: [Haiku-commits] r26418 - haiku/trunk/build/jam Message-ID: <200807151152.m6FBqChU025901@sheep.berlios.de> Author: mmlr Date: 2008-07-15 13:52:08 +0200 (Tue, 15 Jul 2008) New Revision: 26418 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26418&view=rev Modified: haiku/trunk/build/jam/BuildSetup Log: Add -Wno-multichar to the kernel warning flags to avoid useless warnings. Modified: haiku/trunk/build/jam/BuildSetup =================================================================== --- haiku/trunk/build/jam/BuildSetup 2008-07-15 11:28:18 UTC (rev 26417) +++ haiku/trunk/build/jam/BuildSetup 2008-07-15 11:52:08 UTC (rev 26418) @@ -305,8 +305,9 @@ HAIKU_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-ctor-dtor-privacy -Woverloaded-virtual -Wpointer-arith -Wcast-align -Wsign-compare ; -HAIKU_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes ; -HAIKU_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs ; +HAIKU_KERNEL_WARNING_CCFLAGS = -Wall -Wno-trigraphs -Wmissing-prototypes + -Wno-multichar ; +HAIKU_KERNEL_WARNING_C++FLAGS = -Wall -Wno-trigraphs -Wno-multichar ; # debug flags HAIKU_DEBUG_FLAGS ?= -ggdb ; From mmlr at mail.berlios.de Tue Jul 15 13:53:10 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Tue, 15 Jul 2008 13:53:10 +0200 Subject: [Haiku-commits] r26419 - haiku/trunk/headers/build Message-ID: <200807151153.m6FBrAW6025965@sheep.berlios.de> Author: mmlr Date: 2008-07-15 13:53:07 +0200 (Tue, 15 Jul 2008) New Revision: 26419 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26419&view=rev Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h Log: Avoid redefinition of B_NOT_SUPPORTED on BeOS build platform. Modified: haiku/trunk/headers/build/HaikuBuildCompatibility.h =================================================================== --- haiku/trunk/headers/build/HaikuBuildCompatibility.h 2008-07-15 11:52:08 UTC (rev 26418) +++ haiku/trunk/headers/build/HaikuBuildCompatibility.h 2008-07-15 11:53:07 UTC (rev 26419) @@ -146,7 +146,7 @@ #endif #if !defined(HAIKU_TARGET_PLATFORM_HAIKU) && !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) -# ifndef HAIKU_HOST_PLATFORM_DANO +# if !defined(B_NOT_SUPPORTED) && !defined(HAIKU_HOST_PLATFORM_DANO) # define B_NOT_SUPPORTED (B_ERROR) # endif # define B_KERNEL_READ_AREA 0 From stippi at mail.berlios.de Tue Jul 15 15:17:23 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:17:23 +0200 Subject: [Haiku-commits] r26420 - haiku/trunk/src/kits/interface Message-ID: <200807151317.m6FDHNFK010908@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:17:20 +0200 (Tue, 15 Jul 2008) New Revision: 26420 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26420&view=rev Modified: haiku/trunk/src/kits/interface/TextView.cpp Log: Insignificant cleanup and comment typo fixes... Modified: haiku/trunk/src/kits/interface/TextView.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextView.cpp 2008-07-15 11:53:07 UTC (rev 26419) +++ haiku/trunk/src/kits/interface/TextView.cpp 2008-07-15 13:17:20 UTC (rev 26420) @@ -2684,7 +2684,7 @@ */ void BTextView::_InitObject(BRect textRect, const BFont *initialFont, - const rgb_color *initialColor) + const rgb_color *initialColor) { BFont font; if (initialFont == NULL) @@ -2703,7 +2703,7 @@ // We put these here instead of in the constructor initializer list // to have less code duplication, and a single place where to do changes - // if needed., + // if needed. fTextRect = textRect; fMinTextRectWidth = fTextRect.Width(); fSelStart = fSelEnd = 0; From stippi at mail.berlios.de Tue Jul 15 15:17:55 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:17:55 +0200 Subject: [Haiku-commits] r26421 - haiku/trunk/src/kits/interface Message-ID: <200807151317.m6FDHtie010990@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:17:52 +0200 (Tue, 15 Jul 2008) New Revision: 26421 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26421&view=rev Modified: haiku/trunk/src/kits/interface/View.cpp Log: Added comment about possibly invalidating the layout when changing the font. Modified: haiku/trunk/src/kits/interface/View.cpp =================================================================== --- haiku/trunk/src/kits/interface/View.cpp 2008-07-15 13:17:20 UTC (rev 26420) +++ haiku/trunk/src/kits/interface/View.cpp 2008-07-15 13:17:52 UTC (rev 26421) @@ -2241,6 +2241,8 @@ fState->UpdateServerFontState(*fOwner->fLink); } + + // TODO: InvalidateLayout() here for convenience? } From stippi at mail.berlios.de Tue Jul 15 15:20:31 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:20:31 +0200 Subject: [Haiku-commits] r26422 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807151320.m6FDKVZc011539@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:20:26 +0200 (Tue, 15 Jul 2008) New Revision: 26422 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26422&view=rev Modified: haiku/trunk/headers/os/interface/StringView.h haiku/trunk/src/kits/interface/StringView.cpp Log: * Cache a fPreferredSize following the example of BButton. Changed GetPreferredSize() accordingly. * No longer adds margins to the left/right side and top/bottom. These will make it difficult to make exact visual alignments with other controls and labels. * Invalidate the layout in SetText(). Modified: haiku/trunk/headers/os/interface/StringView.h =================================================================== --- haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:17:52 UTC (rev 26421) +++ haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:20:26 UTC (rev 26422) @@ -19,6 +19,8 @@ const char* text, uint32 resizeFlags = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_WILL_DRAW); + BStringView(const char* name, const char* text, + uint32 flags = B_WILL_DRAW); BStringView(BMessage* data); virtual ~BStringView(); @@ -53,7 +55,15 @@ virtual void AllDetached(); virtual status_t GetSupportedSuites(BMessage* data); +// TODO: should be implemented and invalidate the layout +// virtual void SetFont(const BFont* font, +// uint32 mask = B_FONT_ALL); + + virtual void InvalidateLayout(bool descendants = false); + + virtual BSize MinSize(); virtual BSize MaxSize(); + virtual BSize PreferredSize(); private: virtual status_t Perform(perform_code d, void* arg); @@ -61,11 +71,14 @@ virtual void _ReservedStringView2(); virtual void _ReservedStringView3(); + BSize _ValidatePreferredSize(); + BStringView &operator=(const BStringView&); char* fText; alignment fAlign; - uint32 _reserved[3]; + BSize fPreferredSize; + uint32 _reserved[1]; }; #endif // _STRING_VIEW_H Modified: haiku/trunk/src/kits/interface/StringView.cpp =================================================================== --- haiku/trunk/src/kits/interface/StringView.cpp 2008-07-15 13:17:52 UTC (rev 26421) +++ haiku/trunk/src/kits/interface/StringView.cpp 2008-07-15 13:20:26 UTC (rev 26422) @@ -1,12 +1,14 @@ /* - * Copyright 2001-2005, Haiku Inc. + * Copyright 2001-2008, Haiku Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Frans van Nispen (xlr8 at tref.nl) + * Ingo Weinhold + * Stephan A?mus */ -/** BStringView draw a non-editable text string */ +//! BStringView draws a non-editable text string. #include @@ -22,17 +24,28 @@ BStringView::BStringView(BRect frame, const char* name, const char* text, - uint32 resizeMask, uint32 flags) - : BView(frame, name, resizeMask, flags) + uint32 resizeMask, uint32 flags) + : BView(frame, name, resizeMask, flags), + fText(text ? strdup(text) : NULL), + fAlign(B_ALIGN_LEFT), + fPreferredSize(-1, -1) { - fText = text ? strdup(text) : NULL; - fAlign = B_ALIGN_LEFT; } +BStringView::BStringView(const char* name, const char* text, uint32 flags) + : BView(name, flags), + fText(text ? strdup(text) : NULL), + fAlign(B_ALIGN_LEFT), + fPreferredSize(-1, -1) +{ +} + + BStringView::BStringView(BMessage* data) - : BView(data), - fText(NULL) + : BView(data), + fText(NULL), + fPreferredSize(-1, -1) { int32 align; if (data->FindInt32("_align", &align) == B_OK) @@ -82,11 +95,13 @@ void BStringView::SetText(const char* text) { - if ((text && fText && !strcmp(text, fText)) - || (!text && !fText)) + if ((text && fText && !strcmp(text, fText)) || (!text && !fText)) return; + free(fText); fText = text ? strdup(text) : NULL; + + InvalidateLayout(); Invalidate(); } @@ -132,19 +147,22 @@ font_height fontHeight; GetFontHeight(&fontHeight); - float y = Bounds().bottom - ceil(fontHeight.descent); + BRect bounds = Bounds(); + + float y = (bounds.top + bounds.bottom - ceilf(fontHeight.ascent) + - ceilf(fontHeight.descent)) / 2.0 + ceilf(fontHeight.ascent); float x; switch (fAlign) { case B_ALIGN_RIGHT: - x = Bounds().Width() - StringWidth(fText) - 2.0f; + x = bounds.Width() - StringWidth(fText); break; case B_ALIGN_CENTER: - x = (Bounds().Width() - StringWidth(fText)) / 2.0f; + x = (bounds.Width() - StringWidth(fText)) / 2.0; break; default: - x = 2.0f; + x = 0.0; break; } @@ -169,19 +187,13 @@ void BStringView::GetPreferredSize(float* _width, float* _height) { - if (!fText) { - BView::GetPreferredSize(_width, _height); - return; - } + _ValidatePreferredSize(); if (_width) - *_width = 4.0f + ceil(StringWidth(fText)); + *_width = fPreferredSize.width; - if (_height) { - font_height fontHeight; - GetFontHeight(&fontHeight); - *_height = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 2.0f; - } + if (_height) + *_height = fPreferredSize.height; } @@ -270,13 +282,37 @@ } +void +BStringView::InvalidateLayout(bool descendants) +{ + // invalidate cached preferred size + fPreferredSize.Set(-1, -1); + + BView::InvalidateLayout(descendants); +} + + BSize +BStringView::MinSize() +{ + return BLayoutUtils::ComposeSize(ExplicitMinSize(), + _ValidatePreferredSize()); +} + + +BSize BStringView::MaxSize() { - float width, height; - GetPreferredSize(&width, &height); + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), + _ValidatePreferredSize()); +} - return BLayoutUtils::ComposeSize(ExplicitMaxSize(), BSize(width, height)); + +BSize +BStringView::PreferredSize() +{ + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), + _ValidatePreferredSize()); } @@ -298,3 +334,22 @@ // Assignment not allowed (private) return *this; } + +BSize +BStringView::_ValidatePreferredSize() +{ + if (fPreferredSize.width < 0) { + // width + fPreferredSize.width = ceilf(StringWidth(fText)); + + // height + font_height fontHeight; + GetFontHeight(&fontHeight); + + fPreferredSize.height = ceilf(fontHeight.ascent + fontHeight.descent + + fontHeight.leading); + } + + return fPreferredSize; +} + From stippi at mail.berlios.de Tue Jul 15 15:22:32 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:22:32 +0200 Subject: [Haiku-commits] r26423 - haiku/trunk/src/kits/interface Message-ID: <200807151322.m6FDMWMY012131@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:22:29 +0200 (Tue, 15 Jul 2008) New Revision: 26423 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26423&view=rev Modified: haiku/trunk/src/kits/interface/TextControl.cpp Log: Minor cleanup again. Modified: haiku/trunk/src/kits/interface/TextControl.cpp =================================================================== --- haiku/trunk/src/kits/interface/TextControl.cpp 2008-07-15 13:20:26 UTC (rev 26422) +++ haiku/trunk/src/kits/interface/TextControl.cpp 2008-07-15 13:22:29 UTC (rev 26423) @@ -731,8 +731,7 @@ fText = static_cast(FindView("_input_")); if (fText == NULL) { - BRect frame(fDivider, bounds.top, - bounds.right, bounds.bottom); + BRect frame(fDivider, bounds.top, bounds.right, bounds.bottom); // we are stroking the frame around the text view, which // is 2 pixels wide frame.InsetBy(2.0, 3.0); From stippi at mail.berlios.de Tue Jul 15 15:23:32 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:23:32 +0200 Subject: [Haiku-commits] r26424 - haiku/trunk/src/kits/interface Message-ID: <200807151323.m6FDNWiZ012238@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:23:29 +0200 (Tue, 15 Jul 2008) New Revision: 26424 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26424&view=rev Modified: haiku/trunk/src/kits/interface/Button.cpp Log: * Small coding style improvements. * fPreferredSize was not initialized for the archive constructor. * Added comment to archive constructor, because I was wondering how the default button status was reconstructed or the archive code path. Modified: haiku/trunk/src/kits/interface/Button.cpp =================================================================== --- haiku/trunk/src/kits/interface/Button.cpp 2008-07-15 13:22:29 UTC (rev 26423) +++ haiku/trunk/src/kits/interface/Button.cpp 2008-07-15 13:23:29 UTC (rev 26424) @@ -60,10 +60,13 @@ BButton::BButton(BMessage *archive) - : BControl (archive) + : BControl(archive), + fPreferredSize(-1, -1) { if (archive->FindBool("_default", &fDrawAsDefault) != B_OK) fDrawAsDefault = false; + // NOTE: Default button state will be synchronized with the window + // in AttachedToWindow(). } @@ -247,7 +250,7 @@ const float x = (rect.right - stringWidth) / 2.0; const float labelY = bounds.top + ((bounds.Height() - fh.ascent - fh.descent) / 2.0) - + fh.ascent + 1.0; + + fh.ascent + 1.0; const float focusLineY = labelY + fh.descent; /* speed trick: @@ -260,8 +263,10 @@ if (pushed) { rect.InsetBy(2.0, 2.0); InvertRect(rect); - } else - DrawFocusLine(x, focusLineY, stringWidth, IsFocus() && Window()->IsActive()); + } else { + DrawFocusLine(x, focusLineY, stringWidth, IsFocus() + && Window()->IsActive()); + } return; } @@ -294,19 +299,24 @@ bevelColor2 = panelBgColor; if (IsDefault()) { - borderBevelShadow = tint_color(dark1BorderColor, (B_NO_TINT + B_DARKEN_1_TINT) / 2); + borderBevelShadow = tint_color(dark1BorderColor, + (B_NO_TINT + B_DARKEN_1_TINT) / 2); borderBevelLight = tint_color(dark1BorderColor, B_LIGHTEN_1_TINT); - borderBevelLight.red = (borderBevelLight.red + panelBgColor.red) / 2; - borderBevelLight.green = (borderBevelLight.green + panelBgColor.green) / 2; - borderBevelLight.blue = (borderBevelLight.blue + panelBgColor.blue) / 2; + borderBevelLight.red = (borderBevelLight.red + panelBgColor.red) + / 2; + borderBevelLight.green = (borderBevelLight.green + + panelBgColor.green) / 2; + borderBevelLight.blue = (borderBevelLight.blue + + panelBgColor.blue) / 2; dark1BorderColor = tint_color(dark1BorderColor, B_DARKEN_3_TINT); dark2BorderColor = tint_color(dark1BorderColor, B_DARKEN_4_TINT); bevelColorRBCorner = borderBevelShadow; } else { - borderBevelShadow = tint_color(panelBgColor, (B_NO_TINT + B_DARKEN_1_TINT) / 2); + borderBevelShadow = tint_color(panelBgColor, + (B_NO_TINT + B_DARKEN_1_TINT) / 2); borderBevelLight = buttonBgColor; bevelColorRBCorner = dark1BorderColor; From superstippi at gmx.de Tue Jul 15 15:28:52 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 15 Jul 2008 15:28:52 +0200 Subject: [Haiku-commits] r26422 - in haiku/trunk: headers/os/interface src/kits/interface In-Reply-To: <200807151320.m6FDKVZc011539@sheep.berlios.de> References: <200807151320.m6FDKVZc011539@sheep.berlios.de> Message-ID: <20080715152852.16877.4@stippis2.1216119101.fake> Hi, stippi at mail.berlios.de wrote: > Modified: haiku/trunk/headers/os/interface/StringView.h > =================================================================== > --- haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:17:52 > UTC (rev 26421) > +++ haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:20:26 > + > + virtual void InvalidateLayout(bool descendants = > false); > + > + virtual BSize MinSize(); > virtual BSize MaxSize(); > + virtual BSize PreferredSize(); This change might be broken, since I added virtual functions but did not remove reserved slots. Will check and correct if necessary. Best regards, -Stephan From anevilyak at gmail.com Tue Jul 15 15:33:10 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 15 Jul 2008 08:33:10 -0500 Subject: [Haiku-commits] r26422 - in haiku/trunk: headers/os/interface src/kits/interface In-Reply-To: <20080715152852.16877.4@stippis2.1216119101.fake> References: <200807151320.m6FDKVZc011539@sheep.berlios.de> <20080715152852.16877.4@stippis2.1216119101.fake> Message-ID: On Tue, Jul 15, 2008 at 8:28 AM, Stephan Assmus wrote: =================================================================== >> --- haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:17:52 >> UTC (rev 26421) >> +++ haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:20:26 >> + >> + virtual void InvalidateLayout(bool descendants = >> false); >> + >> + virtual BSize MinSize(); >> virtual BSize MaxSize(); >> + virtual BSize PreferredSize(); > > This change might be broken, since I added virtual functions but did not > remove reserved slots. Will check and correct if necessary. > I believe that change doesn't affect anything since those are overrides from BView, though the order of virtuals will still matter. However...this change seems to have broken the build: /usr/home/rene/devel/haiku/src/kits/interface/StringView.cpp:150: declaration of `bounds' shadows a parameter Regards, Rene From stippi at mail.berlios.de Tue Jul 15 15:55:48 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 15:55:48 +0200 Subject: [Haiku-commits] r26425 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807151355.m6FDtmbV019957@sheep.berlios.de> Author: stippi Date: 2008-07-15 15:55:44 +0200 (Tue, 15 Jul 2008) New Revision: 26425 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26425&view=rev Modified: haiku/trunk/headers/os/interface/StringView.h haiku/trunk/src/kits/interface/StringView.cpp Log: * Implement SetFont() and invalidate the layout. More controls should probably do this. * Fix build, appearantly I made a last minute change in Draw()... BTW, confirmed that adding virtuals declared in the base class is ok for binary compatibility. Modified: haiku/trunk/headers/os/interface/StringView.h =================================================================== --- haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:23:29 UTC (rev 26424) +++ haiku/trunk/headers/os/interface/StringView.h 2008-07-15 13:55:44 UTC (rev 26425) @@ -55,9 +55,8 @@ virtual void AllDetached(); virtual status_t GetSupportedSuites(BMessage* data); -// TODO: should be implemented and invalidate the layout -// virtual void SetFont(const BFont* font, -// uint32 mask = B_FONT_ALL); + virtual void SetFont(const BFont* font, + uint32 mask = B_FONT_ALL); virtual void InvalidateLayout(bool descendants = false); Modified: haiku/trunk/src/kits/interface/StringView.cpp =================================================================== --- haiku/trunk/src/kits/interface/StringView.cpp 2008-07-15 13:23:29 UTC (rev 26424) +++ haiku/trunk/src/kits/interface/StringView.cpp 2008-07-15 13:55:44 UTC (rev 26425) @@ -137,7 +137,7 @@ void -BStringView::Draw(BRect bounds) +BStringView::Draw(BRect updateRect) { if (!fText) return; @@ -283,6 +283,16 @@ void +BStringView::SetFont(const BFont* font, uint32 mask) +{ + BView::SetFont(font, mask); + + InvalidateLayout(); + Invalidate(); +} + + +void BStringView::InvalidateLayout(bool descendants) { // invalidate cached preferred size From superstippi at gmx.de Tue Jul 15 15:58:46 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 15 Jul 2008 15:58:46 +0200 Subject: [Haiku-commits] r26422 - in haiku/trunk: headers/os/interface src/kits/interface In-Reply-To: References: <200807151320.m6FDKVZc011539@sheep.berlios.de> <20080715152852.16877.4@stippis2.1216119101.fake> Message-ID: <20080715155846.17275.6@stippis2.1216119101.fake> Rene Gollent wrote: > On Tue, Jul 15, 2008 at 8:28 AM, Stephan Assmus > wrote: =================================================================== > >> --- haiku/trunk/headers/os/interface/StringView.h 2008-07-15 > >> 13:17:52 > >> UTC (rev 26421) > >> +++ haiku/trunk/headers/os/interface/StringView.h 2008-07-15 > >> 13:20:26 > >> + > >> + virtual void InvalidateLayout(bool descendants = > >> false); > >> + > >> + virtual BSize MinSize(); > >> virtual BSize MaxSize(); > >> + virtual BSize PreferredSize(); > > > > This change might be broken, since I added virtual functions but did > > not remove reserved slots. Will check and correct if necessary. > > > > I believe that change doesn't affect anything since those are overrides > from BView, though the order of virtuals will still matter. Ingo + Axel say that order does not matter if the base class declares them. I figure it matters in the base class though. I wouldn't know though... :-) > However...this change seems to have broken the build: > > /usr/home/rene/devel/haiku/src/kits/interface/StringView.cpp:150: > declaration of `bounds' shadows a parameter Thanks, just noticed myself. I thought I had compiled afterwards, but obviously not so. Best regards, -Stephan From zooey at mail.berlios.de Tue Jul 15 17:09:32 2008 From: zooey at mail.berlios.de (zooey at BerliOS) Date: Tue, 15 Jul 2008 17:09:32 +0200 Subject: [Haiku-commits] r26426 - haiku/trunk/src/add-ons/kernel/drivers/tty Message-ID: <200807151509.m6FF9W34029269@sheep.berlios.de> Author: zooey Date: 2008-07-15 17:09:32 +0200 (Tue, 15 Jul 2008) New Revision: 26426 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26426&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp Log: Fix problem with openssh failing to connect to OpenSolaris and Zeta servers: * we need to initialize c_ospeed and c_ispeed, as a value of 0 means 'hangup' - which is not a good default, I suppose Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2008-07-15 13:55:44 UTC (rev 26425) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp 2008-07-15 15:09:32 UTC (rev 26426) @@ -785,6 +785,8 @@ termios.c_cflag = B19200 | CS8 | CREAD | HUPCL; // enable receiver, hang up on last close termios.c_lflag = ECHO | ISIG | ICANON; + termios.c_ispeed = B19200; + termios.c_ospeed = B19200; // control characters termios.c_cc[VINTR] = CTRL('C'); From stippi at mail.berlios.de Tue Jul 15 17:41:07 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 17:41:07 +0200 Subject: [Haiku-commits] r26427 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807151541.m6FFf7S3000503@sheep.berlios.de> Author: stippi Date: 2008-07-15 17:41:03 +0200 (Tue, 15 Jul 2008) New Revision: 26427 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26427&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: Add one more optimization for an often used case of bitmap rendering. B_RGBA32 and B_RGB32 in B_OP_OVER no longer go through the generic AGG code path, but have an optimized version now, as long as the bitmap is not scaled. B_RGB32 needs to handle B_TRANSPARENT_MAGIC_RGBA32, while B_RGBA32 works just like regular alpha blending. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 15:09:32 UTC (rev 26426) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 15:41:03 UTC (rev 26427) @@ -1253,7 +1253,7 @@ // copy_bitmap_row_cmap8_over static inline void copy_bitmap_row_cmap8_over(uint8* dst, const uint8* src, int32 numPixels, - const rgb_color* colorMap) + const rgb_color* colorMap) { uint32* d = (uint32*)dst; const uint8* s = src; @@ -1268,15 +1268,30 @@ // copy_bitmap_row_bgr32_copy static inline void copy_bitmap_row_bgr32_copy(uint8* dst, const uint8* src, int32 numPixels, - const rgb_color* colorMap) + const rgb_color* colorMap) { memcpy(dst, src, numPixels * 4); } +// copy_bitmap_row_bgr32_over +static inline void +copy_bitmap_row_bgr32_over(uint8* dst, const uint8* src, int32 numPixels, + const rgb_color* colorMap) +{ + uint32* d = (uint32*)dst; + uint32* s = (uint32*)src; + while (numPixels--) { + if (*s != B_TRANSPARENT_MAGIC_RGBA32) + *(uint32*)d = *(uint32*)s; + d++; + s++; + } +} + // copy_bitmap_row_bgr32_alpha static inline void copy_bitmap_row_bgr32_alpha(uint8* dst, const uint8* src, int32 numPixels, - const rgb_color* colorMap) + const rgb_color* colorMap) { uint32* d = (uint32*)dst; int32 bytes = numPixels * 4; @@ -1291,7 +1306,7 @@ b[1] = ((src[1] - b[1]) * src[3] + (b[1] << 8)) >> 8; b[2] = ((src[2] - b[2]) * src[3] + (b[2] << 8)) >> 8; } - d ++; + d++; b += 4; src += 4; } @@ -1326,8 +1341,7 @@ // _DrawBitmap void Painter::_DrawBitmap(agg::rendering_buffer& srcBuffer, color_space format, - BRect actualBitmapRect, BRect bitmapRect, - BRect viewRect) const + BRect actualBitmapRect, BRect bitmapRect, BRect viewRect) const { if (!fValidClipping || !bitmapRect.IsValid() || !bitmapRect.Intersects(actualBitmapRect) @@ -1390,21 +1404,29 @@ if (xScale == 1.0 && yScale == 1.0) { if (fDrawingMode == B_OP_COPY) { _DrawBitmapNoScale32(copy_bitmap_row_bgr32_copy, 4, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, xOffset, yOffset, viewRect); return; + } else if (fDrawingMode == B_OP_OVER) { + if (format == B_RGB32) + _DrawBitmapNoScale32(copy_bitmap_row_bgr32_over, 4, + srcBuffer, xOffset, yOffset, viewRect); + else + _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, + srcBuffer, xOffset, yOffset, viewRect); + return; } else if (fDrawingMode == B_OP_ALPHA && fAlphaSrcMode == B_PIXEL_ALPHA && fAlphaFncMode == B_ALPHA_OVERLAY) { _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, xOffset, yOffset, viewRect); return; } } if (format == B_RGBA32 || fDrawingMode == B_OP_COPY) { _DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, - xScale, yScale, viewRect); - break; + xScale, yScale, viewRect); + return; } // otherwise fall through to get proper transparency handling for // B_RGB32 where a B_TRANSPARENT_MAGIC might be set on pixels @@ -1413,11 +1435,11 @@ if (format == B_CMAP8 && xScale == 1.0 && yScale == 1.0) { if (fDrawingMode == B_OP_COPY) { _DrawBitmapNoScale32(copy_bitmap_row_cmap8_copy, 1, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, xOffset, yOffset, viewRect); return; } else if (fDrawingMode == B_OP_OVER) { _DrawBitmapNoScale32(copy_bitmap_row_cmap8_over, 1, - srcBuffer, xOffset, yOffset, viewRect); + srcBuffer, xOffset, yOffset, viewRect); return; } } @@ -1430,9 +1452,8 @@ // maybe we can use an optimized version BBitmap temp(actualBitmapRect, B_BITMAP_NO_SERVER_LINK, B_RGBA32); status_t err = temp.ImportBits(srcBuffer.buf(), - srcBuffer.height() * srcBuffer.stride(), - srcBuffer.stride(), - 0, format); + srcBuffer.height() * srcBuffer.stride(), + srcBuffer.stride(), 0, format); if (err >= B_OK) { // the original bitmap might have had some of the @@ -1464,11 +1485,11 @@ agg::rendering_buffer convertedBuffer; convertedBuffer.attach((uint8*)temp.Bits(), - (uint32)actualBitmapRect.IntegerWidth() + 1, - (uint32)actualBitmapRect.IntegerHeight() + 1, - temp.BytesPerRow()); + (uint32)actualBitmapRect.IntegerWidth() + 1, + (uint32)actualBitmapRect.IntegerHeight() + 1, + temp.BytesPerRow()); _DrawBitmapGeneric32(convertedBuffer, xOffset, yOffset, - xScale, yScale, viewRect); + xScale, yScale, viewRect); } else { fprintf(stderr, "Painter::_DrawBitmap() - " "colorspace conversion failed: %s\n", strerror(err)); From bonefish at mail.berlios.de Tue Jul 15 17:41:56 2008 From: bonefish at mail.berlios.de (bonefish at mail.berlios.de) Date: Tue, 15 Jul 2008 17:41:56 +0200 Subject: [Haiku-commits] r26428 - haiku/branches/developer/bonefish/vm/src/system/kernel/vm Message-ID: <200807151541.m6FFfugB000645@sheep.berlios.de> Author: bonefish Date: 2008-07-15 17:41:54 +0200 (Tue, 15 Jul 2008) New Revision: 26428 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26428&view=rev Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h Log: Patch by Zhao Shuai: * Added reservation of swap space in Commit(). * Coding style improvements. Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-15 15:41:03 UTC (rev 26427) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.cpp 2008-07-15 15:41:54 UTC (rev 26428) @@ -76,9 +76,11 @@ }; -static int32 swap_space_alloc(int32); -static void swap_space_dealloc(int32, int32); +static int32 swap_page_alloc(int32); +static void swap_page_dealloc(int32, int32); static struct swap_file *find_swap_file(int32); +static status_t swap_space_reserve(size_t); +static void swap_space_unreserve(size_t); static object_cache * sSwapBlockCache; @@ -88,12 +90,16 @@ static struct swap_file *sSwapFileList = NULL; static mutex sSwapFileListLock; -static int sSwapFileCount = 0; static struct swap_file *sSwapFileAlloc = NULL; //allocate from here +static int32 sSwapFileCount = 0; +static off_t sAvailSwapSpace = 0; +static mutex sAvailSwapSpaceLock; + VMAnonymousCache::~VMAnonymousCache() { + swap_space_unreserve(fCommittedSwapSize); vm_unreserve_memory(committed_size); } @@ -113,6 +119,7 @@ fHasPrecommitted = false; fPrecommittedPages = min_c(numPrecommittedPages, 255); fGuardedSize = numGuardPages * B_PAGE_SIZE; + fCommittedSwapSize = 0; return B_OK; } @@ -133,6 +140,13 @@ size = precommitted; } + // reserve swap space first, only when running out of swap space, + // reserve real memory + if (swap_space_reserve(size) == B_OK) { + fCommittedSwapSize = size; + return B_OK; + } + // Check to see how much we could commit - we need real memory if (size > committed_size) { @@ -160,12 +174,9 @@ VMAnonymousCache::Read(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - iovec iov; - int32 i, j; - off_t cacheOffset = offset >> PAGE_SHIFT; - for (i = 0; i < (int)count; i = j) { + for (int32 i = 0, j = 0; i < (int)count; i = j) { int32 startPageIndex = _SwapBlockGetAddress(cacheOffset + i); for (j = i + 1; j <(int)count; j++) { int32 pageIndex = _SwapBlockGetAddress(cacheOffset + j); @@ -180,18 +191,19 @@ } off_t pos = (startPageIndex - swapFile->first_page) * PAGE_SIZE; + iovec iov; iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); iov.iov_len = (j - i) * PAGE_SIZE; - status_t status = vfs_read_pages(swapFile->vnode, NULL, pos, &iov, j - i, - _numBytes, fsReenter); + status_t status = vfs_read_pages(swapFile->vnode, NULL, pos, &iov, + j - i, _numBytes, fsReenter); if(status != B_OK) return status; for (int32 k = i; k < j - i; k++) _SwapBlockFree(cacheOffset + k); - swap_space_dealloc(startPageIndex, j - i); + swap_page_dealloc(startPageIndex, j - i); } return B_OK; @@ -202,17 +214,12 @@ VMAnonymousCache::Write(off_t offset, const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter) { - iovec iov; - int32 pageIndex; - offset >>= PAGE_SHIFT; - iov.iov_base = vecs->iov_base; - iov.iov_len = vecs->iov_len; - int32 n = count; for (int32 i = 0; i < (int)count; i += n) { + int32 pageIndex; //try to allocate n pages, if fail, try to allocate n/2 - while ((pageIndex = swap_space_alloc(n)) == SWAP_PAGE_NONE + while ((pageIndex = swap_page_alloc(n)) == SWAP_PAGE_NONE && n >= 2) n >>= 1; if (pageIndex == SWAP_PAGE_NONE) @@ -228,11 +235,12 @@ } off_t pos = (pageIndex - swapFile->first_page) * PAGE_SIZE; + iovec iov; iov.iov_base = (void *)((int)vecs->iov_base + i * PAGE_SIZE); iov.iov_len = n * PAGE_SIZE; - status_t status = vfs_write_pages(swapFile->vnode, NULL, pos, &iov, n, - _numBytes, fsReenter); + status_t status = vfs_write_pages(swapFile->vnode, NULL, pos, &iov, + n, _numBytes, fsReenter); if (status != B_OK) return status; } @@ -298,28 +306,32 @@ committed_size = actualSize; } - int32 sourceSwapIndex = SWAP_PAGE_NONE; // page index in the swap file - for (off_t offset = source->virtual_base; offset < source->virtual_end; offset += PAGE_SIZE) { - sourceSwapIndex = source->_SwapBlockGetAddress(offset); - if (sourceSwapIndex == SWAP_PAGE_NONE) // this page is not swapped out + int32 sourceSwapIndex = source->_SwapBlockGetAddress(offset); + + if (sourceSwapIndex == SWAP_PAGE_NONE) + // this page is not swapped out continue; - else if (LookupPage(offset)) { - // this page is shadowed and we can find it in the new cache, - // free the swap block and swap space - source->_SwapBlockFree(offset); - swap_space_dealloc(sourceSwapIndex, 1); - } + + if (LookupPage(offset)) + // this page is shadowed and we can find it in the new cache, + // free the swap space + swap_page_dealloc(sourceSwapIndex, 1); else { int32 swapIndex = _SwapBlockGetAddress(offset); - if (swapIndex == SWAP_PAGE_NONE) - // the page is not shadowed, assign the swap address to the new cache + + if (swapIndex == SWAP_PAGE_NONE) { + // the page is not shadowed, + // assign the swap address to the new cache _SwapBlockBuild(offset, sourceSwapIndex); - else // the page is shadowed but is also swapped out - swap_space_dealloc(sourceSwapIndex, 1); - source->_SwapBlockFree(offset); + } else { + // the page is shadowed and is also swapped out + swap_page_dealloc(sourceSwapIndex, 1); + } } + + source->_SwapBlockFree(offset); } } @@ -327,10 +339,10 @@ swap_block** VMAnonymousCache::_SwapHash(off_t cacheOffset) { - cacheOffset &= ~(off_t)(SWAP_BLOCK_MASK); + cacheOffset &= ~(off_t)SWAP_BLOCK_MASK; - struct swap_block **pswap = - &sSwapHash[(cacheOffset ^ (int)(int *)this) & sSwapHashMask]; + struct swap_block **pswap + = &sSwapHash[(cacheOffset ^ (int)(int *)this) & sSwapHashMask]; struct swap_block *swap = *pswap; while (swap != NULL) { @@ -351,19 +363,20 @@ struct swap_block **pswap = _SwapHash(cacheOffset); struct swap_block *swap = *pswap; if (swap == NULL) { - swap = *pswap = (struct swap_block *)object_cache_alloc(sSwapBlockCache, CACHE_DONT_SLEEP); + swap = *pswap = (struct swap_block *) + object_cache_alloc(sSwapBlockCache, CACHE_DONT_SLEEP); if (swap == NULL) { mutex_unlock(&sSwapHashLock); panic("swap block cache allocation error\n"); } - swap->hash_next = NULL; - swap->cache = this; - swap->cache_offset = cacheOffset & ~(off_t)SWAP_BLOCK_MASK; - swap->used = 0; + swap->hash_next = NULL; + swap->cache = this; + swap->cache_offset = cacheOffset & ~(off_t)SWAP_BLOCK_MASK; + swap->used = 0; - for (int32 i = 0; i < SWAP_BLOCK_PAGES; i++) - swap->swap_pages[i] = SWAP_PAGE_NONE; + for (int32 i = 0; i < SWAP_BLOCK_PAGES; i++) + swap->swap_pages[i] = SWAP_PAGE_NONE; } int32 blockIndex = cacheOffset & SWAP_BLOCK_MASK; @@ -401,12 +414,12 @@ int32 VMAnonymousCache::_SwapBlockGetAddress(off_t cacheOffset) { - int32 pageIndex = SWAP_PAGE_NONE; - mutex_lock(&sSwapHashLock); struct swap_block **pswap = _SwapHash(cacheOffset); struct swap_block *swap = *pswap; + + int32 pageIndex = SWAP_PAGE_NONE; if (swap != NULL) { int32 blockIndex = cacheOffset & SWAP_BLOCK_MASK; pageIndex = swap->swap_pages[blockIndex]; @@ -424,8 +437,8 @@ struct swap_file *swapFile = sSwapFileList; while (swapFile != NULL) { - if (pageIndex >= swapFile->first_page && - pageIndex < swapFile->last_page) + if (pageIndex >= swapFile->first_page + && pageIndex < swapFile->last_page) break; else swapFile = swapFile->next; @@ -436,7 +449,7 @@ static int32 -swap_space_alloc(int32 npages) +swap_page_alloc(int32 npages) { int32 hint, j; @@ -449,7 +462,8 @@ mutex_lock(&sSwapFileAlloc->lock); hint = sSwapFileAlloc->hint; - int32 pageCount = sSwapFileAlloc->last_page - sSwapFileAlloc->first_page; + int32 pageCount = sSwapFileAlloc->last_page + - sSwapFileAlloc->first_page; int32 i = 0; while (i < npages && (hint + npages) < pageCount) { @@ -485,8 +499,8 @@ // if this swap file has used more than 90% percent of its pages // switch to another - if (sSwapFileAlloc->used > - 9 * (sSwapFileAlloc->last_page - sSwapFileAlloc->first_page) / 10) + if (sSwapFileAlloc->used + > 9 * (sSwapFileAlloc->last_page - sSwapFileAlloc->first_page) / 10) sSwapFileAlloc = sSwapFileAlloc->next; mutex_unlock(&sSwapFileAlloc->lock); @@ -496,7 +510,7 @@ static void -swap_space_dealloc(int32 pageIndex, int32 npages) +swap_page_dealloc(int32 pageIndex, int32 npages) { struct swap_file *swapFile = find_swap_file(pageIndex); @@ -516,6 +530,29 @@ } +static status_t +swap_space_reserve(size_t amount) +{ + mutex_lock(&sAvailSwapSpaceLock); + if (sAvailSwapSpace >= amount) { + sAvailSwapSpace -= amount; + return B_OK; + } + mutex_unlock(&sAvailSwapSpaceLock); + + return B_ERROR; +} + + +static void +swap_space_unreserve(size_t amount) +{ + mutex_lock(&sAvailSwapSpaceLock); + sAvailSwapSpace += amount; + mutex_unlock(&sAvailSwapSpaceLock); +} + + status_t swap_file_add(char *path) { @@ -524,7 +561,8 @@ if (status != B_OK) return status; - struct swap_file *swap = (struct swap_file *)malloc(sizeof(struct swap_file)); + struct swap_file *swap + = (struct swap_file *)malloc(sizeof(struct swap_file)); if (swap == NULL) return B_NO_MEMORY; @@ -569,8 +607,11 @@ } sSwapFileCount++; + mutex_unlock(&sSwapFileListLock); - mutex_unlock(&sSwapFileListLock); + mutex_lock(&sAvailSwapSpaceLock); + sAvailSwapSpace += pageCount * PAGE_SIZE; + mutex_unlock(&sAvailSwapSpaceLock); return B_OK; } @@ -612,9 +653,12 @@ } sSwapFileCount--; - mutex_unlock(&sSwapFileListLock); + mutex_lock(&sAvailSwapSpaceLock); + sAvailSwapSpace -= (swapFile->last_page - swapFile->first_page) * PAGE_SIZE; + mutex_unlock(&sAvailSwapSpaceLock); + mutex_destroy(&swapFile->lock); free(swapFile->maps); free(swapFile); @@ -633,8 +677,8 @@ panic("can't create object cache for swap blocks\n"); // init swap hash table - sSwapHash = (struct swap_block **)malloc(sizeof(struct swap_block *) * - SWAP_HASH_SIZE); + sSwapHash = (struct swap_block **)malloc(sizeof(struct swap_block *) + * SWAP_HASH_SIZE); if (sSwapHash == NULL) panic("swap hash table allocation error\n"); sSwapHashMask = SWAP_HASH_SIZE - 1; @@ -644,4 +688,8 @@ mutex_init(&sSwapFileListLock, "swaplist"); sSwapFileAlloc = sSwapFileList; sSwapFileCount = 0; + + // init available swap space + mutex_init(&sAvailSwapSpaceLock, "avail swap page"); + sAvailSwapSpace = 0; } Modified: haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h =================================================================== --- haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-15 15:41:03 UTC (rev 26427) +++ haiku/branches/developer/bonefish/vm/src/system/kernel/vm/VMAnonymousCache.h 2008-07-15 15:41:54 UTC (rev 26428) @@ -44,6 +44,7 @@ bool fHasPrecommitted; uint8 fPrecommittedPages; int32 fGuardedSize; + off_t fCommittedSwapSize; }; From axeld at mail.berlios.de Tue Jul 15 17:55:28 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 17:55:28 +0200 Subject: [Haiku-commits] r26429 - haiku/trunk/src/apps/activitymonitor Message-ID: <200807151555.m6FFtSVK003499@sheep.berlios.de> Author: axeld Date: 2008-07-15 17:55:28 +0200 (Tue, 15 Jul 2008) New Revision: 26429 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26429&view=rev Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp Log: * DataHistory::ValueAt() now interpolates between two values in case the time doesn't match exactly one data item (before, it would have returned the value of the closest but earlier value). * This almost removes the effect that the older values seem to change with every refresh (because the time did not always match exactly)). Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-15 15:41:54 UTC (rev 26428) +++ haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-15 15:55:28 UTC (rev 26429) @@ -172,9 +172,14 @@ // search in left part right = index - 1; } else { - if (index + 1 >= fBuffer.CountItems() - || fBuffer.ItemAt(index + 1)->time > time) { + data_item* nextItem = fBuffer.ItemAt(index + 1); + if (nextItem == NULL) + return item->value; + if (nextItem->time > time) { // found item + int64 value = item->value; + value += int64(double(nextItem->value - value) + / (nextItem->time - item->time) * (time - item->time)); return item->value; } From axeld at mail.berlios.de Tue Jul 15 17:59:26 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 17:59:26 +0200 Subject: [Haiku-commits] r26430 - haiku/trunk/src/apps/activitymonitor Message-ID: <200807151559.m6FFxQBd003863@sheep.berlios.de> Author: axeld Date: 2008-07-15 17:59:26 +0200 (Tue, 15 Jul 2008) New Revision: 26430 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26430&view=rev Modified: haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp Log: * Fixed a possible overflow issue - for some reason, the page (and other) counter are int32 in system_info. * This fixes the new issue Bruno saw after the previous fix of bug #2140. Modified: haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp 2008-07-15 15:55:28 UTC (rev 26429) +++ haiku/trunk/src/apps/activitymonitor/SystemInfo.cpp 2008-07-15 15:59:26 UTC (rev 26430) @@ -48,7 +48,7 @@ SystemInfo::CachedMemory() const { #ifdef __HAIKU__ - return fSystemInfo.cached_pages * B_PAGE_SIZE; + return (uint64)fSystemInfo.cached_pages * B_PAGE_SIZE; #else return 0LL; #endif @@ -58,14 +58,14 @@ uint64 SystemInfo::UsedMemory() const { - return fSystemInfo.used_pages * B_PAGE_SIZE; + return (uint64)fSystemInfo.used_pages * B_PAGE_SIZE; } uint64 SystemInfo::MaxMemory() const { - return fSystemInfo.max_pages * B_PAGE_SIZE; + return (uint64)fSystemInfo.max_pages * B_PAGE_SIZE; } From stippi at mail.berlios.de Tue Jul 15 18:46:49 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 18:46:49 +0200 Subject: [Haiku-commits] r26431 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807151646.m6FGkngB025678@sheep.berlios.de> Author: stippi Date: 2008-07-15 18:46:39 +0200 (Tue, 15 Jul 2008) New Revision: 26431 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26431&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: Rearrange Painter::_DrawBitmap() so that the optimized codepaths for unscaled drawings are used for bitmaps that needed to be converted to B_RGBA32. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 15:59:26 UTC (rev 26430) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 16:46:39 UTC (rev 26431) @@ -7,7 +7,7 @@ * rendering pipe-lines for stroke, fills, bitmap and text rendering. */ - +#include #include #include @@ -36,6 +36,7 @@ #include "DrawState.h" +#include #include "DrawingMode.h" #include "PatternHandler.h" #include "RenderingBuffer.h" @@ -45,7 +46,9 @@ #include "Painter.h" +using std::nothrow; +#undef TRACE //#define TRACE_PAINTER #ifdef TRACE_PAINTER # define TRACE(x...) printf(x) @@ -76,7 +79,6 @@ fValidClipping(false), fDrawingText(false), fAttached(false), - fSubpixelAntialias(true), fPenSize(1.0), fClippingRegion(NULL), @@ -86,6 +88,7 @@ fLineCapMode(B_BUTT_CAP), fLineJoinMode(B_MITER_JOIN), fMiterLimit(B_DEFAULT_MITER_LIMIT), + fSubpixelAntialias(true), fPatternHandler(), fTextRenderer(fSubpixRenderer, fRenderer, fRendererBin, fUnpackedScanline) @@ -1397,106 +1400,102 @@ double xOffset = viewRect.left - bitmapRect.left; double yOffset = viewRect.top - bitmapRect.top; - switch (format) { - case B_RGB32: - case B_RGBA32: { - // maybe we can use an optimized version - if (xScale == 1.0 && yScale == 1.0) { - if (fDrawingMode == B_OP_COPY) { - _DrawBitmapNoScale32(copy_bitmap_row_bgr32_copy, 4, - srcBuffer, xOffset, yOffset, viewRect); - return; - } else if (fDrawingMode == B_OP_OVER) { - if (format == B_RGB32) - _DrawBitmapNoScale32(copy_bitmap_row_bgr32_over, 4, - srcBuffer, xOffset, yOffset, viewRect); - else - _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, - srcBuffer, xOffset, yOffset, viewRect); - return; - } else if (fDrawingMode == B_OP_ALPHA - && fAlphaSrcMode == B_PIXEL_ALPHA - && fAlphaFncMode == B_ALPHA_OVERLAY) { - _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, - srcBuffer, xOffset, yOffset, viewRect); - return; - } + // optimized code path for B_CMAP8 and no scale + if (xScale == 1.0 && yScale == 1.0) { + if (format == B_CMAP8) { + if (fDrawingMode == B_OP_COPY) { + _DrawBitmapNoScale32(copy_bitmap_row_cmap8_copy, 1, + srcBuffer, xOffset, yOffset, viewRect); + return; + } else if (fDrawingMode == B_OP_OVER) { + _DrawBitmapNoScale32(copy_bitmap_row_cmap8_over, 1, + srcBuffer, xOffset, yOffset, viewRect); + return; } - - if (format == B_RGBA32 || fDrawingMode == B_OP_COPY) { - _DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, - xScale, yScale, viewRect); + } else if (format == B_RGB32) { + if (fDrawingMode == B_OP_OVER) { + _DrawBitmapNoScale32(copy_bitmap_row_bgr32_over, 4, + srcBuffer, xOffset, yOffset, viewRect); return; } - // otherwise fall through to get proper transparency handling for - // B_RGB32 where a B_TRANSPARENT_MAGIC might be set on pixels } - default: { - if (format == B_CMAP8 && xScale == 1.0 && yScale == 1.0) { - if (fDrawingMode == B_OP_COPY) { - _DrawBitmapNoScale32(copy_bitmap_row_cmap8_copy, 1, - srcBuffer, xOffset, yOffset, viewRect); - return; - } else if (fDrawingMode == B_OP_OVER) { - _DrawBitmapNoScale32(copy_bitmap_row_cmap8_over, 1, - srcBuffer, xOffset, yOffset, viewRect); - return; - } - } + } - // TODO: this is only a temporary implementation, - // to really handle other colorspaces, one would - // rather do the conversion with much less overhead, - // for example in the nn filter (hm), or in the - // scanline generator (better) - // maybe we can use an optimized version - BBitmap temp(actualBitmapRect, B_BITMAP_NO_SERVER_LINK, B_RGBA32); - status_t err = temp.ImportBits(srcBuffer.buf(), - srcBuffer.height() * srcBuffer.stride(), - srcBuffer.stride(), 0, format); + BBitmap* temp = NULL; + ObjectDeleter tempDeleter; - if (err >= B_OK) { - // the original bitmap might have had some of the - // transaparent magic colors set that we now need to - // make transparent in our RGBA32 bitmap again. - switch (format) { - case B_RGB32: - _TransparentMagicToAlpha((uint32 *)srcBuffer.buf(), - srcBuffer.width(), srcBuffer.height(), - srcBuffer.stride(), B_TRANSPARENT_MAGIC_RGBA32, - &temp); - break; + if ((format != B_RGBA32 && format != B_RGB32) + || (format == B_RGB32 && fDrawingMode != B_OP_COPY)) { + temp = new (nothrow) BBitmap(actualBitmapRect, B_BITMAP_NO_SERVER_LINK, + B_RGBA32); + if (temp == NULL) { + fprintf(stderr, "Painter::_DrawBitmap() - " + "out of memory for creating temporary conversion bitmap\n"); + return; + } - // TODO: not sure if this applies to B_RGBA15 too. It - // should not because B_RGBA15 actually has an alpha - // channel itself and it should have been preserved - // when importing the bitmap. Maybe it applies to - // B_RGB16 though? - case B_RGB15: - _TransparentMagicToAlpha((uint16 *)srcBuffer.buf(), - srcBuffer.width(), srcBuffer.height(), - srcBuffer.stride(), B_TRANSPARENT_MAGIC_RGBA15, - &temp); - break; + tempDeleter.SetTo(temp); - default: - break; - } + status_t err = temp->ImportBits(srcBuffer.buf(), + srcBuffer.height() * srcBuffer.stride(), + srcBuffer.stride(), 0, format); + if (err < B_OK) { + fprintf(stderr, "Painter::_DrawBitmap() - " + "colorspace conversion failed: %s\n", strerror(err)); + return; + } - agg::rendering_buffer convertedBuffer; - convertedBuffer.attach((uint8*)temp.Bits(), - (uint32)actualBitmapRect.IntegerWidth() + 1, - (uint32)actualBitmapRect.IntegerHeight() + 1, - temp.BytesPerRow()); - _DrawBitmapGeneric32(convertedBuffer, xOffset, yOffset, - xScale, yScale, viewRect); - } else { - fprintf(stderr, "Painter::_DrawBitmap() - " - "colorspace conversion failed: %s\n", strerror(err)); - } - break; + // the original bitmap might have had some of the + // transaparent magic colors set that we now need to + // make transparent in our RGBA32 bitmap again. + switch (format) { + case B_RGB32: + _TransparentMagicToAlpha((uint32 *)srcBuffer.buf(), + srcBuffer.width(), srcBuffer.height(), + srcBuffer.stride(), B_TRANSPARENT_MAGIC_RGBA32, + temp); + break; + + // TODO: not sure if this applies to B_RGBA15 too. It + // should not because B_RGBA15 actually has an alpha + // channel itself and it should have been preserved + // when importing the bitmap. Maybe it applies to + // B_RGB16 though? + case B_RGB15: + _TransparentMagicToAlpha((uint16 *)srcBuffer.buf(), + srcBuffer.width(), srcBuffer.height(), + srcBuffer.stride(), B_TRANSPARENT_MAGIC_RGBA15, + temp); + break; + + default: + break; } + + srcBuffer.attach((uint8*)temp->Bits(), + (uint32)actualBitmapRect.IntegerWidth() + 1, + (uint32)actualBitmapRect.IntegerHeight() + 1, + temp->BytesPerRow()); } + + // maybe we can use an optimized version if there is no scale + if (xScale == 1.0 && yScale == 1.0) { + if (fDrawingMode == B_OP_COPY) { + _DrawBitmapNoScale32(copy_bitmap_row_bgr32_copy, 4, srcBuffer, + xOffset, yOffset, viewRect); + return; + } else if (fDrawingMode == B_OP_OVER + || (fDrawingMode == B_OP_ALPHA + && fAlphaSrcMode == B_PIXEL_ALPHA + && fAlphaFncMode == B_ALPHA_OVERLAY)) { + _DrawBitmapNoScale32(copy_bitmap_row_bgr32_alpha, 4, srcBuffer, + xOffset, yOffset, viewRect); + return; + } + } + + // for all other cases (non-optimized drawing mode or scaled drawing) + _DrawBitmapGeneric32(srcBuffer, xOffset, yOffset, xScale, yScale, viewRect); } #define DEBUG_DRAW_BITMAP 0 From superstippi at gmx.de Tue Jul 15 18:49:27 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 15 Jul 2008 18:49:27 +0200 Subject: [Haiku-commits] r26431 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: <200807151646.m6FGkngB025678@sheep.berlios.de> References: <200807151646.m6FGkngB025678@sheep.berlios.de> Message-ID: <20080715184927.20035.8@stippis2.1216119101.fake> stippi at mail.berlios.de wrote: > Author: stippi > Date: 2008-07-15 18:46:39 +0200 (Tue, 15 Jul 2008) New Revision: 26431 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26431&view=rev > > Modified: > haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp > Log: > Rearrange Painter::_DrawBitmap() so that the optimized codepaths for > unscaled drawings are used for bitmaps that needed to be converted to > B_RGBA32. Darn, I was a bit quick with the commit message... this is actually "mmlr + stippi". Credit where credit is due! Best regards, -Stephan From ingo_weinhold at gmx.de Tue Jul 15 19:01:17 2008 From: ingo_weinhold at gmx.de (Ingo Weinhold) Date: Tue, 15 Jul 2008 19:01:17 +0200 Subject: [Haiku-commits] r26426 - haiku/trunk/src/add-ons/kernel/drivers/tty In-Reply-To: <200807151509.m6FF9W34029269@sheep.berlios.de> References: <200807151509.m6FF9W34029269@sheep.berlios.de> Message-ID: <20080715190117.374.1@knochen-vm.localdomain> On 2008-07-15 at 17:09:32 [+0200], zooey at BerliOS wrote: > Author: zooey > Date: 2008-07-15 17:09:32 +0200 (Tue, 15 Jul 2008) > New Revision: 26426 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26426&view=rev > > Modified: > haiku/trunk/src/add-ons/kernel/drivers/tty/tty.cpp > Log: > Fix problem with openssh failing to connect to OpenSolaris and Zeta servers: > * we need to initialize c_ospeed and c_ispeed, as a value of 0 means > 'hangup' - which is not a good default, I suppose Very nice! Certainly not the place where I would expected the problem. CU, Ingo From stippi at mail.berlios.de Tue Jul 15 19:06:20 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 19:06:20 +0200 Subject: [Haiku-commits] r26432 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807151706.m6FH6KB7016002@sheep.berlios.de> Author: stippi Date: 2008-07-15 19:06:14 +0200 (Tue, 15 Jul 2008) New Revision: 26432 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26432&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: Small code and comment cleanups as well as clarifications. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 16:46:39 UTC (rev 26431) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 17:06:14 UTC (rev 26432) @@ -157,8 +157,12 @@ // NOTE: The custom clipping in "data" is ignored, because it has already // been taken into account elsewhere - // TODO: optimize "context switch" for speed... - // but for now... + // NOTE: Usually this function is only used when the "current view" + // is switched in the ServerWindow and after the decorator has drawn + // and messed up the state. For other graphics state changes, the + // Painter methods are used directly, so this function is much less + // speed critical than it used to be. + SetPenSize(data->PenSize()); SetFont(data); @@ -167,19 +171,21 @@ // any of these conditions means we need to use a different drawing // mode instance - bool updateDrawingMode = !(data->GetPattern() == fPatternHandler.GetPattern()) || - data->GetDrawingMode() != fDrawingMode || - (data->GetDrawingMode() == B_OP_ALPHA && (data->AlphaSrcMode() != fAlphaSrcMode || - data->AlphaFncMode() != fAlphaFncMode)); + bool updateDrawingMode + = !(data->GetPattern() == fPatternHandler.GetPattern()) + || data->GetDrawingMode() != fDrawingMode + || (data->GetDrawingMode() == B_OP_ALPHA + && (data->AlphaSrcMode() != fAlphaSrcMode + || data->AlphaFncMode() != fAlphaFncMode)); - fDrawingMode = data->GetDrawingMode(); - fAlphaSrcMode = data->AlphaSrcMode(); - fAlphaFncMode = data->AlphaFncMode(); + fDrawingMode = data->GetDrawingMode(); + fAlphaSrcMode = data->AlphaSrcMode(); + fAlphaFncMode = data->AlphaFncMode(); fPatternHandler.SetPattern(data->GetPattern()); fPatternHandler.SetOffsets(xOffset, yOffset); - fLineCapMode = data->LineCapMode(); - fLineJoinMode = data->LineJoinMode(); - fMiterLimit = data->MiterLimit(); + fLineCapMode = data->LineCapMode(); + fLineJoinMode = data->LineJoinMode(); + fMiterLimit = data->MiterLimit(); // adopt the color *after* the pattern is set // to set the renderers to the correct color @@ -1180,7 +1186,7 @@ // has been implemented for B_OP_COPY and a couple others (the // DrawingMode*Solid ones) as of now. The PixelFormat knows the // PatternHandler and makes its decision based on the pattern. - // The last parameter to SetDrawingMode() is a flag if a special + // The last parameter to SetDrawingMode() is a special flag // for when Painter is used to draw text. In this case, another // special version of B_OP_COPY is used that acts like R5 in that // anti-aliased pixel are not rendered against the actual background From axeld at mail.berlios.de Tue Jul 15 19:09:11 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 19:09:11 +0200 Subject: [Haiku-commits] r26433 - haiku/trunk/src/apps/activitymonitor Message-ID: <200807151709.m6FH9BGL018609@sheep.berlios.de> Author: axeld Date: 2008-07-15 19:09:08 +0200 (Tue, 15 Jul 2008) New Revision: 26433 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26433&view=rev Modified: haiku/trunk/src/apps/activitymonitor/DataSource.cpp Log: * Made the network I/O byte per second computation more accurate. Modified: haiku/trunk/src/apps/activitymonitor/DataSource.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/DataSource.cpp 2008-07-15 17:06:14 UTC (rev 26432) +++ haiku/trunk/src/apps/activitymonitor/DataSource.cpp 2008-07-15 17:09:08 UTC (rev 26433) @@ -897,8 +897,8 @@ { uint64 transferred = fIn ? info.NetworkReceived() : info.NetworkSent(); - int64 bytesPerSecond = uint64((transferred - fPreviousBytes) - / ((info.Time() - fPreviousTime) / 1000000.0)); + int64 bytesPerSecond = uint64(double(transferred - fPreviousBytes) + / (info.Time() - fPreviousTime) * 1000000.0); fPreviousBytes = transferred; fPreviousTime = info.Time(); From axeld at mail.berlios.de Tue Jul 15 19:10:54 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 19:10:54 +0200 Subject: [Haiku-commits] r26434 - haiku/trunk/src/apps/activitymonitor Message-ID: <200807151710.m6FHAsuc020185@sheep.berlios.de> Author: axeld Date: 2008-07-15 19:10:52 +0200 (Tue, 15 Jul 2008) New Revision: 26434 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26434&view=rev Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp haiku/trunk/src/apps/activitymonitor/ActivityView.h Log: * Offloaded the data source retrieval into another thread for more accuracy. Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.cpp =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-15 17:09:08 UTC (rev 26433) +++ haiku/trunk/src/apps/activitymonitor/ActivityView.cpp 2008-07-15 17:10:52 UTC (rev 26434) @@ -14,6 +14,7 @@ # include #endif #include +#include #include #include #include @@ -93,7 +94,6 @@ const bigtime_t kInitialRefreshInterval = 500000LL; -const uint32 kMsgRefresh = 'refr'; const uint32 kMsgToggleDataSource = 'tgds'; const uint32 kMsgToggleLegend = 'tglg'; @@ -392,7 +392,8 @@ ActivityView::ActivityView(BRect frame, const char* name, const BMessage* settings, uint32 resizingMode) : BView(frame, name, resizingMode, - B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), + fSourcesLock("data sources") { _Init(settings); @@ -407,10 +408,12 @@ ActivityView::ActivityView(const char* name, const BMessage* settings) #ifdef __HAIKU__ - : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) + : BView(name, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), #else - : BView(BRect(0,0,300,200), name, B_FOLLOW_NONE, B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) + : BView(BRect(0,0,300,200), name, B_FOLLOW_NONE, + B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), #endif + fSourcesLock("data sources") { SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -585,6 +588,8 @@ DataSource* ActivityView::FindDataSource(const DataSource* search) { + BAutolock _(fSourcesLock); + for (int32 i = fSources.CountItems(); i-- > 0;) { DataSource* source = fSources.ItemAt(i); if (!strcmp(source->Name(), search->Name())) @@ -601,6 +606,8 @@ if (source == NULL) return B_BAD_VALUE; + BAutolock _(fSourcesLock); + int32 insert = DataSource::IndexOf(source); for (int32 i = 0; i < fSources.CountItems() && i < insert; i++) { DataSource* before = fSources.ItemAt(i); @@ -667,6 +674,8 @@ { bool removed = false; + BAutolock _(fSourcesLock); + while (true) { DataSource* source = FindDataSource(remove); debug_printf("SEARCH %s, found %p\n", remove->Name(), source); @@ -697,6 +706,8 @@ void ActivityView::RemoveAllDataSources() { + BAutolock _(fSourcesLock); + fSources.MakeEmpty(); fValues.MakeEmpty(); } @@ -708,8 +719,10 @@ Looper()->AddHandler(fSystemInfoHandler); fSystemInfoHandler->StartWatching(); - BMessage refresh(kMsgRefresh); - fRunner = new BMessageRunner(this, &refresh, fRefreshInterval); + fRefreshSem = create_sem(0, "refresh sem"); + fRefreshThread = spawn_thread(&_RefreshThread, "source refresh", + B_NORMAL_PRIORITY, this); + resume_thread(fRefreshThread); FrameResized(Bounds().Width(), Bounds().Height()); } @@ -721,7 +734,8 @@ fSystemInfoHandler->StopWatching(); Looper()->RemoveHandler(fSystemInfoHandler); - delete fRunner; + delete_sem(fRefreshSem); + wait_for_thread(fRefreshThread, NULL); } @@ -896,6 +910,8 @@ Invalidate(_HistoryFrame()); } else { // check each legend color box + BAutolock _(fSourcesLock); + BRect legendFrame = _LegendFrame(); for (int32 i = 0; i < fSources.CountItems(); i++) { BRect frame = _LegendColorFrameAt(legendFrame, i); @@ -923,10 +939,6 @@ ActivityMonitor::ShowAbout(); break; - case kMsgRefresh: - _Refresh(); - break; - case kMsgToggleDataSource: { int32 index; @@ -1022,6 +1034,8 @@ font_height fontHeight; GetFontHeight(&fontHeight); + BAutolock _(fSourcesLock); + int32 rows = (fSources.CountItems() + 1) / 2; return rows * (4 + ceilf(fontHeight.ascent) + ceilf(fontHeight.descent) + ceilf(fontHeight.leading)); @@ -1056,6 +1070,8 @@ else frame.left = frame.right - floorf(frame.Width() / 2) + 5; + BAutolock _(fSourcesLock); + int32 rows = (fSources.CountItems() + 1) / 2; float height = floorf((frame.Height() - 5) / rows); @@ -1146,6 +1162,7 @@ // Draw values view->SetPenSize(2); + BAutolock _(fSourcesLock); for (uint32 i = fSources.CountItems(); i-- > 0;) { DataSource* source = fSources.ItemAt(i); @@ -1210,6 +1227,7 @@ // draw legend + BAutolock _(fSourcesLock); BRect legendFrame = _LegendFrame(); SetLowColor(fLegendBackgroundColor); @@ -1252,22 +1270,46 @@ void ActivityView::_Refresh() { - SystemInfo info(fSystemInfoHandler); + bigtime_t lastTimeout = system_time() - fRefreshInterval; - // TODO: run refresh in another thread to decouple it from the UI! + while (true) { + status_t status = acquire_sem_etc(fRefreshSem, 1, B_ABSOLUTE_TIMEOUT, + lastTimeout + fRefreshInterval); + if (status == B_OK || status == B_BAD_SEM_ID) + break; + if (status == B_INTERRUPTED) + continue; - for (uint32 i = fSources.CountItems(); i-- > 0;) { - DataSource* source = fSources.ItemAt(i); - DataHistory* values = fValues.ItemAt(i); + SystemInfo info(fSystemInfoHandler); + lastTimeout += fRefreshInterval; - int64 value = source->NextValue(info); - values->AddValue(info.Time(), value); - } + fSourcesLock.Lock(); - bigtime_t now = info.Time(); - if (fLastRefresh + fDrawInterval <= now) { - Invalidate(); - fLastRefresh = now; + for (uint32 i = fSources.CountItems(); i-- > 0;) { + DataSource* source = fSources.ItemAt(i); + DataHistory* values = fValues.ItemAt(i); + + int64 value = source->NextValue(info); + values->AddValue(info.Time(), value); + } + + fSourcesLock.Unlock(); + + bigtime_t now = info.Time(); + if (fLastRefresh + fDrawInterval <= now) { + if (LockLooper()) { + Invalidate(); + UnlockLooper(); + fLastRefresh = now; + } + } } } + +/*static*/ status_t +ActivityView::_RefreshThread(void* self) +{ + ((ActivityView*)self)->_Refresh(); + return B_OK; +} Modified: haiku/trunk/src/apps/activitymonitor/ActivityView.h =================================================================== --- haiku/trunk/src/apps/activitymonitor/ActivityView.h 2008-07-15 17:09:08 UTC (rev 26433) +++ haiku/trunk/src/apps/activitymonitor/ActivityView.h 2008-07-15 17:10:52 UTC (rev 26434) @@ -8,8 +8,9 @@ #include +#include +#include #include -#include #include "CircularBuffer.h" #include "DataSource.h" @@ -95,6 +96,7 @@ void _Init(const BMessage* settings); ::Scale* _ScaleFor(scale_type type); void _Refresh(); + static status_t _RefreshThread(void* self); void _UpdateOffscreenBitmap(); BView* _OffscreenView(); void _UpdateFrame(); @@ -121,9 +123,11 @@ BLayoutItem* fHistoryLayoutItem; BLayoutItem* fLegendLayoutItem; #endif + mutable BLocker fSourcesLock; BObjectList fSources; BObjectList fValues; - BMessageRunner* fRunner; + thread_id fRefreshThread; + sem_id fRefreshSem; bigtime_t fRefreshInterval; bigtime_t fLastRefresh; bigtime_t fDrawInterval; From axeld at mail.berlios.de Tue Jul 15 19:54:59 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 19:54:59 +0200 Subject: [Haiku-commits] r26435 - haiku/trunk/build/jam Message-ID: <200807151754.m6FHsx19004209@sheep.berlios.de> Author: axeld Date: 2008-07-15 19:54:58 +0200 (Tue, 15 Jul 2008) New Revision: 26435 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26435&view=rev Modified: haiku/trunk/build/jam/MiscRules Log: * Added an "update-all" build profile action that updates all files. This can be used to update an installation without erasing the whole volume (ie. it works like install-haiku on BFS capable platforms). Modified: haiku/trunk/build/jam/MiscRules =================================================================== --- haiku/trunk/build/jam/MiscRules 2008-07-15 17:10:52 UTC (rev 26434) +++ haiku/trunk/build/jam/MiscRules 2008-07-15 17:54:58 UTC (rev 26435) @@ -30,7 +30,7 @@ # add-ons if $(INCLUDE_GPL_ADDONS) = 1 { SubInclude $(1) ; - } + } } @@ -331,6 +331,12 @@ HAIKU_INCLUDE_IN_IMAGE on $(HAIKU_BUILD_PROFILE_PARAMETERS) = 1 ; } + case "update-all" : { + JAM_TARGETS = $(buildTarget) ; + SetUpdateHaikuImageOnly 1 ; + HAIKU_INCLUDE_IN_IMAGE = 1 ; + } + case "mount" : { if $(type) = "install" { Exit "Build action \"mount\" not supported for profile type" From stippi at mail.berlios.de Tue Jul 15 20:18:14 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 20:18:14 +0200 Subject: [Haiku-commits] r26436 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807151818.m6FIIE6F008770@sheep.berlios.de> Author: stippi Date: 2008-07-15 20:18:07 +0200 (Tue, 15 Jul 2008) New Revision: 26436 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26436&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: mmlr + stippi: Found an incompatibility with BeOS, where Haiku behaves correctly, though, after our changes: The alpha channel of B_RGB32 bitmaps is ignored, but B_TRANSPARENT_MAGIC_RGBA32 pixels are considered fully transparent. In BeOS, B_RGB32 are simply treated as B_RGBA32, but only in B_OP_ALPHA. We have added a comment as well as the code that would enabled the BeOS behavior. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 17:54:58 UTC (rev 26435) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 18:18:07 UTC (rev 26436) @@ -1430,8 +1430,20 @@ BBitmap* temp = NULL; ObjectDeleter tempDeleter; + + if ((format != B_RGBA32 && format != B_RGB32) - || (format == B_RGB32 && fDrawingMode != B_OP_COPY)) { + || (format == B_RGB32 && fDrawingMode != B_OP_COPY +#if 0 +// Enabling this would make the behavior compatible to BeOS, which +// treats B_RGB32 bitmaps as B_RGB*A*32 bitmaps in B_OP_ALPHA - unlike in +// all other drawing modes, where B_TRANSPARENT_MAGIC_RGBA32 is handled. +// B_RGB32 bitmaps therefore don't draw correctly on BeOS if they actually +// use this color, unless the alpha channel contains 255 for all other +// pixels, which is inconsistent. + && fDrawingMode != B_OP_ALPHA) +#endif + ) { temp = new (nothrow) BBitmap(actualBitmapRect, B_BITMAP_NO_SERVER_LINK, B_RGBA32); if (temp == NULL) { From stippi at mail.berlios.de Tue Jul 15 20:20:04 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Tue, 15 Jul 2008 20:20:04 +0200 Subject: [Haiku-commits] r26437 - haiku/trunk/src/apps/networkstatus Message-ID: <200807151820.m6FIK4Mu009138@sheep.berlios.de> Author: stippi Date: 2008-07-15 20:20:01 +0200 (Tue, 15 Jul 2008) New Revision: 26437 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26437&view=rev Modified: haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp Log: mmlr + stippi: Use B_RGBA32 if you mean that instead of B_RGB32. The IconUtils could be changed to either refuse B_RGB32 or give them an invalid alpha channel with just B_TRANSPARENT_MAGIC_RGBA32. That would make that mistake more obvious. Modified: haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp =================================================================== --- haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp 2008-07-15 18:18:07 UTC (rev 26436) +++ haiku/trunk/src/apps/networkstatus/NetworkStatusView.cpp 2008-07-15 18:20:01 UTC (rev 26437) @@ -149,7 +149,7 @@ data = resources.LoadResource(B_VECTOR_ICON_TYPE, kNetworkStatusNoDevice + i, &size); if (data != NULL) { - BBitmap* icon = new BBitmap(Bounds(), B_RGB32); + BBitmap* icon = new BBitmap(Bounds(), B_RGBA32); if (icon->InitCheck() == B_OK && BIconUtils::GetVectorIcon((const uint8 *)data, size, icon) == B_OK) { From anevilyak at mail.berlios.de Tue Jul 15 20:26:41 2008 From: anevilyak at mail.berlios.de (anevilyak at BerliOS) Date: Tue, 15 Jul 2008 20:26:41 +0200 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter Message-ID: <200807151826.m6FIQfOR010466@sheep.berlios.de> Author: anevilyak Date: 2008-07-15 20:26:40 +0200 (Tue, 15 Jul 2008) New Revision: 26438 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26438&view=rev Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp Log: Build fix. Modified: haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp =================================================================== --- haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 18:20:01 UTC (rev 26437) +++ haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp 2008-07-15 18:26:40 UTC (rev 26438) @@ -1441,9 +1441,9 @@ // B_RGB32 bitmaps therefore don't draw correctly on BeOS if they actually // use this color, unless the alpha channel contains 255 for all other // pixels, which is inconsistent. - && fDrawingMode != B_OP_ALPHA) + && fDrawingMode != B_OP_ALPHA #endif - ) { + )) { temp = new (nothrow) BBitmap(actualBitmapRect, B_BITMAP_NO_SERVER_LINK, B_RGBA32); if (temp == NULL) { From superstippi at gmx.de Tue Jul 15 21:22:15 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Tue, 15 Jul 2008 21:22:15 +0200 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: <200807151826.m6FIQfOR010466@sheep.berlios.de> References: <200807151826.m6FIQfOR010466@sheep.berlios.de> Message-ID: <20080715212215.23527.10@stippis2.1216119101.fake> anevilyak at BerliOS wrote: > Author: anevilyak > Date: 2008-07-15 20:26:40 +0200 (Tue, 15 Jul 2008) New Revision: 26438 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26438&view=rev > > Modified: > haiku/trunk/src/servers/app/drawing/Painter/Painter.cpp > Log: > Build fix. Argh! Sorry... You keep having to clean up after me... I guess I owe you Beer at BeGeistert! :-) Best regards, -Stephan From axeld at mail.berlios.de Tue Jul 15 21:23:35 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Tue, 15 Jul 2008 21:23:35 +0200 Subject: [Haiku-commits] r26439 - haiku/trunk/build/jam Message-ID: <200807151923.m6FJNZxG018938@sheep.berlios.de> Author: axeld Date: 2008-07-15 21:23:34 +0200 (Tue, 15 Jul 2008) New Revision: 26439 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26439&view=rev Modified: haiku/trunk/build/jam/ImageRules Log: * When updating all targets, symlinks and directories are now also recreated. * Removed superfluous white space. Modified: haiku/trunk/build/jam/ImageRules =================================================================== --- haiku/trunk/build/jam/ImageRules 2008-07-15 18:26:40 UTC (rev 26438) +++ haiku/trunk/build/jam/ImageRules 2008-07-15 19:23:34 UTC (rev 26439) @@ -11,7 +11,7 @@ } else { grist = $(gristToPrepend) ; } - + return $(target:G=$(grist)) ; } @@ -110,7 +110,7 @@ __is_on_image on $(directory) = true ; DIRECTORY_TOKENS on $(directory) = $(directoryTokens) ; NotFile $(directory) ; - + # mark the parent dir as not to be created local parent = [ FReverse $(directoryTokens) ] ; parent = [ FReverse $(parent[2-]) ] ; @@ -138,6 +138,19 @@ return $(filteredTargets) ; } + +rule IncludeAllTargetsInContainer container +{ + local filterVar + = [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ; + if $(filterVar) { + return $($(filterVar)) ; + } + + return ; +} + + rule AddFilesToContainer container : directoryTokens : targets : destName { # AddFilesToContainer : : @@ -149,7 +162,8 @@ # If the image shall only be updated, we filter out all targets not marked # accordingly. - if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { + if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + && ! [ IncludeAllTargetsInContainer $(container) ] { local filterVar = [ on $(container) return $(HAIKU_INCLUDE_IN_CONTAINER_VAR) ] ; if $(filterVar) { @@ -198,7 +212,8 @@ # # If the image shall only be updated, we don't add any symlinks. - if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { + if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + && ! [ IncludeAllTargetsInContainer $(container) ] { return ; } @@ -238,6 +253,7 @@ # If the image shall only be updated, we don't copy any directories if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + && ! [ IncludeAllTargetsInContainer $(container) ] && ! $(alwaysUpdate) { return ; } @@ -279,7 +295,8 @@ : $(targets) ; # If the image shall only be updated, we don't add any symlinks. - if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { + if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + && ! [ IncludeAllTargetsInContainer $(container) ] { return ; } @@ -316,7 +333,8 @@ # # If the image shall only be updated, we don't add any symlinks. - if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { + if [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + && ! [ IncludeAllTargetsInContainer $(container) ] { return ; } @@ -336,7 +354,7 @@ } local name = $(target:BS) ; - local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ; + local linkTarget = [ FDirName /boot $(installDir:G=) $(name) ] ; AddSymlinkToContainer $(container) : beos system add-ons kernel boot : $(linkTarget) : $(name) ; @@ -369,7 +387,8 @@ # If the image shall only be updated, we don't create directories. if $(dirsToCreate) - && ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] { + && ( ! [ on $(container) return $(HAIKU_CONTAINER_UPDATE_ONLY) ] + || [ IncludeAllTargetsInContainer $(container) ] ) { Depends $(scriptBody) : $(dirsToCreate) ; CreateContainerMakeDirectoriesScript1 $(scriptBody) : $(dirsToCreate) ; @@ -380,20 +399,20 @@ local resourceFiles = [ on $(dir) return $(ATTRIBUTE_FILES) ] ; if $(resourceFiles) { local dirTokens = [ on $(dir) return $(DIRECTORY_TOKENS) ] ; - + # translate resources file to file with attributes local attributeFile = $(script)-attributes-$(dirTokens:J=-) ; ResAttr $(attributeFile) : $(resourceFiles) ; - + # use a unique dummy target for this file, on which we # can define the TARGET_DIR variable local dummyTarget = $(script)-attributes-dummy-$(dir:G=) ; NotFile $(dummyTarget) ; TARGET_DIR on $(dummyTarget) = $(dir:G=) ; - + Depends $(dummyTarget) : $(initScript) $(attributeFile) ; Depends $(script) : $(dummyTarget) ; - + AppendToContainerMakeDirectoriesScriptAttributes $(dummyTarget) : $(initScript) $(attributeFile) ; } @@ -442,7 +461,7 @@ NotFile $(dummyTarget) ; TARGET_DIR on $(dummyTarget) = $(dir:G=) ; INSTALL_TARGET_NAME on $(dummyTarget) = $(name) ; - + Depends $(dummyTarget) : $(initScript) $(target) ; Depends $(script) : $(dummyTarget) ; @@ -467,7 +486,7 @@ OUTPUT_SCRIPT on $(dummyTarget) = $(initScript) ; AppendToContainerCopyFilesScript $(dummyTarget) : $(targets) ; } - + local symlinks = [ on $(dir) return $(SYMLINKS_TO_INSTALL) ] ; local symlink ; for symlink in $(symlinks) { @@ -492,22 +511,26 @@ } } + actions piecemeal AppendToContainerCopyFilesScript bind OUTPUT_SCRIPT { echo \$cp "\"\${sPrefix}$(2)\"" "\"\${tPrefix}$(TARGET_DIR)\"" >> $(OUTPUT_SCRIPT) } + actions AppendToContainerCopyFilesScriptSingleFile { echo \$cp "\"\${sPrefix}$(2[2])\"" \ "\"\${tPrefix}$(TARGET_DIR)/$(INSTALL_TARGET_NAME)\"" >> $(2[1]) } + actions AddSymlinkToContainerCopyFilesScript { echo \$ln -sfn "\"$(SYMLINK_TARGET)\"" "\"\${tPrefix}$(1:G=)\"" >> $(2[1]) } + actions AddDirectoryToContainerCopyFilesScript { echo \$cp -r $(EXCLUDE_PATTERNS) "\"\${sPrefix}$(SOURCE_DIRECTORY)/.\"" \ @@ -725,7 +748,7 @@ actions BuildHaikuImageUserGroupFile { - echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1) + echo "$(HAIKU_IMAGE_USER_GROUP_ENTRIES)" | tr '|' '\n' > $(1) } rule AddUserToHaikuImage user : uid : gid : home : shell : realName From anevilyak at gmail.com Tue Jul 15 22:17:31 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 15 Jul 2008 15:17:31 -0500 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: <20080715212215.23527.10@stippis2.1216119101.fake> References: <200807151826.m6FIQfOR010466@sheep.berlios.de> <20080715212215.23527.10@stippis2.1216119101.fake> Message-ID: On Tue, Jul 15, 2008 at 2:22 PM, Stephan Assmus wrote: > Argh! Sorry... You keep having to clean up after me... I guess I owe you > Beer at BeGeistert! :-) > No worries :) And on the plus side for you, I don't drink beer anyways so seems you're safe :) Regards, Rene From haiku at kaldience.com Wed Jul 16 01:30:27 2008 From: haiku at kaldience.com (Maurice Kalinowski) Date: Wed, 16 Jul 2008 01:30:27 +0200 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: References: <200807151826.m6FIQfOR010466@sheep.berlios.de> <20080715212215.23527.10@stippis2.1216119101.fake> Message-ID: <487D3313.6050400@kaldience.com> Rene Gollent wrote: > On Tue, Jul 15, 2008 at 2:22 PM, Stephan Assmus wrote: > >> Argh! Sorry... You keep having to clean up after me... I guess I owe you >> Beer at BeGeistert! :-) >> >> > > No worries :) And on the plus side for you, I don't drink beer anyways > so seems you're safe :) > > Right, you're more the Absinth guy, if I remember correctly :P Maurice From haiku at kaldience.com Wed Jul 16 01:28:17 2008 From: haiku at kaldience.com (Maurice Kalinowski) Date: Wed, 16 Jul 2008 01:28:17 +0200 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: References: <200807151826.m6FIQfOR010466@sheep.berlios.de> <20080715212215.23527.10@stippis2.1216119101.fake> Message-ID: <487D3291.1060104@kaldience.com> Rene Gollent wrote: > On Tue, Jul 15, 2008 at 2:22 PM, Stephan Assmus wrote: > >> Argh! Sorry... You keep having to clean up after me... I guess I owe you >> Beer at BeGeistert! :-) >> >> > > No worries :) And on the plus side for you, I don't drink beer anyways > so seems you're safe :) > Right, you're more the Absinth guy, if I remember correctly :P Maurice From anevilyak at gmail.com Wed Jul 16 02:43:02 2008 From: anevilyak at gmail.com (Rene Gollent) Date: Tue, 15 Jul 2008 19:43:02 -0500 Subject: [Haiku-commits] r26438 - haiku/trunk/src/servers/app/drawing/Painter In-Reply-To: <487D3291.1060104@kaldience.com> References: <200807151826.m6FIQfOR010466@sheep.berlios.de> <20080715212215.23527.10@stippis2.1216119101.fake> <487D3291.1060104@kaldience.com> Message-ID: On Tue, Jul 15, 2008 at 6:28 PM, Maurice Kalinowski wrote: > Right, you're more the Absinth guy, if I remember correctly :P > Um.... no ;) I like my brain functional :) Rene From leavengood at gmail.com Wed Jul 16 03:17:50 2008 From: leavengood at gmail.com (Ryan Leavengood) Date: Tue, 15 Jul 2008 21:17:50 -0400 Subject: [Haiku-commits] r26408 - haiku/trunk/src/apps/midiplayer In-Reply-To: <20080715132140.761.1@stippis2.1216119101.fake> References: <200807141641.m6EGfOIx020371@sheep.berlios.de> <20080715132140.761.1@stippis2.1216119101.fake> Message-ID: On Tue, Jul 15, 2008 at 7:21 AM, Stephan Assmus wrote: > > nice patch (and article, although I would prefer to use the dark on light > scheme for the code sections)! Yeah I was thinking maybe a lighter scheme was better but several people seemed to like the darker one enough. > My only comment is that you could change > some of the constructors to use the new layout friendly versions: Good idea, I should have done that in the article. I tried to apply this patch but it did not work so please just submit these changes. > Maybe I get around to add layout friendly constructors to the classes > missing them, then the rest could be changed as well. I may do that too. Ryan From umccullough at gmail.com Wed Jul 16 03:29:58 2008 From: umccullough at gmail.com (Urias McCullough) Date: Tue, 15 Jul 2008 18:29:58 -0700 Subject: [Haiku-commits] r26435 - haiku/trunk/build/jam In-Reply-To: <200807151754.m6FHsx19004209@sheep.berlios.de> References: <200807151754.m6FHsx19004209@sheep.berlios.de> Message-ID: <1e80d8750807151829n43c12ea0y52b1a13f861e4369@mail.gmail.com> 2008/7/15 axeld at BerliOS : > Author: axeld > Date: 2008-07-15 19:54:58 +0200 (Tue, 15 Jul 2008) > New Revision: 26435 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26435&view=rev > > Modified: > haiku/trunk/build/jam/MiscRules > Log: > * Added an "update-all" build profile action that updates all files. This can > be used to update an installation without erasing the whole volume (ie. it > works like install-haiku on BFS capable platforms). VERY nice :) Thanks for this. From stefano.ceccherini at gmail.com Wed Jul 16 08:55:33 2008 From: stefano.ceccherini at gmail.com (Stefano Ceccherini) Date: Wed, 16 Jul 2008 08:55:33 +0200 Subject: [Haiku-commits] r25948 - haiku/trunk/src/kits/interface In-Reply-To: <4854475A.5040700@zappotek.com> References: <200806130024.m5D0O2nd022152@sheep.berlios.de> <20080613225122.463.2@knochen-vm.1213389699.fake> <4852EE25.2020304@zappotek.com> <4854475A.5040700@zappotek.com> Message-ID: <894b9700807152355j6f0d7208u6cd59f2953c23606@mail.gmail.com> 2008/6/15 Alexandre Deckner : > I'm looking at it right now. This code is older than the svn repository, > it's been there for a while. > In BMenu::_ComputeLayout i commented the part that adjust the width > depending on the resizing mode. Everything works fine so far (except > tracker menubar now). > I looked at older revisions and there was a comment saying this code is > there for BMenuBar. Anyone familiar with this part? Stefano? I'll have a > look at BMenuBar anyway. Sorry, I just realized I never replied to this mail. BMenu::_ComputeLayout() calculates the layout also when the BMenu is a BMenuBar (IOW: BMenuBar doesn't have its own method to do that). In that case, if the resizing mode is B_FOLLOW_LEFT_RIGHT, the preferred width of the menubar is the width of the parent view/window. From marcusoverhagen at arcor.de Wed Jul 16 13:07:57 2008 From: marcusoverhagen at arcor.de (Marcus Overhagen) Date: Wed, 16 Jul 2008 13:07:57 +0200 Subject: [Haiku-commits] r26437 - haiku/trunk/src/apps/networkstatus In-Reply-To: <200807151820.m6FIK4Mu009138@sheep.berlios.de> References: <200807151820.m6FIK4Mu009138@sheep.berlios.de> Message-ID: <487DD68D.7090000@arcor.de> stippi at mail.berlios.de schrieb: > Use B_RGBA32 if you mean that instead of B_RGB32. The IconUtils could be > changed to either refuse B_RGB32 or give them an invalid alpha channel > with just B_TRANSPARENT_MAGIC_RGBA32. That would make that mistake more > obvious. IconUtils could simply call debugger() as done for other progamming mistakes. The looper must be locked, Marcus From superstippi at gmx.de Wed Jul 16 13:19:07 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Wed, 16 Jul 2008 13:19:07 +0200 Subject: [Haiku-commits] r26408 - haiku/trunk/src/apps/midiplayer In-Reply-To: References: <200807141641.m6EGfOIx020371@sheep.berlios.de> <20080715132140.761.1@stippis2.1216119101.fake> Message-ID: <20080716131907.685.1@stippis2.1216206969.fake> Hi, Ryan Leavengood wrote: > On Tue, Jul 15, 2008 at 7:21 AM, Stephan Assmus > wrote: > > > > nice patch (and article, although I would prefer to use the dark on > > light scheme for the code sections)! > > Yeah I was thinking maybe a lighter scheme was better but several people > seemed to like the darker one enough. But it kind of looks alien to the usual scheme we have. > > My only comment is that you could change > > some of the constructors to use the new layout friendly versions: > > Good idea, I should have done that in the article. I tried to apply this > patch but it did not work so please just submit these changes. Ok, will do! :-) > > Maybe I get around to add layout friendly constructors to the classes > > missing them, then the rest could be changed as well. > > I may do that too. Ok cool. I was going to look at BSlider next, will let you know before I work on another one. Best regards, -Stephan From superstippi at gmx.de Wed Jul 16 13:23:42 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Wed, 16 Jul 2008 13:23:42 +0200 Subject: [Haiku-commits] r26437 - haiku/trunk/src/apps/networkstatus In-Reply-To: <487DD68D.7090000@arcor.de> References: <200807151820.m6FIK4Mu009138@sheep.berlios.de> <487DD68D.7090000@arcor.de> Message-ID: <20080716132342.719.2@stippis2.1216206969.fake> Marcus Overhagen wrote: > stippi at mail.berlios.de schrieb: > > > Use B_RGBA32 if you mean that instead of B_RGB32. The IconUtils could > > be changed to either refuse B_RGB32 or give them an invalid alpha > > channel with just B_TRANSPARENT_MAGIC_RGBA32. That would make that > > mistake more obvious. > > IconUtils could simply call debugger() as done for other progamming > mistakes. That is actually a pretty useful idea. Will implement that. The view already has a parent, -Stephan From stippi at mail.berlios.de Wed Jul 16 15:46:10 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 15:46:10 +0200 Subject: [Haiku-commits] r26440 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807161346.m6GDkAOS009780@sheep.berlios.de> Author: stippi Date: 2008-07-16 15:46:05 +0200 (Wed, 16 Jul 2008) New Revision: 26440 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26440&view=rev Modified: haiku/trunk/headers/os/interface/Slider.h haiku/trunk/src/kits/interface/Slider.cpp Log: * Added layout friendly constructor * Use constructor lists for initializing members * Simplified initial SetBarColor() * Update the offscreen view with ViewColor() and LowColor(), someone might have changed it after AttachedToWindow() was called. * Cleanup here and there Modified: haiku/trunk/headers/os/interface/Slider.h =================================================================== --- haiku/trunk/headers/os/interface/Slider.h 2008-07-15 19:23:34 UTC (rev 26439) +++ haiku/trunk/headers/os/interface/Slider.h 2008-07-16 13:46:05 UTC (rev 26440) @@ -45,6 +45,11 @@ uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); + BSlider(const char *name, const char *label, + BMessage *message, int32 minValue, int32 maxValue, + orientation posture, thumb_style thumbType = B_BLOCK_THUMB, + uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); + BSlider(BMessage *data); virtual ~BSlider(); @@ -135,7 +140,8 @@ float BarThickness() const; virtual void SetBarThickness(float thickness); - virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); + virtual void SetFont(const BFont *font, + uint32 properties = B_FONT_ALL); virtual void SetLimits(int32 minimum, int32 maximum); Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-07-15 19:23:34 UTC (rev 26439) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 13:46:05 UTC (rev 26440) @@ -23,33 +23,31 @@ #include -BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, - int32 minValue, int32 maxValue, thumb_style thumbType, - uint32 resizingMode, uint32 flags) - : BControl(frame, name, label, message, resizingMode, flags) -{ - fModificationMessage = NULL; - fSnoozeAmount = 20000; - fOrientation = B_HORIZONTAL; - fBarThickness = 6.0f; - fMinLimitLabel = NULL; - fMaxLimitLabel = NULL; - fMinValue = minValue; - fMaxValue = maxValue; +BSlider::BSlider(BRect frame, const char* name, const char* label, + BMessage* message, int32 minValue, int32 maxValue, + thumb_style thumbType, uint32 resizingMode, uint32 flags) + : BControl(frame, name, label, message, resizingMode, flags), + fModificationMessage(NULL), + fSnoozeAmount(20000), - fKeyIncrementValue = 1; - fHashMarkCount = 0; - fHashMarks = B_HASH_MARKS_NONE; - fStyle = thumbType; + fMinLimitLabel(NULL), + fMaxLimitLabel(NULL), - if (Style() == B_BLOCK_THUMB) { - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - } else { - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - } + fMinValue(minValue), + fMaxValue(maxValue), + fKeyIncrementValue(1), + fHashMarkCount(0), + fHashMarks(B_HASH_MARKS_NONE), + + fStyle(thumbType), + + fOrientation(B_HORIZONTAL), + fBarThickness(6.0) +{ + SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_DARKEN_4_TINT)); + UseFillColor(false, NULL); _InitObject(); @@ -57,32 +55,64 @@ } -BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, - int32 minValue, int32 maxValue, orientation posture, - thumb_style thumbType, uint32 resizingMode, uint32 flags) - : BControl(frame, name, label, message, resizingMode, flags) +BSlider::BSlider(BRect frame, const char *name, const char *label, + BMessage *message, int32 minValue, int32 maxValue, + orientation posture, thumb_style thumbType, uint32 resizingMode, + uint32 flags) + : BControl(frame, name, label, message, resizingMode, flags), + fModificationMessage(NULL), + fSnoozeAmount(20000), + + fMinLimitLabel(NULL), + fMaxLimitLabel(NULL), + + fMinValue(minValue), + fMaxValue(maxValue), + fKeyIncrementValue(1), + + fHashMarkCount(0), + fHashMarks(B_HASH_MARKS_NONE), + + fStyle(thumbType), + + fOrientation(posture), + fBarThickness(6.0) { - fModificationMessage = NULL; - fSnoozeAmount = 20000; - fOrientation = posture; - fBarThickness = 6.0f; - fMinLimitLabel = NULL; - fMaxLimitLabel = NULL; - fMinValue = minValue; - fMaxValue = maxValue; + SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_DARKEN_4_TINT)); - fKeyIncrementValue = 1; - fHashMarkCount = 0; - fHashMarks = B_HASH_MARKS_NONE; - fStyle = thumbType; + UseFillColor(false, NULL); - if (Style() == B_BLOCK_THUMB) - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - else - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); + _InitObject(); + SetValue(0); +} + +BSlider::BSlider(const char *name, const char *label, BMessage *message, + int32 minValue, int32 maxValue, orientation posture, + thumb_style thumbType, uint32 flags) + : BControl(name, label, message, flags), + fModificationMessage(NULL), + fSnoozeAmount(20000), + + fMinLimitLabel(NULL), + fMaxLimitLabel(NULL), + + fMinValue(minValue), + fMaxValue(maxValue), + fKeyIncrementValue(1), + + fHashMarkCount(0), + fHashMarks(B_HASH_MARKS_NONE), + + fStyle(thumbType), + + fOrientation(posture), + fBarThickness(6.0) +{ + SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), + B_DARKEN_4_TINT)); + UseFillColor(false, NULL); _InitObject(); @@ -96,7 +126,7 @@ fModificationMessage = NULL; if (archive->HasMessage("_mod_msg")) { - BMessage *message = new BMessage; + BMessage* message = new BMessage; archive->FindMessage("_mod_msg", message); @@ -107,14 +137,12 @@ SetSnoozeAmount(20000); rgb_color color; - - if (archive->FindInt32("_fcolor", (int32 *)&color) == B_OK) { + if (archive->FindInt32("_fcolor", (int32 *)&color) == B_OK) UseFillColor(true, &color); - } else + else UseFillColor(false); int32 orient; - if (archive->FindInt32("_orient", &orient) == B_OK) fOrientation = (orientation)orient; else @@ -123,7 +151,8 @@ fMinLimitLabel = NULL; fMaxLimitLabel = NULL; - const char *minlbl = NULL, *maxlbl = NULL; + const char* minlbl = NULL; + const char* maxlbl = NULL; archive->FindString("_minlbl", &minlbl); archive->FindString("_maxlbl", &maxlbl); @@ -143,32 +172,22 @@ fHashMarkCount = 11; int16 hashloc; - if (archive->FindInt16("_hashloc", &hashloc) == B_OK) fHashMarks = (hash_mark_location)hashloc; else fHashMarks = B_HASH_MARKS_NONE; int16 sstyle; - if (archive->FindInt16("_sstyle", &sstyle) == B_OK) fStyle = (thumb_style)sstyle; else fStyle = B_BLOCK_THUMB; - if (archive->FindInt32("_bcolor", (int32 *)&color) == B_OK) - SetBarColor(color); - else { - if (Style() == B_BLOCK_THUMB) - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - else - SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), - B_DARKEN_4_TINT)); - } + if (archive->FindInt32("_bcolor", (int32 *)&color) != B_OK) + color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT); + SetBarColor(color); float bthickness; - if (archive->FindFloat("_bthickness", &bthickness) == B_OK) fBarThickness = bthickness; else @@ -181,8 +200,7 @@ BSlider::~BSlider() { #if USE_OFF_SCREEN_VIEW - if (fOffScreenBits) - delete fOffScreenBits; + delete fOffScreenBits; #endif delete fModificationMessage; @@ -558,18 +576,13 @@ void BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) { - if (minLabel) { - free(fMinLimitLabel); - fMinLimitLabel = strdup(minLabel); - } + free(fMinLimitLabel); + fMinLimitLabel = minLabel ? strdup(minLabel) : NULL; - if (maxLabel) { - free(fMaxLimitLabel); - fMaxLimitLabel = strdup(maxLabel); - } + free(fMaxLimitLabel); + fMaxLimitLabel = maxLabel ? strdup(maxLabel) : NULL; - // TODO: Auto resizing?!? I would not want this as an app programmer! - ResizeToPreferred(); + InvalidateLayout(); Invalidate(); } @@ -596,74 +609,75 @@ if (value > fMaxValue) value = fMaxValue; - if (value != Value()) { - BPoint loc; - float range = (float)(fMaxValue - fMinValue); - if (range == 0) - range = 1; + if (value == Value()) + return; - float pos = (float)(value - fMinValue) / range * - _MaxPosition() - _MinPosition(); + BPoint loc; + float range = (float)(fMaxValue - fMinValue); + if (range == 0) + range = 1; - if (fOrientation == B_HORIZONTAL) { - loc.x = ceil(_MinPosition() + pos); - loc.y = 0; - } else { - loc.x = 0; - loc.y = floor(_MaxPosition() - pos); - } + float pos = (float)(value - fMinValue) / range * + _MaxPosition() - _MinPosition(); - BRect oldThumbFrame = ThumbFrame(); + if (fOrientation == B_HORIZONTAL) { + loc.x = ceil(_MinPosition() + pos); + loc.y = 0; + } else { + loc.x = 0; + loc.y = floor(_MaxPosition() - pos); + } - // While it would be enough to do this dependent on fUseFillColor, - // that doesn't work out if DrawBar() has been overridden by a sub class - if (fOrientation == B_HORIZONTAL) - oldThumbFrame.top = BarFrame().top; - else - oldThumbFrame.right = BarFrame().right; + BRect oldThumbFrame = ThumbFrame(); - _SetLocation(loc); + // While it would be enough to do this dependent on fUseFillColor, + // that doesn't work out if DrawBar() has been overridden by a sub class + if (fOrientation == B_HORIZONTAL) + oldThumbFrame.top = BarFrame().top; + else + oldThumbFrame.right = BarFrame().right; - BControl::SetValueNoUpdate(value); - BRect invalid = oldThumbFrame | ThumbFrame(); + _SetLocation(loc); - if (Style() == B_TRIANGLE_THUMB) { - // 1) we need to take care of pixels touched because of - // anti-aliasing - // 2) we need to update the region with the focus mark as well - // (a method BSlider::FocusMarkFrame() would be nice as well) - if (fOrientation == B_HORIZONTAL) { - if (IsFocus()) - invalid.bottom += 2; - invalid.InsetBy(-1, 0); - } else { - if (IsFocus()) - invalid.left -= 2; - invalid.InsetBy(0, -1); - } + BControl::SetValueNoUpdate(value); + BRect invalid = oldThumbFrame | ThumbFrame(); + + if (Style() == B_TRIANGLE_THUMB) { + // 1) we need to take care of pixels touched because of + // anti-aliasing + // 2) we need to update the region with the focus mark as well + // (a method BSlider::FocusMarkFrame() would be nice as well) + if (fOrientation == B_HORIZONTAL) { + if (IsFocus()) + invalid.bottom += 2; + invalid.InsetBy(-1, 0); + } else { + if (IsFocus()) + invalid.left -= 2; + invalid.InsetBy(0, -1); } + } - Invalidate(invalid); + Invalidate(invalid); - // update text label + // update text label - float oldWidth = 0.0f, width = 0.0f; - if (fUpdateText != NULL) - oldWidth = StringWidth(fUpdateText); + float oldWidth = 0.0f, width = 0.0f; + if (fUpdateText != NULL) + oldWidth = StringWidth(fUpdateText); - fUpdateText = UpdateText(); - if (fUpdateText != NULL) - width = StringWidth(fUpdateText); + fUpdateText = UpdateText(); + if (fUpdateText != NULL) + width = StringWidth(fUpdateText); - width = ceilf(max_c(width, oldWidth)) + 2.0f; - if (width != 0) { - font_height fontHeight; - GetFontHeight(&fontHeight); + width = ceilf(max_c(width, oldWidth)) + 2.0f; + if (width != 0) { + font_height fontHeight; + GetFontHeight(&fontHeight); - BRect rect(-width, 0, 0, ceilf(fontHeight.ascent + fontHeight.descent)); - rect.OffsetBy(Bounds().Width(), 0); - Invalidate(rect); - } + BRect rect(-width, 0, 0, ceilf(fontHeight.ascent + fontHeight.descent)); + rect.OffsetBy(Bounds().Width(), 0); + Invalidate(rect); } } @@ -740,6 +754,8 @@ return; if (fOffScreenBits->Lock()) { + fOffScreenView->SetViewColor(ViewColor()); + fOffScreenView->SetLowColor(ViewColor()); #endif if (background.Frame().IsValid()) From stippi at mail.berlios.de Wed Jul 16 16:41:14 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 16:41:14 +0200 Subject: [Haiku-commits] r26441 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807161441.m6GEfEIT014509@sheep.berlios.de> Author: stippi Date: 2008-07-16 16:41:10 +0200 (Wed, 16 Jul 2008) New Revision: 26441 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26441&view=rev Modified: haiku/trunk/headers/os/interface/Slider.h haiku/trunk/src/kits/interface/Slider.cpp Log: First round of BSlider fixes to be more layout friendly: * Improve the minimum size calculation and cache it. * Invalidate the layout on various property changes that require it. Vertical BSliders are very broken... that's up next. Modified: haiku/trunk/headers/os/interface/Slider.h =================================================================== --- haiku/trunk/headers/os/interface/Slider.h 2008-07-16 13:46:05 UTC (rev 26440) +++ haiku/trunk/headers/os/interface/Slider.h 2008-07-16 14:41:10 UTC (rev 26441) @@ -145,6 +145,12 @@ virtual void SetLimits(int32 minimum, int32 maximum); + virtual void InvalidateLayout(bool descendants = false); + + virtual BSize MinSize(); + virtual BSize MaxSize(); + virtual BSize PreferredSize(); + private: void _DrawBlockThumb(); void _DrawTriangleThumb(); @@ -156,6 +162,8 @@ float _MaxPosition() const; bool _ConstrainPoint(BPoint& point, BPoint compare) const; + BSize _ValidateMinSize(); + virtual void _ReservedSlider5(); virtual void _ReservedSlider6(); virtual void _ReservedSlider7(); @@ -201,10 +209,12 @@ orientation fOrientation; float fBarThickness; + BSize fMinSize; + #if USE_OFF_SCREEN_VIEW + uint32 _reserved[5]; +#else uint32 _reserved[7]; -#else - uint32 _reserved[9]; #endif }; Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 13:46:05 UTC (rev 26440) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 14:41:10 UTC (rev 26441) @@ -9,6 +9,8 @@ */ +#include + #include #include @@ -16,13 +18,12 @@ #include #include +#include #include #include #include -#include - BSlider::BSlider(BRect frame, const char* name, const char* label, BMessage* message, int32 minValue, int32 maxValue, thumb_style thumbType, uint32 resizingMode, uint32 flags) @@ -223,6 +224,7 @@ #endif fUpdateText = NULL; + fMinSize.Set(-1, -1); } @@ -736,6 +738,9 @@ } +// #pragma mark - drawing + + void BSlider::Draw(BRect updateRect) { @@ -743,9 +748,9 @@ BRegion background(updateRect); background.Exclude(BarFrame()); - // ToDo: the triangle thumb doesn't delete its background, so we still have to do it - // Note, this also creates a different behaviour for subclasses, depending on the - // thumb style - if possible this should be avoided. + // ToDo: the triangle thumb doesn't delete its background, so we still have + // to do it Note, this also creates a different behaviour for subclasses, + // depending on the thumb style - if possible this should be avoided. if (Style() == B_BLOCK_THUMB) background.Exclude(ThumbFrame()); @@ -1095,6 +1100,9 @@ } +// #pragma mark - + + char* BSlider::UpdateText() const { @@ -1229,86 +1237,13 @@ void BSlider::GetPreferredSize(float* _width, float* _height) { - font_height fontHeight; - GetFontHeight(&fontHeight); + BSize preferredSize = PreferredSize(); - float width, height; - int32 rows = 0; + if (_width) + *_width = preferredSize.width; - if (Orientation() == B_HORIZONTAL) { - width = Frame().Width(); - height = 12.0f + fBarThickness; - - float labelWidth = 0; - if (Label()) { - labelWidth = StringWidth(Label()); - rows++; - } - - float minWidth = 0; - if (MinLimitLabel()) - minWidth = StringWidth(MinLimitLabel()); - if (MaxLimitLabel()) { - // some space between the labels - if (MinLimitLabel()) - minWidth += 8.0f; - - minWidth += StringWidth(MaxLimitLabel()); - } - - if (minWidth > width) - width = minWidth; - if (labelWidth > width) - width = labelWidth; - if (width < 32.0f) - width = 32.0f; - - if (MinLimitLabel() || MaxLimitLabel()) - rows++; - - height += rows * ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f); - } else { - // B_VERTICAL - width = 12.0f + fBarThickness; - height = Frame().Height(); - - // find largest label - - float minWidth = 0; - if (Label()) { - minWidth = StringWidth(Label()); - rows++; - } - if (MinLimitLabel()) { - float width = StringWidth(MinLimitLabel()); - if (width > minWidth) - minWidth = width; - rows++; - } - if (MaxLimitLabel()) { - float width = StringWidth(MaxLimitLabel()); - if (width > minWidth) - minWidth = width; - rows++; - } - - if (minWidth > width) - width = minWidth; - - float minHeight = 32.0f + rows - * ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f); - - if (Label() && MaxLimitLabel()) - minHeight -= 4.0f; - - if (minHeight > height) - height = minHeight; - } - - if (_width) - *_width = width; if (_height) - *_height = height; + *_height = preferredSize.height; } @@ -1412,6 +1347,7 @@ BSlider::SetHashMarks(hash_mark_location where) { fHashMarks = where; + InvalidateLayout(); Invalidate(); } @@ -1427,6 +1363,7 @@ BSlider::SetStyle(thumb_style style) { fStyle = style; + InvalidateLayout(); Invalidate(); } @@ -1497,6 +1434,7 @@ BSlider::SetOrientation(orientation posture) { fOrientation = posture; + InvalidateLayout(); Invalidate(); } @@ -1511,8 +1449,12 @@ void BSlider::SetBarThickness(float thickness) { - if (thickness >= 1.0f) + if (thickness < 1.0) + thickness = 1.0; + if (thickness != fBarThickness) { fBarThickness = thickness; + InvalidateLayout(); + } } @@ -1529,6 +1471,8 @@ } } #endif + + InvalidateLayout(); } @@ -1550,7 +1494,54 @@ } +// #pragma mark - layout related + + void +BSlider::InvalidateLayout(bool descendants) +{ + // invalidate cached preferred size + fMinSize.Set(-1, -1); + + BControl::InvalidateLayout(descendants); +} + + +BSize +BSlider::MinSize() +{ + return BLayoutUtils::ComposeSize(ExplicitMinSize(), + _ValidateMinSize()); +} + + +BSize +BSlider::MaxSize() +{ + BSize maxSize = _ValidateMinSize(); + if (fOrientation == B_HORIZONTAL) + maxSize.width = B_SIZE_UNLIMITED; + else + maxSize.height = B_SIZE_UNLIMITED; + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), maxSize); +} + + +BSize +BSlider::PreferredSize() +{ + BSize preferredSize = _ValidateMinSize(); + if (fOrientation == B_HORIZONTAL) + preferredSize.width = max_c(100.0, preferredSize.width); + else + preferredSize.height = max_c(100.0, preferredSize.height); + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), preferredSize); +} + + +// #pragma mark - private + +void BSlider::_DrawBlockThumb() { BRect frame = ThumbFrame(); @@ -1794,6 +1785,87 @@ } +BSize +BSlider::_ValidateMinSize() +{ + if (fMinSize.width >= 0) { + // the preferred size is up to date + return fMinSize; + } + + font_height fontHeight; + GetFontHeight(&fontHeight); + + float width = 0.0; + float height = 0.0; + int32 rows = 0; + + if (Orientation() == B_HORIZONTAL) { + height = 12.0 + fBarThickness; + + float labelWidth = 0; + if (Label()) { + labelWidth = StringWidth(Label()); + rows++; + } + + if (MinLimitLabel()) + width = StringWidth(MinLimitLabel()); + if (MaxLimitLabel()) { + // some space between the labels + if (MinLimitLabel()) + width += 8.0; + + width += StringWidth(MaxLimitLabel()); + } + + if (labelWidth > width) + width = labelWidth; + if (width < 32.0) + width = 32.0; + + if (MinLimitLabel() || MaxLimitLabel()) + rows++; + + height += rows * (ceilf(fontHeight.ascent) + + ceilf(fontHeight.descent) + 4.0); + } else { + // B_VERTICAL + width = 12.0 + fBarThickness; + + // find largest label + float labelWidth = 0; + if (Label()) { + labelWidth = StringWidth(Label()); + rows++; + } + if (MinLimitLabel()) { + labelWidth = max_c(labelWidth, StringWidth(MinLimitLabel())); + rows++; + } + if (MaxLimitLabel()) { + labelWidth = max_c(labelWidth, StringWidth(MaxLimitLabel())); + rows++; + } + + width = max_c(labelWidth, width); + + height = 32.0 + rows * (ceilf(fontHeight.ascent) + + ceilf(fontHeight.descent) + 4.0); + + if (Label() && MaxLimitLabel()) + height -= 4.0f; + } + + fMinSize.width = width; + fMinSize.height = height; + + return fMinSize; +} + + +// #pragma mark - FBC padding + void BSlider::_ReservedSlider5() {} void BSlider::_ReservedSlider6() {} void BSlider::_ReservedSlider7() {} From stippi at mail.berlios.de Wed Jul 16 17:06:18 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 17:06:18 +0200 Subject: [Haiku-commits] r26442 - in haiku/trunk/src/tests/kits/interface/layout/widget_layout_test: . tests Message-ID: <200807161506.m6GF6IYu016787@sheep.berlios.de> Author: stippi Date: 2008-07-16 17:06:13 +0200 (Wed, 16 Jul 2008) New Revision: 26442 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26442&view=rev Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp Log: Added a test for BSlider Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-07-16 14:41:10 UTC (rev 26441) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/Jamfile 2008-07-16 15:06:13 UTC (rev 26442) @@ -27,6 +27,7 @@ MenuBarTest.cpp MenuFieldTest.cpp MenuTest.cpp + SliderTest.cpp : be ; Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-07-16 14:41:10 UTC (rev 26441) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp 2008-07-16 15:06:13 UTC (rev 26442) @@ -17,6 +17,7 @@ #include "MenuBarTest.h" #include "MenuFieldTest.h" #include "MenuTest.h" +#include "SliderTest.h" #include "StringView.h" #include "Test.h" #include "TwoDimensionalSliderView.h" @@ -45,6 +46,7 @@ { "BMenu", MenuTest::CreateTest }, { "BMenuBar", MenuBarTest::CreateTest }, { "BMenuField", MenuFieldTest::CreateTest }, + { "BSlider", SliderTest::CreateTest }, { NULL, NULL } }; Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp 2008-07-16 14:41:10 UTC (rev 26441) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp 2008-07-16 15:06:13 UTC (rev 26442) @@ -0,0 +1,472 @@ +/* + * Copyright 2008, Stephan A?mus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "SliderTest.h" + +#include + +#include +#include + +#include "GroupView.h" +#include "RadioButton.h" +#include "TestView.h" + + +// messages +enum { + MSG_ORIENTATION_CHANGED = 'orch', + MSG_THUMB_STYLE_CHANGED = 'tstc', + MSG_HASH_MARKS_CHANGED = 'hmch', + MSG_BAR_THICKNESS_CHANGED = 'btch', + MSG_LABEL_CHANGED = 'lbch', + MSG_LIMIT_LABELS_CHANGED = 'lmch' +}; + + +// OrientationRadioButton +class SliderTest::OrientationRadioButton : public LabeledRadioButton { +public: + OrientationRadioButton(const char* label, enum orientation orientation) + : LabeledRadioButton(label), + fOrientation(orientation) + { + } + + enum orientation fOrientation; +}; + +// ThumbStyleRadioButton +class SliderTest::ThumbStyleRadioButton : public LabeledRadioButton { +public: + ThumbStyleRadioButton(const char* label, enum thumb_style style) + : LabeledRadioButton(label), + fStyle(style) + { + } + + thumb_style fStyle; +}; + +// HashMarkLocationRadioButton +class SliderTest::HashMarkLocationRadioButton : public LabeledRadioButton { +public: + HashMarkLocationRadioButton(const char* label, enum hash_mark_location + location) + : LabeledRadioButton(label), + fLocation(location) + { + } + + hash_mark_location fLocation; +}; + + +// ThicknessRadioButton +class SliderTest::ThicknessRadioButton : public LabeledRadioButton { +public: + ThicknessRadioButton(const char* label, float thickness) + : LabeledRadioButton(label), + fThickness(thickness) + { + } + + float fThickness; +}; + + +// LabelRadioButton +class SliderTest::LabelRadioButton : public LabeledRadioButton { +public: + LabelRadioButton(const char* label, const char* sliderLabel) + : LabeledRadioButton(label), + fLabel(sliderLabel) + { + } + + const char* fLabel; +}; + + +// LimitLabelsRadioButton +class SliderTest::LimitLabelsRadioButton : public LabeledRadioButton { +public: + LimitLabelsRadioButton(const char* label, const char* minLabel, + const char* maxLabel) + : LabeledRadioButton(label), + fMinLabel(minLabel), + fMaxLabel(maxLabel) + { + } + + const char* fMinLabel; + const char* fMaxLabel; +}; + + +// constructor +SliderTest::SliderTest() + : Test("Slider", NULL), + fSlider(new BSlider("test slider", "Label", NULL, 1, 100, B_HORIZONTAL)), + fOrientationRadioGroup(NULL), + fThumbStyleRadioGroup(NULL), + fHashMarkLocationRadioGroup(NULL), + fBarThicknessRadioGroup(NULL), + fLabelRadioGroup(NULL), + fLimitLabelsRadioGroup(NULL) +{ + SetView(fSlider); +} + + +// destructor +SliderTest::~SliderTest() +{ + delete fOrientationRadioGroup; + delete fThumbStyleRadioGroup; + delete fHashMarkLocationRadioGroup; + delete fBarThicknessRadioGroup; + delete fLabelRadioGroup; + delete fLimitLabelsRadioGroup; +} + + +// CreateTest +Test* +SliderTest::CreateTest() +{ + return new SliderTest; +} + + +// ActivateTest +void +SliderTest::ActivateTest(View* controls) +{ + // BSlider sets its background color to that of its parent in + // AttachedToWindow(). Override. + rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); + fSlider->SetViewColor(background); + fSlider->SetLowColor(background); + fSlider->SetHashMarkCount(10); + + GroupView* group = new GroupView(B_VERTICAL); + group->SetFrame(controls->Bounds()); + group->SetSpacing(0, 4); + controls->AddChild(group); + + GroupView* hGroup = new GroupView(B_HORIZONTAL); + group->AddChild(hGroup); + + // the radio button group for selecting the orientation + + GroupView* vGroup = new GroupView(B_VERTICAL); + vGroup->SetSpacing(0, 4); + hGroup->AddChild(vGroup); + + fOrientationRadioGroup = new RadioButtonGroup( + new BMessage(MSG_ORIENTATION_CHANGED), this); + + // horizontal + LabeledRadioButton* button = new OrientationRadioButton("Horizontal", + B_HORIZONTAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // vertical + button = new OrientationRadioButton("Vertical", B_VERTICAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // default to horizontal + fOrientationRadioGroup->SelectButton(0L); + + // the radio button group for selecting the thumb style + + vGroup = new GroupView(B_VERTICAL); + vGroup->SetSpacing(0, 4); + hGroup->AddChild(vGroup); + + fThumbStyleRadioGroup = new RadioButtonGroup( + new BMessage(MSG_THUMB_STYLE_CHANGED), this); + + // block thumb + button = new ThumbStyleRadioButton("Block thumb", B_BLOCK_THUMB); + vGroup->AddChild(button); + fThumbStyleRadioGroup->AddButton(button->GetRadioButton()); + + // triangle thumb + button = new ThumbStyleRadioButton("Triangle thumb", B_TRIANGLE_THUMB); + vGroup->AddChild(button); + fThumbStyleRadioGroup->AddButton(button->GetRadioButton()); + + // default to block thumb + fThumbStyleRadioGroup->SelectButton(0L); + + // spacing + group->AddChild(new VStrut(10)); + + // the radio button group for selecting the thumb style + + fHashMarkLocationRadioGroup = new RadioButtonGroup( + new BMessage(MSG_HASH_MARKS_CHANGED), this); + + // no hash marks + button = new HashMarkLocationRadioButton("No hash marks", + B_HASH_MARKS_NONE); + group->AddChild(button); + fHashMarkLocationRadioGroup->AddButton(button->GetRadioButton()); + + // left/top hash marks + button = new HashMarkLocationRadioButton("Left/top hash marks", + B_HASH_MARKS_TOP); + group->AddChild(button); + fHashMarkLocationRadioGroup->AddButton(button->GetRadioButton()); + + // right/bottom hash marks + button = new HashMarkLocationRadioButton("Right/bottom hash marks", + B_HASH_MARKS_BOTTOM); + group->AddChild(button); + fHashMarkLocationRadioGroup->AddButton(button->GetRadioButton()); + + // both side hash marks + button = new HashMarkLocationRadioButton("Both sides hash marks", + B_HASH_MARKS_BOTH); + group->AddChild(button); + fHashMarkLocationRadioGroup->AddButton(button->GetRadioButton()); + + // default to no hash marks + fHashMarkLocationRadioGroup->SelectButton(0L); + + // spacing + group->AddChild(new VStrut(10)); + + // the radio button group for selecting the bar thickness + + fBarThicknessRadioGroup = new RadioButtonGroup( + new BMessage(MSG_BAR_THICKNESS_CHANGED), this); + + // default bar thickness + button = new ThicknessRadioButton("Thin bar", 1.0); + group->AddChild(button); + fBarThicknessRadioGroup->AddButton(button->GetRadioButton()); + + // thicker bar + button = new ThicknessRadioButton("Normal bar", fSlider->BarThickness()); + group->AddChild(button); + fBarThicknessRadioGroup->AddButton(button->GetRadioButton()); + + // very thick bar + button = new ThicknessRadioButton("Thick bar", 25.0); + group->AddChild(button); + fBarThicknessRadioGroup->AddButton(button->GetRadioButton()); + + // default to default thickness + fBarThicknessRadioGroup->SelectButton(1L); + + // spacing + group->AddChild(new VStrut(10)); + + // the radio button group for selecting the label + + fLabelRadioGroup = new RadioButtonGroup(new BMessage(MSG_LABEL_CHANGED), + this); + + // no label + button = new LabelRadioButton("No label", NULL); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // label string + button = new LabelRadioButton("Label", "Label"); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // long label string + button = new LabelRadioButton("Long label", + "Quite Long Label for a BSlider"); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // default to normal label + fLabelRadioGroup->SelectButton(1L); + + // spacing + group->AddChild(new VStrut(10)); + + // the radio button group for selecting the limit labels + + fLimitLabelsRadioGroup = new RadioButtonGroup( + new BMessage(MSG_LIMIT_LABELS_CHANGED), this); + + // no limit labels + button = new LimitLabelsRadioButton("No limit labels", NULL, NULL); + group->AddChild(button); + fLimitLabelsRadioGroup->AddButton(button->GetRadioButton()); + + // normal limit label strings + button = new LimitLabelsRadioButton("Normal limit labels", "Min", "Max"); + group->AddChild(button); + fLimitLabelsRadioGroup->AddButton(button->GetRadioButton()); + + // long limit label strings + button = new LimitLabelsRadioButton("Long limit labels", + "Very long min label", "Very long max label"); + group->AddChild(button); + fLimitLabelsRadioGroup->AddButton(button->GetRadioButton()); + + // default to no limit labels + fLimitLabelsRadioGroup->SelectButton(0L); + + + // glue + group->AddChild(new Glue()); +} + + +// DectivateTest +void +SliderTest::DectivateTest() +{ +} + + +// MessageReceived +void +SliderTest::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_ORIENTATION_CHANGED: + _UpdateOrientation(); + break; + case MSG_THUMB_STYLE_CHANGED: + _UpdateThumbStyle(); + break; + case MSG_HASH_MARKS_CHANGED: + _UpdateHashMarkLocation(); + break; + case MSG_BAR_THICKNESS_CHANGED: + _UpdateBarThickness(); + break; + case MSG_LABEL_CHANGED: + _UpdateLabel(); + break; + case MSG_LIMIT_LABELS_CHANGED: + _UpdateLimitLabels(); + break; + default: + Test::MessageReceived(message); + break; + } +} + + +// _UpdateOrientation +void +SliderTest::_UpdateOrientation() +{ + if (fOrientationRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fOrientationRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + OrientationRadioButton* button = dynamic_cast( + parent); + if (button) + fSlider->SetOrientation(button->fOrientation); + } +} + +// _UpdateThumbStyle +void +SliderTest::_UpdateThumbStyle() +{ + if (fThumbStyleRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fThumbStyleRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + ThumbStyleRadioButton* button = dynamic_cast( + parent); + if (button) + fSlider->SetStyle(button->fStyle); + } +} + +// _UpdateHashMarkLocation +void +SliderTest::_UpdateHashMarkLocation() +{ + if (fHashMarkLocationRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fHashMarkLocationRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + HashMarkLocationRadioButton* button + = dynamic_cast(parent); + if (button) + fSlider->SetHashMarks(button->fLocation); + } +} + +// _UpdateBarThickness +void +SliderTest::_UpdateBarThickness() +{ + if (fBarThicknessRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fBarThicknessRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + ThicknessRadioButton* button + = dynamic_cast(parent); + if (button) + fSlider->SetBarThickness(button->fThickness); + } +} + +// _UpdateLabel +void +SliderTest::_UpdateLabel() +{ + if (fLabelRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton = fLabelRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + LabelRadioButton* button = dynamic_cast(parent); + if (button) + fSlider->SetLabel(button->fLabel); + } +} + +// _UpdateLimitLabels +void +SliderTest::_UpdateLimitLabels() +{ + if (fLimitLabelsRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fLimitLabelsRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + LimitLabelsRadioButton* button = dynamic_cast( + parent); + if (button) + fSlider->SetLimitLabels(button->fMinLabel, button->fMaxLabel); + } +} + Added: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h 2008-07-16 14:41:10 UTC (rev 26441) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h 2008-07-16 15:06:13 UTC (rev 26442) @@ -0,0 +1,55 @@ +/* + * Copyright 2008, Stephan A?mus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_SLIDER_TEST_H +#define WIDGET_LAYOUT_TEST_SLIDER_TEST_H + + +#include "Test.h" + + +class BSlider; +class RadioButtonGroup; + + +class SliderTest : public Test { +public: + SliderTest(); + virtual ~SliderTest(); + + static Test* CreateTest(); + + virtual void ActivateTest(View* controls); + virtual void DectivateTest(); + + virtual void MessageReceived(BMessage* message); + +private: + void _UpdateOrientation(); + void _UpdateThumbStyle(); + void _UpdateHashMarkLocation(); + void _UpdateBarThickness(); + void _UpdateLabel(); + void _UpdateLimitLabels(); + +private: + class OrientationRadioButton; + class ThumbStyleRadioButton; + class HashMarkLocationRadioButton; + class ThicknessRadioButton; + class LabelRadioButton; + class LimitLabelsRadioButton; + + BSlider* fSlider; + RadioButtonGroup* fOrientationRadioGroup; + RadioButtonGroup* fThumbStyleRadioGroup; + RadioButtonGroup* fHashMarkLocationRadioGroup; + RadioButtonGroup* fBarThicknessRadioGroup; + RadioButtonGroup* fLabelRadioGroup; + RadioButtonGroup* fLimitLabelsRadioGroup; +}; + + +#endif // WIDGET_LAYOUT_TEST_SLIDER_TEST_H From stippi at mail.berlios.de Wed Jul 16 17:15:26 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 17:15:26 +0200 Subject: [Haiku-commits] r26443 - haiku/trunk/src/kits/interface Message-ID: <200807161515.m6GFFQ4Y017891@sheep.berlios.de> Author: stippi Date: 2008-07-16 17:15:24 +0200 (Wed, 16 Jul 2008) New Revision: 26443 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26443&view=rev Modified: haiku/trunk/src/kits/interface/Slider.cpp Log: If the user specified a hashmark location other than B_HASH_MARKS_NONE, draw at least two hash marks, even if the hash mark count has never been configured. Also means the minimum hashmark count is 2 instead of 1 as before. I think this behavior is more what one would expect, I turned on hashmarks and wondered why nothing happened until I realized I needed to configure the count as well. Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 15:06:13 UTC (rev 26442) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 15:15:24 UTC (rev 26443) @@ -926,32 +926,36 @@ void BSlider::DrawHashMarks() { + if (fHashMarks == B_HASH_MARKS_NONE) + return; + BRect frame = HashMarksFrame(); - BView *view = OffscreenView(); + BView* view = OffscreenView(); rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color lightenmax; rgb_color darken2; if (IsEnabled()) { - lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); - darken2 = tint_color(no_tint, B_DARKEN_2_TINT); + lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT); + darken2 = tint_color(no_tint, B_DARKEN_2_TINT); } else { - lightenmax = tint_color(no_tint, B_LIGHTEN_2_TINT); - darken2 = tint_color(no_tint, B_DARKEN_1_TINT); + lightenmax = tint_color(no_tint, B_LIGHTEN_2_TINT); + darken2 = tint_color(no_tint, B_DARKEN_1_TINT); } float pos = _MinPosition(); - float factor = 0.0f; - if (fHashMarkCount > 1) - factor = (_MaxPosition() - pos) / (fHashMarkCount - 1); + int32 hashMarkCount = max_c(fHashMarkCount, 2); + // draw at least two hashmarks at min/max if + // fHashMarks != B_HASH_MARKS_NONE + float factor = (_MaxPosition() - pos) / (hashMarkCount - 1); - if (fHashMarks & B_HASH_MARKS_TOP && fHashMarkCount > 0) { + if (fHashMarks & B_HASH_MARKS_TOP) { - view->BeginLineArray(fHashMarkCount * 2); + view->BeginLineArray(hashMarkCount * 2); if (fOrientation == B_HORIZONTAL) { - for (int32 i = 0; i < fHashMarkCount; i++) { + for (int32 i = 0; i < hashMarkCount; i++) { view->AddLine(BPoint(pos, frame.top), BPoint(pos, frame.top + 5), darken2); view->AddLine(BPoint(pos + 1, frame.top), @@ -960,7 +964,7 @@ pos += factor; } } else { - for (int32 i = 0; i < fHashMarkCount; i++) { + for (int32 i = 0; i < hashMarkCount; i++) { view->AddLine(BPoint(frame.left, pos), BPoint(frame.left + 5, pos), darken2); view->AddLine(BPoint(frame.left, pos + 1), @@ -975,11 +979,12 @@ pos = _MinPosition(); - if (fHashMarks & B_HASH_MARKS_BOTTOM && fHashMarkCount > 0) { - view->BeginLineArray(fHashMarkCount * 2); + if (fHashMarks & B_HASH_MARKS_BOTTOM) { + view->BeginLineArray(hashMarkCount * 2); + if (fOrientation == B_HORIZONTAL) { - for (int32 i = 0; i < fHashMarkCount; i++) { + for (int32 i = 0; i < hashMarkCount; i++) { view->AddLine(BPoint(pos, frame.bottom - 5), BPoint(pos, frame.bottom), darken2); view->AddLine(BPoint(pos + 1, frame.bottom - 5), @@ -988,7 +993,7 @@ pos += factor; } } else { - for (int32 i = 0; i < fHashMarkCount; i++) { + for (int32 i = 0; i < hashMarkCount; i++) { view->AddLine(BPoint(frame.right - 5, pos), BPoint(frame.right, pos), darken2); view->AddLine(BPoint(frame.right - 5, pos + 1), From stippi at mail.berlios.de Wed Jul 16 17:56:01 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 17:56:01 +0200 Subject: [Haiku-commits] r26444 - haiku/trunk/src/kits/interface Message-ID: <200807161556.m6GFu1RY021249@sheep.berlios.de> Author: stippi Date: 2008-07-16 17:55:58 +0200 (Wed, 16 Jul 2008) New Revision: 26444 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26444&view=rev Modified: haiku/trunk/src/kits/interface/Slider.cpp Log: The vertical slider is now at least functionally working, although the rendering code needs some love. Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 15:15:24 UTC (rev 26443) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 15:55:58 UTC (rev 26444) @@ -687,9 +687,18 @@ int32 BSlider::ValueForPoint(BPoint location) const { - float position = fOrientation == B_HORIZONTAL ? location.x : location.y; - float min = _MinPosition(); - float max = _MaxPosition(); + float min; + float max; + float position; + if (fOrientation == B_HORIZONTAL) { + min = _MinPosition(); + max = _MaxPosition(); + position = location.x; + } else { + max = _MinPosition(); + min = _MaxPosition(); + position = min + (max - location.y); + } if (position < min) position = min; From oruizdorantes at mail.berlios.de Wed Jul 16 19:30:40 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 16 Jul 2008 19:30:40 +0200 Subject: [Haiku-commits] r26445 - haiku/trunk/headers/posix/sys Message-ID: <200807161730.m6GHUepO019937@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-16 19:30:36 +0200 (Wed, 16 Jul 2008) New Revision: 26445 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26445&view=rev Modified: haiku/trunk/headers/posix/sys/socket.h Log: Add AF_BLUETOOTH sockets family - Feel free to change the index Modified: haiku/trunk/headers/posix/sys/socket.h =================================================================== --- haiku/trunk/headers/posix/sys/socket.h 2008-07-16 15:55:58 UTC (rev 26444) +++ haiku/trunk/headers/posix/sys/socket.h 2008-07-16 17:30:36 UTC (rev 26445) @@ -26,7 +26,8 @@ #define AF_NOTIFY 8 #define AF_LOCAL 9 #define AF_UNIX AF_LOCAL -#define AF_MAX 10 +#define AF_BLUETOOTH 10 +#define AF_MAX 11 /* Protocol families, deprecated */ #define PF_UNSPEC AF_UNSPEC @@ -36,6 +37,7 @@ #define PF_INET6 AF_INET6 #define PF_LOCAL AF_LOCAL #define PF_UNIX AF_UNIX +#define PF_BLUETOOTH AF_BLUETOOTH /* Socket types */ #define SOCK_STREAM 1 From korli at mail.berlios.de Wed Jul 16 19:36:27 2008 From: korli at mail.berlios.de (korli at BerliOS) Date: Wed, 16 Jul 2008 19:36:27 +0200 Subject: [Haiku-commits] r26446 - haiku/trunk/src/add-ons/kernel/drivers/audio/hda Message-ID: <200807161736.m6GHaRK3020715@sheep.berlios.de> Author: korli Date: 2008-07-16 19:36:27 +0200 (Wed, 16 Jul 2008) New Revision: 26446 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26446&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp Log: fix alignment Modified: haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-16 17:30:36 UTC (rev 26445) +++ haiku/trunk/src/add-ons/kernel/drivers/audio/hda/hda_controller.cpp 2008-07-16 17:36:27 UTC (rev 26446) @@ -303,7 +303,7 @@ /* Determine rirb offset in memory and total size of corb+alignment+rirb */ rirbOffset = (controller->corb_length * sizeof(corb_t) + 0x7f) & ~0x7f; posOffset = (rirbOffset + controller->rirb_length * sizeof(rirb_t) + 0x7f) - & 0x7f; + & ~0x7f; posSize = 8 * (controller->num_input_streams + controller->num_output_streams + controller->num_bidir_streams); From stippi at mail.berlios.de Wed Jul 16 20:37:48 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 20:37:48 +0200 Subject: [Haiku-commits] r26447 - in haiku/trunk: headers/os/interface src/kits/interface Message-ID: <200807161837.m6GIbm8e027638@sheep.berlios.de> Author: stippi Date: 2008-07-16 20:37:44 +0200 (Wed, 16 Jul 2008) New Revision: 26447 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26447&view=rev Modified: haiku/trunk/headers/os/interface/Slider.h haiku/trunk/src/kits/interface/Slider.cpp Log: * Changed the signature of UpdateText() to return a "const char*" (char* really makes no sense if the pointer belongs to the derived class and only confuses). Note this change does not affect binary compatibility. * Introduced a new MaxUpdateTextWidth() virtual method which is really necessary to handle the update text correctly in the layout. * Introduced a new UpdateTextChanged() method which can be called to notify the control of a changed update text. Internally, SetValue() also uses it. * Handle the width or height of the UpdateText() correctly in the layout. For horizontal layout, the width was forgotten to be included in GetPreferredSize(), for vertical layout, it was completely broken before. * Handle invalidation correctly when the UpdateText() changes. * Remove the arbitrary insets for labels from the border the control. This makes it easier to align the control's labels with other controls. Modified: haiku/trunk/headers/os/interface/Slider.h =================================================================== --- haiku/trunk/headers/os/interface/Slider.h 2008-07-16 17:36:27 UTC (rev 26446) +++ haiku/trunk/headers/os/interface/Slider.h 2008-07-16 18:37:44 UTC (rev 26447) @@ -91,7 +91,8 @@ virtual void DrawThumb(); virtual void DrawFocusMark(); virtual void DrawText(); - virtual char* UpdateText() const; + virtual const char* UpdateText() const; + void UpdateTextChanged(); virtual BRect BarFrame() const; virtual BRect HashMarksFrame() const; @@ -145,6 +146,8 @@ virtual void SetLimits(int32 minimum, int32 maximum); + virtual float MaxUpdateTextWidth(); + virtual void InvalidateLayout(bool descendants = false); virtual BSize MinSize(); @@ -164,7 +167,6 @@ BSize _ValidateMinSize(); - virtual void _ReservedSlider5(); virtual void _ReservedSlider6(); virtual void _ReservedSlider7(); virtual void _ReservedSlider8(); @@ -187,7 +189,7 @@ char* fMinLimitLabel; char* fMaxLimitLabel; - char* fUpdateText; + const char* fUpdateText; int32 fMinValue; int32 fMaxValue; @@ -211,10 +213,12 @@ BSize fMinSize; + float fMaxUpdateTextWidth; + #if USE_OFF_SCREEN_VIEW - uint32 _reserved[5]; + uint32 _reserved[4]; #else - uint32 _reserved[7]; + uint32 _reserved[6]; #endif }; Modified: haiku/trunk/src/kits/interface/Slider.cpp =================================================================== --- haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 17:36:27 UTC (rev 26446) +++ haiku/trunk/src/kits/interface/Slider.cpp 2008-07-16 18:37:44 UTC (rev 26447) @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -225,6 +226,7 @@ fUpdateText = NULL; fMinSize.Set(-1, -1); + fMaxUpdateTextWidth = -1.0; } @@ -662,25 +664,7 @@ Invalidate(invalid); - // update text label - - float oldWidth = 0.0f, width = 0.0f; - if (fUpdateText != NULL) - oldWidth = StringWidth(fUpdateText); - - fUpdateText = UpdateText(); - if (fUpdateText != NULL) - width = StringWidth(fUpdateText); - - width = ceilf(max_c(width, oldWidth)) + 2.0f; - if (width != 0) { - font_height fontHeight; - GetFontHeight(&fontHeight); - - BRect rect(-width, 0, 0, ceilf(fontHeight.ascent + fontHeight.descent)); - rect.OffsetBy(Bounds().Width(), 0); - Invalidate(rect); - } + UpdateTextChanged(); } @@ -1069,47 +1053,54 @@ font_height fontHeight; GetFontHeight(&fontHeight); - if (Orientation() == B_HORIZONTAL) { if (Label()) - view->DrawString(Label(), BPoint(2.0f, ceilf(fontHeight.ascent))); + view->DrawString(Label(), BPoint(0.0, ceilf(fontHeight.ascent))); // the update text is updated in SetValue() only if (fUpdateText != NULL) { - view->DrawString(fUpdateText, BPoint(bounds.right - StringWidth(fUpdateText) - - 2.0f, ceilf(fontHeight.ascent))); + view->DrawString(fUpdateText, BPoint(bounds.right + - StringWidth(fUpdateText), ceilf(fontHeight.ascent))); } - if (fMinLimitLabel) - view->DrawString(fMinLimitLabel, BPoint(2.0f, bounds.bottom - 4.0f)); + if (fMinLimitLabel) { + view->DrawString(fMinLimitLabel, BPoint(0.0, bounds.bottom + - fontHeight.descent)); + } if (fMaxLimitLabel) { view->DrawString(fMaxLimitLabel, BPoint(bounds.right - - StringWidth(fMaxLimitLabel) - 2.0f, bounds.bottom - 4.0f)); + - StringWidth(fMaxLimitLabel), bounds.bottom + - fontHeight.descent)); } } else { + float lineHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent) + + ceilf(fontHeight.leading); + float baseLine = ceilf(fontHeight.ascent); + if (Label()) { - view->DrawString(Label(), BPoint(bounds.Width() / 2.0f - - StringWidth(Label()) / 2.0f, - fontHeight.ascent)); + view->DrawString(Label(), BPoint((bounds.Width() + - StringWidth(Label())) / 2.0, baseLine)); + baseLine += lineHeight; } - if (fUpdateText != NULL) { - view->DrawString(fUpdateText, BPoint(bounds.Width() / 2.0f - - StringWidth(fUpdateText) / 2.0f, bounds.bottom - fontHeight.descent - 4.0f)); - } - if (fMaxLimitLabel) { - view->DrawString(fMaxLimitLabel, BPoint(bounds.Width() / 2.0f - - StringWidth(fMaxLimitLabel) / 2.0f, fontHeight.ascent + (Label() - ? ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading + 2.0f) - : 0.0f))); + view->DrawString(fMaxLimitLabel, BPoint((bounds.Width() + - StringWidth(fMaxLimitLabel)) / 2.0, baseLine)); } + baseLine = bounds.bottom - ceilf(fontHeight.descent); + if (fMinLimitLabel) { - view->DrawString(fMinLimitLabel, BPoint(bounds.Width() / 2.0f - - StringWidth(fMinLimitLabel) / 2.0f, bounds.bottom - 2.0f)); + view->DrawString(fMinLimitLabel, BPoint((bounds.Width() + - StringWidth(fMinLimitLabel)) / 2.0, baseLine)); + baseLine -= lineHeight; } + + if (fUpdateText != NULL) { + view->DrawString(fUpdateText, BPoint((bounds.Width() + - StringWidth(fUpdateText)) / 2.0, baseLine)); + } } } @@ -1117,13 +1108,59 @@ // #pragma mark - -char* +const char* BSlider::UpdateText() const { return NULL; } +void +BSlider::UpdateTextChanged() +{ + // update text label + float oldWidth = 0.0; + if (fUpdateText != NULL) + oldWidth = StringWidth(fUpdateText); + + const char* oldUpdateText = fUpdateText; + fUpdateText = UpdateText(); + bool updateTextOnOff = fUpdateText == NULL && oldUpdateText != NULL + || fUpdateText != NULL && oldUpdateText == NULL; + + float newWidth = 0.0; + if (fUpdateText != NULL) + newWidth = StringWidth(fUpdateText); + + float width = ceilf(max_c(newWidth, oldWidth)) + 2.0f; + if (width != 0) { + font_height fontHeight; + GetFontHeight(&fontHeight); + + float height = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent); + float lineHeight = height + ceilf(fontHeight.leading); + BRect invalid(Bounds()); + if (fOrientation == B_HORIZONTAL) + invalid = BRect(invalid.right - width, 0, invalid.right, height); + else { + if (!updateTextOnOff) { + invalid.left = (invalid.left + invalid.right - width) / 2; + invalid.right = invalid.left + width; + if (fMinLimitLabel) + invalid.bottom -= lineHeight; + invalid.top = invalid.bottom - height; + } + } + Invalidate(invalid); + } + + float oldMaxUpdateTextWidth = fMaxUpdateTextWidth; + fMaxUpdateTextWidth = MaxUpdateTextWidth(); + if (oldMaxUpdateTextWidth != fMaxUpdateTextWidth) + InvalidateLayout(); +} + + BRect BSlider::BarFrame() const { @@ -1132,36 +1169,40 @@ font_height fontHeight; GetFontHeight(&fontHeight); - float textHeight = (float)ceil(fontHeight.ascent + fontHeight.descent); - - if (fStyle == B_BLOCK_THUMB) { - if (Orientation() == B_HORIZONTAL) { - frame.left = 8.0f; - frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); - frame.right -= 8.0f; - frame.bottom = frame.top + fBarThickness; - } else { - frame.left = floor((frame.Width() - fBarThickness) / 2.0f); - frame.top = 12.0f + (Label() ? textHeight : 0.0f) + - (fMaxLimitLabel ? textHeight : 0.0f); - frame.right = frame.left + fBarThickness; - frame.bottom = frame.bottom - 8.0f - - (fMinLimitLabel ? textHeight + 4 : 0.0f); - } + float textHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent); + float leading = ceilf(fontHeight.leading); + + float thumbInset; + if (fStyle == B_BLOCK_THUMB) + thumbInset = 8.0; + else + thumbInset = 7.0; + + if (Orientation() == B_HORIZONTAL) { + frame.left = thumbInset; + frame.top = 6.0 + (Label() ? textHeight + 4.0 : 0.0); + frame.right -= thumbInset; + frame.bottom = frame.top + fBarThickness; } else { - if (Orientation() == B_HORIZONTAL) { - frame.left = 7.0f; - frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); - frame.right -= 7.0f; - frame.bottom = frame.top + fBarThickness; - } else { - frame.left = floor((frame.Width() - fBarThickness) / 2.0f); - frame.top = 11.0f + (Label() ? textHeight : 0.0f) + - (fMaxLimitLabel ? textHeight : 0.0f); - frame.right = frame.left + fBarThickness; - frame.bottom = frame.bottom - 7.0f - - (fMinLimitLabel ? textHeight + 4 : 0.0f); + frame.left = floorf((frame.Width() - fBarThickness) / 2.0); + frame.top = thumbInset; + if (Label()) + frame.top += textHeight; + if (fMaxLimitLabel) { + frame.top += textHeight; + if (Label()) + frame.top += leading; } + + frame.right = frame.left + fBarThickness; + frame.bottom = frame.bottom - thumbInset; + if (fMinLimitLabel) + frame.bottom -= textHeight; + if (fUpdateText) { + frame.bottom -= textHeight; + if (fMinLimitLabel) + frame.bottom -= leading; + } } return frame; @@ -1174,11 +1215,11 @@ BRect frame(BarFrame()); if (fOrientation == B_HORIZONTAL) { - frame.top -= 6.0f; - frame.bottom += 6.0f; + frame.top -= 6.0; + frame.bottom += 6.0; } else { - frame.left -= 6.0f; - frame.right += 6.0f; + frame.left -= 6.0; + frame.right += 6.0; } return frame; @@ -1193,25 +1234,25 @@ // and spread them further apart for the thumb BRect frame = Bounds(); - font_height fheight; - GetFontHeight(&fheight); + font_height fontHeight; + GetFontHeight(&fontHeight); - float textHeight = (float)ceil(fheight.ascent + fheight.descent); + float textHeight = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent); if (fStyle == B_BLOCK_THUMB) { if (Orientation() == B_HORIZONTAL) { frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + - _MinPosition()) - 8.0f; - frame.top = 2.0f + (Label() ? textHeight + 4.0f : 0.0f); - frame.right = frame.left + 17.0f; - frame.bottom = frame.top + fBarThickness + 7.0f; + _MinPosition()) - 8.0; + frame.top = 2.0 + (Label() ? textHeight + 4.0 : 0.0); + frame.right = frame.left + 17.0; + frame.bottom = frame.top + fBarThickness + 7.0; } else { - frame.left = floor((frame.Width() - fBarThickness) / 2.0f) - 4; + frame.left = floor((frame.Width() - fBarThickness) / 2.0) - 4; frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + - _MinPosition()) - 8.0f; - frame.right = frame.left + fBarThickness + 7.0f; - frame.bottom = frame.top + 17; + _MinPosition()) - 8.0; + frame.right = frame.left + fBarThickness + 7.0; + frame.bottom = frame.top + 17.0; } } else { if (Orientation() == B_HORIZONTAL) { @@ -1508,6 +1549,22 @@ } +float +BSlider::MaxUpdateTextWidth() +{ + // very simplistic implementation that assumes the string will be widest + // at the maximum value + int32 value = Value(); + SetValueNoUpdate(fMaxValue); + float width = StringWidth(UpdateText()); + SetValueNoUpdate(value); + // in case the derived class uses a fixed buffer, the contents + // should be reset for the old value + UpdateText(); + return width; +} + + // #pragma mark - layout related @@ -1812,23 +1869,35 @@ float width = 0.0; float height = 0.0; - int32 rows = 0; + if (fMaxUpdateTextWidth < 0.0) + fMaxUpdateTextWidth = MaxUpdateTextWidth(); + if (Orientation() == B_HORIZONTAL) { height = 12.0 + fBarThickness; + int32 rows = 0; float labelWidth = 0; + int32 labelRows = 0; + float labelSpacing = StringWidth("M") * 2; if (Label()) { labelWidth = StringWidth(Label()); - rows++; + labelRows = 1; } + if (fMaxUpdateTextWidth > 0.0) { + if (labelWidth > 0) + labelWidth += labelSpacing; + labelWidth += fMaxUpdateTextWidth; + labelRows = 1; + } + rows += labelRows; if (MinLimitLabel()) width = StringWidth(MinLimitLabel()); if (MaxLimitLabel()) { // some space between the labels if (MinLimitLabel()) - width += 8.0; + width += labelSpacing; width += StringWidth(MaxLimitLabel()); } @@ -1846,29 +1915,32 @@ } else { // B_VERTICAL width = 12.0 + fBarThickness; + height = 32.0; + float lineHeightNoLeading = ceilf(fontHeight.ascent) + + ceilf(fontHeight.descent); + float lineHeight = lineHeightNoLeading + ceilf(fontHeight.leading); + // find largest label float labelWidth = 0; if (Label()) { labelWidth = StringWidth(Label()); - rows++; + height += lineHeightNoLeading; } + if (MaxLimitLabel()) { + labelWidth = max_c(labelWidth, StringWidth(MaxLimitLabel())); + height += Label() ? lineHeight : lineHeightNoLeading; + } if (MinLimitLabel()) { labelWidth = max_c(labelWidth, StringWidth(MinLimitLabel())); - rows++; + height += lineHeightNoLeading; } - if (MaxLimitLabel()) { - labelWidth = max_c(labelWidth, StringWidth(MaxLimitLabel())); - rows++; + if (fMaxUpdateTextWidth > 0.0) { + labelWidth = max_c(labelWidth, fMaxUpdateTextWidth); + height += MinLimitLabel() ? lineHeight : lineHeightNoLeading; } width = max_c(labelWidth, width); - - height = 32.0 + rows * (ceilf(fontHeight.ascent) - + ceilf(fontHeight.descent) + 4.0); - - if (Label() && MaxLimitLabel()) - height -= 4.0f; } fMinSize.width = width; @@ -1880,7 +1952,6 @@ // #pragma mark - FBC padding -void BSlider::_ReservedSlider5() {} void BSlider::_ReservedSlider6() {} void BSlider::_ReservedSlider7() {} void BSlider::_ReservedSlider8() {} @@ -1897,17 +1968,25 @@ } -// #pragma mark - R4.5 compatibility +// #pragma mark - BeOS compatibility #if __GNUC__ < 3 extern "C" -void _ReservedSlider4__7BSlider(BSlider *slider, int32 minimum, int32 maximum) +void +_ReservedSlider4__7BSlider(BSlider *slider, int32 minimum, int32 maximum) { slider->BSlider::SetLimits(minimum, maximum); } +extern "C" +float +_ReservedSlider5__7BSlider(BSlider *slider) +{ + return slider->BSlider::MaxUpdateTextWidth(); +} + extern "C" void _ReservedSlider1__7BSlider() {} extern "C" void _ReservedSlider2__7BSlider() {} extern "C" void _ReservedSlider3__7BSlider() {} From stippi at mail.berlios.de Wed Jul 16 20:42:40 2008 From: stippi at mail.berlios.de (stippi at mail.berlios.de) Date: Wed, 16 Jul 2008 20:42:40 +0200 Subject: [Haiku-commits] r26448 - haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests Message-ID: <200807161842.m6GIgeP6028320@sheep.berlios.de> Author: stippi Date: 2008-07-16 20:42:37 +0200 (Wed, 16 Jul 2008) New Revision: 26448 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26448&view=rev Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h Log: Also test the UpdateText() behavior. Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp 2008-07-16 18:37:44 UTC (rev 26447) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.cpp 2008-07-16 18:42:37 UTC (rev 26448) @@ -11,6 +11,7 @@ #include #include +#include "CheckBox.h" #include "GroupView.h" #include "RadioButton.h" #include "TestView.h" @@ -23,10 +24,32 @@ MSG_HASH_MARKS_CHANGED = 'hmch', MSG_BAR_THICKNESS_CHANGED = 'btch', MSG_LABEL_CHANGED = 'lbch', - MSG_LIMIT_LABELS_CHANGED = 'lmch' + MSG_LIMIT_LABELS_CHANGED = 'lmch', + MSG_UPDATE_TEXT_CHANGED = 'utch' }; +// TestSlider +class SliderTest::TestSlider : public BSlider { +public: + TestSlider() + : BSlider("test slider", "Label", NULL, 1, 100, B_HORIZONTAL), + fExportUpdateText(false) + { + } + + virtual char* UpdateText() const + { + if (!fExportUpdateText) + return NULL; + sprintf(fUpdateText, "%ld", Value()); + return fUpdateText; + } + + mutable char fUpdateText[32]; + bool fExportUpdateText; +}; + // OrientationRadioButton class SliderTest::OrientationRadioButton : public LabeledRadioButton { public: @@ -110,13 +133,14 @@ // constructor SliderTest::SliderTest() : Test("Slider", NULL), - fSlider(new BSlider("test slider", "Label", NULL, 1, 100, B_HORIZONTAL)), + fSlider(new TestSlider()), fOrientationRadioGroup(NULL), fThumbStyleRadioGroup(NULL), fHashMarkLocationRadioGroup(NULL), fBarThicknessRadioGroup(NULL), fLabelRadioGroup(NULL), - fLimitLabelsRadioGroup(NULL) + fLimitLabelsRadioGroup(NULL), + fUpdateTextCheckBox(NULL) { SetView(fSlider); } @@ -321,7 +345,15 @@ // default to no limit labels fLimitLabelsRadioGroup->SelectButton(0L); + // spacing + group->AddChild(new VStrut(10)); + // update text + fUpdateTextCheckBox = new LabeledCheckBox("Update text", + new BMessage(MSG_UPDATE_TEXT_CHANGED), this); + group->AddChild(fUpdateTextCheckBox); + + // glue group->AddChild(new Glue()); } @@ -357,6 +389,9 @@ case MSG_LIMIT_LABELS_CHANGED: _UpdateLimitLabels(); break; + case MSG_UPDATE_TEXT_CHANGED: + _UpdateUpdateText(); + break; default: Test::MessageReceived(message); break; @@ -470,3 +505,15 @@ } } +// _UpdateUpdateText +void +SliderTest::_UpdateUpdateText() +{ + if (!fUpdateTextCheckBox + || fUpdateTextCheckBox->IsSelected() == fSlider->fExportUpdateText) + return; + + fSlider->fExportUpdateText = fUpdateTextCheckBox->IsSelected(); + fSlider->UpdateTextChanged(); +} + Modified: haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h =================================================================== --- haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h 2008-07-16 18:37:44 UTC (rev 26447) +++ haiku/trunk/src/tests/kits/interface/layout/widget_layout_test/tests/SliderTest.h 2008-07-16 18:42:37 UTC (rev 26448) @@ -10,7 +10,7 @@ #include "Test.h" -class BSlider; +class LabeledCheckBox; class RadioButtonGroup; @@ -33,8 +33,10 @@ void _UpdateBarThickness(); void _UpdateLabel(); void _UpdateLimitLabels(); + void _UpdateUpdateText(); private: + class TestSlider; class OrientationRadioButton; class ThumbStyleRadioButton; class HashMarkLocationRadioButton; @@ -42,13 +44,14 @@ class LabelRadioButton; class LimitLabelsRadioButton; - BSlider* fSlider; + TestSlider* fSlider; RadioButtonGroup* fOrientationRadioGroup; RadioButtonGroup* fThumbStyleRadioGroup; RadioButtonGroup* fHashMarkLocationRadioGroup; RadioButtonGroup* fBarThicknessRadioGroup; RadioButtonGroup* fLabelRadioGroup; RadioButtonGroup* fLimitLabelsRadioGroup; + LabeledCheckBox* fUpdateTextCheckBox; }; From oruizdorantes at mail.berlios.de Wed Jul 16 21:04:58 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 16 Jul 2008 21:04:58 +0200 Subject: [Haiku-commits] r26449 - in haiku/trunk: headers/os/bluetooth src/kits/bluetooth Message-ID: <200807161904.m6GJ4wIY031197@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-16 21:04:53 +0200 (Wed, 16 Jul 2008) New Revision: 26449 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26449&view=rev Modified: haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp Log: Resolve allocation of multiple Messengers,(Mika Lindqvist) Modified: haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h =================================================================== --- haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h 2008-07-16 18:42:37 UTC (rev 26448) +++ haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h 2008-07-16 19:04:53 UTC (rev 26449) @@ -31,38 +31,39 @@ class DiscoveryAgent { public: - + static const int GIAC = BT_GIAC; static const int LIAC = BT_LIAC; - + static const int PREKNOWN = BT_PREKNOWN; static const int CACHED = BT_CACHED; static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE; - + RemoteDevicesList RetrieveDevices(int option); /* TODO */ status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */ status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs); status_t CancelInquiry(DiscoveryListener* listener); - + /* int searchServices(int[] attrSet, UUID[] uuidSet, RemoteDevice btDev, DiscoveryListener discListener); - - bool cancelServiceSearch(int transID); + + bool cancelServiceSearch(int transID); BString selectService(UUID uuid, int security, boolean master); */ - + private: - DiscoveryAgent(LocalDevice* ld); - void SetLocalDeviceOwner(LocalDevice* ld); + DiscoveryAgent(LocalDevice* ld); + ~DiscoveryAgent(); + void SetLocalDeviceOwner(LocalDevice* ld); - DiscoveryListener* fLastUsedListener; - LocalDevice* fLocalDevice; - - friend class LocalDevice; + DiscoveryListener* fLastUsedListener; + LocalDevice* fLocalDevice; + BMessenger* fMessenger; + friend class LocalDevice; }; } Modified: haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-16 18:42:37 UTC (rev 26448) +++ haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp 2008-07-16 19:04:53 UTC (rev 26449) @@ -43,10 +43,9 @@ status_t DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) { - BMessenger* btsm = NULL; size_t size; - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + if (fMessenger == NULL) return B_ERROR; if (secs < 1 || secs > 61 ) @@ -81,7 +80,7 @@ request.AddInt16("eventExpected", HCI_EVENT_INQUIRY_COMPLETE); - if (btsm->SendMessage(&request, listener) == B_OK) + if (fMessenger->SendMessage(&request, listener) == B_OK) { return B_OK; } @@ -94,10 +93,9 @@ status_t DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) { - BMessenger* btsm = NULL; //TODO: this should be a member field size_t size; - if ((btsm = _RetrieveBluetoothMessenger()) == NULL) + if (fMessenger == NULL) return B_ERROR; void* cancelInquiryCommand = NULL; @@ -114,11 +112,11 @@ request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY_CANCEL)); - if (btsm->SendMessage(&request, &reply) == B_OK) { + if (fMessenger->SendMessage(&request, &reply) == B_OK) { if (reply.FindInt8("status", &bt_status ) == B_OK ) { - return bt_status; - } - } + return bt_status; + } + } return B_ERROR; } @@ -131,8 +129,16 @@ DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) { - fLocalDevice = ld; + fLocalDevice = ld; + fMessenger = _RetrieveBluetoothMessenger(); } +DiscoveryAgent::~DiscoveryAgent() +{ + if (fMessenger) + delete fMessenger; } + + +} From mmu_man at mail.berlios.de Wed Jul 16 21:06:39 2008 From: mmu_man at mail.berlios.de (mmu_man at BerliOS) Date: Wed, 16 Jul 2008 21:06:39 +0200 Subject: [Haiku-commits] r26450 - haiku/trunk/headers/os/media Message-ID: <200807161906.m6GJ6dB2031415@sheep.berlios.de> Author: mmu_man Date: 2008-07-16 21:06:39 +0200 (Wed, 16 Jul 2008) New Revision: 26450 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26450&view=rev Modified: haiku/trunk/headers/os/media/MediaDefs.h Log: Add identifier for 64 bit float raw audio format, really just to show we can support it without hacking the API :) Modified: haiku/trunk/headers/os/media/MediaDefs.h =================================================================== --- haiku/trunk/headers/os/media/MediaDefs.h 2008-07-16 19:04:53 UTC (rev 26449) +++ haiku/trunk/headers/os/media/MediaDefs.h 2008-07-16 19:06:39 UTC (rev 26450) @@ -242,6 +242,7 @@ struct media_raw_audio_format { enum { // for "format" B_AUDIO_FLOAT = 0x24, // 0 == mid, -1.0 == bottom, 1.0 == top (the preferred format for non-game audio) + B_AUDIO_DOUBLE = 0x28, // 0 == mid, -1.0 == bottom, 1.0 == top (only useful for pro audio) B_AUDIO_INT = 0x4, // 0 == mid, 0x80000001 == bottom, 0x7fffffff == top (all >16-bit formats, left-adjusted) B_AUDIO_SHORT = 0x2, // 0 == mid, -32767 == bottom, +32767 == top B_AUDIO_UCHAR = 0x11, // 128 == mid, 1 == bottom, 255 == top (discouraged but supported format) From oruizdorantes at mail.berlios.de Wed Jul 16 21:25:49 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 16 Jul 2008 21:25:49 +0200 Subject: [Haiku-commits] r26451 - in haiku/trunk: headers/private/bluetooth src/kits/bluetooth Message-ID: <200807161925.m6GJPnSL003769@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-16 21:25:44 +0200 (Wed, 16 Jul 2008) New Revision: 26451 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26451&view=rev Modified: haiku/trunk/headers/private/bluetooth/CommandManager.h haiku/trunk/src/kits/bluetooth/CommandManager.cpp Log: Add to the command manager the connection accept and reject commands Modified: haiku/trunk/headers/private/bluetooth/CommandManager.h =================================================================== --- haiku/trunk/headers/private/bluetooth/CommandManager.h 2008-07-16 19:06:39 UTC (rev 26450) +++ haiku/trunk/headers/private/bluetooth/CommandManager.h 2008-07-16 19:25:44 UTC (rev 26451) @@ -22,6 +22,8 @@ void* buildInquiryCancel(size_t* outsize); void* buildPinCodeRequestReply(bdaddr_t bdaddr, uint8 length, char pincode[16], size_t* outsize); void* buildPinCodeRequestNegativeReply(bdaddr_t bdaddr, size_t* outsize); +void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize); +void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize); /* OGF_INFORMATIONAL_PARAM */ void* buildReadBufferSize(size_t* outsize); Modified: haiku/trunk/src/kits/bluetooth/CommandManager.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/CommandManager.cpp 2008-07-16 19:06:39 UTC (rev 26450) +++ haiku/trunk/src/kits/bluetooth/CommandManager.cpp 2008-07-16 19:25:44 UTC (rev 26451) @@ -99,6 +99,7 @@ #pragma mark - LINK CONTROL - #endif + void* buildCreateConnection(bdaddr_t bdaddr) { /* @@ -157,6 +158,7 @@ return command; } + void* buildInquiryCancel(size_t* outsize) { @@ -205,6 +207,37 @@ } +void* buildAcceptConnectionRequest(bdaddr_t bdaddr, uint8 role, size_t* outsize) +{ + struct hci_cp_accept_conn_req* param; + + void* command = buildCommand(OGF_LINK_CONTROL, OCF_ACCEPT_CONN_REQ, + (void**) ¶m, sizeof(struct hci_cp_accept_conn_req), outsize); + + if (command != NULL) { + param->bdaddr = bdaddr; + param->role = role; + } + + return command; +} + + +void* buildRejectConnectionRequest(bdaddr_t bdaddr, size_t* outsize) +{ + struct hci_cp_reject_conn_req* param; + + void *command = buildCommand(OGF_LINK_CONTROL, OCF_REJECT_CONN_REQ, + (void**) ¶m, sizeof(struct hci_cp_reject_conn_req), outsize); + + if (command != NULL) { + param->bdaddr = bdaddr; + } + + return command; +} + + #if 0 #pragma mark - INFORMATIONAL_PARAM - #endif From oruizdorantes at mail.berlios.de Wed Jul 16 21:30:55 2008 From: oruizdorantes at mail.berlios.de (oruizdorantes at mail.berlios.de) Date: Wed, 16 Jul 2008 21:30:55 +0200 Subject: [Haiku-commits] r26452 - in haiku/trunk: headers/private/bluetooth src/kits/bluetooth Message-ID: <200807161930.m6GJUtjc004213@sheep.berlios.de> Author: oruizdorantes Date: 2008-07-16 21:30:45 +0200 (Wed, 16 Jul 2008) New Revision: 26452 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26452&view=rev Modified: haiku/trunk/headers/private/bluetooth/CommandManager.h haiku/trunk/src/kits/bluetooth/CommandManager.cpp Log: -Update copyright -whitespaces cleanups Modified: haiku/trunk/headers/private/bluetooth/CommandManager.h =================================================================== --- haiku/trunk/headers/private/bluetooth/CommandManager.h 2008-07-16 19:25:44 UTC (rev 26451) +++ haiku/trunk/headers/private/bluetooth/CommandManager.h 2008-07-16 19:30:45 UTC (rev 26452) @@ -1,5 +1,6 @@ /* - * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2008 Mika Lindqvist * * All rights reserved. Distributed under the terms of the MIT License. * Modified: haiku/trunk/src/kits/bluetooth/CommandManager.cpp =================================================================== --- haiku/trunk/src/kits/bluetooth/CommandManager.cpp 2008-07-16 19:25:44 UTC (rev 26451) +++ haiku/trunk/src/kits/bluetooth/CommandManager.cpp 2008-07-16 19:30:45 UTC (rev 26452) @@ -1,5 +1,6 @@ /* * Copyright 2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com + * Copyright 2008 Mika Lindqvist * * All rights reserved. Distributed under the terms of the MIT License. * @@ -25,22 +26,22 @@ #else size_t* size = (size_t*)malloc(psize + sizeof(struct hci_command_header) + sizeof(size_t)); *outsize = psize + sizeof(struct hci_command_header) + sizeof(size_t); - + *size = psize + sizeof(struct hci_command_header); header = (struct hci_command_header*) (((uint8*)size)+4); #endif - + if (header != NULL) { - + header->opcode = B_HOST_TO_LENDIAN_INT16(PACK_OPCODE(ogf, ocf)); header->clen = psize; - + if (param != NULL && psize != 0) { *param = ((uint8*)header) + sizeof(struct hci_command_header); } } -#ifdef BT_IOCTLS_PASS_SIZE +#ifdef BT_IOCTLS_PASS_SIZE return header; #else return (void*)size; @@ -69,8 +70,8 @@ { struct hci_write_scan_enable* param; void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE, (void**) ¶m, sizeof(struct hci_write_scan_enable), outsize); - - + + if (command != NULL) { param->scan = scanmode; } @@ -84,8 +85,8 @@ { struct hci_write_authentication_enable* param; void* command = buildCommand(OGF_CONTROL_BASEBAND, OCF_WRITE_AUTH_ENABLE, (void**) ¶m, sizeof(struct hci_write_authentication_enable), outsize); - - + + if (command != NULL) { param->authentication = auth; } @@ -126,10 +127,10 @@ void* buildRemoteNameRequest(bdaddr_t bdaddr,uint8 pscan_rep_mode, uint16 clock_offset, size_t* outsize) { - + struct hci_remote_name_request* param; void* command = buildCommand(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST, (void**) ¶m, sizeof(struct hci_remote_name_request), outsize); - + if (command != NULL) { param->bdaddr = bdaddr; param->pscan_rep_mode = pscan_rep_mode; @@ -246,13 +247,13 @@ void* buildReadBufferSize(size_t* outsize) { return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE, NULL, 0, outsize); -} +} void* buildReadBdAddr(size_t* outsize) { return buildCommand(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR, NULL, 0, outsize); -} +} From superstippi at gmx.de Wed Jul 16 23:57:52 2008 From: superstippi at gmx.de (Stephan Assmus) Date: Wed, 16 Jul 2008 23:57:52 +0200 Subject: [Haiku-commits] r26449 - in haiku/trunk: headers/os/bluetooth src/kits/bluetooth In-Reply-To: <200807161904.m6GJ4wIY031197@sheep.berlios.de> References: <200807161904.m6GJ4wIY031197@sheep.berlios.de> Message-ID: <20080716235752.22328.6@stippis2.1216210872.fake> oruizdorantes at mail.berlios.de wrote: > Author: oruizdorantes > Date: 2008-07-16 21:04:53 +0200 (Wed, 16 Jul 2008) New Revision: 26449 > ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26449&view=rev > > Modified: > haiku/trunk/headers/os/bluetooth/DiscoveryAgent.h > haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp > Log: > Resolve allocation of multiple Messengers,(Mika Lindqvist) [...] > +DiscoveryAgent::~DiscoveryAgent() > +{ > + if (fMessenger) > + delete fMessenger; Please don't check pointers before using delete, delete[] or free(). These functions already perform the check. Best regards, -Stephan From mmlr at mail.berlios.de Thu Jul 17 00:17:35 2008 From: mmlr at mail.berlios.de (mmlr at mail.berlios.de) Date: Thu, 17 Jul 2008 00:17:35 +0200 Subject: [Haiku-commits] r26453 - in haiku/trunk/src/add-ons/kernel: drivers/tty file_systems/ext2 Message-ID: <200807162217.m6GMHZ3W008960@sheep.berlios.de> Author: mmlr Date: 2008-07-17 00:17:29 +0200 (Thu, 17 Jul 2008) New Revision: 26453 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26453&view=rev Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/master.cpp haiku/trunk/src/add-ons/kernel/drivers/tty/slave.cpp haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp Log: Add missing string.h that would otherwise soon break the build. Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/master.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/master.cpp 2008-07-16 19:30:45 UTC (rev 26452) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/master.cpp 2008-07-16 22:17:29 UTC (rev 26453) @@ -7,6 +7,7 @@ #include "tty_private.h" #include +#include #include Modified: haiku/trunk/src/add-ons/kernel/drivers/tty/slave.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/tty/slave.cpp 2008-07-16 19:30:45 UTC (rev 26452) +++ haiku/trunk/src/add-ons/kernel/drivers/tty/slave.cpp 2008-07-16 22:17:29 UTC (rev 26453) @@ -5,6 +5,7 @@ #include +#include #include Modified: haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-16 19:30:45 UTC (rev 26452) +++ haiku/trunk/src/add-ons/kernel/file_systems/ext2/Volume.cpp 2008-07-16 22:17:29 UTC (rev 26453) @@ -12,6 +12,7 @@ #include #include #include +#include #include #include From axeld at mail.berlios.de Thu Jul 17 00:43:52 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 17 Jul 2008 00:43:52 +0200 Subject: [Haiku-commits] r26454 - in haiku/trunk: headers/private/kernel src/add-ons/kernel/network/protocols/unix src/system/kernel Message-ID: <200807162243.m6GMhqgA000114@sheep.berlios.de> Author: axeld Date: 2008-07-17 00:43:50 +0200 (Thu, 17 Jul 2008) New Revision: 26454 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26454&view=rev Modified: haiku/trunk/headers/private/kernel/condition_variable.h haiku/trunk/src/add-ons/kernel/network/protocols/unix/UnixFifo.cpp haiku/trunk/src/system/kernel/condition_variable.cpp Log: bonefish + axeld: * Removed the superfluous "flags" parameter from ConditionVariable::Add() that we forgot there when we moved the flags field from ConditionVariableEntry::Add() to Wait(). * Using this method was therefore not a good idea - only UnixFifo did, though. Modified: haiku/trunk/headers/private/kernel/condition_variable.h =================================================================== --- haiku/trunk/headers/private/kernel/condition_variable.h 2008-07-16 22:17:29 UTC (rev 26453) +++ haiku/trunk/headers/private/kernel/condition_variable.h 2008-07-16 22:43:50 UTC (rev 26454) @@ -35,8 +35,7 @@ inline ConditionVariable* Variable() const { return fVariable; } private: - inline void AddToVariable(ConditionVariable* variable, - uint32 flags); + inline void AddToVariable(ConditionVariable* variable); private: ConditionVariable* fVariable; @@ -60,8 +59,7 @@ inline void NotifyOne(bool threadsLocked = false); inline void NotifyAll(bool threadsLocked = false); - void Add(ConditionVariableEntry* entry, - uint32 flags = 0); + void Add(ConditionVariableEntry* entry); const void* Object() const { return fObject; } Modified: haiku/trunk/src/add-ons/kernel/network/protocols/unix/UnixFifo.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/network/protocols/unix/UnixFifo.cpp 2008-07-16 22:17:29 UTC (rev 26453) +++ haiku/trunk/src/add-ons/kernel/network/protocols/unix/UnixFifo.cpp 2008-07-16 22:43:50 UTC (rev 26454) @@ -447,10 +447,11 @@ while (fReaders.Head() != &request && !(IsReadShutdown() && fBuffer.Readable() == 0)) { ConditionVariableEntry entry; - fReadCondition.Add(&entry, B_CAN_INTERRUPT); + fReadCondition.Add(&entry); mutex_unlock(&fLock); - status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT, timeout); + status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, + timeout); mutex_lock(&fLock); if (error != B_OK) @@ -473,10 +474,11 @@ while (fBuffer.Readable() == 0 && !IsReadShutdown() && !IsWriteShutdown()) { ConditionVariableEntry entry; - fReadCondition.Add(&entry, B_CAN_INTERRUPT); + fReadCondition.Add(&entry); mutex_unlock(&fLock); - status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT, timeout); + status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, + timeout); mutex_lock(&fLock); if (error != B_OK) @@ -503,10 +505,11 @@ // wait for the request to reach the front of the queue while (fWriters.Head() != &request && !IsWriteShutdown()) { ConditionVariableEntry entry; - fWriteCondition.Add(&entry, B_CAN_INTERRUPT); + fWriteCondition.Add(&entry); mutex_unlock(&fLock); - status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT, timeout); + status_t error = entry.Wait(B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, + timeout); mutex_lock(&fLock); if (error != B_OK) @@ -529,19 +532,19 @@ while (error == B_OK && fBuffer.Writable() == 0 && !IsWriteShutdown() && !IsReadShutdown()) { ConditionVariableEntry entry; - fWriteCondition.Add(&entry, B_CAN_INTERRUPT); - + fWriteCondition.Add(&entry); + mutex_unlock(&fLock); - error = entry.Wait(B_ABSOLUTE_TIMEOUT, timeout); + error = entry.Wait(B_ABSOLUTE_TIMEOUT | B_CAN_INTERRUPT, timeout); mutex_lock(&fLock); if (error != B_OK) RETURN_ERROR(error); } - + if (IsWriteShutdown()) RETURN_ERROR(UNIX_FIFO_SHUTDOWN); - + if (IsReadShutdown()) RETURN_ERROR(EPIPE); Modified: haiku/trunk/src/system/kernel/condition_variable.cpp =================================================================== --- haiku/trunk/src/system/kernel/condition_variable.cpp 2008-07-16 22:17:29 UTC (rev 26453) +++ haiku/trunk/src/system/kernel/condition_variable.cpp 2008-07-16 22:43:50 UTC (rev 26454) @@ -171,17 +171,14 @@ inline void -ConditionVariableEntry::AddToVariable(ConditionVariable* variable, uint32 flags) +ConditionVariableEntry::AddToVariable(ConditionVariable* variable) { fThread = thread_get_current_thread(); - thread_prepare_to_block(fThread, flags, - THREAD_BLOCK_TYPE_CONDITION_VARIABLE, fVariable); - - // add to the variable InterruptsSpinLocker _(sConditionVariablesLock); fVariable = variable; + fWaitStatus = STATUS_ADDED; fVariable->fEntries.Add(this); } @@ -246,9 +243,9 @@ void -ConditionVariable::Add(ConditionVariableEntry* entry, uint32 flags) +ConditionVariable::Add(ConditionVariableEntry* entry) { - entry->AddToVariable(this, flags); + entry->AddToVariable(this); } From axeld at mail.berlios.de Thu Jul 17 00:55:21 2008 From: axeld at mail.berlios.de (axeld at BerliOS) Date: Thu, 17 Jul 2008 00:55:21 +0200 Subject: [Haiku-commits] r26455 - in haiku/trunk: headers/os/drivers headers/private/kernel src/system/kernel src/system/kernel/arch/x86 src/system/kernel/vm Message-ID: <200807162255.m6GMtLYx018793@sheep.berlios.de> Author: axeld Date: 2008-07-17 00:55:17 +0200 (Thu, 17 Jul 2008) New Revision: 26455 ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=26455&view=rev Modified: haiku/trunk/headers/os/drivers/KernelExport.h haiku/trunk/headers/private/kernel/vm.h haiku/trunk/headers/private/kernel/vm_address_space.h haiku/trunk/src/system/kernel/arch/x86/vm86.cpp haiku/trunk/src/system/kernel/elf.cpp haiku/trunk/src/system/kernel/team.cpp haiku/trunk/src/system/kernel/thread.cpp haiku/trunk/src/system/kernel/vm/vm.cpp haiku/trunk/src/system/kernel/vm/vm_address_space.cpp Log: * Added [un]lock_memory_etc() versions that accept a team_id as first argument. This allows drivers to lock the memory outside of the original team context. * create_area_etc() got a struct team as first argument, but that should have been a team_id. * Removed delete_area_etc() - there is already vm_delete_area() doing the same thing. * Renamed vm_get_address_space_by_id() to vm_get_address_space(), as there is no other method of getting an address space. * Removed erroneous white space. Modified: haiku/trunk/headers/os/drivers/KernelExport.h =================================================================== --- haiku/trunk/headers/os/drivers/KernelExport.h 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/headers/os/drivers/KernelExport.h 2008-07-16 22:55:17 UTC (rev 26455) @@ -144,8 +144,12 @@ extern int send_signal_etc(pid_t thread, uint signal, uint32 flags); /* virtual memory */ -extern long lock_memory(void *buffer, ulong numBytes, ulong flags); -extern long unlock_memory(void *buffer, ulong numBytes, ulong flags); +extern status_t lock_memory_etc(team_id team, void *buffer, size_t numBytes, + uint32 flags); +extern status_t lock_memory(void *buffer, size_t numBytes, uint32 flags); +extern status_t unlock_memory_etc(team_id team, void *address, + size_t numBytes, uint32 flags); +extern status_t unlock_memory(void *buffer, size_t numBytes, uint32 flags); extern long get_memory_map(const void *buffer, ulong size, physical_entry *table, long numEntries); extern area_id map_physical_memory(const char *areaName, @@ -168,7 +172,7 @@ extern int add_debugger_command(char *name, debugger_command_hook hook, char *help); extern int remove_debugger_command(char *name, - debugger_command_hook hook); + debugger_command_hook hook); /* Miscellaneous */ extern void spin(bigtime_t microseconds); Modified: haiku/trunk/headers/private/kernel/vm.h =================================================================== --- haiku/trunk/headers/private/kernel/vm.h 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/headers/private/kernel/vm.h 2008-07-16 22:55:17 UTC (rev 26455) @@ -46,9 +46,8 @@ void forbid_page_faults(void); // private kernel only extension (should be moved somewhere else): -area_id create_area_etc(struct team *team, const char *name, void **address, +area_id create_area_etc(team_id team, const char *name, void **address, uint32 addressSpec, uint32 size, uint32 lock, uint32 protection); -status_t delete_area_etc(struct team *team, area_id area); status_t vm_unreserve_address_range(team_id team, void *address, addr_t size); status_t vm_reserve_address_range(team_id team, void **_address, Modified: haiku/trunk/headers/private/kernel/vm_address_space.h =================================================================== --- haiku/trunk/headers/private/kernel/vm_address_space.h 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/headers/private/kernel/vm_address_space.h 2008-07-16 22:55:17 UTC (rev 26455) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2005, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. * * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. @@ -32,7 +32,7 @@ team_id vm_kernel_address_space_id(void); struct vm_address_space *vm_get_current_user_address_space(void); team_id vm_current_user_address_space_id(void); -struct vm_address_space *vm_get_address_space_by_id(team_id aid); +struct vm_address_space *vm_get_address_space(team_id team); void vm_put_address_space(struct vm_address_space *aspace); #define vm_swap_address_space(aspace) arch_vm_aspace_swap(aspace) Modified: haiku/trunk/src/system/kernel/arch/x86/vm86.cpp =================================================================== --- haiku/trunk/src/system/kernel/arch/x86/vm86.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/arch/x86/vm86.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -547,9 +547,8 @@ ramSize = VM86_MIN_RAM_SIZE; void *address = (void *)0; - state->ram_area = create_area_etc(team, "dos", &address, B_EXACT_ADDRESS, - ramSize, B_NO_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA - | B_READ_AREA | B_WRITE_AREA); + state->ram_area = create_area_etc(team->id, "dos", &address, + B_EXACT_ADDRESS, ramSize, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (state->ram_area < B_OK) { ret = state->ram_area; TRACE("Could not create RAM area\n"); @@ -566,7 +565,7 @@ goto error; } ret = user_memcpy((void *)0, address, 0x502); - *((uint32 *)0) = 0xDEADBEEF; + *((uint32 *)0) = 0xdeadbeef; delete_area(vectors); if (ret != B_OK) goto error; @@ -586,9 +585,9 @@ error: if (state->bios_area > B_OK) - delete_area_etc(team, state->bios_area); + vm_delete_area(team->id, state->bios_area, true); if (state->ram_area > B_OK) - delete_area_etc(team, state->ram_area); + vm_delete_area(team->id, state->ram_area, true); return ret; } @@ -601,9 +600,9 @@ struct team *team = thread_get_current_thread()->team; if (state->bios_area > B_OK) - delete_area_etc(team, state->bios_area); + vm_delete_area(team->id, state->bios_area, true); if (state->ram_area > B_OK) - delete_area_etc(team, state->ram_area); + vm_delete_area(team->id, state->ram_area, true); } Modified: haiku/trunk/src/system/kernel/elf.cpp =================================================================== --- haiku/trunk/src/system/kernel/elf.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/elf.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -1457,8 +1457,9 @@ snprintf(regionName, B_OS_NAME_LENGTH, "%s_bss%d", baseName, i); regionAddress += fileUpperBound; - id = create_area_etc(team, regionName, (void **)®ionAddress, - B_EXACT_ADDRESS, bss_size, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); + id = create_area_etc(team->id, regionName, + (void **)®ionAddress, B_EXACT_ADDRESS, bss_size, + B_NO_LOCK, B_READ_AREA | B_WRITE_AREA); if (id < B_OK) { dprintf("error allocating bss area: %s!\n", strerror(id)); status = B_NOT_AN_EXECUTABLE; Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/team.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -160,7 +160,7 @@ for (int32 i = 0; !out.IsFull() && i < fArgCount; i++) { out.Print(" \"%s\"", args); args += strlen(args) + 1; - } + } } private: @@ -812,7 +812,7 @@ { void* address = (void*)KERNEL_USER_DATA_BASE; size_t size = 4 * B_PAGE_SIZE; - team->user_data_area = create_area_etc(team, "user area", &address, + team->user_data_area = create_area_etc(team->id, "user area", &address, B_BASE_ADDRESS, size, B_FULL_LOCK, B_READ_AREA | B_WRITE_AREA); if (team->user_data_area < 0) return team->user_data_area; @@ -830,7 +830,7 @@ delete_team_user_data(struct team* team) { if (team->user_data_area >= 0) { - delete_area_etc(team, team->user_data_area); + vm_delete_area(team->id, team->user_data_area, true); team->user_data = 0; team->used_user_data = 0; team->user_data_size = 0; @@ -989,8 +989,9 @@ // the exact location at the end of the user stack area sprintf(ustack_name, "%s_main_stack", team->name); - t->user_stack_area = create_area_etc(team, ustack_name, (void **)&t->user_stack_base, - B_EXACT_ADDRESS, sizeLeft, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA | B_STACK_AREA); + t->user_stack_area = create_area_etc(team->id, ustack_name, + (void **)&t->user_stack_base, B_EXACT_ADDRESS, sizeLeft, B_NO_LOCK, + B_READ_AREA | B_WRITE_AREA | B_STACK_AREA); if (t->user_stack_area < 0) { dprintf("team_create_thread_start: could not create default user stack region\n"); @@ -1050,7 +1051,7 @@ runtimeLoaderPath.LockBuffer(), runtimeLoaderPath.BufferSize()); if (err < B_OK) { TRACE(("team_create_thread_start: find_directory() failed: %s\n", - strerror(err))); + strerror(err))); return err; } runtimeLoaderPath.UnlockBuffer(); @@ -1064,7 +1065,7 @@ // Luckily, we don't have to clean up the mess we created - that's // done for us by the normal team deletion process TRACE(("team_create_thread_start: elf_load_user_image() failed: " - "%s\n", strerror(err))); + "%s\n", strerror(err))); return err; } @@ -1210,7 +1211,7 @@ if (loadingInfo.result < B_OK) return loadingInfo.result; - } + } // notify the debugger user_debug_team_created(team->id); @@ -1849,11 +1850,11 @@ info->team = team->id; info->thread_count = team->num_threads; info->image_count = count_images(team); - //info->area_count = + //info->area_count = info->debugger_nub_thread = team->debug_info.nub_thread; info->debugger_nub_port = team->debug_info.nub_port; - //info->uid = - //info->gid = + //info->uid = + //info->gid = strlcpy(info->args, team->args, sizeof(info->args)); info->argc = 1; @@ -2187,7 +2188,7 @@ session->controlling_tty = -1; - // send SIGHUP to the foreground + // send SIGHUP to the foreground if (session->foreground_group >= 0) { send_signal_etc(-session->foreground_group, SIGHUP, SIGNAL_FLAG_TEAMS_LOCKED); @@ -2206,7 +2207,7 @@ send_signal_etc(-childGroup->id, SIGCONT, SIGNAL_FLAG_TEAMS_LOCKED); } - + child = child->siblings_next; } } else { @@ -2216,7 +2217,7 @@ process_group* childGroup = child->group; if (!childGroup->orphaned) update_orphaned_process_group(childGroup, team->id); - + child = child->siblings_next; } @@ -2509,8 +2510,8 @@ return B_OK; } - - + + status_t stop_watching_team(team_id teamID, void (*hook)(team_id, void *), void *data) { @@ -3304,7 +3305,7 @@ team_info info; if (!IS_USER_ADDRESS(userInfo)) - return B_BAD_ADDRESS; + return B_BAD_ADDRESS; status = _get_team_info(id, &info, sizeof(team_info)); if (status == B_OK) { Modified: haiku/trunk/src/system/kernel/thread.cpp =================================================================== --- haiku/trunk/src/system/kernel/thread.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/thread.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -502,7 +502,7 @@ snprintf(stack_name, B_OS_NAME_LENGTH, "%s_%ld_stack", attributes.name, thread->id); - thread->user_stack_area = create_area_etc(team, stack_name, + thread->user_stack_area = create_area_etc(team->id, stack_name, (void **)&thread->user_stack_base, B_BASE_ADDRESS, thread->user_stack_size + TLS_SIZE, B_NO_LOCK, B_READ_AREA | B_WRITE_AREA | B_STACK_AREA); @@ -1003,7 +1003,7 @@ switch (thread->wait.type) { case THREAD_BLOCK_TYPE_SNOOZE: return "zzz"; - + case THREAD_BLOCK_TYPE_SEMAPHORE: { sem_id sem = (sem_id)(addr_t)thread->wait.object; @@ -1314,7 +1314,7 @@ if (team->address_space != NULL && thread->user_stack_area >= 0) { area_id area = thread->user_stack_area; thread->user_stack_area = -1; - delete_area_etc(team, area); + vm_delete_area(team->id, area, true); } struct job_control_entry *death = NULL; @@ -2550,7 +2550,7 @@ return -1; } - return 0; + return 0; } @@ -2563,7 +2563,7 @@ return -1; } - return 0; + return 0; } Modified: haiku/trunk/src/system/kernel/vm/vm.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/vm/vm.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -272,7 +272,7 @@ status_t AddressSpaceReadLocker::SetTo(team_id team) { - fSpace = vm_get_address_space_by_id(team); + fSpace = vm_get_address_space(team); if (fSpace == NULL) return B_BAD_TEAM_ID; @@ -365,7 +365,7 @@ status_t AddressSpaceWriteLocker::SetTo(team_id team) { - fSpace = vm_get_address_space_by_id(team); + fSpace = vm_get_address_space(team); if (fSpace == NULL) return B_BAD_TEAM_ID; @@ -557,7 +557,7 @@ MultiAddressSpaceLocker::AddTeam(team_id team, bool writeLock, vm_address_space** _space) { - return _AddAddressSpace(vm_get_address_space_by_id(team), writeLock, + return _AddAddressSpace(vm_get_address_space(team), writeLock, _space); } @@ -1327,7 +1327,7 @@ area = addressSpace->areas; while (area != NULL) { vm_area* nextArea = area->address_space_next; - + if (area->id != RESERVED_AREA_ID) { addr_t areaLast = area->base + (area->size - 1); if (area->base < lastAddress && address < areaLast) { @@ -1335,7 +1335,7 @@ return B_NOT_ALLOWED; } } - + area = nextArea; } } @@ -2599,7 +2599,7 @@ status_t vm_get_page_mapping(team_id team, addr_t vaddr, addr_t *paddr) { - vm_address_space *addressSpace = vm_get_address_space_by_id(team); + vm_address_space *addressSpace = vm_get_address_space(team); if (addressSpace == NULL) return B_BAD_TEAM_ID; @@ -5021,8 +5021,8 @@ } -long -lock_memory(void *address, ulong numBytes, ulong flags) +status_t +lock_memory_etc(team_id team, void *address, size_t numBytes, uint32 flags) { vm_address_space *addressSpace = NULL; struct vm_translation_map *map; @@ -5032,9 +5032,12 @@ bool isUser = IS_USER_ADDRESS(address); bool needsLocking = true; - if (isUser) - addressSpace = vm_get_current_user_address_space(); - else + if (isUser) { + if (team == B_CURRENT_TEAM) + addressSpace = vm_get_current_user_address_space(); + else + addressSpace = vm_get_address_space(team); + } else addressSpace = vm_get_kernel_address_space(); if (addressSpace == NULL) return B_ERROR; @@ -5107,9 +5110,16 @@ } -long -unlock_memory(void *address, ulong numBytes, ulong flags) +status_t +lock_memory(void *address, size_t numBytes, uint32 flags) { + return lock_memory_etc(B_CURRENT_TEAM, address, numBytes, flags); +} + + +status_t +unlock_memory_etc(team_id team, void *address, size_t numBytes, uint32 flags) +{ vm_address_space *addressSpace = NULL; struct vm_translation_map *map; addr_t unalignedBase = (addr_t)address; @@ -5117,9 +5127,12 @@ addr_t base = ROUNDOWN(unalignedBase, B_PAGE_SIZE); bool needsLocking = true; - if (IS_USER_ADDRESS(address)) - addressSpace = vm_get_current_user_address_space(); - else + if (IS_USER_ADDRESS(address)) { + if (team == B_CURRENT_TEAM) + addressSpace = vm_get_current_user_address_space(); + else + addressSpace = vm_get_address_space(team); + } else addressSpace = vm_get_kernel_address_space(); if (addressSpace == NULL) return B_ERROR; @@ -5162,10 +5175,16 @@ } -/** According to the BeBook, this function should always succeed. - * This is no longer the case. - */ +status_t +unlock_memory(void *address, size_t numBytes, uint32 flags) +{ + return unlock_memory_etc(B_CURRENT_TEAM, address, numBytes, flags); +} + +/*! According to the BeBook, this function should always succeed. + This is no longer the case. +*/ long get_memory_map(const void *address, ulong numBytes, physical_entry *table, long numEntries) @@ -5434,13 +5453,13 @@ area_id -create_area_etc(struct team *team, const char *name, void **address, uint32 addressSpec, - uint32 size, uint32 lock, uint32 protection) +create_area_etc(team_id team, const char *name, void **address, + uint32 addressSpec, uint32 size, uint32 lock, uint32 protection) { fix_protection(&protection); - return vm_create_anonymous_area(team->id, (char *)name, address, - addressSpec, size, lock, protection, false, true); + return vm_create_anonymous_area(team, (char *)name, address, addressSpec, + size, lock, protection, false, true); } @@ -5456,13 +5475,6 @@ status_t -delete_area_etc(struct team *team, area_id area) -{ - return vm_delete_area(team->id, area, true); -} - - -status_t delete_area(area_id area) { return vm_delete_area(vm_kernel_address_space_id(), area, true); @@ -5841,7 +5853,7 @@ address += rangeSize; size -= rangeSize; } - + // NOTE: If I understand it correctly the purpose of MS_INVALIDATE is to // synchronize multiple mappings of the same file. In our VM they never get // out of sync, though, so we don't have to do anything. Modified: haiku/trunk/src/system/kernel/vm/vm_address_space.cpp =================================================================== --- haiku/trunk/src/system/kernel/vm/vm_address_space.cpp 2008-07-16 22:43:50 UTC (rev 26454) +++ haiku/trunk/src/system/kernel/vm/vm_address_space.cpp 2008-07-16 22:55:17 UTC (rev 26455) @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Axel D?rfler, axeld at pinc-software.de. All rights reserved. + * Copyright 2002-2008, Axel D?rfler, axeld at pinc-software.de. All rights reserved. * Distributed under the terms