2 Simple DirectMedia Layer
3 Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../../SDL_internal.h"
23 #if defined(__HAIKU__)
25 /* Handle the BeApp specific portions of the application */
28 #include <storage/AppFileInfo.h>
29 #include <storage/Path.h>
30 #include <storage/Entry.h>
31 #include <storage/File.h>
34 #include "SDL_BApp.h" /* SDL_BApp class definition */
35 #include "SDL_BeApp.h"
36 #include "SDL_timer.h"
37 #include "SDL_error.h"
39 #include "../../video/haiku/SDL_BWin.h"
45 #include "../../thread/SDL_systhread.h"
47 /* Flag to tell whether or not the Be application is active or not */
48 static int SDL_BeAppActive = 0;
49 static SDL_Thread *SDL_AppThread = NULL;
52 StartBeApp(void *unused)
56 // default application signature
57 const char *signature = "application/x-SDL-executable";
58 // dig resources for correct signature
61 if (get_next_image_info(B_CURRENT_TEAM, &cookie, &info) == B_OK) {
62 BFile f(info.name, O_RDONLY);
63 if (f.InitCheck() == B_OK) {
64 BAppFileInfo app_info(&f);
65 if (app_info.InitCheck() == B_OK) {
66 char sig[B_MIME_TYPE_LENGTH];
67 if (app_info.GetSignature(sig) == B_OK)
68 signature = strndup(sig, B_MIME_TYPE_LENGTH);
73 App = new SDL_BApp(signature);
80 /* Initialize the Be Application, if it's not already started */
84 /* Create the BApplication that handles appserver interaction */
85 if (SDL_BeAppActive <= 0) {
86 SDL_AppThread = SDL_CreateThreadInternal(StartBeApp, "SDLApplication", 0, NULL);
87 if (SDL_AppThread == NULL) {
88 return SDL_SetError("Couldn't create BApplication thread");
91 /* Change working directory to that of executable */
93 if (B_OK == be_app->GetAppInfo(&info)) {
94 entry_ref ref = info.ref;
96 if (B_OK == entry.SetTo(&ref)) {
98 if (B_OK == path.SetTo(&entry)) {
99 if (B_OK == path.GetParent(&path)) {
108 } while ((be_app == NULL) || be_app->IsLaunching());
110 /* Mark the application active */
114 /* Increment the application reference count */
117 /* The app is running, and we're ready to go */
121 /* Quit the Be Application, if there's nothing left to do */
125 /* Decrement the application reference count */
128 /* If the reference count reached zero, clean up the app */
129 if (SDL_BeAppActive == 0) {
130 if (SDL_AppThread != NULL) {
131 if (be_app != NULL) { /* Not tested */
132 be_app->PostMessage(B_QUIT_REQUESTED);
134 SDL_WaitThread(SDL_AppThread, NULL);
135 SDL_AppThread = NULL;
137 /* be_app should now be NULL since be_app has quit */
145 /* SDL_BApp functions */
146 void SDL_BApp::ClearID(SDL_BWin *bwin) {
147 _SetSDLWindow(NULL, bwin->GetID());
148 int32 i = _GetNumWindowSlots() - 1;
149 while(i >= 0 && GetSDLWindow(i) == NULL) {
155 #endif /* __HAIKU__ */
157 /* vi: set ts=4 sw=4 expandtab: */