zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_BeApp.cc
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 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_config.h"
22 
23 #if defined(__BEOS__) || defined(__HAIKU__)
24 
25 /* Handle the BeApp specific portions of the application */
26 
27 #include <AppKit.h>
28 #include <storage/Path.h>
29 #include <storage/Entry.h>
30 #include <unistd.h>
31 
32 #include "SDL_BApp.h" /* SDL_BApp class definition */
33 #include "SDL_BeApp.h"
34 #include "SDL_thread.h"
35 #include "SDL_timer.h"
36 #include "SDL_error.h"
37 
38 #include "../../video/bwindow/SDL_BWin.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 /* Flag to tell whether or not the Be application is active or not */
44 int SDL_BeAppActive = 0;
45 static SDL_Thread *SDL_AppThread = NULL;
46 
47 static int
48 StartBeApp(void *unused)
49 {
50  BApplication *App;
51 
52  App = new SDL_BApp("application/x-SDL-executable");
53 
54  App->Run();
55  delete App;
56  return (0);
57 }
58 
59 /* Initialize the Be Application, if it's not already started */
60 int
61 SDL_InitBeApp(void)
62 {
63  /* Create the BApplication that handles appserver interaction */
64  if (SDL_BeAppActive <= 0) {
65  SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL);
66  if (SDL_AppThread == NULL) {
67  return SDL_SetError("Couldn't create BApplication thread");
68  }
69 
70  /* Change working to directory to that of executable */
71  app_info info;
72  if (B_OK == be_app->GetAppInfo(&info)) {
73  entry_ref ref = info.ref;
74  BEntry entry;
75  if (B_OK == entry.SetTo(&ref)) {
76  BPath path;
77  if (B_OK == path.SetTo(&entry)) {
78  if (B_OK == path.GetParent(&path)) {
79  chdir(path.Path());
80  }
81  }
82  }
83  }
84 
85  do {
86  SDL_Delay(10);
87  } while ((be_app == NULL) || be_app->IsLaunching());
88 
89  /* Mark the application active */
90  SDL_BeAppActive = 0;
91  }
92 
93  /* Increment the application reference count */
95 
96  /* The app is running, and we're ready to go */
97  return (0);
98 }
99 
100 /* Quit the Be Application, if there's nothing left to do */
101 void
102 SDL_QuitBeApp(void)
103 {
104  /* Decrement the application reference count */
105  --SDL_BeAppActive;
106 
107  /* If the reference count reached zero, clean up the app */
108  if (SDL_BeAppActive == 0) {
109  if (SDL_AppThread != NULL) {
110  if (be_app != NULL) { /* Not tested */
111  be_app->PostMessage(B_QUIT_REQUESTED);
112  }
113  SDL_WaitThread(SDL_AppThread, NULL);
114  SDL_AppThread = NULL;
115  }
116  /* be_app should now be NULL since be_app has quit */
117  }
118 }
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 /* SDL_BApp functions */
125 void SDL_BApp::ClearID(SDL_BWin *bwin) {
126  _SetSDLWindow(NULL, bwin->GetID());
127  int32 i = _GetNumWindowSlots() - 1;
128  while(i >= 0 && GetSDLWindow(i) == NULL) {
129  _PopBackWindow();
130  --i;
131  }
132 }
133 
134 #endif /* __BEOS__ */
135 
136 /* vi: set ts=4 sw=4 expandtab: */
#define NULL
Definition: ftobjs.h:61
int SDL_InitBeApp(void)
void SDL_QuitBeApp(void)
int SDL_BeAppActive
GLsizei const GLchar *const * path
Definition: glew.h:5828
DECLSPEC void SDLCALL SDL_WaitThread(SDL_Thread *thread, int *status)
Definition: SDL_thread.c:399
DECLSPEC void SDLCALL SDL_Delay(Uint32 ms)
Wait a specified number of milliseconds before returning.
Definition: SDL_systimer.c:70
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
int32 GetID()
Definition: SDL_BWin.h:409
DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(SDL_ThreadFunction fn, const char *name, void *data)
SDL_Window * GetSDLWindow(int32 winID)
Definition: SDL_BApp.h:188
void ClearID(SDL_BWin *bwin)
GLclampf ref
Definition: gl2ext.h:1455
int i
Definition: pngrutil.c:1377