From fc4d98a2c09fcc8e96eda3f9a234ae9cd71dba48 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 14:28:44 -0400 Subject: [PATCH 01/18] Coding style fixes, no functionnal changes. Following comments from Axel about a previous commit of mine. Sorry Axel for the delay. --- src/apps/codycam/CodyCam.cpp | 3 +-- src/apps/icon-o-matic/IconEditorApp.cpp | 4 ++-- src/apps/mediaconverter/MediaConverterWindow.cpp | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/apps/codycam/CodyCam.cpp b/src/apps/codycam/CodyCam.cpp index 0df1c060a6..2b79880cd9 100644 --- a/src/apps/codycam/CodyCam.cpp +++ b/src/apps/codycam/CodyCam.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -23,8 +24,6 @@ #include #include -#include - #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "CodyCam" diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp index 27f73a9484..69d3b54439 100644 --- a/src/apps/icon-o-matic/IconEditorApp.cpp +++ b/src/apps/icon-o-matic/IconEditorApp.cpp @@ -13,12 +13,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include "support_settings.h" @@ -331,7 +331,7 @@ IconEditorApp::_LastFilePath(path_kind which) path = fLastOpenPath.String(); break; } - if (!path) { + if (path == NULL) { BPath homePath; if (find_directory(B_USER_DIRECTORY, &homePath) == B_OK) diff --git a/src/apps/mediaconverter/MediaConverterWindow.cpp b/src/apps/mediaconverter/MediaConverterWindow.cpp index d97dcb1b0e..c6288660d2 100644 --- a/src/apps/mediaconverter/MediaConverterWindow.cpp +++ b/src/apps/mediaconverter/MediaConverterWindow.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -31,8 +32,6 @@ #include #include -#include - #include "MediaFileInfoView.h" #include "MediaFileListView.h" #include "MessageConstants.h" From af350aa21891c6d37934df7686e2cba1d0f4f29f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 20 Jul 2012 23:24:33 +0200 Subject: [PATCH 02/18] Add private shared class ArgumentVector The parser is based on the FS shell's ArgVector. --- headers/private/shared/ArgumentVector.h | 53 +++++++ src/kits/shared/ArgumentVector.cpp | 203 ++++++++++++++++++++++++ src/kits/shared/Jamfile | 1 + 3 files changed, 257 insertions(+) create mode 100644 headers/private/shared/ArgumentVector.h create mode 100644 src/kits/shared/ArgumentVector.cpp diff --git a/headers/private/shared/ArgumentVector.h b/headers/private/shared/ArgumentVector.h new file mode 100644 index 0000000000..0b32a8743d --- /dev/null +++ b/headers/private/shared/ArgumentVector.h @@ -0,0 +1,53 @@ +/* + * Copyright 2007-2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ARGUMENT_VECTOR_H +#define _ARGUMENT_VECTOR_H + + +#include + + +namespace BPrivate { + + +class ArgumentVector { +public: + enum ParseError { + NO_ERROR, + NO_MEMORY, + UNTERMINATED_QUOTED_STRING, + TRAILING_BACKSPACE + }; + +public: + ArgumentVector(); + ~ArgumentVector(); + + int32 ArgumentCount() const { return fCount; } + const char* const* Arguments() const { return fArguments; } + + char** DetachArguments(); + // Caller must free() -- it's all one big allocation at the + // returned pointer. + + ParseError Parse(const char* commandLine, + const char** _errorLocation = NULL); + +private: + struct Parser; + +private: + char** fArguments; + int32 fCount; +}; + + +} // namespace BPrivate + + +using BPrivate::ArgumentVector; + + +#endif // _ARGUMENT_VECTOR_H diff --git a/src/kits/shared/ArgumentVector.cpp b/src/kits/shared/ArgumentVector.cpp new file mode 100644 index 0000000000..c678f5de7c --- /dev/null +++ b/src/kits/shared/ArgumentVector.cpp @@ -0,0 +1,203 @@ +/* + * Copyright 2007-2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include + +#include +#include + +#include +#include + + +struct ArgumentVector::Parser { + ParseError Parse(const char* commandLine, const char*& _errorLocation) + { + // init temporary arg/argv storage + fCurrentArg.clear(); + fCurrentArgStarted = false; + fArgVector.clear(); + fTotalStringSize = 0; + + for (; *commandLine; commandLine++) { + char c = *commandLine; + + // whitespace delimits args and is otherwise ignored + if (isspace(c)) { + _PushCurrentArg(); + continue; + } + + const char* errorBase = commandLine; + + switch (c) { + case '\'': + // quoted string -- no quoting + while (*++commandLine != '\'') { + c = *commandLine; + if (c == '\0') { + _errorLocation = errorBase; + return UNTERMINATED_QUOTED_STRING; + } + _PushCharacter(c); + } + break; + + case '"': + // quoted string -- some quoting + while (*++commandLine != '"') { + c = *commandLine; + if (c == '\0') { + _errorLocation = errorBase; + return UNTERMINATED_QUOTED_STRING; + } + + if (c == '\\') { + c = *++commandLine; + if (c == '\0') { + _errorLocation = errorBase; + return UNTERMINATED_QUOTED_STRING; + } + + // only '\' and '"' can be quoted, otherwise the + // the '\' is treated as a normal char + if (c != '\\' && c != '"') + _PushCharacter('\\'); + } + + _PushCharacter(c); + } + break; + + case '\\': + // quoted char + c = *++commandLine; + if (c == '\0') { + _errorLocation = errorBase; + return TRAILING_BACKSPACE; + } + _PushCharacter(c); + break; + + default: + // normal char + _PushCharacter(c); + break; + } + } + + // commit last arg + _PushCurrentArg(); + + return NO_ERROR; + } + + const std::vector& ArgVector() const + { + return fArgVector; + } + + size_t TotalStringSize() const + { + return fTotalStringSize; + } + +private: + void _PushCurrentArg() + { + if (fCurrentArgStarted) { + fArgVector.push_back(fCurrentArg); + fTotalStringSize += fCurrentArg.length() + 1; + fCurrentArgStarted = false; + } + } + + void _PushCharacter(char c) + { + if (!fCurrentArgStarted) { + fCurrentArg = ""; + fCurrentArgStarted = true; + } + + fCurrentArg += c; + } + +private: + // temporaries + std::string fCurrentArg; + bool fCurrentArgStarted; + std::vector fArgVector; + size_t fTotalStringSize; +}; + + +ArgumentVector::ArgumentVector() + : + fArguments(NULL), + fCount(0) +{ +} + + +ArgumentVector::~ArgumentVector() +{ + free(fArguments); +} + + +char** +ArgumentVector::DetachArguments() +{ + char** arguments = fArguments; + fArguments = NULL; + fCount = 0; + return arguments; +} + + +ArgumentVector::ParseError +ArgumentVector::Parse(const char* commandLine, const char** _errorLocation) +{ + free(DetachArguments()); + + ParseError error; + const char* errorLocation = commandLine; + + try { + Parser parser; + error = parser.Parse(commandLine, errorLocation); + + if (error == NO_ERROR) { + // Create a char* array and copy everything into a single + // allocation. + int count = parser.ArgVector().size(); + size_t arraySize = (count + 1) * sizeof(char*); + fArguments = (char**)malloc( + arraySize + parser.TotalStringSize()); + if (fArguments != 0) { + char* argument = (char*)(fArguments + count + 1); + for (int i = 0; i < count; i++) { + fArguments[i] = argument; + const std::string& sourceArgument = parser.ArgVector()[i]; + size_t argumentSize = sourceArgument.length() + 1; + memcpy(argument, sourceArgument.c_str(), argumentSize); + argument += argumentSize; + } + + fArguments[count] = NULL; + fCount = count; + } else + error = NO_MEMORY; + } + } catch (...) { + error = NO_MEMORY; + } + + if (error != NO_ERROR && _errorLocation != NULL) + *_errorLocation = errorLocation; + + return error; +} diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index d56a8b6fe2..8992caa24f 100644 --- a/src/kits/shared/Jamfile +++ b/src/kits/shared/Jamfile @@ -15,6 +15,7 @@ UsePrivateHeaders kernel libroot ; StaticLibrary libshared.a : AboutMenuItem.cpp AboutWindow.cpp + ArgumentVector.cpp CalendarView.cpp ColorQuantizer.cpp CommandPipe.cpp From 0f1f968ffb6f4b19193ccad1a4edae9e9a46ab19 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 20 Jul 2012 23:26:14 +0200 Subject: [PATCH 03/18] Debugger: Actually create the CLI, if requested --- src/apps/debugger/Debugger.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/apps/debugger/Debugger.cpp b/src/apps/debugger/Debugger.cpp index c7a687c855..f5617470aa 100644 --- a/src/apps/debugger/Debugger.cpp +++ b/src/apps/debugger/Debugger.cpp @@ -56,7 +56,7 @@ static const char* kUsage = "\n" "Options:\n" " -h, --help - Print this usage info and exit.\n" - " -c, --cli - Use command line user interface (not yet implemented)\n" + " -c, --cli - Use command line user interface\n" ; @@ -397,7 +397,8 @@ Debugger::ArgvReceived(int32 argc, char** argv) return; } - start_team_debugger(team, &fSettingsManager, this, thread, stopInMain); + start_team_debugger(team, &fSettingsManager, this, thread, stopInMain, + options.useCLI); } @@ -481,6 +482,7 @@ Debugger::_FindTeamDebugger(team_id teamID) const // #pragma mark - + int main(int argc, const char* const* argv) { @@ -493,20 +495,15 @@ main(int argc, const char* const* argv) Options options; parse_arguments(argc, argv, false, options); - if (options.useCLI) { - // TODO: implement - fprintf(stderr, "Error: Command line interface unimplemented\n"); + Debugger app; + status_t error = app.Init(); + if (error != B_OK) { + fprintf(stderr, "Error: Failed to init application: %s\n", + strerror(error)); return 1; - } else { - Debugger app; - status_t error = app.Init(); - if (error != B_OK) { - fprintf(stderr, "Error: Failed to init application: %s\n", - strerror(error)); - return 1; - } - - app.Run(); } + + app.Run(); + return 0; } From 6d60b554e6d6cee2a7e73e95b5e06374c9f2e32f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 20 Jul 2012 23:30:34 +0200 Subject: [PATCH 04/18] Debugger: Some basic work to get the CLI going There's an input loop thread which reads and parses command lines and the infrastructure for registering and executing commands. Currently only "help" and "quit" commands are implemented. --- src/apps/debugger/Jamfile | 7 +- .../user_interface/cli/CliCommand.cpp | 20 ++ .../debugger/user_interface/cli/CliCommand.h | 33 +++ .../debugger/user_interface/cli/CliContext.h | 13 + .../cli/CommandLineUserInterface.cpp | 236 +++++++++++++++++- .../cli/CommandLineUserInterface.h | 35 +++ 6 files changed, 338 insertions(+), 6 deletions(-) create mode 100644 src/apps/debugger/user_interface/cli/CliCommand.cpp create mode 100644 src/apps/debugger/user_interface/cli/CliCommand.h create mode 100644 src/apps/debugger/user_interface/cli/CliContext.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 193bc20961..80c98fe660 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -169,12 +169,13 @@ Application Debugger : # user_interface UserInterface.cpp + # user_interface/cli + CliCommand.cpp + CommandLineUserInterface.cpp + # user_interface/gui GraphicalUserInterface.cpp - # user_interface/cli - CommandLineUserInterface.cpp - # user_interface/gui/model VariablesViewState.cpp VariablesViewStateHistory.cpp diff --git a/src/apps/debugger/user_interface/cli/CliCommand.cpp b/src/apps/debugger/user_interface/cli/CliCommand.cpp new file mode 100644 index 0000000000..c83c8cfbad --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliCommand.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + + +#include "CliCommand.h" + + +CliCommand::CliCommand(const char* summary, const char* usage) + : + fSummary(summary), + fUsage(usage) +{ +} + + +CliCommand::~CliCommand() +{ +} diff --git a/src/apps/debugger/user_interface/cli/CliCommand.h b/src/apps/debugger/user_interface/cli/CliCommand.h new file mode 100644 index 0000000000..2a65e19aa3 --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliCommand.h @@ -0,0 +1,33 @@ +/* + * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef CLI_COMMAND_H +#define CLI_COMMAND_H + + +#include + + +class CliContext; + + +class CliCommand : public BReferenceable { +public: + CliCommand(const char* summary, + const char* usage); + virtual ~CliCommand(); + + const char* Summary() const { return fSummary; } + const char* Usage() const { return fUsage; } + + virtual void Execute(int argc, const char* const* argv, + CliContext& context) = 0; + +private: + const char* fSummary; + const char* fUsage; +}; + + +#endif // CLI_COMMAND_H diff --git a/src/apps/debugger/user_interface/cli/CliContext.h b/src/apps/debugger/user_interface/cli/CliContext.h new file mode 100644 index 0000000000..df318160a9 --- /dev/null +++ b/src/apps/debugger/user_interface/cli/CliContext.h @@ -0,0 +1,13 @@ +/* + * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ +#ifndef CLI_CONTEXT_H +#define CLI_CONTEXT_H + + +class CliContext { +}; + + +#endif // CLI_CONTEXT_H diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index 95fd5f29fb..ab53011fb2 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -1,13 +1,106 @@ /* * Copyright 2011, Rene Gollent, rene@gollent.com. + * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ #include "CommandLineUserInterface.h" +#include + +#include + +#include +#include + +#include "CliCommand.h" +#include "CliContext.h" + + +// #pragma mark - CommandEntry + + +struct CommandLineUserInterface::CommandEntry { + CommandEntry(const BString& name, CliCommand* command) + : + fName(name), + fCommand(command) + { + } + + const BString& Name() const + { + return fName; + } + + CliCommand* Command() const + { + return fCommand.Get(); + } + +private: + BString fName; + BReference fCommand; +}; + + +// #pragma mark - HelpCommand + + +struct CommandLineUserInterface::HelpCommand : CliCommand { + HelpCommand(CommandLineUserInterface* userInterface) + : + CliCommand("print a list of all commands", + "%s\n" + "Prints a list of all commands."), + fUserInterface(userInterface) + { + } + + virtual void Execute(int argc, const char* const* argv, CliContext& context) + { + fUserInterface->_PrintHelp(); + } + +private: + CommandLineUserInterface* fUserInterface; +}; + + +// #pragma mark - HelpCommand + + +struct CommandLineUserInterface::QuitCommand : CliCommand { + QuitCommand(CommandLineUserInterface* userInterface) + : + CliCommand("quit Debugger", + "%s\n" + "Quits Debugger."), + fUserInterface(userInterface) + { + } + + virtual void Execute(int argc, const char* const* argv, CliContext& context) + { + fUserInterface->fListener->UserInterfaceQuitRequested(); + } + +private: + CommandLineUserInterface* fUserInterface; +}; + + +// #pragma mark - CommandLineUserInterface + CommandLineUserInterface::CommandLineUserInterface() + : + fThread(-1), + fTeam(NULL), + fListener(NULL), + fCommands(20, true), + fTerminating(false) { } @@ -27,33 +120,48 @@ CommandLineUserInterface::ID() const status_t CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener) { - return B_UNSUPPORTED; + fTeam = team; + fListener = listener; + + status_t error = _RegisterCommands(); + if (error != B_OK) + return error; + + fThread = spawn_thread(&_InputLoopEntry, "CLI", B_NORMAL_PRIORITY, this); + if (fThread < 0) + return fThread; + + return B_OK; } void CommandLineUserInterface::Show() { + resume_thread(fThread); } void CommandLineUserInterface::Terminate() { + fTerminating = true; + // TODO: Signal the thread so it wakes up! + wait_for_thread(fThread, NULL); } status_t CommandLineUserInterface::LoadSettings(const TeamUISettings* settings) { - return B_UNSUPPORTED; + return B_OK; } status_t CommandLineUserInterface::SaveSettings(TeamUISettings*& settings) const { - return B_UNSUPPORTED;; + return B_OK; } @@ -71,3 +179,125 @@ CommandLineUserInterface::SynchronouslyAskUser(const char* title, { return 0; } + + +/*static*/ status_t +CommandLineUserInterface::_InputLoopEntry(void* data) +{ + return ((CommandLineUserInterface*)data)->_InputLoop(); +} + + +status_t +CommandLineUserInterface::_InputLoop() +{ + while (!fTerminating) { + // read a command line + printf("debugger> "); + fflush(stdout); + char buffer[256]; + if (fgets(buffer, sizeof(buffer), stdin) == NULL) + break; + + // parse the command line + ArgumentVector args; + const char* parseErrorLocation; + switch (args.Parse(buffer, &parseErrorLocation)) { + case ArgumentVector::NO_ERROR: + break; + case ArgumentVector::NO_MEMORY: + printf("Insufficient memory parsing the command line.\n"); + continue; + case ArgumentVector::UNTERMINATED_QUOTED_STRING: + printf("Parse error: Unterminated quoted string starting at " + "character %zu.\n", parseErrorLocation - buffer + 1); + continue; + case ArgumentVector::TRAILING_BACKSPACE: + printf("Parse error: trailing backspace.\n"); + continue; + } + + if (args.ArgumentCount() == 0) + continue; + + _ExecuteCommand(args.ArgumentCount(), args.Arguments()); + } + + return B_OK; +} + + +status_t +CommandLineUserInterface::_RegisterCommands() +{ + if (_RegisterCommand("help", new(std::nothrow) HelpCommand(this)) && + _RegisterCommand("quit", new(std::nothrow) QuitCommand(this))) { + return B_OK; + } + + return B_NO_MEMORY; +} + + +bool +CommandLineUserInterface::_RegisterCommand(const BString& name, + CliCommand* command) +{ + BReference commandReference(command, true); + if (name.IsEmpty() || command == NULL) + return false; + + CommandEntry* entry = new(std::nothrow) CommandEntry(name, command); + if (entry == NULL || !fCommands.AddItem(entry)) { + delete entry; + return false; + } + + return true; +} + + +void +CommandLineUserInterface::_ExecuteCommand(int argc, const char* const* argv) +{ + const char* commandName = argv[0]; + size_t commandNameLength = strlen(commandName); + + CommandEntry* firstEntry = NULL; + for (int32 i = 0; CommandEntry* entry = fCommands.ItemAt(i); i++) { + if (entry->Name().Compare(commandName, commandNameLength) == 0) { + if (firstEntry != NULL) { + printf("Ambiguous command \"%s\".\n", commandName); + return; + } + + firstEntry = entry; + } + } + + if (firstEntry == NULL) { + printf("Unknown command \"%s\".\n", commandName); + return; + } + + CliContext context; + firstEntry->Command()->Execute(argc, argv, context); +} + + +void +CommandLineUserInterface::_PrintHelp() +{ + // determine longest command name + int32 longestCommandName = 0; + for (int32 i = 0; CommandEntry* entry = fCommands.ItemAt(i); i++) { + longestCommandName + = std::max(longestCommandName, entry->Name().Length()); + } + + // print the command list + for (int32 i = 0; CommandEntry* entry = fCommands.ItemAt(i); i++) { + printf("%*s - %s\n", (int)longestCommandName, entry->Name().String(), + entry->Command()->Summary()); + } +} diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index 4d04a7c2ee..b581f36b90 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -1,14 +1,21 @@ /* * Copyright 2011, Rene Gollent, rene@gollent.com. + * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ #ifndef COMMAND_LINE_USER_INTERFACE_H #define COMMAND_LINE_USER_INTERFACE_H +#include +#include + #include "UserInterface.h" +class CliCommand; + + class CommandLineUserInterface : public UserInterface { public: CommandLineUserInterface(); @@ -33,6 +40,34 @@ public: const char* message, const char* choice1, const char* choice2, const char* choice3); +private: + struct CommandEntry; + typedef BObjectList CommandList; + + struct HelpCommand; + struct QuitCommand; + + // GCC 2 support + friend struct HelpCommand; + friend struct QuitCommand; + +private: + static status_t _InputLoopEntry(void* data); + status_t _InputLoop(); + + status_t _RegisterCommands(); + bool _RegisterCommand(const BString& name, + CliCommand* command); + void _ExecuteCommand(int argc, + const char* const* argv); + void _PrintHelp(); + +private: + thread_id fThread; + Team* fTeam; + UserInterfaceListener* fListener; + CommandList fCommands; + bool fTerminating; }; From 739ed61c38bf8e712f6c9b88c20ed5a860acfc00 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 15:21:30 -0400 Subject: [PATCH 05/18] CID 709703: Order of ops was unclear, but insignificant --- src/apps/webpositive/tabview/TabContainerView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/webpositive/tabview/TabContainerView.cpp b/src/apps/webpositive/tabview/TabContainerView.cpp index 52217fa9c7..7f231e1d9c 100644 --- a/src/apps/webpositive/tabview/TabContainerView.cpp +++ b/src/apps/webpositive/tabview/TabContainerView.cpp @@ -140,7 +140,7 @@ TabContainerView::MouseDown(BPoint where) // Middle click outside tabs should always open a new tab. fClickCount = 2; } else if (clicks > 1) - fClickCount = fClickCount++; + fClickCount++; else fClickCount = 1; } From c6df3cf4dc01fa0e77abd093d717ecdbee87f465 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 15:34:16 -0400 Subject: [PATCH 06/18] CID 702244: Uninit members were never used --- src/apps/icon-o-matic/CanvasView.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/apps/icon-o-matic/CanvasView.h b/src/apps/icon-o-matic/CanvasView.h index b022ca3555..57dfa94dbf 100644 --- a/src/apps/icon-o-matic/CanvasView.h +++ b/src/apps/icon-o-matic/CanvasView.h @@ -118,9 +118,6 @@ private: BPoint fScrollOffsetStart; uint32 fMouseFilterMode; - - BBitmap* fOffsreenBitmap; - BView* fOffsreenView; }; #endif // CANVAS_VIEW_H From cd383c3378a59c29329c5c8f47bb4d9ed93854b8 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 15:51:57 -0400 Subject: [PATCH 07/18] CID 610802: Unchecked return of FindMessage() --- src/apps/icon-o-matic/IconEditorApp.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/apps/icon-o-matic/IconEditorApp.cpp b/src/apps/icon-o-matic/IconEditorApp.cpp index 69d3b54439..d667ce90ce 100644 --- a/src/apps/icon-o-matic/IconEditorApp.cpp +++ b/src/apps/icon-o-matic/IconEditorApp.cpp @@ -372,7 +372,11 @@ IconEditorApp::_RestoreSettings() // Compensate offset for next window... fLastWindowFrame.OffsetBy(-kWindowOffset, -kWindowOffset); } - settings.FindMessage("window settings", &fLastWindowSettings); + BMessage lastSettings; + if (settings.FindMessage("window settings", &lastSettings) + == B_OK) { + fLastWindowSettings = lastSettings; + } int32 mode; if (settings.FindInt32("export mode", &mode) >= B_OK) From a65ef315855554757c1d65ab807d7969cf485257 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 16:28:56 -0400 Subject: [PATCH 08/18] CID 609036: Avoid to exceed length of string --- src/system/libroot/posix/syslog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/libroot/posix/syslog.cpp b/src/system/libroot/posix/syslog.cpp index ca50038cd2..7ed66d97de 100644 --- a/src/system/libroot/posix/syslog.cpp +++ b/src/system/libroot/posix/syslog.cpp @@ -215,7 +215,7 @@ void openlog_team(const char *ident, int options, int facility) { if (ident != NULL) - strcpy(sTeamContext.ident, ident); + strlcpy(sTeamContext.ident, ident, sizeof(sTeamContext.ident)); sTeamContext.options = options; sTeamContext.facility = SYSLOG_FACILITY(facility); From 8f226f2e879cd42bdeee49585b50033e7b0e967e Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 17:19:07 -0400 Subject: [PATCH 09/18] CID 602195: use sizeof() of structure rather than pointer --- src/add-ons/kernel/file_systems/ntfs/ntfsdir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c b/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c index e222434897..bc3bb5e92f 100644 --- a/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c +++ b/src/add-ons/kernel/file_systems/ntfs/ntfsdir.c @@ -183,7 +183,7 @@ fs_readdir(fs_volume *_vol, fs_vnode *_node, void *_cookie, struct dirent *buf, TRACE("fs_readdir - ENTER (sizeof(buf)=%d, bufsize=%d, num=%d\n", sizeof(buf), bufsize, *num); - if (!ns || !node || !cookie || !num || bufsize < sizeof(buf)) { + if (!ns || !node || !cookie || !num || bufsize < sizeof(*buf)) { result = EINVAL; goto exit; } From 599150a3fc4811bd8e66777cf9f1a4e6c371d947 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 18:13:49 -0400 Subject: [PATCH 10/18] CID 701957: opendir() NULL returns weren't accounted for. --- src/tools/rm_attrs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/rm_attrs.cpp b/src/tools/rm_attrs.cpp index 49a696ed45..e25ee9af57 100644 --- a/src/tools/rm_attrs.cpp +++ b/src/tools/rm_attrs.cpp @@ -89,7 +89,7 @@ remove_dir_contents(Path& path, bool force, bool removeAttributes) { // open the dir DIR* dir = opendir(path.GetPath()); - if (dir < 0) { + if (dir == NULL) { fprintf(stderr, "Error: Failed to open dir \"%s\": %s\n", path.GetPath(), strerror(errno)); return; From cb1f2e6525cd8c221a6b4571674d288858a394d4 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 18:27:30 -0400 Subject: [PATCH 11/18] Precedence of operators issues Bitwise OR is taking precedence on Conditional operator. CID 701957, CID 602560 --- .../usb_webcam/addons/sonix/SonixCamDevice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.cpp b/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.cpp index e0f3df6fc4..eb20ace8eb 100644 --- a/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.cpp +++ b/src/add-ons/media/media-add-ons/usb_webcam/addons/sonix/SonixCamDevice.cpp @@ -407,8 +407,8 @@ SonixCamDevice::ReadIIC(uint8 address, uint8 *data) if (!Sensor()) return B_NO_INIT; //dprintf(ID "sonix_i2c_write_multi(, %02x, %d, {%02x, %02x, %02x, %02x, %02x})\n", slave, count, d0, d1, d2, d3, d4); - buffer[0] = (1 << 4) | Sensor()->Use400kHz()?0x01:0 - | Sensor()->UseRealIIC()?0x80:0; + buffer[0] = (1 << 4) | (Sensor()->Use400kHz()?0x01:0) + | (Sensor()->UseRealIIC()?0x80:0); buffer[1] = Sensor()->IICWriteAddress(); buffer[2] = address; buffer[7] = 0x10; /* absolutely no idea why V4L2 driver use that value */ @@ -421,8 +421,8 @@ SonixCamDevice::ReadIIC(uint8 address, uint8 *data) //dprintf(ID "sonix_i2c_write_multi(, %02x, %d, {%02x, %02x, %02x, %02x, %02x})\n", slave, count, d0, d1, d2, d3, d4); - buffer[0] = (1 << 4) | Sensor()->Use400kHz()?0x01:0 - | 0x02 | Sensor()->UseRealIIC()?0x80:0; /* read 1 byte */ + buffer[0] = (1 << 4) | (Sensor()->Use400kHz()?0x01:0) + | 0x02 | (Sensor()->UseRealIIC()?0x80:0); /* read 1 byte */ buffer[1] = Sensor()->IICReadAddress();//IICWriteAddress buffer[7] = 0x10; /* absolutely no idea why V4L2 driver use that value */ err = WriteReg(SN9C102_I2C_SETUP, buffer, 8); From 902a98ad8340bbbef72bf98b6096ed091abf08f1 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 20 Jul 2012 19:32:04 -0400 Subject: [PATCH 12/18] Fix #8753. - Store whether or not the use of the horizontal scrollbar is desired on the class itself. If the CLV was set to use the horizontal scrollbar, and then asked to lay itself out while hidden, it would incorrectly assume the horizontal scrollbar wasn't in use, and consequently repositioned its views such that the horizontal scrollbar and outline view overlapped. --- headers/private/interface/ColumnListView.h | 4 +-- src/kits/interface/ColumnListView.cpp | 35 +++++++++++----------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/headers/private/interface/ColumnListView.h b/headers/private/interface/ColumnListView.h index 33773acd8e..2acbbdbb6c 100644 --- a/headers/private/interface/ColumnListView.h +++ b/headers/private/interface/ColumnListView.h @@ -385,9 +385,8 @@ protected: virtual void DoLayout(); private: - void _Init(bool showHorizontalScrollbar); + void _Init(); void _GetChildViewRects(const BRect& bounds, - bool showHorizontalScrollBar, BRect& titleRect, BRect& outlineRect, BRect& vScrollBarRect, BRect& hScrollBarRect); @@ -404,6 +403,7 @@ private: bool fSortingEnabled; float fLatchWidth; border_style fBorderStyle; + bool fShowingHorizontalScrollBar; }; #endif // _COLUMN_LIST_VIEW_H diff --git a/src/kits/interface/ColumnListView.cpp b/src/kits/interface/ColumnListView.cpp index b31cf0c0a4..c89e77284c 100644 --- a/src/kits/interface/ColumnListView.cpp +++ b/src/kits/interface/ColumnListView.cpp @@ -728,9 +728,10 @@ BColumnListView::BColumnListView(BRect rect, const char* name, fSelectionMessage(NULL), fSortingEnabled(true), fLatchWidth(kLatchWidth), - fBorderStyle(border) + fBorderStyle(border), + fShowingHorizontalScrollBar(showHorizontalScrollbar) { - _Init(showHorizontalScrollbar); + _Init(); } @@ -742,9 +743,10 @@ BColumnListView::BColumnListView(const char* name, uint32 flags, fSelectionMessage(NULL), fSortingEnabled(true), fLatchWidth(kLatchWidth), - fBorderStyle(border) + fBorderStyle(border), + fShowingHorizontalScrollBar(showHorizontalScrollbar) { - _Init(showHorizontalScrollbar); + _Init(); } @@ -1857,8 +1859,8 @@ BColumnListView::PreferredSize() BRect outlineRect; BRect vScrollBarRect; BRect hScrollBarRect; - _GetChildViewRects(Bounds(), !fHorizontalScrollBar->IsHidden(), - titleRect, outlineRect, vScrollBarRect, hScrollBarRect); + _GetChildViewRects(Bounds(), titleRect, outlineRect, vScrollBarRect, + hScrollBarRect); // Start with the extra width for border and scrollbars etc. size.width = titleRect.left - Bounds().left; size.width += Bounds().right - titleRect.right; @@ -1901,8 +1903,8 @@ BColumnListView::DoLayout() BRect outlineRect; BRect vScrollBarRect; BRect hScrollBarRect; - _GetChildViewRects(Bounds(), !fHorizontalScrollBar->IsHidden(), - titleRect, outlineRect, vScrollBarRect, hScrollBarRect); + _GetChildViewRects(Bounds(), titleRect, outlineRect, vScrollBarRect, + hScrollBarRect); fTitleView->MoveTo(titleRect.LeftTop()); fTitleView->ResizeTo(titleRect.Width(), titleRect.Height()); @@ -1923,7 +1925,7 @@ BColumnListView::DoLayout() void -BColumnListView::_Init(bool showHorizontalScrollbar) +BColumnListView::_Init() { SetViewColor(B_TRANSPARENT_32_BIT); @@ -1940,8 +1942,8 @@ BColumnListView::_Init(bool showHorizontalScrollbar) BRect outlineRect; BRect vScrollBarRect; BRect hScrollBarRect; - _GetChildViewRects(bounds, showHorizontalScrollbar, titleRect, outlineRect, - vScrollBarRect, hScrollBarRect); + _GetChildViewRects(bounds, titleRect, outlineRect, vScrollBarRect, + hScrollBarRect); fOutlineView = new OutlineView(outlineRect, &fColumns, &fSortColumns, this); AddChild(fOutlineView); @@ -1959,7 +1961,7 @@ BColumnListView::_Init(bool showHorizontalScrollbar) "horizontal_scroll_bar", fTitleView, 0.0, bounds.Width(), B_HORIZONTAL); AddChild(fHorizontalScrollBar); - if (!showHorizontalScrollbar) + if (!fShowingHorizontalScrollBar) fHorizontalScrollBar->Hide(); fOutlineView->FixScrollBar(true); @@ -1967,9 +1969,8 @@ BColumnListView::_Init(bool showHorizontalScrollbar) void -BColumnListView::_GetChildViewRects(const BRect& bounds, - bool showHorizontalScrollbar, BRect& titleRect, BRect& outlineRect, - BRect& vScrollBarRect, BRect& hScrollBarRect) +BColumnListView::_GetChildViewRects(const BRect& bounds, BRect& titleRect, + BRect& outlineRect, BRect& vScrollBarRect, BRect& hScrollBarRect) { titleRect = bounds; titleRect.bottom = titleRect.top + kTitleHeight; @@ -1980,7 +1981,7 @@ BColumnListView::_GetChildViewRects(const BRect& bounds, outlineRect = bounds; outlineRect.top = titleRect.bottom + 1.0; outlineRect.right -= B_V_SCROLL_BAR_WIDTH; - if (showHorizontalScrollbar) + if (fShowingHorizontalScrollBar) outlineRect.bottom -= B_H_SCROLL_BAR_HEIGHT; vScrollBarRect = bounds; @@ -1989,7 +1990,7 @@ BColumnListView::_GetChildViewRects(const BRect& bounds, #endif vScrollBarRect.left = vScrollBarRect.right - B_V_SCROLL_BAR_WIDTH; - if (showHorizontalScrollbar) + if (fShowingHorizontalScrollBar) vScrollBarRect.bottom -= B_H_SCROLL_BAR_HEIGHT; hScrollBarRect = bounds; From 2d5785ba12f796e972151830a0465b68f3d7e34d Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Fri, 20 Jul 2012 19:41:12 -0400 Subject: [PATCH 13/18] CID 611239: Fix resource leak --- src/kits/media/SoundFile.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/kits/media/SoundFile.cpp b/src/kits/media/SoundFile.cpp index 8a0371673e..7428680f72 100644 --- a/src/kits/media/SoundFile.cpp +++ b/src/kits/media/SoundFile.cpp @@ -361,8 +361,11 @@ BSoundFile::_ref_to_file(const entry_ref *ref) raw = &mf.u.raw_audio; } - if (raw == NULL) + if (raw == NULL) { + delete media; + delete file; return B_ERROR; + } fSamplingRate = (int)raw->frame_rate; fChannelCount = raw->channel_count; From fd2ea9d89306d270d9a16ece3afa0733f29bdaf5 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 20 Jul 2012 22:38:28 -0400 Subject: [PATCH 14/18] Fix #8737. - Updated haikuwebkit package with fixes for context menus and file downloads from aldeck's github repository. --- build/jam/OptionalBuildFeatures | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jam/OptionalBuildFeatures b/build/jam/OptionalBuildFeatures index 60d0b71710..ecf27e82ab 100644 --- a/build/jam/OptionalBuildFeatures +++ b/build/jam/OptionalBuildFeatures @@ -435,7 +435,7 @@ if [ IsOptionalHaikuImagePackageAdded WebPositive ] { HAIKU_BUILD_FEATURE_WEBKIT = 1 ; } -HAIKU_WEBKIT_FILE = haikuwebkit-1.1.2-x86-gcc4-2012-07-11.zip ; +HAIKU_WEBKIT_FILE = haikuwebkit-1.1.3-x86-gcc4-2012-07-20.zip ; if $(HAIKU_BUILD_FEATURE_WEBKIT) { if $(TARGET_ARCH) != x86 { From 667fd4d0eaf904b3928d52c740e0bbc7bdc88f86 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Fri, 20 Jul 2012 23:01:23 -0400 Subject: [PATCH 15/18] Update webkit package with one additional bugfix. --- build/jam/OptionalBuildFeatures | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/jam/OptionalBuildFeatures b/build/jam/OptionalBuildFeatures index ecf27e82ab..398a59ea40 100644 --- a/build/jam/OptionalBuildFeatures +++ b/build/jam/OptionalBuildFeatures @@ -435,7 +435,7 @@ if [ IsOptionalHaikuImagePackageAdded WebPositive ] { HAIKU_BUILD_FEATURE_WEBKIT = 1 ; } -HAIKU_WEBKIT_FILE = haikuwebkit-1.1.3-x86-gcc4-2012-07-20.zip ; +HAIKU_WEBKIT_FILE = haikuwebkit-1.1.3-x86-gcc4-2012-07-20-1.zip ; if $(HAIKU_BUILD_FEATURE_WEBKIT) { if $(TARGET_ARCH) != x86 { From 5ba5e31f8a59cb5f3299edd7af256d0fb4db12aa Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Sat, 21 Jul 2012 02:48:40 +0000 Subject: [PATCH 16/18] usb_serial: clean up usb device identification * Update FTDI, KLSI, Prolific, and Silicon drivers to share a common structural layout for device identification. * More flexible and cleaner than massive switch case statements. * Avoids the problem of different chipsets from identical vendors. --- .../kernel/drivers/ports/usb_serial/FTDI.cpp | 11 +- .../kernel/drivers/ports/usb_serial/FTDI.h | 15 +- .../kernel/drivers/ports/usb_serial/KLSI.h | 15 +- .../drivers/ports/usb_serial/Prolific.h | 40 +- .../drivers/ports/usb_serial/SerialDevice.cpp | 485 ++---------------- .../drivers/ports/usb_serial/SerialDevice.h | 12 + .../drivers/ports/usb_serial/Silicon.cpp | 3 + .../kernel/drivers/ports/usb_serial/Silicon.h | 146 +++++- 8 files changed, 235 insertions(+), 492 deletions(-) diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp index 1d77c605c1..649975bbd9 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp +++ b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.cpp @@ -4,10 +4,16 @@ * * Copyright (c) 2003 by Siarzhuk Zharski * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ + + #include "FTDI.h" #include "FTDIRegs.h" + FTDIDevice::FTDIDevice(usb_device device, uint16 vendorID, uint16 productID, const char *description) : SerialDevice(device, vendorID, productID, description), @@ -46,7 +52,7 @@ FTDIDevice::AddDevice(const usb_configuration_info *config) } if (pipesSet >= 3) { - if (ProductID() == PRODUCT_FTDI_8U100AX) + if (ProductID() == 0x8372) // AU100AX fHeaderLength = 1; else fHeaderLength = 0; @@ -84,7 +90,8 @@ FTDIDevice::SetLineCoding(usb_cdc_line_coding *lineCoding) lineCoding->databits); int32 rate = 0; - if (ProductID() == PRODUCT_FTDI_8U100AX) { + if (ProductID() == 0x8372) { + // AU100AX switch (lineCoding->speed) { case 300: rate = ftdi_sio_b300; break; case 600: rate = ftdi_sio_b600; break; diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h index 05b7cb2a3d..7e32721aed 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h +++ b/src/add-ons/kernel/drivers/ports/usb_serial/FTDI.h @@ -4,16 +4,24 @@ * * Copyright (c) 2003 by Siarzhuk Zharski * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ #ifndef _USB_FTDI_H_ #define _USB_FTDI_H_ + #include "SerialDevice.h" + /* supported vendor and product ids */ -#define VENDOR_FTDI 0x0403 -#define PRODUCT_FTDI_8U100AX 0x8372 -#define PRODUCT_FTDI_8U232AM 0x6001 +#define VENDOR_FTDI 0x0403 + +const usb_serial_device kFTDIDevices[] = { + {VENDOR_FTDI, 0x8372, "FTDI 8U100AX serial converter"}, + {VENDOR_FTDI, 0x6001, "FTDI 8U232AM serial converter"} +}; #define FTDI_BUFFER_SIZE 64 @@ -40,4 +48,5 @@ private: uint8 fStatusLSR; }; + #endif //_USB_FTDI_H_ diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/KLSI.h b/src/add-ons/kernel/drivers/ports/usb_serial/KLSI.h index bc2dce506f..52e1e78700 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/KLSI.h +++ b/src/add-ons/kernel/drivers/ports/usb_serial/KLSI.h @@ -8,13 +8,19 @@ #ifndef _USB_KLSI_H_ #define _USB_KLSI_H_ + #include "SerialDevice.h" + /* supported vendor and product ids */ -#define VENDOR_PALM 0x0830 -#define VENDOR_KLSI 0x05e9 -#define PRODUCT_PALM_CONNECT 0x0080 -#define PRODUCT_KLSI_KL5KUSB105D 0x00c0 +#define VENDOR_PALM 0x0830 +#define VENDOR_KLSI 0x05e9 + +const usb_serial_device kKLSIDevices[] = { + {VENDOR_PALM, 0x0080, "PalmConnect RS232"}, + {VENDOR_KLSI, 0x00c0, "KLSI KL5KUSB105D"} +}; + /* protocol defines */ #define KLSI_SET_REQUEST 0x01 @@ -58,4 +64,5 @@ virtual void OnWrite(const char *buffer, size_t *numBytes, virtual void OnClose(); }; + #endif //_USB_KLSI_H_ diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/Prolific.h b/src/add-ons/kernel/drivers/ports/usb_serial/Prolific.h index 81e6de0843..acae2541f4 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/Prolific.h +++ b/src/add-ons/kernel/drivers/ports/usb_serial/Prolific.h @@ -4,36 +4,43 @@ * * Copyright (c) 2003-2004 by Siarzhuk Zharski * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ #ifndef _USB_PROLIFIC_H_ #define _USB_PROLIFIC_H_ + #include "ACM.h" + /* supported vendor and product ids */ #define VENDOR_PROLIFIC 0x067b -#define VENDOR_IODATA 0x04bb #define VENDOR_ATEN 0x0557 -#define VENDOR_TDK 0x04bf -#define VENDOR_RATOC 0x0584 #define VENDOR_ELECOM 0x056e -#define VENDOR_SOURCENEXT 0x0833 -#define VENDOR_HAL 0x0b41 +#define VENDOR_HAL 0x0b41 +#define VENDOR_IODATA 0x04bb +#define VENDOR_RATOC 0x0584 +#define VENDOR_SOURCENEXT 0x0833 +#define VENDOR_TDK 0x04bf + +const usb_serial_device kProlificDevices[] = { + {VENDOR_PROLIFIC, 0x04bb, "PL2303 Serial adapter (IODATA USB-RSAQ2)"}, + {VENDOR_PROLIFIC, 0x2303, "PL2303 Serial adapter (ATEN/IOGEAR UC232A)"}, + {VENDOR_ATEN, 0x2008, "Aten Serial adapter"}, + {VENDOR_ELECOM, 0x5003, "Elecom UC-SGT"}, + {VENDOR_HAL, 0x0011, "HAL Corporation Crossam2+USB"}, + {VENDOR_IODATA, 0x0a03, "I/O Data USB serial adapter USB-RSAQ1"}, + {VENDOR_RATOC, 0xb000, "Ratoc USB serial adapter REX-USB60"}, + {VENDOR_SOURCENEXT, 0x039f, "SOURCENEXT KeikaiDenwa 8"}, + {VENDOR_SOURCENEXT, 0x039f, "SOURCENEXT KeikaiDenwa 8 with charger"}, + {VENDOR_TDK, 0x0117, "TDK USB-PHS Adapter UHA6400"} +}; -#define PRODUCT_IODATA_USBRSAQ 0x0a03 -#define PRODUCT_PROLIFIC_RSAQ2 0x04bb -#define PRODUCT_ATEN_UC232A 0x2008 -#define PRODUCT_PROLIFIC_PL2303 0x2303 -#define PRODUCT_TDK_UHA6400 0x0117 -#define PRODUCT_RATOC_REXUSB60 0xb000 -#define PRODUCT_ELECOM_UCSGT 0x5003 -#define PRODUCT_SOURCENEXT_KEIKAI8 0x039f -#define PRODUCT_SOURCENEXT_KEIKAI8_CHG 0x012e -#define PRODUCT_HAL_IMR001 0x0011 /* protocol defines */ #define PROLIFIC_SET_REQUEST 0x01 - #define PROLIFIC_BUF_SIZE 256 struct request_item; @@ -55,4 +62,5 @@ private: bool fIsHX; }; + #endif //_USB_PROLIFIC_H_ diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp index 0d76a31550..2d8e62e528 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp +++ b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.cpp @@ -4,7 +4,12 @@ * * Copyright (c) 2003 by Siarzhuk Zharski * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ + + #include #include "SerialDevice.h" @@ -714,451 +719,47 @@ SerialDevice * SerialDevice::MakeDevice(usb_device device, uint16 vendorID, uint16 productID) { - const char *description = NULL; - - switch (vendorID) { - case VENDOR_IODATA: - case VENDOR_ATEN: - case VENDOR_TDK: - case VENDOR_RATOC: - case VENDOR_PROLIFIC: - case VENDOR_ELECOM: - case VENDOR_SOURCENEXT: - case VENDOR_HAL: - { - switch (productID) { - case PRODUCT_PROLIFIC_RSAQ2: - description = "PL2303 Serial adapter (IODATA USB-RSAQ2)"; - break; - case PRODUCT_IODATA_USBRSAQ: - description = "I/O Data USB serial adapter USB-RSAQ1"; - break; - case PRODUCT_ATEN_UC232A: - description = "Aten Serial adapter"; - break; - case PRODUCT_TDK_UHA6400: - description = "TDK USB-PHS Adapter UHA6400"; - break; - case PRODUCT_RATOC_REXUSB60: - description = "Ratoc USB serial adapter REX-USB60"; - break; - case PRODUCT_PROLIFIC_PL2303: - description = "PL2303 Serial adapter (ATEN/IOGEAR UC232A)"; - break; - case PRODUCT_ELECOM_UCSGT: - description = "Elecom UC-SGT"; - break; - case PRODUCT_SOURCENEXT_KEIKAI8: - description = "SOURCENEXT KeikaiDenwa 8"; - break; - case PRODUCT_SOURCENEXT_KEIKAI8_CHG: - description = "SOURCENEXT KeikaiDenwa 8 with charger"; - break; - case PRODUCT_HAL_IMR001: - description = "HAL Corporation Crossam2+USB"; - break; - } - - if (description == NULL) - break; - - return new(std::nothrow) ProlificDevice(device, vendorID, productID, - description); + // FTDI Serial Device + for (uint32 i = 0; i < sizeof(kFTDIDevices) + / sizeof(kFTDIDevices[0]); i++) { + if (vendorID == kFTDIDevices[i].vendorID + && productID == kFTDIDevices[i].productID) { + return new(std::nothrow) FTDIDevice(device, vendorID, productID, + kFTDIDevices[i].deviceName); } - - case VENDOR_FTDI: - { - switch (productID) { - case PRODUCT_FTDI_8U100AX: - description = "FTDI 8U100AX serial converter"; - break; - case PRODUCT_FTDI_8U232AM: - description = "FTDI 8U232AM serial converter"; - break; - } - - if (description == NULL) - break; - - return new(std::nothrow) FTDIDevice(device, vendorID, productID, - description); - } - - case VENDOR_PALM: - case VENDOR_KLSI: - { - switch (productID) { - case PRODUCT_PALM_CONNECT: - description = "PalmConnect RS232"; - break; - case PRODUCT_KLSI_KL5KUSB105D: - description = "KLSI KL5KUSB105D"; - break; - } - - if (description == NULL) - break; - - return new(std::nothrow) KLSIDevice(device, vendorID, productID, - description); - } - - case VENDOR_RENESAS: - { - switch (productID) { - case 0x0053: - description = "Renesas RX610 RX-Stick"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_AKATOM: - { - switch (productID) { - case 0x066A: - description = "AKTAKOM ACE-1001"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_PIRELLI: - { - switch (productID) { - case 0xE000: - case 0xE003: - description = "Pirelli DP-L10 GSM Mobile"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_CYPHERLAB: - { - switch (productID) { - case 0x1000: - description = "Cipherlab CCD Barcode Scanner"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_GEMALTO: - { - switch (productID) { - case 0x5501: - description = "Gemalto contactless smartcard reader"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_DIGIANSWER: - { - switch (productID) { - case 0x000A: - description = "Digianswer ZigBee MAC device"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_MEI: - { - switch (productID) { - case 0x1100: - case 0x1101: - description = "MEI Acceptor"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_DYNASTREAM: - { - switch (productID) { - case 0x1003: - case 0x1004: - case 0x1006: - description = "Dynastream ANT development board"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_KNOCKOFF: - { - switch (productID) { - case 0xAA26: - description = "Knock-off DCU-11"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_SIEMENS: - { - switch (productID) { - case 0x10C5: - description = "Siemens MC60"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_NOKIA: - { - switch (productID) { - case 0xAC70: - description = "Nokia CA-42"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_SILICON: - { - switch (productID) { - case 0x0F91: - case 0x1101: - case 0x1601: - case 0x800A: - case 0x803B: - case 0x8044: - case 0x804E: - case 0x8053: - case 0x8054: - case 0x8066: - case 0x806F: - case 0x807A: - case 0x80CA: - case 0x80DD: - case 0x80F6: - case 0x8115: - case 0x813D: - case 0x813F: - case 0x814A: - case 0x814B: - case 0x8156: - case 0x815E: - case 0x818B: - case 0x819F: - case 0x81A6: - case 0x81AC: - case 0x81AD: - case 0x81C8: - case 0x81E2: - case 0x81E7: - case 0x81E8: - case 0x81F2: - case 0x8218: - case 0x822B: - case 0x826B: - case 0x8293: - case 0x82F9: - case 0x8341: - case 0x8382: - case 0x83A8: - case 0x83D8: - case 0x8411: - case 0x8418: - case 0x846E: - case 0x8477: - case 0x85EA: - case 0x85EB: - case 0x8664: - case 0x8665: - case 0xEA60: - case 0xEA61: - case 0xEA71: - case 0xF001: - case 0xF002: - case 0xF003: - case 0xF004: - description = "Silicon Labs CP210x USB UART converter"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_SILICON2: - { - switch (productID) { - case 0xEA61: - description = "Silicon Labs GPRS USB Modem"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_SILICON3: - { - switch (productID) { - case 0xEA6A: - description = "Silicon Labs GPRS USB Modem 100EU"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_BALTECH: - { - switch (productID) { - case 0x9999: - description = "Balteck card reader"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_OWEN: - { - switch (productID) { - case 0x0004: - description = "Owen AC4 USB-RS485 Converter"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_CLIPSAL: - { - switch (productID) { - case 0x0303: - description = "Clipsal 5500PCU C-Bus USB interface"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_JABLOTRON: - { - switch (productID) { - case 0x0001: - description = "Jablotron serial interface"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_WIENER: - { - switch (productID) { - case 0x0010: - case 0x0011: - case 0x0012: - case 0x0015: - description = "W-IE-NE-R Plein & Baus GmbH device"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_WAVESENSE: - { - switch (productID) { - case 0xAAAA: - description = "Wavesense Jazz blood glucose meter"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_VAISALA: - { - switch (productID) { - case 0x0200: - description = "Vaisala USB instrument"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_ELV: - { - switch (productID) { - case 0xE00F: - description = "ELV USB I²C interface"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_WAGO: - { - switch (productID) { - case 0x07A6: - description = "WAGO 750-923 USB Service"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - case VENDOR_DW700: - { - switch (productID) { - case 0x9500: - description = "DW700 GPS USB interface"; - break; - } - - if (description != NULL) - goto SILICON; - break; - } - -SILICON: - return new(std::nothrow) SiliconDevice(device, vendorID, productID, - description); } + // KLSI Serial Device + for (uint32 i = 0; i < sizeof(kKLSIDevices) + / sizeof(kKLSIDevices[0]); i++) { + if (vendorID == kKLSIDevices[i].vendorID + && productID == kKLSIDevices[i].productID) { + return new(std::nothrow) KLSIDevice(device, vendorID, productID, + kKLSIDevices[i].deviceName); + } + } + + // Prolific Serial Device + for (uint32 i = 0; i < sizeof(kProlificDevices) + / sizeof(kProlificDevices[0]); i++) { + if (vendorID == kProlificDevices[i].vendorID + && productID == kProlificDevices[i].productID) { + return new(std::nothrow) ProlificDevice(device, vendorID, productID, + kProlificDevices[i].deviceName); + } + } + + // Silicon Serial Device + for (uint32 i = 0; i < sizeof(kSiliconDevices) + / sizeof(kSiliconDevices[0]); i++) { + if (vendorID == kSiliconDevices[i].vendorID + && productID == kSiliconDevices[i].productID) { + return new(std::nothrow) SiliconDevice(device, vendorID, productID, + kSiliconDevices[i].deviceName); + } + } + + // Otherwise, return standard ACM device return new(std::nothrow) ACMDevice(device, vendorID, productID, "CDC ACM compatible device"); } diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h index e27ecddb7a..57afc10cb7 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h +++ b/src/add-ons/kernel/drivers/ports/usb_serial/SerialDevice.h @@ -4,12 +4,24 @@ * * Copyright (c) 2003 by Siarzhuk Zharski * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ #ifndef _USB_DEVICE_H_ #define _USB_DEVICE_H_ + #include "Driver.h" + +struct usb_serial_device { + uint32 vendorID; + uint32 productID; + const char* deviceName; +}; + + class SerialDevice { public: SerialDevice(usb_device device, diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.cpp b/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.cpp index 5f3a33e451..f902302f98 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.cpp +++ b/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.cpp @@ -1,6 +1,9 @@ /* * Copyright 2011, Adrien Destugues * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ diff --git a/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.h b/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.h index 3c1897dac4..e12916b94b 100644 --- a/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.h +++ b/src/add-ons/kernel/drivers/ports/usb_serial/Silicon.h @@ -1,12 +1,133 @@ /* * Copyright 2011, Adrien Destugues * Distributed under the terms of the MIT License. + * + * Authors: + * Alexander von Gluck IV, kallisti5@unixzen.com */ #ifndef _USB_SILICON_H_ #define _USB_SILICON_H_ + #include "SerialDevice.h" + +/* supported vendor and product ids */ +#define VENDOR_RENESAS 0x045B +#define VENDOR_AKATOM 0x0471 +#define VENDOR_PIRELLI 0x0489 +#define VENDOR_CYPHERLAB 0x0745 +#define VENDOR_GEMALTO 0x08E6 +#define VENDOR_DIGIANSWER 0x08FD +#define VENDOR_MEI 0x0BED +#define VENDOR_DYNASTREAM 0x0FCF +#define VENDOR_KNOCKOFF 0x10A6 +#define VENDOR_SIEMENS 0x10AB +#define VENDOR_NOKIA 0x10B5 +#define VENDOR_SILICON 0x10C4 +#define VENDOR_SILICON2 0x10C5 +#define VENDOR_SILICON3 0x10CE +#define VENDOR_BALTECH 0x13AD +#define VENDOR_OWEN 0x1555 +#define VENDOR_CLIPSAL 0x166A +#define VENDOR_JABLOTRON 0x16D6 +#define VENDOR_WIENER 0x16DC +#define VENDOR_WAVESENSE 0x17F4 +#define VENDOR_VAISALA 0x1843 +#define VENDOR_ELV 0x18EF +#define VENDOR_WAGO 0x1BE3 +#define VENDOR_DW700 0x413C + +const usb_serial_device kSiliconDevices[] = { + {VENDOR_RENESAS, 0x0053, "Renesas RX610 RX-Stick"}, + {VENDOR_AKATOM, 0x066A, "AKTAKOM ACE-1001"}, + {VENDOR_PIRELLI, 0xE000, "Pirelli DP-L10 GSM Mobile"}, + {VENDOR_PIRELLI, 0xE003, "Pirelli DP-L10 GSM Mobile"}, + {VENDOR_CYPHERLAB, 0x1000, "Cipherlab CCD Barcode Scanner"}, + {VENDOR_GEMALTO, 0x5501, "Gemalto contactless smartcard reader"}, + {VENDOR_DIGIANSWER, 0x000A, "Digianswer ZigBee MAC device"}, + {VENDOR_MEI, 0x1100, "MEI Acceptor"}, + {VENDOR_MEI, 0x1101, "MEI Acceptor"}, + {VENDOR_DYNASTREAM, 0x1003, "Dynastream ANT development board"}, + {VENDOR_DYNASTREAM, 0x1004, "Dynastream ANT development board"}, + {VENDOR_DYNASTREAM, 0x1006, "Dynastream ANT development board"}, + {VENDOR_KNOCKOFF, 0xAA26, "Knock-off DCU-11"}, + {VENDOR_SIEMENS, 0x10C5, "Siemens MC60"}, + {VENDOR_NOKIA, 0xAC70, "Nokia CA-42"}, + {VENDOR_BALTECH, 0x9999, "Balteck card reader"}, + {VENDOR_OWEN, 0x0004, "Owen AC4 USB-RS485 Converter"}, + {VENDOR_CLIPSAL, 0x0303, "Clipsal 5500PCU C-Bus USB interface"}, + {VENDOR_JABLOTRON, 0x0001, "Jablotron serial interface"}, + {VENDOR_WIENER, 0x0010, "W-IE-NE-R Plein & Baus GmbH device"}, + {VENDOR_WIENER, 0x0011, "W-IE-NE-R Plein & Baus GmbH device"}, + {VENDOR_WIENER, 0x0012, "W-IE-NE-R Plein & Baus GmbH device"}, + {VENDOR_WIENER, 0x0015, "W-IE-NE-R Plein & Baus GmbH device"}, + {VENDOR_WAVESENSE, 0xAAAA, "Wavesense Jazz blood glucose meter"}, + {VENDOR_VAISALA, 0x0200, "Vaisala USB instrument"}, + {VENDOR_ELV, 0xE00F, "ELV USB I²C interface"}, + {VENDOR_WAGO, 0x07A6, "WAGO 750-923 USB Service"}, + {VENDOR_DW700, 0x9500, "DW700 GPS USB interface"}, + {VENDOR_SILICON, 0x0F91, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x1101, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x1601, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x800A, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x803B, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8044, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x804E, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8053, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8054, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8066, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x806F, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x807A, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x80CA, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x80DD, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x80F6, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8115, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x813D, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x813F, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x814A, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x814B, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8156, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x815E, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x818B, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x819F, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81A6, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81AC, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81AD, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81C8, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81E2, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81E7, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81E8, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x81F2, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8218, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x822B, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x826B, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8293, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x82F9, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8341, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8382, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x83A8, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x83D8, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8411, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8418, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x846E, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8477, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x85EA, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x85EB, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8664, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0x8665, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xEA60, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xEA61, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xEA71, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xF001, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xF002, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xF003, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON, 0xF004, "Silicon Labs CP210x USB UART converter"}, + {VENDOR_SILICON2, 0xEA61, "Silicon Labs GPRS USB Modem"}, + {VENDOR_SILICON3, 0xEA6A, "Silicon Labs GPRS USB Modem 100EU"} +}; + + class SiliconDevice : public SerialDevice { public: SiliconDevice(usb_device device, uint16 vendorID, @@ -98,30 +219,5 @@ status_t WriteConfig(CP210XRequest request, uint16_t* data, size_t size); }; -#define VENDOR_RENESAS 0x045B -#define VENDOR_AKATOM 0x0471 -#define VENDOR_PIRELLI 0x0489 -#define VENDOR_CYPHERLAB 0x0745 -#define VENDOR_GEMALTO 0x08E6 -#define VENDOR_DIGIANSWER 0x08FD -#define VENDOR_MEI 0x0BED -#define VENDOR_DYNASTREAM 0x0FCF -#define VENDOR_KNOCKOFF 0x10A6 -#define VENDOR_SIEMENS 0x10AB -#define VENDOR_NOKIA 0x10B5 -#define VENDOR_SILICON 0x10C4 -#define VENDOR_SILICON2 0x10C5 -#define VENDOR_SILICON3 0x10CE -#define VENDOR_BALTECH 0x13AD -#define VENDOR_OWEN 0x1555 -#define VENDOR_CLIPSAL 0x166A -#define VENDOR_JABLOTRON 0x16D6 -#define VENDOR_WIENER 0x16DC -#define VENDOR_WAVESENSE 0x17F4 -#define VENDOR_VAISALA 0x1843 -#define VENDOR_ELV 0x18EF -#define VENDOR_WAGO 0x1BE3 -#define VENDOR_DW700 0x413C - #endif //_USB_SILICON_H_ From 0a592099a94eb3727053c0e2ca571398dff75701 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 21 Jul 2012 09:18:34 +0200 Subject: [PATCH 17/18] Debugger: Rework CLI setup to no longer create a BApplication The main thread does now serve the CLI input loop. --- src/apps/debugger/Debugger.cpp | 259 +++++++++++++----- .../cli/CommandLineUserInterface.cpp | 47 +++- .../cli/CommandLineUserInterface.h | 8 +- 3 files changed, 245 insertions(+), 69 deletions(-) diff --git a/src/apps/debugger/Debugger.cpp b/src/apps/debugger/Debugger.cpp index f5617470aa..bac8ac0d13 100644 --- a/src/apps/debugger/Debugger.cpp +++ b/src/apps/debugger/Debugger.cpp @@ -88,6 +88,13 @@ struct Options { }; +struct DebuggedProgramInfo { + team_id team; + thread_id thread; + bool stopInMain; +}; + + static bool parse_arguments(int argc, const char* const* argv, bool noOutput, Options& options) @@ -174,25 +181,104 @@ parse_arguments(int argc, const char* const* argv, bool noOutput, return true; } +static status_t +global_init() +{ + status_t error = TypeHandlerRoster::CreateDefault(); + if (error != B_OK) + return error; + error = ValueHandlerRoster::CreateDefault(); + if (error != B_OK) + return error; + + return B_OK; +} + + +/** + * Finds or runs the program to debug, depending on the command line options. + * @param options The parsed command line options. + * @param _info The info for the program to fill in. Will only be filled in + * if successful. + * @return \c true, if the program has been found or ran. + */ +static bool +get_debugged_program(const Options& options, DebuggedProgramInfo& _info) +{ + team_id team = options.team; + thread_id thread = options.thread; + bool stopInMain = false; + + // If command line arguments were given, start the program. + if (options.commandLineArgc > 0) { + printf("loading program: \"%s\" ...\n", options.commandLineArgv[0]); + // TODO: What about the CWD? + thread = load_program(options.commandLineArgv, + options.commandLineArgc, false); + if (thread < 0) { + // TODO: Notify the user! + fprintf(stderr, "Error: Failed to load program \"%s\": %s\n", + options.commandLineArgv[0], strerror(thread)); + return false; + } + + team = thread; + // main thread ID == team ID + stopInMain = true; + } + + // no parameters given, prompt the user to attach to a team + if (team < 0 && thread < 0) + return false; + + // no team, but a thread -- get team + if (team < 0) { + printf("no team yet, getting thread info...\n"); + thread_info threadInfo; + status_t error = get_thread_info(thread, &threadInfo); + if (error != B_OK) { + // TODO: Notify the user! + fprintf(stderr, "Error: Failed to get info for thread \"%ld\": " + "%s\n", thread, strerror(error)); + return false; + } + + team = threadInfo.team; + } + printf("team: %ld, thread: %ld\n", team, thread); + + _info.team = team; + _info.thread = thread; + _info.stopInMain = stopInMain; + return true; +} + + +/** + * Creates a TeamDebugger for the given team. If userInterface is given, + * that user interface is used (the caller retains its reference), otherwise + * a graphical user interface is created. + */ static TeamDebugger* start_team_debugger(team_id teamID, SettingsManager* settingsManager, TeamDebugger::Listener* listener, thread_id threadID = -1, - bool stopInMain = false, bool useCLI = false) + bool stopInMain = false, UserInterface* userInterface = NULL) { if (teamID < 0) return NULL; - UserInterface* userInterface = useCLI - ? (UserInterface*)new(std::nothrow) CommandLineUserInterface - : (UserInterface*)new(std::nothrow) GraphicalUserInterface; - + BReference userInterfaceReference; if (userInterface == NULL) { - // TODO: Notify the user! - fprintf(stderr, "Error: Out of memory!\n"); - return NULL; + userInterface = new(std::nothrow) GraphicalUserInterface; + if (userInterface == NULL) { + // TODO: Notify the user! + fprintf(stderr, "Error: Out of memory!\n"); + return NULL; + } + + userInterfaceReference.SetTo(userInterface, true); } - BReference userInterfaceReference(userInterface, true); status_t error = B_NO_MEMORY; @@ -213,6 +299,7 @@ start_team_debugger(team_id teamID, SettingsManager* settingsManager, return debugger; } + // #pragma mark - Debugger application class @@ -247,6 +334,26 @@ private: }; +// #pragma mark - CliDebugger + + +class CliDebugger : private TeamDebugger::Listener { +public: + CliDebugger(); + ~CliDebugger(); + + bool Run(const Options& options); + +private: + // TeamDebugger::Listener + virtual void TeamDebuggerStarted(TeamDebugger* debugger); + virtual void TeamDebuggerQuit(TeamDebugger* debugger); +}; + + +// #pragma mark - Debugger application class + + Debugger::Debugger() : BApplication(kDebuggerSignature), @@ -266,11 +373,7 @@ Debugger::~Debugger() status_t Debugger::Init() { - status_t error = TypeHandlerRoster::CreateDefault(); - if (error != B_OK) - return error; - - error = ValueHandlerRoster::CreateDefault(); + status_t error = global_init(); if (error != B_OK) return error; @@ -348,63 +451,22 @@ Debugger::ArgvReceived(int32 argc, char** argv) return; } - team_id team = options.team; - thread_id thread = options.thread; - bool stopInMain = false; - - // If command line arguments were given, start the program. - if (options.commandLineArgc > 0) { - printf("loading program: \"%s\" ...\n", options.commandLineArgv[0]); - // TODO: What about the CWD? - thread = load_program(options.commandLineArgv, - options.commandLineArgc, false); - if (thread < 0) { - // TODO: Notify the user! - fprintf(stderr, "Error: Failed to load program \"%s\": %s\n", - options.commandLineArgv[0], strerror(thread)); - return; - } - - team = thread; - // main thread ID == team ID - stopInMain = true; - } - - // no parameters given, prompt the user to attach to a team - if (team < 0 && thread < 0) + DebuggedProgramInfo programInfo; + if (!get_debugged_program(options, programInfo)) return; - // If we've got - if (team < 0) { - printf("no team yet, getting thread info...\n"); - thread_info threadInfo; - status_t error = get_thread_info(thread, &threadInfo); - if (error != B_OK) { - // TODO: Notify the user! - fprintf(stderr, "Error: Failed to get info for thread \"%ld\": " - "%s\n", thread, strerror(error)); - return; - } - - team = threadInfo.team; - } - printf("team: %ld, thread: %ld\n", team, thread); - - TeamDebugger* debugger = _FindTeamDebugger(team); + TeamDebugger* debugger = _FindTeamDebugger(programInfo.team); if (debugger != NULL) { - printf("There's already a debugger for team: %ld\n", team); + printf("There's already a debugger for team: %ld\n", programInfo.team); debugger->Activate(); return; } - start_team_debugger(team, &fSettingsManager, this, thread, stopInMain, - options.useCLI); + start_team_debugger(programInfo.team, &fSettingsManager, this, + programInfo.thread, programInfo.stopInMain); } -// TeamDebugger::Listener - - void Debugger::TeamDebuggerStarted(TeamDebugger* debugger) { @@ -480,6 +542,76 @@ Debugger::_FindTeamDebugger(team_id teamID) const } +// #pragma mark - CliDebugger + + +CliDebugger::CliDebugger() +{ +} + + +CliDebugger::~CliDebugger() +{ +} + + +bool +CliDebugger::Run(const Options& options) +{ + // initialize global objects and settings manager + status_t error = global_init(); + if (error != B_OK) { + fprintf(stderr, "Error: Global initialization failed: %s\n", + strerror(error)); + return false; + } + + SettingsManager settingsManager; + error = settingsManager.Init(); + if (error != B_OK) { + fprintf(stderr, "Error: Settings manager initialization failed: " + "%s\n", strerror(error)); + return false; + } + + // create the command line UI + CommandLineUserInterface* userInterface + = new(std::nothrow) CommandLineUserInterface; + if (userInterface == NULL) { + fprintf(stderr, "Error: Out of memory!\n"); + return false; + } + BReference userInterfaceReference(userInterface, true); + + // get/run the program to be debugged and start the team debugger + DebuggedProgramInfo programInfo; + if (!get_debugged_program(options, programInfo)) + return false; + + if (start_team_debugger(programInfo.team, &settingsManager, this, + programInfo.thread, programInfo.stopInMain, userInterface) + == NULL) { + return false; + } + + userInterface->Run(); + + return true; +} + + +void +CliDebugger::TeamDebuggerStarted(TeamDebugger* debugger) +{ +} + + +void +CliDebugger::TeamDebuggerQuit(TeamDebugger* debugger) +{ +} + + // #pragma mark - @@ -495,6 +627,11 @@ main(int argc, const char* const* argv) Options options; parse_arguments(argc, argv, false, options); + if (options.useCLI) { + CliDebugger debugger; + return debugger.Run(options) ? 0 : 1; + } + Debugger app; status_t error = app.Init(); if (error != B_OK) { diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp index ab53011fb2..09db85f913 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.cpp @@ -96,10 +96,11 @@ private: CommandLineUserInterface::CommandLineUserInterface() : - fThread(-1), fTeam(NULL), fListener(NULL), fCommands(20, true), + fShowSemaphore(-1), + fShown(false), fTerminating(false) { } @@ -107,6 +108,8 @@ CommandLineUserInterface::CommandLineUserInterface() CommandLineUserInterface::~CommandLineUserInterface() { + if (fShowSemaphore >= 0) + delete_sem(fShowSemaphore); } @@ -127,9 +130,9 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener) if (error != B_OK) return error; - fThread = spawn_thread(&_InputLoopEntry, "CLI", B_NORMAL_PRIORITY, this); - if (fThread < 0) - return fThread; + fShowSemaphore = create_sem(0, "show CLI"); + if (fShowSemaphore < 0) + return fShowSemaphore; return B_OK; } @@ -138,7 +141,8 @@ CommandLineUserInterface::Init(Team* team, UserInterfaceListener* listener) void CommandLineUserInterface::Show() { - resume_thread(fThread); + fShown = true; + release_sem(fShowSemaphore); } @@ -146,8 +150,18 @@ void CommandLineUserInterface::Terminate() { fTerminating = true; - // TODO: Signal the thread so it wakes up! - wait_for_thread(fThread, NULL); + + if (fShown) { + // TODO: Signal the thread so it wakes up! + + // Wait for input loop to finish. + while (acquire_sem(fShowSemaphore) == B_INTERRUPTED) { + } + } else { + // The main thread will still be blocked in Run(). Unblock it. + delete_sem(fShowSemaphore); + fShowSemaphore = -1; + } } @@ -181,6 +195,25 @@ CommandLineUserInterface::SynchronouslyAskUser(const char* title, } +void +CommandLineUserInterface::Run() +{ + // Wait for the Show() semaphore to be released. + status_t error; + do { + error = acquire_sem(fShowSemaphore); + } while (error == B_INTERRUPTED); + + if (error != B_OK) + return; + + _InputLoop(); + + // Release the Show() semaphore to signal Terminate(). + release_sem(fShowSemaphore); +} + + /*static*/ status_t CommandLineUserInterface::_InputLoopEntry(void* data) { diff --git a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h index b581f36b90..9d0c0714b5 100644 --- a/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h +++ b/src/apps/debugger/user_interface/cli/CommandLineUserInterface.h @@ -40,6 +40,11 @@ public: const char* message, const char* choice1, const char* choice2, const char* choice3); + void Run(); + // Called by the main thread, when + // everything has been set up. Enters the + // input loop. + private: struct CommandEntry; typedef BObjectList CommandList; @@ -63,10 +68,11 @@ private: void _PrintHelp(); private: - thread_id fThread; Team* fTeam; UserInterfaceListener* fListener; CommandList fCommands; + sem_id fShowSemaphore; + bool fShown; bool fTerminating; }; From e6e6f56ccf702fe4bc09821b8064861a200122a8 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sat, 21 Jul 2012 14:09:08 +0100 Subject: [PATCH 18/18] Include compat/sys/kernel.h rather than "kernel.h". Using "kernel.h" was pulling in the private kernel.h header instead, which was causing a build failure on my branch since arch_cpu.h is C++-only there. --- src/libs/compat/freebsd_network/clock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/compat/freebsd_network/clock.c b/src/libs/compat/freebsd_network/clock.c index 91a095429d..fce43ccef2 100644 --- a/src/libs/compat/freebsd_network/clock.c +++ b/src/libs/compat/freebsd_network/clock.c @@ -5,7 +5,8 @@ #include "device.h" -#include "kernel.h" + +#include int ticks;