SDL 2.0
SDL_BeApp.cc
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4
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.
8
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:
12
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.
20*/
21#include "../../SDL_internal.h"
22
23#if defined(__HAIKU__)
24
25/* Handle the BeApp specific portions of the application */
26
27#include <AppKit.h>
28#include <storage/AppFileInfo.h>
29#include <storage/Path.h>
30#include <storage/Entry.h>
31#include <storage/File.h>
32#include <unistd.h>
33
34#include "SDL_BApp.h" /* SDL_BApp class definition */
35#include "SDL_BeApp.h"
36#include "SDL_timer.h"
37#include "SDL_error.h"
38
39#include "../../video/haiku/SDL_BWin.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45#include "../../thread/SDL_systhread.h"
46
47/* Flag to tell whether or not the Be application is active or not */
48static int SDL_BeAppActive = 0;
49static SDL_Thread *SDL_AppThread = NULL;
50
51static int
52StartBeApp(void *unused)
53{
54 BApplication *App;
55
56 // default application signature
57 const char *signature = "application/x-SDL-executable";
58 // dig resources for correct signature
59 image_info info;
60 int32 cookie = 0;
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);
69 }
70 }
71 }
72
73 App = new SDL_BApp(signature);
74
75 App->Run();
76 delete App;
77 return (0);
78}
79
80/* Initialize the Be Application, if it's not already started */
81int
82SDL_InitBeApp(void)
83{
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");
89 }
90
91 /* Change working directory to that of executable */
92 app_info info;
93 if (B_OK == be_app->GetAppInfo(&info)) {
94 entry_ref ref = info.ref;
95 BEntry entry;
96 if (B_OK == entry.SetTo(&ref)) {
97 BPath path;
98 if (B_OK == path.SetTo(&entry)) {
99 if (B_OK == path.GetParent(&path)) {
100 chdir(path.Path());
101 }
102 }
103 }
104 }
105
106 do {
107 SDL_Delay(10);
108 } while ((be_app == NULL) || be_app->IsLaunching());
109
110 /* Mark the application active */
111 SDL_BeAppActive = 0;
112 }
113
114 /* Increment the application reference count */
115 ++SDL_BeAppActive;
116
117 /* The app is running, and we're ready to go */
118 return (0);
119}
120
121/* Quit the Be Application, if there's nothing left to do */
122void
123SDL_QuitBeApp(void)
124{
125 /* Decrement the application reference count */
126 --SDL_BeAppActive;
127
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);
133 }
134 SDL_WaitThread(SDL_AppThread, NULL);
135 SDL_AppThread = NULL;
136 }
137 /* be_app should now be NULL since be_app has quit */
138 }
139}
140
141#ifdef __cplusplus
142}
143#endif
144
145/* SDL_BApp functions */
146void SDL_BApp::ClearID(SDL_BWin *bwin) {
147 _SetSDLWindow(NULL, bwin->GetID());
148 int32 i = _GetNumWindowSlots() - 1;
149 while(i >= 0 && GetSDLWindow(i) == NULL) {
151 --i;
152 }
153}
154
155#endif /* __HAIKU__ */
156
157/* vi: set ts=4 sw=4 expandtab: */
int SDL_InitBeApp(void)
void SDL_QuitBeApp(void)
#define SDL_SetError
#define SDL_Delay
#define SDL_WaitThread
GLfloat f
GLenum GLint ref
GLsizei const GLchar *const * path
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
Definition: SDL_thread.c:429
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:167
void ClearID(SDL_BWin *bwin)
int32 _GetNumWindowSlots()
Definition: SDL_BApp.h:377
void _PopBackWindow()
Definition: SDL_BApp.h:382
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:191
void _SetSDLWindow(SDL_Window *win, int32 winID)
Definition: SDL_BApp.h:373
int32 GetID()
Definition: SDL_BWin.h:434