2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
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
{
29 BApplication(kSignature
),
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
) {
51 fprintf(stderr
, "DebugAnalyzer::ArgvReceived(): Out of "
56 status_t error
= dataSource
->Init(argv
[i
]);
58 fprintf(stderr
, "Failed to create data source for path "
59 "\"%s\": %s\n", argv
[i
], strerror(error
));
64 _CreateWindow(dataSource
);
69 virtual void RefsReceived(BMessage
* message
)
71 printf("RefsReceived()\n");
75 status_t
_CreateWindow(DataSource
* dataSource
)
77 ObjectDeleter
<DataSource
> dataSourceDeleter(dataSource
);
81 window
= new MainWindow(dataSource
);
82 } catch (std::bad_alloc
) {
83 fprintf(stderr
, "DebugAnalyzer::_CreateWindow(): Out of memory!\n");
87 // the data source is owned by the window now
88 dataSourceDeleter
.Detach();
97 virtual void MessageReceived(BMessage
* message
)
99 switch (message
->what
) {
100 case MSG_WINDOW_QUIT
:
101 if (--fWindowCount
== 0)
102 PostMessage(B_QUIT_REQUESTED
);
105 BApplication::MessageReceived(message
);
116 main(int argc
, const char* const* argv
)