BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / debuganalyzer / DebugAnalyzer.cpp
blobd31960416520992f4db20ef5bd78cfdbcecb6a43
1 /*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #include <new>
12 #include <Application.h>
14 #include <AutoDeleter.h>
16 #include "DataSource.h"
17 #include "MessageCodes.h"
19 #include "main_window/MainWindow.h"
22 static const char* const kSignature = "application/x-vnd.Haiku-DebugAnalyzer";
25 class DebugAnalyzer : public BApplication {
26 public:
27 DebugAnalyzer()
29 BApplication(kSignature),
30 fWindowCount(0)
34 virtual void ReadyToRun()
36 printf("ReadyToRun()\n");
37 if (fWindowCount == 0 && _CreateWindow(NULL) != B_OK)
38 PostMessage(B_QUIT_REQUESTED);
41 virtual void ArgvReceived(int32 argc, char** argv)
43 printf("ArgvReceived()\n");
44 for (int32 i = 0; i < argc; i++)
45 printf(" arg %" B_PRId32 ": \"%s\"\n", i, argv[i]);
47 for (int32 i = 1; i < argc; i++) {
48 PathDataSource* dataSource = new(std::nothrow) PathDataSource;
49 if (dataSource == NULL) {
50 // no memory
51 fprintf(stderr, "DebugAnalyzer::ArgvReceived(): Out of "
52 "memory!");
53 return;
56 status_t error = dataSource->Init(argv[i]);
57 if (error != B_OK) {
58 fprintf(stderr, "Failed to create data source for path "
59 "\"%s\": %s\n", argv[i], strerror(error));
60 // TODO: Alert!
61 continue;
64 _CreateWindow(dataSource);
69 virtual void RefsReceived(BMessage* message)
71 printf("RefsReceived()\n");
74 private:
75 status_t _CreateWindow(DataSource* dataSource)
77 ObjectDeleter<DataSource> dataSourceDeleter(dataSource);
79 MainWindow* window;
80 try {
81 window = new MainWindow(dataSource);
82 } catch (std::bad_alloc) {
83 fprintf(stderr, "DebugAnalyzer::_CreateWindow(): Out of memory!\n");
84 return B_NO_MEMORY;
87 // the data source is owned by the window now
88 dataSourceDeleter.Detach();
90 window->Show();
92 fWindowCount++;
94 return B_OK;
97 virtual void MessageReceived(BMessage* message)
99 switch (message->what) {
100 case MSG_WINDOW_QUIT:
101 if (--fWindowCount == 0)
102 PostMessage(B_QUIT_REQUESTED);
103 break;
104 default:
105 BApplication::MessageReceived(message);
106 break;
110 private:
111 int32 fWindowCount;
116 main(int argc, const char* const* argv)
118 DebugAnalyzer app;
119 app.Run();
121 return 0;