Removed old app_server files. server/ will be moved on layer up next.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11970 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
bdef3a8ede
commit
13b81f062e
@ -1,4 +0,0 @@
|
||||
SubDir OBOS_TOP src servers app ;
|
||||
|
||||
SubInclude OBOS_TOP src servers app server ;
|
||||
|
@ -1,84 +0,0 @@
|
||||
#include "scheduler.h"
|
||||
#include <stdio.h>
|
||||
#include <AppDefs.h>
|
||||
#include "AppServer.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
AppServer::AppServer(void) : BApplication("application/x-vnd.obe-OBAppServer")
|
||||
{
|
||||
printf("AppServer()\n");
|
||||
}
|
||||
|
||||
AppServer::~AppServer(void)
|
||||
{
|
||||
printf("~AppServer()\n");
|
||||
|
||||
// kill_thread(PicassoID);
|
||||
// kill_thread(InputID);
|
||||
shutdown_desktop();
|
||||
}
|
||||
|
||||
void AppServer::Initialize(void)
|
||||
{
|
||||
printf("AppServer::Initialize()\n");
|
||||
mouseport=create_port(30,"OBpcreate");
|
||||
messageport=create_port(20,"OBpcreate");
|
||||
|
||||
// Set up the Desktop
|
||||
init_desktop(3);
|
||||
/*
|
||||
// Start up the housekeeping threads
|
||||
PicassoID = spawn_thread(Draw, "picasso", B_DISPLAY_PRIORITY, this);
|
||||
if (PicassoID >= 0)
|
||||
resume_thread(PicassoID);
|
||||
|
||||
InputID = spawn_thread(Draw, "poller", B_DISPLAY_PRIORITY, this);
|
||||
if (InputID >= 0)
|
||||
resume_thread(InputID);
|
||||
|
||||
MainLoop();
|
||||
*/
|
||||
}
|
||||
|
||||
void AppServer::MainLoop(void)
|
||||
{
|
||||
printf("AppServer::MainLoop()\n");
|
||||
// Main loop. Monitors the message queue and dispatches as appropriate
|
||||
int32 msgcode;
|
||||
uint8 *msgbuffer=new uint8[65536];
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if (read_port(messageport,&msgcode,msgbuffer,65536)!=0)
|
||||
{
|
||||
printf("Message sent to OB App server: %ld\n",msgcode);
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
break;
|
||||
}
|
||||
}
|
||||
delete msgbuffer;
|
||||
}
|
||||
|
||||
int32 AppServer::Picasso(void *data)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32 AppServer::Poller(void *data)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AppServer::DispatchMessage(BMessage *msg)
|
||||
{
|
||||
printf("AppServer::DispatchMessage():"); msg->PrintToStream();
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
AppServer *obas = new AppServer();
|
||||
obas->Initialize();
|
||||
obas->Run();
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,28 +0,0 @@
|
||||
#ifndef _OPENBEOS_APP_SERVER_H_
|
||||
#define _OPENBEOS_APP_SERVER_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <Application.h>
|
||||
#include "Globals.h"
|
||||
|
||||
class BMessage;
|
||||
class Desktop;
|
||||
|
||||
class AppServer : public BApplication
|
||||
{
|
||||
public:
|
||||
AppServer(void);
|
||||
~AppServer(void);
|
||||
void Initialize(void);
|
||||
void MainLoop(void);
|
||||
port_id messageport,mouseport;
|
||||
static int32 Picasso(void *data);
|
||||
static int32 Poller(void *data);
|
||||
// void Run(void);
|
||||
|
||||
private:
|
||||
void DispatchMessage(BMessage *pcReq);
|
||||
thread_id DrawID, InputID;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,227 +0,0 @@
|
||||
|
||||
/*
|
||||
Screen.cpp:
|
||||
Function implementations of screen functions in InterfaceDefs.h
|
||||
*/
|
||||
#include <InterfaceDefs.h>
|
||||
#include <List.h>
|
||||
#include <Path.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <stdio.h>
|
||||
#include "DisplayDriver.h"
|
||||
#include "DirectDriver.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
class ServerWindow;
|
||||
class ServerBitmap;
|
||||
class ServerLayer;
|
||||
class Workspace;
|
||||
|
||||
//--------------------GLOBALS-------------------------
|
||||
int32 workspace_count, active_workspace;
|
||||
BList desktop;
|
||||
Workspace *pactive_workspace;
|
||||
color_map system_palette;
|
||||
DisplayDriver *gfxdriver;
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
//-------------------INTERNAL CLASS DEFS--------------
|
||||
class Workspace
|
||||
{
|
||||
public:
|
||||
Workspace(void);
|
||||
Workspace(BPath imagepath);
|
||||
~Workspace();
|
||||
|
||||
BList layerlist;
|
||||
BList focuslist;
|
||||
rgb_color bgcolor;
|
||||
screen_info screendata,
|
||||
olddata;
|
||||
};
|
||||
|
||||
DisplayDriver *get_gfxdriver(void)
|
||||
{
|
||||
return gfxdriver;
|
||||
}
|
||||
|
||||
Workspace::Workspace(void)
|
||||
{
|
||||
workspace_count++;
|
||||
|
||||
// default values
|
||||
layerlist.MakeEmpty();
|
||||
focuslist.MakeEmpty();
|
||||
bgcolor.red=51;
|
||||
bgcolor.green=102;
|
||||
bgcolor.blue=160;
|
||||
screendata.mode=B_CMAP8;
|
||||
screendata.spaces=B_8_BIT_640x480;
|
||||
screendata.refresh_rate=60.0;
|
||||
screendata.min_refresh_rate=60.0;
|
||||
screendata.max_refresh_rate=60.0;
|
||||
screendata.h_position=(uchar)50;
|
||||
screendata.v_position=(uchar)50;
|
||||
screendata.h_size=(uchar)50;
|
||||
screendata.v_size=(uchar)50;
|
||||
olddata=screendata;
|
||||
}
|
||||
|
||||
Workspace::~Workspace(void)
|
||||
{
|
||||
workspace_count--;
|
||||
}
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
//-----------------GLOBAL FUNCTION DEFS---------------
|
||||
|
||||
void init_desktop(int8 workspaces)
|
||||
{
|
||||
printf("init_desktop()\n");
|
||||
/*
|
||||
Create the screen bitmap
|
||||
Get framebuffer area info
|
||||
Call setup_screenmode
|
||||
Create top layer for workspace
|
||||
Set cursor
|
||||
Turn mouse on in display driver
|
||||
*/
|
||||
workspace_count=workspaces;
|
||||
if(workspace_count==0)
|
||||
workspace_count++;
|
||||
|
||||
// Instantiate and initialize display driver
|
||||
gfxdriver=new DirectDriver();
|
||||
gfxdriver->Initialize();
|
||||
if(gfxdriver->IsInitialized())
|
||||
printf("Driver initialized\n");
|
||||
else
|
||||
printf("Driver NOT initialized\n");
|
||||
|
||||
// Create the workspaces we're supposed to have
|
||||
for(int8 i=0; i<workspaces; i++)
|
||||
{
|
||||
desktop.AddItem(new Workspace());
|
||||
}
|
||||
|
||||
printf("Added %d workspaces\n", workspaces);
|
||||
// Load workspace preferences here
|
||||
|
||||
|
||||
// Activate workspace 0
|
||||
pactive_workspace=(Workspace *)desktop.ItemAt(0);
|
||||
gfxdriver->SetScreen(pactive_workspace->screendata.spaces);
|
||||
}
|
||||
|
||||
void shutdown_desktop(void)
|
||||
{
|
||||
printf("Shutdown desktop()\n");
|
||||
int32 i,count=desktop.CountItems();
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
if(desktop.ItemAt(i)!=NULL)
|
||||
delete desktop.ItemAt(i);
|
||||
}
|
||||
desktop.MakeEmpty();
|
||||
delete gfxdriver;
|
||||
}
|
||||
|
||||
int32 count_workspaces(void)
|
||||
{
|
||||
return workspace_count;
|
||||
}
|
||||
|
||||
void set_workspace_count(int32 count)
|
||||
{
|
||||
printf("set_workspace_count(%ld)\n",count);
|
||||
if(count<0)
|
||||
return;
|
||||
|
||||
if(count<active_workspace)
|
||||
activate_workspace(count);
|
||||
|
||||
for(int32 i=count+1;i<=workspace_count;i++)
|
||||
{
|
||||
if(desktop.ItemAt(i)!=NULL)
|
||||
{
|
||||
delete desktop.ItemAt(i);
|
||||
desktop.RemoveItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32 current_workspace(void)
|
||||
{
|
||||
return active_workspace;
|
||||
}
|
||||
|
||||
void activate_workspace(int32 workspace)
|
||||
{
|
||||
printf("activate_workspace(%ld)\n",workspace);
|
||||
if(workspace>workspace_count || workspace<0)
|
||||
return;
|
||||
|
||||
Workspace *proposed=(Workspace *)desktop.ItemAt(workspace);
|
||||
|
||||
if(proposed==NULL)
|
||||
return;
|
||||
|
||||
if(pactive_workspace->screendata.spaces != proposed->screendata.spaces)
|
||||
{
|
||||
gfxdriver->SetScreen(proposed->screendata.spaces);
|
||||
}
|
||||
|
||||
// What else needs to go here? --DW
|
||||
|
||||
}
|
||||
|
||||
const color_map *system_colors(void)
|
||||
{
|
||||
return (const color_map *)&system_palette;
|
||||
}
|
||||
|
||||
status_t set_screen_space(int32 index, uint32 res, bool stick = true)
|
||||
{
|
||||
printf("set_screen_space(%ld,%lu, %s)\n",index,res,(stick==true)?"true":"false");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t get_scroll_bar_info(scroll_bar_info *info)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t set_scroll_bar_info(scroll_bar_info *info)
|
||||
{
|
||||
printf("set_scroll_bar_info()\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
bigtime_t idle_time()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void run_select_printer_panel()
|
||||
{
|
||||
}
|
||||
|
||||
void run_add_printer_panel()
|
||||
{
|
||||
}
|
||||
|
||||
void run_be_about()
|
||||
{
|
||||
}
|
||||
|
||||
void set_focus_follows_mouse(bool follow)
|
||||
{
|
||||
printf("set_focus_follows_mouse(%s)\n",(follow==true)?"true":"false");
|
||||
}
|
||||
|
||||
bool focus_follows_mouse()
|
||||
{
|
||||
return false;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef _OBDESKTOP_H_
|
||||
#define _OBDESKTOP_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
class DisplayDriver;
|
||||
|
||||
typedef enum
|
||||
{ PLACE_MANUAL=0,
|
||||
PLACE_SCALE=1,
|
||||
PLACE_TILE=2
|
||||
} wallpaper_placement;
|
||||
|
||||
void init_desktop(int8 workspaces);
|
||||
void shutdown_desktop(void);
|
||||
DisplayDriver *get_gfxdriver(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
color_space mode;
|
||||
BRect frame;
|
||||
uint32 spaces;
|
||||
float min_refresh_rate;
|
||||
float max_refresh_rate;
|
||||
float refresh_rate;
|
||||
uchar h_position;
|
||||
uchar v_position;
|
||||
uchar h_size;
|
||||
uchar v_size;
|
||||
} screen_info;
|
||||
|
||||
|
||||
#endif
|
@ -1,117 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "DirectDriver.h"
|
||||
|
||||
OBAppServerScreen::OBAppServerScreen(status_t *error)
|
||||
: BWindowScreen("DirectDriver",B_32_BIT_800x600,error,true)
|
||||
{
|
||||
redraw=true;
|
||||
}
|
||||
|
||||
OBAppServerScreen::~OBAppServerScreen(void)
|
||||
{
|
||||
}
|
||||
|
||||
void OBAppServerScreen::MessageReceived(BMessage *msg)
|
||||
{
|
||||
msg->PrintToStream();
|
||||
switch(msg->what)
|
||||
{
|
||||
case B_KEY_DOWN:
|
||||
Disconnect();
|
||||
QuitRequested();
|
||||
break;
|
||||
default:
|
||||
BWindowScreen::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OBAppServerScreen::QuitRequested(void)
|
||||
{
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 OBAppServerScreen::Draw(void *data)
|
||||
{
|
||||
OBAppServerScreen *screen=(OBAppServerScreen *)data;
|
||||
for(;;)
|
||||
{
|
||||
if(screen->connected && screen->redraw)
|
||||
{
|
||||
// Draw a sample background
|
||||
screen->Clear(128,128,128);
|
||||
screen->SimWin(BRect(100,100,250,250));
|
||||
screen->redraw=false;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void OBAppServerScreen::ScreenConnected(bool ok)
|
||||
{
|
||||
if(ok==true)
|
||||
connected=true;
|
||||
else
|
||||
connected=false;
|
||||
}
|
||||
|
||||
void OBAppServerScreen::Clear(uint8 red,uint8 green,uint8 blue)
|
||||
{
|
||||
if(!connected) return;
|
||||
}
|
||||
|
||||
void OBAppServerScreen::SimWin(BRect rect)
|
||||
{
|
||||
if(!connected) return;
|
||||
}
|
||||
|
||||
DirectDriver::DirectDriver(void)
|
||||
{
|
||||
printf("DirectDriver()\n");
|
||||
old_space=B_32_BIT_800x600;
|
||||
}
|
||||
|
||||
DirectDriver::~DirectDriver(void)
|
||||
{
|
||||
printf("~DirectDriver()\n");
|
||||
winscreen->Quit();
|
||||
}
|
||||
|
||||
void DirectDriver::Initialize(void)
|
||||
{
|
||||
printf("DirectDriver::Initialize()\n");
|
||||
status_t stat;
|
||||
winscreen=new OBAppServerScreen(&stat);
|
||||
if(stat==B_OK)
|
||||
{
|
||||
is_initialized=true;
|
||||
winscreen->Show();
|
||||
}
|
||||
else
|
||||
delete winscreen;
|
||||
|
||||
if(winscreen->connected==false)
|
||||
return;
|
||||
ginfo=winscreen->CardInfo();
|
||||
for(int8 i=0;i<48;i++)
|
||||
ghooks[i]=winscreen->CardHookAt(i);
|
||||
}
|
||||
|
||||
void DirectDriver::SafeMode(void)
|
||||
{
|
||||
printf("DirectDriver::SafeMode()\n");
|
||||
Reset();
|
||||
}
|
||||
|
||||
void DirectDriver::Reset(void)
|
||||
{
|
||||
printf("DirectDriver::Reset()\n");
|
||||
if(is_initialized)
|
||||
winscreen->Clear(51,102,160);
|
||||
}
|
||||
|
||||
void DirectDriver::SetScreen(uint32 space)
|
||||
{
|
||||
printf("DirectDriver::SetScreen(%lu)\n",space);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
#ifndef _DIRECTDRIVER_H_
|
||||
#define _DIRECTDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <WindowScreen.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <Message.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class OBAppServerScreen : public BWindowScreen
|
||||
{
|
||||
public:
|
||||
OBAppServerScreen(status_t *error);
|
||||
~OBAppServerScreen(void);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested(void);
|
||||
static int32 Draw(void *data);
|
||||
virtual void ScreenConnected(bool connected);
|
||||
|
||||
// Graphics stuff implemented here for the moment
|
||||
void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
void SimWin(BRect rect);
|
||||
|
||||
int32 DrawID;
|
||||
bool redraw,connected;
|
||||
};
|
||||
|
||||
class DirectDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
DirectDriver(void);
|
||||
virtual ~DirectDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void SetScreen(uint32 space);
|
||||
OBAppServerScreen *winscreen;
|
||||
protected:
|
||||
// Original screen info
|
||||
uint32 old_space;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,34 +0,0 @@
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
DisplayDriver::DisplayDriver(void)
|
||||
{
|
||||
is_initialized=false;
|
||||
cursor_visible=false;
|
||||
}
|
||||
|
||||
DisplayDriver::~DisplayDriver(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::Initialize(void)
|
||||
{ // Loading loop to find proper driver
|
||||
|
||||
}
|
||||
|
||||
bool DisplayDriver::IsInitialized(void)
|
||||
{ // Let dev know whether things worked out ok
|
||||
return is_initialized;
|
||||
}
|
||||
|
||||
void DisplayDriver::SafeMode(void)
|
||||
{ // Set video mode to 640x480x256 mode
|
||||
}
|
||||
|
||||
void DisplayDriver::Reset(void)
|
||||
{ // Reloads and restarts driver. Defaults to a safe mode
|
||||
|
||||
}
|
||||
|
||||
void DisplayDriver::SetScreen(uint32 space)
|
||||
{
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
#ifndef _GFX_DRIVER_H_
|
||||
#define _GFX_DRIVER_H_
|
||||
|
||||
#include <GraphicsCard.h>
|
||||
#include "Desktop.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uchar *xormask, *andmask;
|
||||
int32 width, height;
|
||||
int32 hotx, hoty;
|
||||
|
||||
} cursor_data;
|
||||
|
||||
#ifndef HOOK_DEFINE_CURSOR
|
||||
|
||||
#define HOOK_DEFINE_CURSOR 0
|
||||
#define HOOK_MOVE_CURSOR 1
|
||||
#define HOOK_SHOW_CURSOR 2
|
||||
#define HOOK_DRAW_LINE_8BIT 3
|
||||
#define HOOK_DRAW_LINE_16BIT 12
|
||||
#define HOOK_DRAW_LINE_32BIT 4
|
||||
#define HOOK_DRAW_RECT_8BIT 5
|
||||
#define HOOK_DRAW_RECT_16BIT 13
|
||||
#define HOOK_DRAW_RECT_32BIT 6
|
||||
#define HOOK_BLIT 7
|
||||
#define HOOK_DRAW_ARRAY_8BIT 8
|
||||
#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers
|
||||
#define HOOK_DRAW_ARRAY_32BIT 9
|
||||
#define HOOK_SYNC 10
|
||||
#define HOOK_INVERT_RECT 11
|
||||
|
||||
#endif
|
||||
|
||||
class DisplayDriver
|
||||
{
|
||||
public:
|
||||
DisplayDriver(void);
|
||||
virtual ~DisplayDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void SetScreen(uint32 space);
|
||||
|
||||
virtual bool IsInitialized(void);
|
||||
graphics_card_hook ghooks[48];
|
||||
graphics_card_info *ginfo;
|
||||
cursor_data current_cursor;
|
||||
bool cursor_visible;
|
||||
|
||||
protected:
|
||||
bool is_initialized;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef _SERVER_GLOBALS_H_
|
||||
#define _SERVER_GLOBALS_H_
|
||||
|
||||
#include <List.h>
|
||||
BList *gBitmaplist, *gLayerlist;
|
||||
|
||||
#endif
|
@ -1,181 +0,0 @@
|
||||
#include <Rect.h>
|
||||
#include <Point.h>
|
||||
#include "GraphicsHooks.h"
|
||||
//#include "AppServer.h" // for the framebuffer pointer
|
||||
|
||||
// Structs necessary for our hook functions
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
int32 define_cursor(uchar *xormask, uchar *andmask, int32 width,
|
||||
int32 height, int32 hotx, int32 hoty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 move_cursor(int32 screenx, int32 screeny)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 show_cursor(bool flag)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_line_with_8_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint8 colorindex, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom)
|
||||
{
|
||||
if(cliptorect)
|
||||
{ // Do clipping before we start if we're told to
|
||||
BRect rect(clipleft,cliptop,clipright,clipbottom);
|
||||
BPoint start(startx,starty),end(endx,endy);
|
||||
start.ConstrainTo(rect);
|
||||
end.ConstrainTo(rect);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
int32 draw_line_with_32_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint32 color, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom)
|
||||
{
|
||||
if(cliptorect)
|
||||
{ // Do clipping before we start if we're told to
|
||||
BRect rect(clipleft,cliptop,clipright,clipbottom);
|
||||
BPoint start(startx,starty),end(endx,endy);
|
||||
start.ConstrainTo(rect);
|
||||
end.ConstrainTo(rect);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_rect_with_8_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint8 colorindex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_rect_with_32_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint32 color)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 blit(int32 sourcex, int32 sourcey, int32 destinationx,
|
||||
int32 destinationy, int32 width, int32 height)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_array_with_8_bit_depth(indexed_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_array_with_32_bit_depth(rgb_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 sync(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 invert_rect(int32 left, int32 top, int32 right, int32 bottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_line_with_16_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint16 color, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_rect_with_16_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint16 color)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// hook functions not officially-defined, but which should exist
|
||||
int32 draw_array_with_16_bit_depth(high_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_frect_with_8_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint8 colorindex)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_frect_with_16_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint16 color)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32 draw_frect_with_32_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint32 color)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
rgb_color GetPixel_32(BPoint pt)
|
||||
{
|
||||
// pt.x = floor(pt.x / zoom);
|
||||
// pt.y = floor(pt.y / zoom);
|
||||
rgb_color color;
|
||||
|
||||
uint32 pos_bits=uint32 ( (p_active_layer->bitmap->BytesPerRow()*pt.y) + (pt.x*4) );
|
||||
uint8 *s_bits=(uint8*) p_active_layer->bitmap->Bits() + pos_bits;
|
||||
|
||||
color.blue=*s_bits;
|
||||
s_bits++;
|
||||
color.green=*s_bits;
|
||||
s_bits++;
|
||||
color.red=*s_bits;
|
||||
s_bits++;
|
||||
color.alpha=*s_bits;
|
||||
return color;
|
||||
}
|
||||
|
||||
void SetPixel_32(BPoint where, rgb_color color)
|
||||
{
|
||||
// Make some quick-access pointers
|
||||
BBitmap *work_bmp;
|
||||
work_bmp=p_active_layer->bitmap;
|
||||
|
||||
uint8 *bmpdata=(uint8 *)work_bmp->Bits();
|
||||
|
||||
// Check bounds
|
||||
where.ConstrainTo(work_bmp->Bounds());
|
||||
|
||||
// Calculate offset & jump
|
||||
uint32 bitoffset;
|
||||
bitoffset= uint32 ((where.x*4)+(work_bmp->BytesPerRow()*where.y)); //only counts there - it is similar on all lines
|
||||
bmpdata += bitoffset;
|
||||
|
||||
// Assign color data
|
||||
*bmpdata=color.blue;
|
||||
bmpdata++;
|
||||
*bmpdata=color.green;
|
||||
bmpdata++;
|
||||
*bmpdata=color.red;
|
||||
bmpdata++;
|
||||
*bmpdata=color.alpha;
|
||||
}
|
||||
*/
|
@ -1,60 +0,0 @@
|
||||
// Structs necessary for our hook functions
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
typedef struct
|
||||
{ int16 x1,y1,x2,y2;
|
||||
uint8 color;
|
||||
} indexed_color_line;
|
||||
|
||||
typedef struct
|
||||
{ int16 x1,y1,x2,y2;
|
||||
rgb_color color;
|
||||
} rgb_color_line;
|
||||
|
||||
int32 define_cursor(uchar *xormask, uchar *andmask, int32 width,
|
||||
int32 height, int32 hotx, int32 hoty);
|
||||
int32 move_cursor(int32 screenx, int32 screeny);
|
||||
int32 show_cursor(bool flag);
|
||||
int32 draw_line_with_8_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint8 colorindex, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom);
|
||||
int32 draw_line_with_32_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint32 color, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom);
|
||||
int32 draw_rect_with_8_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint8 colorindex);
|
||||
int32 draw_rect_with_32_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint32 color);
|
||||
int32 blit(int32 sourcex, int32 sourcey, int32 destinationx,
|
||||
int32 destinationy, int32 width, int32 height);
|
||||
int32 draw_array_with_8_bit_depth(indexed_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom);
|
||||
int32 draw_array_with_32_bit_depth(rgb_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom);
|
||||
int32 sync(void);
|
||||
int32 invert_rect(int32 left, int32 top, int32 right, int32 bottom);
|
||||
int32 draw_line_with_16_bit_depth(int32 startx, int32 endx,
|
||||
int32 starty, int32 endy, uint16 color, bool cliptorect,
|
||||
int16 clipleft, int16 cliptop, int16 clipright, int16 clipbottom);
|
||||
int32 draw_rect_with_16_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint16 color);
|
||||
|
||||
|
||||
// Not officially-defined hook functions which should be here
|
||||
typedef struct
|
||||
{ int16 x1,y1,x2,y2;
|
||||
uint16 color;
|
||||
} high_color_line;
|
||||
|
||||
int32 draw_array_with_16_bit_depth(high_color_line *array, int32 numitems,
|
||||
bool cliptorect, int16 clipleft, int16 cliptop,
|
||||
int16 clipright, int16 clipbottom);
|
||||
|
||||
int32 draw_frect_with_8_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint8 colorindex);
|
||||
int32 draw_frect_with_16_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint16 color);
|
||||
int32 draw_frect_with_32_bit_depth(int32 left, int32 top, int32 right,
|
||||
int32 bottom, uint32 color);
|
@ -1,74 +0,0 @@
|
||||
#include "Layer.h"
|
||||
|
||||
Layer::Layer(ServerWindow *Win, const char *Name, BRect &Frame, int32 Flags)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::Layer(ServerBitmap *Bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::~Layer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Show(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Hide(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool Layer::IsVisible(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layer::Update(bool ForceUpdate)
|
||||
{
|
||||
}
|
||||
|
||||
bool Layer::IsBackground(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layer::SetFrame(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
||||
BRect Layer::Frame(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
BRect Layer::Bounds(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
void Layer::Invalidate(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::AddRegion(BRegion *Region)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::RemoveRegions(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::UpdateRegions(bool ForceUpdate=true, bool Root=true)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Draw(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
#ifndef _LAYER_H_
|
||||
#define _LAYER_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Region.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class ServerBitmap;
|
||||
class ServerWindow;
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
Layer(ServerWindow *Win, const char *Name, BRect &Frame, int32 Flags);
|
||||
Layer(ServerBitmap *Bitmap);
|
||||
virtual ~Layer(void);
|
||||
|
||||
void Initialize(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
bool IsVisible(void);
|
||||
void Update(bool ForceUpdate);
|
||||
|
||||
bool IsBackground(void);
|
||||
|
||||
virtual void SetFrame(const BRect &Rect);
|
||||
BRect Frame(void);
|
||||
BRect Bounds(void);
|
||||
|
||||
void Invalidate(const BRect &Rect);
|
||||
void AddRegion(BRegion *Region);
|
||||
void RemoveRegions(void);
|
||||
void UpdateRegions(bool ForceUpdate=true, bool Root=true);
|
||||
|
||||
// Render functions:
|
||||
virtual void Draw(const BRect &Rect);
|
||||
|
||||
const char *name;
|
||||
int32 handle;
|
||||
ServerWindow *window; // Window associated with this. NULL for background layer
|
||||
ServerBitmap *bitmap; // Blasted to screen on redraw. We render to this
|
||||
|
||||
BRect frame;
|
||||
|
||||
BRegion *visible, // Everything currently visible
|
||||
*full, // The complete region
|
||||
*update; // Area to be updated at next redraw
|
||||
|
||||
int32 flags; // Various flags for behavior
|
||||
|
||||
// Render state:
|
||||
BPoint penpos;
|
||||
rgb_color high, low, erase;
|
||||
|
||||
int32 drawingmode;
|
||||
};
|
||||
|
||||
Layer *FindLayer(int32 Handle);
|
||||
|
||||
#endif
|
@ -1,134 +0,0 @@
|
||||
#include "ServerBitmap.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
ServerBitmap::ServerBitmap(BRect rect,color_space cspace,int32 BytesPerLine=0)
|
||||
{
|
||||
width=rect.IntegerWidth()+1;
|
||||
height=rect.IntegerHeight()+1;
|
||||
colorspace=cspace;
|
||||
is_vram=false;
|
||||
|
||||
// Big convoluted mess just to handle every color space and dword align
|
||||
// the buffer
|
||||
switch(cspace)
|
||||
{
|
||||
// Buffer is dword-aligned, so nothing need be done
|
||||
// aside from allocate the memory
|
||||
case B_RGB32:
|
||||
case B_RGBA32:
|
||||
case B_RGB32_BIG:
|
||||
case B_RGBA32_BIG:
|
||||
case B_UVL32:
|
||||
case B_UVLA32:
|
||||
case B_LAB32:
|
||||
case B_LABA32:
|
||||
case B_HSI32:
|
||||
case B_HSIA32:
|
||||
case B_HSV32:
|
||||
case B_HSVA32:
|
||||
case B_HLS32:
|
||||
case B_HLSA32:
|
||||
case B_CMY32:
|
||||
case B_CMYA32:
|
||||
case B_CMYK32:
|
||||
|
||||
// 24-bit=32bit with extra 8 bits ignored
|
||||
case B_RGB24_BIG:
|
||||
case B_RGB24:
|
||||
case B_LAB24:
|
||||
case B_UVL24:
|
||||
case B_HSI24:
|
||||
case B_HSV24:
|
||||
case B_HLS24:
|
||||
case B_CMY24:
|
||||
{
|
||||
if(BytesPerLine<(width*4))
|
||||
bytesperline=width*4;
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
break;
|
||||
}
|
||||
// Calculate size and dword-align
|
||||
|
||||
// 1-bit
|
||||
case B_GRAY1:
|
||||
{
|
||||
int32 numbytes=width>>3;
|
||||
if((width % 8) != 0)
|
||||
numbytes++;
|
||||
if(BytesPerLine<numbytes)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (numbytes+i)%4==0)
|
||||
{
|
||||
bytesperline=numbytes+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
|
||||
}
|
||||
|
||||
// 8-bit
|
||||
case B_CMAP8:
|
||||
case B_GRAY8:
|
||||
case B_YUV411:
|
||||
case B_YUV420:
|
||||
case B_YCbCr422:
|
||||
case B_YCbCr411:
|
||||
case B_YCbCr420:
|
||||
case B_YUV422:
|
||||
{
|
||||
if(BytesPerLine<width)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (width+i)%4==0)
|
||||
{
|
||||
bytesperline=width+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
break;
|
||||
}
|
||||
|
||||
// 16-bit
|
||||
case B_YUV9:
|
||||
case B_YUV12:
|
||||
case B_RGB15:
|
||||
case B_RGBA15:
|
||||
case B_RGB16:
|
||||
case B_RGB16_BIG:
|
||||
case B_RGB15_BIG:
|
||||
case B_RGBA15_BIG:
|
||||
case B_YCbCr444:
|
||||
case B_YUV444:
|
||||
{
|
||||
if(BytesPerLine<width*2)
|
||||
{
|
||||
if( (width*2) % 4 !=0)
|
||||
bytesperline=(width+1)*2;
|
||||
else
|
||||
bytesperline=width*2;
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
break;
|
||||
}
|
||||
case B_NO_COLOR_SPACE:
|
||||
break;
|
||||
}
|
||||
buffer=new uint8[bytesperline*height];
|
||||
driver=get_gfxdriver();;
|
||||
}
|
||||
|
||||
ServerBitmap::~ServerBitmap(void)
|
||||
{
|
||||
delete buffer;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#ifndef _SERVER_BITMAP_H_
|
||||
#define _SERVER_BITMAP_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class ServerBitmap
|
||||
{
|
||||
public:
|
||||
ServerBitmap(BRect rect,color_space cspace,int32 BytesPerLine=0);
|
||||
~ServerBitmap(void);
|
||||
|
||||
int32 width,height;
|
||||
int32 bytesperline;
|
||||
color_space colorspace;
|
||||
uint8 *buffer;
|
||||
DisplayDriver *driver;
|
||||
bool is_vram;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,114 +0,0 @@
|
||||
#include <Rect.h>
|
||||
#include "ServerWindow.h"
|
||||
|
||||
ServerWindow::ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort)
|
||||
{
|
||||
}
|
||||
|
||||
ServerWindow::ServerWindow(ServerApp *App, ServerBitmap *Bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
ServerWindow::~ServerWindow(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::PostMessage(BMessage *msg)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ReplaceDecorator(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Quit(void)
|
||||
{
|
||||
}
|
||||
|
||||
const char *ServerWindow::GetTitle(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ServerApp *ServerWindow::GetApp(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMessenger *ServerWindow::GetAppTarget(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ServerWindow::Show(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Hide(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::SetFocus(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ServerWindow::HasFocus(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerWindow::DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::WindowActivated(bool Active)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ScreenModeChanged(const BPoint Resolustion, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::SetFrame(const BRect &Frame)
|
||||
{
|
||||
}
|
||||
|
||||
BRect ServerWindow::Frame(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
thread_id ServerWindow::Run(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
status_t ServerWindow::Lock(void)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t ServerWindow::Unlock(void)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
bool ServerWindow::IsLocked(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerWindow::DispatchMessage(BMessage *msg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerWindow::DispatchMessage(const void *msg, int nCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerWindow::Loop(void)
|
||||
{
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
#ifndef _SERVERWIN_H_
|
||||
#define _SERVERWIN_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
|
||||
class BString;
|
||||
class BMessenger;
|
||||
class BRect;
|
||||
class BPoint;
|
||||
class ServerApp;
|
||||
class ServerBitmap;
|
||||
class WindowDecorator;
|
||||
|
||||
class ServerWindow
|
||||
{
|
||||
public:
|
||||
ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort);
|
||||
ServerWindow(ServerApp *App, ServerBitmap *Bitmap);
|
||||
virtual ~ServerWindow(void);
|
||||
|
||||
void PostMessage(BMessage *msg);
|
||||
void ReplaceDecorator(void);
|
||||
virtual void Quit(void);
|
||||
const char *GetTitle(void);
|
||||
ServerApp *GetApp(void);
|
||||
BMessenger *GetAppTarget(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
void SetFocus(void);
|
||||
bool HasFocus(void);
|
||||
|
||||
void DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace);
|
||||
void WindowActivated(bool Active);
|
||||
void ScreenModeChanged(const BPoint Resolustion, color_space CSpace);
|
||||
|
||||
void SetFrame(const BRect &Frame);
|
||||
BRect Frame(void);
|
||||
|
||||
thread_id Run(void);
|
||||
status_t Lock(void);
|
||||
status_t Unlock(void);
|
||||
bool IsLocked(void);
|
||||
|
||||
bool DispatchMessage(BMessage *msg);
|
||||
bool DispatchMessage(const void *msg, int nCode);
|
||||
|
||||
void Loop(void);
|
||||
|
||||
const char *title;
|
||||
int32 flags;
|
||||
int32 desktop;
|
||||
|
||||
ServerBitmap *userbitmap;
|
||||
ServerApp *app;
|
||||
|
||||
WindowDecorator *decorator;
|
||||
bigtime_t lasthit; // Time of last mouse click
|
||||
|
||||
thread_id thread;
|
||||
port_id rcvport; // Messages from application
|
||||
port_id sendport; // Messages to application
|
||||
BLocker mutex;
|
||||
BMessenger *apptarget;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,177 +0,0 @@
|
||||
#include <AppDefs.h>
|
||||
#include <stdio.h>
|
||||
#include "ServerProtocol.h"
|
||||
|
||||
#include "AppServer.h"
|
||||
#include "ServerApp.h"
|
||||
#include "PortLink.h"
|
||||
|
||||
AppServer::AppServer(void) : BApplication("application/x-vnd.obe-OBAppServer")
|
||||
{
|
||||
printf("AppServer()\n");
|
||||
|
||||
mouseport=create_port(30,"OBpcreate");
|
||||
// messageport=create_port(20,"OBpcreate");
|
||||
messageport=create_port(20,SERVER_PORT_NAME);
|
||||
printf("Server message port: %ld\n",messageport);
|
||||
applist=new BList(0);
|
||||
quitting_server=false;
|
||||
}
|
||||
|
||||
AppServer::~AppServer(void)
|
||||
{
|
||||
printf("~AppServer()\n");
|
||||
|
||||
ServerApp *temp;
|
||||
for(int32 i=0;i<applist->CountItems();i++)
|
||||
{
|
||||
temp=(ServerApp *)applist->ItemAt(i);
|
||||
if(temp!=NULL)
|
||||
delete temp;
|
||||
}
|
||||
delete applist;
|
||||
}
|
||||
|
||||
thread_id AppServer::Run(void)
|
||||
{
|
||||
printf("AppServer::Run()\n");
|
||||
|
||||
MainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AppServer::MainLoop(void)
|
||||
{
|
||||
printf("AppServer::MainLoop()\n");
|
||||
|
||||
// Main loop. Monitors the message queue and dispatches as appropriate
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(messageport);
|
||||
if(buffersize>0)
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(messageport,&msgcode,msgbuffer,buffersize);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case CREATE_APP:
|
||||
case DELETE_APP:
|
||||
case B_QUIT_REQUESTED:
|
||||
DispatchMessage(msgcode,msgbuffer);
|
||||
break;
|
||||
default:
|
||||
printf("Server received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
if(msgcode==DELETE_APP)
|
||||
{
|
||||
if(quitting_server==true && applist->CountItems()==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AppServer::DispatchMessage(int32 code, int8 *buffer)
|
||||
{
|
||||
int8 *index=buffer;
|
||||
switch(code)
|
||||
{
|
||||
case CREATE_APP:
|
||||
{
|
||||
printf("AppServer: Create App\n");
|
||||
|
||||
// Attached data:
|
||||
// 1) port_id - receiver port of a regular app
|
||||
// 2) char * - signature of the regular app
|
||||
|
||||
// Find the necessary data
|
||||
port_id app_port=*((port_id*)index);
|
||||
index+=sizeof(port_id);
|
||||
|
||||
char *app_signature=(char *)index;
|
||||
|
||||
// Create the ServerApp subthread for this app
|
||||
ServerApp *newapp=new ServerApp(app_port,app_signature);
|
||||
applist->AddItem(newapp);
|
||||
newapp->Run();
|
||||
break;
|
||||
}
|
||||
case DELETE_APP:
|
||||
{
|
||||
// Delete a ServerApp. Received only from the respective ServerApp
|
||||
printf("AppServer: Delete App\n");
|
||||
|
||||
// Attached Data:
|
||||
// 1) thread_id - thread ID of the ServerApp to be deleted
|
||||
|
||||
int32 i, appnum=applist->CountItems();
|
||||
ServerApp *srvapp;
|
||||
thread_id srvapp_id=*((thread_id*)buffer);
|
||||
|
||||
// Run through the list of apps and nuke the proper one
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL && srvapp->monitor_thread==srvapp_id)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->RemoveItem(i);
|
||||
delete srvapp;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
printf("Shutdown sequence initiated.\n");
|
||||
// Attached Data:
|
||||
// none
|
||||
|
||||
// We've been asked to quit, so (for now) broadcast to all
|
||||
// test apps to quit
|
||||
PortLink *applink=new PortLink(0);
|
||||
ServerApp *srvapp;
|
||||
int32 i,appnum=applist->CountItems();
|
||||
|
||||
applink->SetOpCode(QUIT_APP);
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL)
|
||||
{
|
||||
applink->SetPort(srvapp->receiver);
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
delete applink;
|
||||
// So when we delete the last ServerApp, we can exit the server
|
||||
quitting_server=true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("Unexpected message %ld (%lx) in AppServer::DispatchMessage()\n",code,code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
AppServer *obas = new AppServer();
|
||||
obas->Run();
|
||||
delete obas;
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
#ifndef _OPENBEOS_APP_SERVER_H_
|
||||
#define _OPENBEOS_APP_SERVER_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <Application.h>
|
||||
#include <List.h>
|
||||
|
||||
class BMessage;
|
||||
class ServerApp;
|
||||
|
||||
class AppServer : public BApplication
|
||||
{
|
||||
public:
|
||||
AppServer(void);
|
||||
~AppServer(void);
|
||||
thread_id Run(void);
|
||||
void MainLoop(void);
|
||||
port_id messageport,mouseport;
|
||||
|
||||
private:
|
||||
void DispatchMessage(int32 code, int8 *buffer);
|
||||
thread_id DrawID, InputID;
|
||||
bool quitting_server;
|
||||
BList *applist;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,438 +0,0 @@
|
||||
/*
|
||||
PortLink.cpp:
|
||||
A helper class for port-based messaging
|
||||
|
||||
------------------------------------------------------------------------
|
||||
How it works:
|
||||
The class utilizes a fixed-size array of PortLinkData object pointers. When
|
||||
data is attached, a new PortLinkData object is allocated and a copy of the
|
||||
passed data is created inside it. When the time comes for the message to be sent,
|
||||
the data is pieced together into a flattened array and written to the port.
|
||||
------------------------------------------------------------------------
|
||||
Data members:
|
||||
|
||||
*attachments[] - fixed-size array of pointers used to hold the attached data
|
||||
opcode - message value which is sent along with any data
|
||||
target - port to which the message is sent when Flush() is called
|
||||
replyport - port used with synchronous messaging - FlushWithReply()
|
||||
bufferlength - total bytes taken up by attachments
|
||||
num_attachments - internal variable which is used to track which "slot"
|
||||
will be the next one to receive an attachment object
|
||||
*/
|
||||
|
||||
#include "PortLink.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
//#define PLDEBUG
|
||||
|
||||
// Internal data storage class for holding attached data whilst it is waiting
|
||||
// to be Flattened() and then Flushed(). There is no need for this to be called outside
|
||||
// the PortLink class.
|
||||
class PortLinkData
|
||||
{
|
||||
public:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
bool Set(void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
PortLink::PortLink(port_id port)
|
||||
{
|
||||
// For this class to be useful (and to prevent a lot of init problems)
|
||||
// we require a port in the constructor
|
||||
target=port;
|
||||
|
||||
// We start out without any data attached to the port message
|
||||
num_attachments=0;
|
||||
opcode=0;
|
||||
bufferlength=0;
|
||||
replyport=create_port(30,"PortLink reply port");
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
// If, for some odd reason, this is deleted with something attached,
|
||||
// free the memory used by the attachments. We do not flush the queue
|
||||
// because the port may no longer be valid in cases such as the app
|
||||
// is in the process of quitting
|
||||
MakeEmpty();
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode(int32 code)
|
||||
{
|
||||
// Sets the message code. This does not change once the message is sent.
|
||||
// Another call to SetOpCode() is required for such things.
|
||||
opcode=code;
|
||||
}
|
||||
|
||||
void PortLink::SetPort(port_id port)
|
||||
{
|
||||
// Sets the target port. While not necessary in most uses, this exists
|
||||
// mostly to prevent flexibility problems
|
||||
target=port;
|
||||
}
|
||||
|
||||
port_id PortLink::GetPort(void)
|
||||
{
|
||||
// Simply returns the port at which the object is pointed.
|
||||
return target;
|
||||
}
|
||||
|
||||
void PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message off to the target, complete with attachments. NOTE:
|
||||
// the recipient must delete all attachments, being the PortLink object assumes
|
||||
// no responsiblity for the attachments once the message is sent.
|
||||
int8 *msgbuffer;
|
||||
int32 size;
|
||||
|
||||
if(num_attachments>0)
|
||||
{
|
||||
FlattenData(&msgbuffer,&size);
|
||||
|
||||
// Dump message to port, reset attachments, and clean up
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,msgbuffer,size,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,msgbuffer,size);
|
||||
MakeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,NULL,0,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message to the target and then waits for a reply. The target will
|
||||
// receive a message with the first item being the port_id to reply to.
|
||||
// NOTE: like Flush(), any attached data must be deleted.
|
||||
|
||||
// Effectively, an Attach() call inlined for changes
|
||||
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
{
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&replyport,sizeof(port_id)))
|
||||
{
|
||||
bufferlength+=sizeof(port_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Flatten() inlined to make some necessary changes
|
||||
int8 *buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=buffer;
|
||||
size_t size=0;
|
||||
|
||||
// attach our port_id first
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
|
||||
// attach everything else
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
}
|
||||
|
||||
// Flush the thing....FOOSH! :P
|
||||
write_port(target,opcode,buffer,size);
|
||||
MakeEmpty();
|
||||
delete buffer;
|
||||
|
||||
// Now we wait for the reply
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
*buffersize=port_buffer_size(replyport);
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buffersize=port_buffer_size_etc(replyport,0,timeout);
|
||||
if(*buffersize==B_TIMED_OUT)
|
||||
{
|
||||
*status=*buffersize;
|
||||
return NULL;
|
||||
}
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
|
||||
// We got this far, so we apparently have some data
|
||||
*status=B_OK;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void PortLink::Attach(void *data, size_t size)
|
||||
{
|
||||
// This is the member called to attach data to a message. Attachments are
|
||||
// treated to be in 'Append' mode, tacking on each attached piece of data
|
||||
// to the end of the list.
|
||||
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
if(size==0)
|
||||
return;
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
// These functions were added for a major convenience in passing common types
|
||||
// Eventually, I'd like to templatize these, but for now, this'll do
|
||||
|
||||
void PortLink::Attach(int32 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int32);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int16 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int16);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int8 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int8);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(float data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(float);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(bool data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(bool);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BRect data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BRect);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BPoint data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BPoint);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::FlattenData(int8 **buffer,int32 *size)
|
||||
{
|
||||
// This function is where all the magic happens, but it is strictly internal.
|
||||
// It iterates through each PortLinkData object and copies it to the main buffer
|
||||
// which ends up, ultimately, being written to the PortLink's target port.
|
||||
|
||||
// skip if there aree no attachments
|
||||
if(bufferlength<1)
|
||||
return;
|
||||
|
||||
*buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=*buffer;
|
||||
PortLinkData *pld;
|
||||
*size=0;
|
||||
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
*size+=pld->buffersize;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::MakeEmpty(void)
|
||||
{
|
||||
// Nukes all the attachments currently held by the PortLink class
|
||||
if(num_attachments!=0)
|
||||
{
|
||||
for(int i=0; i<num_attachments; i++)
|
||||
{
|
||||
delete attachments[i];
|
||||
}
|
||||
}
|
||||
num_attachments=0;
|
||||
bufferlength=0;
|
||||
}
|
||||
|
||||
PortLinkData::PortLinkData(void)
|
||||
{
|
||||
// Initialize object to empty
|
||||
buffersize=0;
|
||||
}
|
||||
|
||||
PortLinkData::~PortLinkData(void)
|
||||
{
|
||||
// Frees the buffer if we actually used the class to store data
|
||||
if(buffersize>0)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool PortLinkData::Set(void *data, size_t size)
|
||||
{
|
||||
// Function copies the passed to the internal buffers for storage
|
||||
if(size>0 && buffersize==0 && data!=NULL)
|
||||
{
|
||||
buffer=(char *)malloc(size);
|
||||
if(buffer==NULL)
|
||||
return false;
|
||||
memcpy(buffer, data, size);
|
||||
buffersize=size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef _PORTLINK_H_
|
||||
#define _PORTLINK_H_
|
||||
|
||||
#include <Errors.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
#ifndef _PORTLINK_BUFFERSIZE
|
||||
#define _PORTLINK_MAX_ATTACHMENTS 50
|
||||
#endif
|
||||
|
||||
class PortLinkData;
|
||||
|
||||
class PortLink
|
||||
{
|
||||
public:
|
||||
PortLink(port_id port);
|
||||
~PortLink(void);
|
||||
void SetOpCode(int32 code);
|
||||
void SetPort(port_id port);
|
||||
port_id GetPort(void);
|
||||
void Flush(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
|
||||
bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
void Attach(void *data, size_t size);
|
||||
void Attach(int32 data);
|
||||
void Attach(int16 data);
|
||||
void Attach(int8 data);
|
||||
void Attach(float data);
|
||||
void Attach(bool data);
|
||||
void Attach(BRect data);
|
||||
void Attach(BPoint data);
|
||||
void MakeEmpty(void);
|
||||
protected:
|
||||
void FlattenData(int8 **buffer,int32 *size);
|
||||
port_id target, replyport;
|
||||
int32 opcode, bufferlength;
|
||||
int num_attachments;
|
||||
PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,31 +0,0 @@
|
||||
Prototype 2: Messaging
|
||||
|
||||
This is the second proof-of-concept prototype for the OpenBeOS app_server. This demonstrates the use of the PortLink class to send messages quickly and how the server manages processes under normal circumstances (ie, not killing a team). Listed at the end of this file is the sequence of events for a particular task, utilizing only 3 types of components: the Server class, ServerApp application-monitoring nodes, and the application itself. All 3 have been built for R5. Although not formally documented, the code is relatively clean and mostly commented.
|
||||
|
||||
Files Included
|
||||
|
||||
OBAppServer: the actual server
|
||||
OBApp: a skeleton of what's supposed to be an app. Implemented only for testing purposes but some concepts may eventually make their way into the real OBOS BApplication class
|
||||
OBHey: Quick-and-dirty app which sends a message code (in decimal) to a specified port. For the sake of reference, B_QUIT_REQUESTED=1599165009.
|
||||
|
||||
Application launch:
|
||||
1) App constructor
|
||||
2) App->server CREATE_APP
|
||||
3) Server spawns ServerApp
|
||||
4) ServerApp->App SET_PORT
|
||||
5) App reinitializes serverlink to SET_PORT port
|
||||
|
||||
Application quit (from app side):
|
||||
1) ->App B_QUIT_REQUESTED
|
||||
2) App -> ServerApp B_QUIT_REQUESTED and quits
|
||||
3) ServerApp -> Server DELETE_APP and quits
|
||||
4) Server removes ServerApp from list and deletes object
|
||||
|
||||
App Server quit:
|
||||
1) Right now: Server->all ServerApps (QUIT_APP)
|
||||
Eventually: Server->Registrar(BROADCAST_QUIT)
|
||||
1a) Right now: ServerApps->Apps(B_QUIT_REQUESTED)
|
||||
2) Server sets internal flag quitting_server to true
|
||||
3) When server receives DELETE_APP, checks to see if any ServerApps are left.
|
||||
4) If no ServerApps are left after deleting the sender of the delete_app message, server checks to see if quitting_server is set to true
|
||||
5) Server exits
|
@ -1,139 +0,0 @@
|
||||
#include <AppDefs.h>
|
||||
#include "ServerApp.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ServerApp::ServerApp(port_id msgport, char *signature)
|
||||
{
|
||||
printf("New ServerApp %s for app at port %ld\n",signature,msgport);
|
||||
|
||||
// need to copy the signature because the message buffer
|
||||
// owns the copy which we are passed as a parameter.
|
||||
if(signature)
|
||||
{
|
||||
app_sig=new char[strlen(signature)];
|
||||
sprintf(app_sig,signature);
|
||||
}
|
||||
else
|
||||
{
|
||||
app_sig=new char[strlen("Application")];
|
||||
sprintf(app_sig,"Application");
|
||||
}
|
||||
|
||||
// sender is the monitored app's event port
|
||||
sender=msgport;
|
||||
applink=new PortLink(sender);
|
||||
|
||||
// receiver is the port to which the app sends messages for the server
|
||||
receiver=create_port(30,app_sig);
|
||||
printf("ServerApp port for app %s is at %ld\n",app_sig,receiver);
|
||||
if(receiver==B_NO_MORE_PORTS)
|
||||
{
|
||||
// uh-oh. We have a serious problem. Tell the app to quit
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything checks out, so tell the application
|
||||
// where to send future messages
|
||||
applink->SetOpCode(SET_SERVER_PORT);
|
||||
applink->Attach(&receiver,sizeof(port_id));
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
ServerApp::~ServerApp(void)
|
||||
{
|
||||
printf("%s::~ServerApp()\n",app_sig);
|
||||
delete app_sig;
|
||||
delete applink;
|
||||
}
|
||||
|
||||
bool ServerApp::Run(void)
|
||||
{
|
||||
monitor_thread=spawn_thread(MonitorApp,app_sig,B_NORMAL_PRIORITY,this);
|
||||
if(monitor_thread==B_NO_MORE_THREADS || monitor_thread==B_NO_MEMORY)
|
||||
return false;
|
||||
resume_thread(monitor_thread);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 ServerApp::MonitorApp(void *data)
|
||||
{
|
||||
ServerApp *app=(ServerApp *)data;
|
||||
app->Loop();
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ServerApp::Loop(void)
|
||||
{
|
||||
printf("%s::MainLoop()\n",app_sig);
|
||||
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(receiver);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are PortLink messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(receiver,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(receiver,&msgcode,NULL,0);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
// We receive this message when the app we monitor quits
|
||||
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||
if(serverport==B_NAME_NOT_FOUND)
|
||||
{
|
||||
printf("PANIC: ServerApp %s could not find the app_server port!\n",app_sig);
|
||||
break;
|
||||
}
|
||||
printf("ServerApp %s quitting\n",app_sig);
|
||||
applink->SetPort(serverport);
|
||||
applink->SetOpCode(DELETE_APP);
|
||||
applink->Attach(&monitor_thread,sizeof(thread_id));
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
case QUIT_APP:
|
||||
{
|
||||
printf("ServerApp asking %s to quit\n",app_sig);
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("Server received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerApp::DispatchMessage(BMessage *msg)
|
||||
{
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifndef _SRVAPP_H_
|
||||
#define _SRVAPP_H_
|
||||
|
||||
#include <OS.h>
|
||||
class BMessage;
|
||||
class PortLink;
|
||||
|
||||
class ServerApp
|
||||
{
|
||||
public:
|
||||
ServerApp(port_id msgport, char *signature);
|
||||
~ServerApp(void);
|
||||
|
||||
bool Run(void);
|
||||
static int32 MonitorApp(void *data);
|
||||
void Loop(void);
|
||||
void DispatchMessage(BMessage *msg);
|
||||
|
||||
port_id sender,receiver;
|
||||
char *app_sig;
|
||||
thread_id monitor_thread;
|
||||
PortLink *applink;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#ifndef _APPSERVER_PROTOCOL_
|
||||
#define _APPSERVER_PROTOCOL_
|
||||
|
||||
#define CREATE_APP 'drca'
|
||||
#define DELETE_APP 'drda'
|
||||
|
||||
#define SET_SERVER_PORT 'srsp'
|
||||
#define QUIT_APP 'srqa'
|
||||
|
||||
#define SERVER_PORT_NAME "OBappserver"
|
||||
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
#include <SupportDefs.h>
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
Sends a message to the OpenBeOS app_server's message port
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int32 msgcode;
|
||||
|
||||
if(argc>2)
|
||||
{
|
||||
port_id serverport=atoi(argv[1]);
|
||||
msgcode=atoi(argv[2]);
|
||||
|
||||
write_port(serverport,msgcode,NULL,0);
|
||||
printf("Sent %ld to port %ld\n",msgcode,serverport);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("obhey port <message code>\n");
|
||||
return 0;
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
/*
|
||||
OBApp.cpp: App faker for OpenBeOS app_server prototype #2
|
||||
*/
|
||||
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Application.h>
|
||||
#include <Handler.h>
|
||||
#include <Message.h>
|
||||
#include <stdio.h>
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
|
||||
class TestApp
|
||||
{
|
||||
public:
|
||||
TestApp(void);
|
||||
virtual ~TestApp(void);
|
||||
|
||||
void MainLoop(void); // Replaces BLooper message looping
|
||||
|
||||
// Hmm... What's this do? ;^)
|
||||
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
bool Run(void);
|
||||
|
||||
port_id messageport, serverport;
|
||||
char *signature;
|
||||
bool initialized;
|
||||
PortLink *serverlink;
|
||||
};
|
||||
|
||||
|
||||
TestApp::TestApp(void)
|
||||
{
|
||||
printf("TestApp::TestApp()\n");
|
||||
initialized=true;
|
||||
|
||||
// Receives messages from server and others
|
||||
messageport=create_port(50,"msgport");
|
||||
if(messageport==B_BAD_VALUE || messageport==B_NO_MORE_PORTS)
|
||||
{ printf("TestApp: Couldn't create message port\n");
|
||||
initialized=false;
|
||||
}
|
||||
|
||||
// Find the port for the app_server
|
||||
serverport=find_port("OBappserver");
|
||||
if(serverport==B_NAME_NOT_FOUND)
|
||||
{ printf("TestApp: Couldn't find server port\n");
|
||||
initialized=false;
|
||||
|
||||
serverlink=new PortLink(create_port(50,"OBAppServer"));
|
||||
}
|
||||
else
|
||||
{
|
||||
serverlink=new PortLink(serverport);
|
||||
}
|
||||
|
||||
// signature=new char[255];
|
||||
signature=new char[strlen("application/x-vnd.wgp-OBTestApp")];
|
||||
sprintf(signature,"application/x-vnd.wgp-OBTestApp");
|
||||
}
|
||||
|
||||
TestApp::~TestApp(void)
|
||||
{
|
||||
printf("%s::~TestApp()\n",signature);
|
||||
delete signature;
|
||||
|
||||
if(initialized==true)
|
||||
delete serverlink;
|
||||
}
|
||||
|
||||
void TestApp::MainLoop(void)
|
||||
{
|
||||
printf("TestApp::MainLoop()\n");
|
||||
|
||||
// Notify server of app's existence
|
||||
/* BMessage *createmsg=new BMessage(CREATE_APP);
|
||||
createmsg->AddString("signature",signature);
|
||||
// createmsg->AddInt32("PID",PID);
|
||||
createmsg->AddInt32("messageport",messageport);
|
||||
|
||||
printf("port id: %ld\n",messageport);
|
||||
printf("signature: %s\n",signature);
|
||||
|
||||
write_port(serverport,CREATE_APP,createmsg,sizeof(*createmsg));
|
||||
*/
|
||||
serverlink->SetOpCode(CREATE_APP);
|
||||
serverlink->Attach(&messageport,sizeof(port_id));
|
||||
// serverlink.Attach(PID);
|
||||
serverlink->Attach(signature,strlen(signature));
|
||||
serverlink->Flush();
|
||||
|
||||
int32 msgcode;
|
||||
uint8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(messageport);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are flattened messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new uint8[buffersize];
|
||||
bytesread=read_port(messageport,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(messageport,&msgcode,NULL,0);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
// Attached data:
|
||||
// None
|
||||
printf("%s: Quit requested\n",signature);
|
||||
serverlink->SetOpCode(msgcode);
|
||||
serverlink->Flush();
|
||||
break;
|
||||
}
|
||||
case SET_SERVER_PORT:
|
||||
{
|
||||
// Attached data:
|
||||
// port_id - id of the port of the corresponding ServerApp
|
||||
if(buffersize<1)
|
||||
{
|
||||
printf("%s: Set Server Port has no attached data\n",signature);
|
||||
break;
|
||||
}
|
||||
printf("%s: Set Server Port to %ld\n",signature,*((port_id *)msgbuffer));
|
||||
serverport=*((port_id *)msgbuffer);
|
||||
serverlink->SetPort(serverport);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
printf("OBTestApp received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
{
|
||||
printf("Quitting %s\n",signature);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void TestApp::DispatchMessage(BMessage *msg, BHandler *handler)
|
||||
{
|
||||
printf("TestApp::DispatchMessage()\n");
|
||||
}
|
||||
|
||||
void TestApp::MessageReceived(BMessage *msg)
|
||||
{
|
||||
printf("TestApp::MessageReceived()\n");
|
||||
}
|
||||
|
||||
bool TestApp::Run(void)
|
||||
{
|
||||
printf("TestApp::Run()\n");
|
||||
// if(!initialized)
|
||||
// return false;
|
||||
|
||||
MainLoop();
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestApp app;
|
||||
app.Run();
|
||||
}
|
@ -1,438 +0,0 @@
|
||||
/*
|
||||
PortLink.cpp:
|
||||
A helper class for port-based messaging
|
||||
|
||||
------------------------------------------------------------------------
|
||||
How it works:
|
||||
The class utilizes a fixed-size array of PortLinkData object pointers. When
|
||||
data is attached, a new PortLinkData object is allocated and a copy of the
|
||||
passed data is created inside it. When the time comes for the message to be sent,
|
||||
the data is pieced together into a flattened array and written to the port.
|
||||
------------------------------------------------------------------------
|
||||
Data members:
|
||||
|
||||
*attachments[] - fixed-size array of pointers used to hold the attached data
|
||||
opcode - message value which is sent along with any data
|
||||
target - port to which the message is sent when Flush() is called
|
||||
replyport - port used with synchronous messaging - FlushWithReply()
|
||||
bufferlength - total bytes taken up by attachments
|
||||
num_attachments - internal variable which is used to track which "slot"
|
||||
will be the next one to receive an attachment object
|
||||
*/
|
||||
|
||||
#include "PortLink.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
//#define PLDEBUG
|
||||
|
||||
// Internal data storage class for holding attached data whilst it is waiting
|
||||
// to be Flattened() and then Flushed(). There is no need for this to be called outside
|
||||
// the PortLink class.
|
||||
class PortLinkData
|
||||
{
|
||||
public:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
bool Set(void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
PortLink::PortLink(port_id port)
|
||||
{
|
||||
// For this class to be useful (and to prevent a lot of init problems)
|
||||
// we require a port in the constructor
|
||||
target=port;
|
||||
|
||||
// We start out without any data attached to the port message
|
||||
num_attachments=0;
|
||||
opcode=0;
|
||||
bufferlength=0;
|
||||
replyport=create_port(30,"PortLink reply port");
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
// If, for some odd reason, this is deleted with something attached,
|
||||
// free the memory used by the attachments. We do not flush the queue
|
||||
// because the port may no longer be valid in cases such as the app
|
||||
// is in the process of quitting
|
||||
MakeEmpty();
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode(int32 code)
|
||||
{
|
||||
// Sets the message code. This does not change once the message is sent.
|
||||
// Another call to SetOpCode() is required for such things.
|
||||
opcode=code;
|
||||
}
|
||||
|
||||
void PortLink::SetPort(port_id port)
|
||||
{
|
||||
// Sets the target port. While not necessary in most uses, this exists
|
||||
// mostly to prevent flexibility problems
|
||||
target=port;
|
||||
}
|
||||
|
||||
port_id PortLink::GetPort(void)
|
||||
{
|
||||
// Simply returns the port at which the object is pointed.
|
||||
return target;
|
||||
}
|
||||
|
||||
void PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message off to the target, complete with attachments. NOTE:
|
||||
// the recipient must delete all attachments, being the PortLink object assumes
|
||||
// no responsiblity for the attachments once the message is sent.
|
||||
int8 *msgbuffer;
|
||||
int32 size;
|
||||
|
||||
if(num_attachments>0)
|
||||
{
|
||||
FlattenData(&msgbuffer,&size);
|
||||
|
||||
// Dump message to port, reset attachments, and clean up
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,msgbuffer,size,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,msgbuffer,size);
|
||||
MakeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,NULL,0,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message to the target and then waits for a reply. The target will
|
||||
// receive a message with the first item being the port_id to reply to.
|
||||
// NOTE: like Flush(), any attached data must be deleted.
|
||||
|
||||
// Effectively, an Attach() call inlined for changes
|
||||
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
{
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&replyport,sizeof(port_id)))
|
||||
{
|
||||
bufferlength+=sizeof(port_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Flatten() inlined to make some necessary changes
|
||||
int8 *buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=buffer;
|
||||
size_t size=0;
|
||||
|
||||
// attach our port_id first
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
|
||||
// attach everything else
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
}
|
||||
|
||||
// Flush the thing....FOOSH! :P
|
||||
write_port(target,opcode,buffer,size);
|
||||
MakeEmpty();
|
||||
delete buffer;
|
||||
|
||||
// Now we wait for the reply
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
*buffersize=port_buffer_size(replyport);
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buffersize=port_buffer_size_etc(replyport,0,timeout);
|
||||
if(*buffersize==B_TIMED_OUT)
|
||||
{
|
||||
*status=*buffersize;
|
||||
return NULL;
|
||||
}
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
|
||||
// We got this far, so we apparently have some data
|
||||
*status=B_OK;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void PortLink::Attach(void *data, size_t size)
|
||||
{
|
||||
// This is the member called to attach data to a message. Attachments are
|
||||
// treated to be in 'Append' mode, tacking on each attached piece of data
|
||||
// to the end of the list.
|
||||
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
if(size==0)
|
||||
return;
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
// These functions were added for a major convenience in passing common types
|
||||
// Eventually, I'd like to templatize these, but for now, this'll do
|
||||
|
||||
void PortLink::Attach(int32 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int32);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int16 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int16);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int8 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int8);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(float data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(float);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(bool data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(bool);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BRect data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BRect);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BPoint data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BPoint);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::FlattenData(int8 **buffer,int32 *size)
|
||||
{
|
||||
// This function is where all the magic happens, but it is strictly internal.
|
||||
// It iterates through each PortLinkData object and copies it to the main buffer
|
||||
// which ends up, ultimately, being written to the PortLink's target port.
|
||||
|
||||
// skip if there aree no attachments
|
||||
if(bufferlength<1)
|
||||
return;
|
||||
|
||||
*buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=*buffer;
|
||||
PortLinkData *pld;
|
||||
*size=0;
|
||||
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
*size+=pld->buffersize;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::MakeEmpty(void)
|
||||
{
|
||||
// Nukes all the attachments currently held by the PortLink class
|
||||
if(num_attachments!=0)
|
||||
{
|
||||
for(int i=0; i<num_attachments; i++)
|
||||
{
|
||||
delete attachments[i];
|
||||
}
|
||||
}
|
||||
num_attachments=0;
|
||||
bufferlength=0;
|
||||
}
|
||||
|
||||
PortLinkData::PortLinkData(void)
|
||||
{
|
||||
// Initialize object to empty
|
||||
buffersize=0;
|
||||
}
|
||||
|
||||
PortLinkData::~PortLinkData(void)
|
||||
{
|
||||
// Frees the buffer if we actually used the class to store data
|
||||
if(buffersize>0)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool PortLinkData::Set(void *data, size_t size)
|
||||
{
|
||||
// Function copies the passed to the internal buffers for storage
|
||||
if(size>0 && buffersize==0 && data!=NULL)
|
||||
{
|
||||
buffer=(char *)malloc(size);
|
||||
if(buffer==NULL)
|
||||
return false;
|
||||
memcpy(buffer, data, size);
|
||||
buffersize=size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef _PORTLINK_H_
|
||||
#define _PORTLINK_H_
|
||||
|
||||
#include <Errors.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
#ifndef _PORTLINK_BUFFERSIZE
|
||||
#define _PORTLINK_MAX_ATTACHMENTS 50
|
||||
#endif
|
||||
|
||||
class PortLinkData;
|
||||
|
||||
class PortLink
|
||||
{
|
||||
public:
|
||||
PortLink(port_id port);
|
||||
~PortLink(void);
|
||||
void SetOpCode(int32 code);
|
||||
void SetPort(port_id port);
|
||||
port_id GetPort(void);
|
||||
void Flush(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
|
||||
bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
void Attach(void *data, size_t size);
|
||||
void Attach(int32 data);
|
||||
void Attach(int16 data);
|
||||
void Attach(int8 data);
|
||||
void Attach(float data);
|
||||
void Attach(bool data);
|
||||
void Attach(BRect data);
|
||||
void Attach(BPoint data);
|
||||
void MakeEmpty(void);
|
||||
protected:
|
||||
void FlattenData(int8 **buffer,int32 *size);
|
||||
port_id target, replyport;
|
||||
int32 opcode, bufferlength;
|
||||
int num_attachments;
|
||||
PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,12 +0,0 @@
|
||||
#ifndef _APPSERVER_PROTOCOL_
|
||||
#define _APPSERVER_PROTOCOL_
|
||||
|
||||
#define CREATE_APP 'drca'
|
||||
#define DELETE_APP 'drda'
|
||||
|
||||
#define SET_SERVER_PORT 'srsp'
|
||||
#define QUIT_APP 'srqa'
|
||||
|
||||
#define SERVER_PORT_NAME "OBappserver"
|
||||
|
||||
#endif
|
@ -1,295 +0,0 @@
|
||||
#include <Message.h>
|
||||
#include <AppDefs.h>
|
||||
#include "scheduler.h"
|
||||
#include <stdio.h>
|
||||
#include "AppServer.h"
|
||||
#include "ServerApp.h"
|
||||
#include "Desktop.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
AppServer::AppServer(void) : BApplication("application/x-vnd.obe-OBAppServer")
|
||||
{
|
||||
// printf("AppServer()\n");
|
||||
|
||||
mouseport=create_port(30,SERVER_INPUT_PORT);
|
||||
messageport=create_port(20,SERVER_PORT_NAME);
|
||||
// printf("Server message port: %ld\n",messageport);
|
||||
// printf("Server input port: %ld\n",mouseport);
|
||||
applist=new BList(0);
|
||||
quitting_server=false;
|
||||
exit_poller=false;
|
||||
|
||||
// Set up the Desktop
|
||||
init_desktop(3);
|
||||
|
||||
// Spawn our input-polling thread
|
||||
poller_id = spawn_thread(PollerThread, "Poller", B_NORMAL_PRIORITY, this);
|
||||
if (poller_id >= 0)
|
||||
resume_thread(poller_id);
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
AppServer::~AppServer(void)
|
||||
{
|
||||
shutdown_desktop();
|
||||
|
||||
ServerApp *temp;
|
||||
for(int32 i=0;i<applist->CountItems();i++)
|
||||
{
|
||||
temp=(ServerApp *)applist->ItemAt(i);
|
||||
if(temp!=NULL)
|
||||
delete temp;
|
||||
}
|
||||
delete applist;
|
||||
}
|
||||
|
||||
thread_id AppServer::Run(void)
|
||||
{
|
||||
//printf("AppServer::Run()\n");
|
||||
|
||||
MainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AppServer::MainLoop(void)
|
||||
{
|
||||
// Main loop (duh). Monitors the message queue and dispatches as appropriate.
|
||||
// Input messages are handled by the poller, however.
|
||||
|
||||
//printf("AppServer::MainLoop()\n");
|
||||
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(messageport);
|
||||
if(buffersize>0)
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(messageport,&msgcode,msgbuffer,buffersize);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case CREATE_APP:
|
||||
case DELETE_APP:
|
||||
case B_QUIT_REQUESTED:
|
||||
DispatchMessage(msgcode,msgbuffer);
|
||||
break;
|
||||
default:
|
||||
//printf("Server received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
if(msgcode==DELETE_APP || msgcode==B_QUIT_REQUESTED)
|
||||
{
|
||||
if(quitting_server==true && applist->CountItems()==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Make sure our polling thread has exited
|
||||
if(find_thread("Poller")!=B_NAME_NOT_FOUND)
|
||||
kill_thread(poller_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AppServer::DispatchMessage(int32 code, int8 *buffer)
|
||||
{
|
||||
int8 *index=buffer;
|
||||
switch(code)
|
||||
{
|
||||
case CREATE_APP:
|
||||
{
|
||||
// Create the ServerApp to node monitor a new BApplication
|
||||
|
||||
//printf("AppServer: Create App\n");
|
||||
|
||||
// Attached data:
|
||||
// 1) port_id - receiver port of a regular app
|
||||
// 2) char * - signature of the regular app
|
||||
|
||||
// Find the necessary data
|
||||
port_id app_port=*((port_id*)index);
|
||||
index+=sizeof(port_id);
|
||||
|
||||
char *app_signature=(char *)index;
|
||||
|
||||
// Create the ServerApp subthread for this app
|
||||
ServerApp *newapp=new ServerApp(app_port,app_signature);
|
||||
applist->AddItem(newapp);
|
||||
newapp->Run();
|
||||
break;
|
||||
}
|
||||
case DELETE_APP:
|
||||
{
|
||||
// Delete a ServerApp. Received only from the respective ServerApp when a
|
||||
// BApplication asks it to quit.
|
||||
|
||||
//printf("AppServer: Delete App\n");
|
||||
|
||||
// Attached Data:
|
||||
// 1) thread_id - thread ID of the ServerApp to be deleted
|
||||
|
||||
int32 i, appnum=applist->CountItems();
|
||||
ServerApp *srvapp;
|
||||
thread_id srvapp_id=*((thread_id*)buffer);
|
||||
|
||||
// Run through the list of apps and nuke the proper one
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL && srvapp->monitor_thread==srvapp_id)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->RemoveItem(i);
|
||||
delete srvapp;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
//printf("Shutdown sequence initiated.\n");
|
||||
|
||||
// Attached Data:
|
||||
// none
|
||||
|
||||
// We've been asked to quit, so (for now) broadcast to all
|
||||
// test apps to quit. This situation will occur only when the server
|
||||
// is compiled as a regular Be application.
|
||||
PortLink *applink=new PortLink(0);
|
||||
ServerApp *srvapp;
|
||||
int32 i,appnum=applist->CountItems();
|
||||
|
||||
applink->SetOpCode(QUIT_APP);
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL)
|
||||
{
|
||||
applink->SetPort(srvapp->receiver);
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
delete applink;
|
||||
// So when we delete the last ServerApp, we can exit the server
|
||||
quitting_server=true;
|
||||
exit_poller=true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//printf("Unexpected message %ld (%lx) in AppServer::DispatchMessage()\n",code,code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AppServer::Poller(void)
|
||||
{
|
||||
// This thread handles nothing but input messages for mouse and keyboard
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL,*index;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(mouseport);
|
||||
if(buffersize>0)
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(mouseport,&msgcode,msgbuffer,buffersize);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case B_MOUSE_DOWN:
|
||||
{
|
||||
//printf("AppServer: Mouse Down\n");
|
||||
|
||||
// Attached data:
|
||||
// 1) int64 - time of mouse click
|
||||
// 2) float - x coordinate of mouse click
|
||||
// 3) float - y coordinate of mouse click
|
||||
// 4) int32 - modifier keys down during click
|
||||
// 5) int32 - buttons down
|
||||
// 6) int32 - number of clicks
|
||||
break;
|
||||
}
|
||||
case B_MOUSE_MOVED:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) int64 - time of mouse click
|
||||
// 2) float - x coordinate of mouse click
|
||||
// 3) float - y coordinate of mouse click
|
||||
// 4) int32 - buttons down
|
||||
|
||||
index=msgbuffer;
|
||||
|
||||
// Throw away the time sent - for now
|
||||
index += sizeof(int64);
|
||||
|
||||
float tempx=0,tempy=0;
|
||||
tempx=*((float*)index);
|
||||
index+=sizeof(float);
|
||||
tempy=*((float*)index);
|
||||
index+=sizeof(float);
|
||||
|
||||
driver->MoveCursorTo((int)tempx,(int)tempy);
|
||||
break;
|
||||
}
|
||||
case B_MOUSE_UP:
|
||||
{
|
||||
//printf("AppServer: Mouse Up\n");
|
||||
|
||||
// Attached data:
|
||||
// 1) int64 - time of mouse click
|
||||
// 2) float - x coordinate of mouse click
|
||||
// 3) float - y coordinate of mouse click
|
||||
// 4) int32 - buttons down
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//printf("Server::Poller received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(exit_poller)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32 AppServer::PollerThread(void *data)
|
||||
{
|
||||
//printf("Starting Poller thread...\n");
|
||||
AppServer *server=(AppServer *)data;
|
||||
|
||||
server->Poller(); // This won't return until it's told to
|
||||
|
||||
//printf("Exiting Poller thread...\n");
|
||||
exit_thread(B_OK);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
AppServer *obas = new AppServer();
|
||||
obas->Run();
|
||||
delete obas;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
#ifndef _OPENBEOS_APP_SERVER_H_
|
||||
#define _OPENBEOS_APP_SERVER_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <Application.h>
|
||||
#include <List.h>
|
||||
|
||||
class BMessage;
|
||||
class ServerApp;
|
||||
class DisplayDriver;
|
||||
|
||||
class AppServer : public BApplication
|
||||
{
|
||||
public:
|
||||
AppServer(void);
|
||||
~AppServer(void);
|
||||
thread_id Run(void);
|
||||
void MainLoop(void);
|
||||
port_id messageport,mouseport;
|
||||
void Poller(void);
|
||||
|
||||
private:
|
||||
void DispatchMessage(int32 code, int8 *buffer);
|
||||
static int32 PollerThread(void *data);
|
||||
|
||||
bool quitting_server;
|
||||
BList *applist;
|
||||
thread_id poller_id;
|
||||
bool exit_poller;
|
||||
DisplayDriver *driver;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,44 +0,0 @@
|
||||
#include <iostream.h>
|
||||
#include <String.h>
|
||||
#include "DebugTools.h"
|
||||
|
||||
void PrintStatusToStream(status_t value)
|
||||
{
|
||||
// Function which simply translates a returned status code into a string
|
||||
// and dumps it to stdout
|
||||
BString outstr;
|
||||
switch(value)
|
||||
{
|
||||
case B_OK:
|
||||
outstr="B_OK ";
|
||||
break;
|
||||
case B_NAME_NOT_FOUND:
|
||||
outstr="B_NAME_NOT_FOUND ";
|
||||
break;
|
||||
case B_BAD_VALUE:
|
||||
outstr="B_BAD_VALUE ";
|
||||
break;
|
||||
case B_ERROR:
|
||||
outstr="B_ERROR ";
|
||||
break;
|
||||
case B_TIMED_OUT:
|
||||
outstr="B_TIMED_OUT ";
|
||||
break;
|
||||
case B_NO_MORE_PORTS:
|
||||
outstr="B_NO_MORE_PORTS ";
|
||||
break;
|
||||
case B_WOULD_BLOCK:
|
||||
outstr="B_WOULD_BLOCK ";
|
||||
break;
|
||||
case B_BAD_PORT_ID:
|
||||
outstr="B_BAD_PORT_ID ";
|
||||
break;
|
||||
case B_BAD_TEAM_ID:
|
||||
outstr="B_BAD_TEAM_ID ";
|
||||
break;
|
||||
default:
|
||||
outstr="undefined status value in debugtools::PrintStatusToStream() ";
|
||||
break;
|
||||
}
|
||||
cout << "Status: " << outstr.String();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
#ifndef _DEBUGTOOLS_H_
|
||||
#define _DEBUGTOOLS_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
void PrintStatusToStream(status_t value);
|
||||
|
||||
#endif
|
@ -1,227 +0,0 @@
|
||||
/*
|
||||
Desktop.cpp:
|
||||
Code necessary to handle the Desktop, defined as the collection of workspaces.
|
||||
*/
|
||||
#include <InterfaceDefs.h>
|
||||
#include <List.h>
|
||||
#include <Path.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <stdio.h>
|
||||
#include "DisplayDriver.h"
|
||||
#include "ViewDriver.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
class ServerWindow;
|
||||
class ServerBitmap;
|
||||
class ServerLayer;
|
||||
class Workspace;
|
||||
|
||||
//--------------------GLOBALS-------------------------
|
||||
int32 workspace_count, active_workspace;
|
||||
BList desktop;
|
||||
Workspace *pactive_workspace;
|
||||
color_map system_palette;
|
||||
ViewDriver *gfxdriver;
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
//-------------------INTERNAL CLASS DEFS--------------
|
||||
class Workspace
|
||||
{
|
||||
public:
|
||||
Workspace(void);
|
||||
Workspace(BPath imagepath);
|
||||
~Workspace();
|
||||
|
||||
BList layerlist;
|
||||
BList focuslist;
|
||||
rgb_color bgcolor;
|
||||
screen_info screendata,
|
||||
olddata;
|
||||
};
|
||||
|
||||
DisplayDriver *get_gfxdriver(void)
|
||||
{
|
||||
return gfxdriver;
|
||||
}
|
||||
|
||||
Workspace::Workspace(void)
|
||||
{
|
||||
workspace_count++;
|
||||
|
||||
// default values
|
||||
layerlist.MakeEmpty();
|
||||
focuslist.MakeEmpty();
|
||||
bgcolor.red=51;
|
||||
bgcolor.green=102;
|
||||
bgcolor.blue=160;
|
||||
screendata.mode=B_CMAP8;
|
||||
screendata.spaces=B_8_BIT_640x480;
|
||||
screendata.refresh_rate=60.0;
|
||||
screendata.min_refresh_rate=60.0;
|
||||
screendata.max_refresh_rate=60.0;
|
||||
screendata.h_position=(uchar)50;
|
||||
screendata.v_position=(uchar)50;
|
||||
screendata.h_size=(uchar)50;
|
||||
screendata.v_size=(uchar)50;
|
||||
olddata=screendata;
|
||||
}
|
||||
|
||||
Workspace::~Workspace(void)
|
||||
{
|
||||
workspace_count--;
|
||||
}
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
//-----------------GLOBAL FUNCTION DEFS---------------
|
||||
|
||||
void init_desktop(int8 workspaces)
|
||||
{
|
||||
workspace_count=workspaces;
|
||||
if(workspace_count==0)
|
||||
workspace_count++;
|
||||
|
||||
// Instantiate and initialize display driver
|
||||
gfxdriver=new ViewDriver();
|
||||
gfxdriver->Initialize();
|
||||
if(gfxdriver->IsInitialized())
|
||||
printf("Driver initialized\n");
|
||||
else
|
||||
printf("Driver NOT initialized\n");
|
||||
|
||||
// Create the workspaces we're supposed to have
|
||||
for(int8 i=0; i<workspaces; i++)
|
||||
{
|
||||
desktop.AddItem(new Workspace());
|
||||
}
|
||||
|
||||
// Load workspace preferences here
|
||||
|
||||
|
||||
// Activate workspace 0
|
||||
pactive_workspace=(Workspace *)desktop.ItemAt(0);
|
||||
gfxdriver->SetScreen(pactive_workspace->screendata.spaces);
|
||||
|
||||
// Clear the screen
|
||||
gfxdriver->Clear(80,85,152);
|
||||
|
||||
// Draw a couple primitives just so we can see something
|
||||
rgb_color color;
|
||||
color.red=255;
|
||||
color.green=0;
|
||||
color.blue=0;
|
||||
color.alpha=255;
|
||||
gfxdriver->FillRect(BRect(10,10,50,50),color);
|
||||
color.green=255;
|
||||
gfxdriver->FillEllipse(BRect(50,10,100,50),color);
|
||||
}
|
||||
|
||||
void shutdown_desktop(void)
|
||||
{
|
||||
int32 i,count=desktop.CountItems();
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
if(desktop.ItemAt(i)!=NULL)
|
||||
delete desktop.ItemAt(i);
|
||||
}
|
||||
desktop.MakeEmpty();
|
||||
gfxdriver->Shutdown();
|
||||
delete gfxdriver;
|
||||
}
|
||||
|
||||
int32 count_workspaces(void)
|
||||
{
|
||||
return workspace_count;
|
||||
}
|
||||
|
||||
void set_workspace_count(int32 count)
|
||||
{
|
||||
//printf("set_workspace_count(%ld)\n",count);
|
||||
if(count<0)
|
||||
return;
|
||||
|
||||
if(count<active_workspace)
|
||||
activate_workspace(count);
|
||||
|
||||
for(int32 i=count+1;i<=workspace_count;i++)
|
||||
{
|
||||
if(desktop.ItemAt(i)!=NULL)
|
||||
{
|
||||
delete desktop.ItemAt(i);
|
||||
desktop.RemoveItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32 current_workspace(void)
|
||||
{
|
||||
return active_workspace;
|
||||
}
|
||||
|
||||
void activate_workspace(int32 workspace)
|
||||
{
|
||||
//printf("activate_workspace(%ld)\n",workspace);
|
||||
if(workspace>workspace_count || workspace<0)
|
||||
return;
|
||||
|
||||
Workspace *proposed=(Workspace *)desktop.ItemAt(workspace);
|
||||
|
||||
if(proposed==NULL)
|
||||
return;
|
||||
|
||||
if(pactive_workspace->screendata.spaces != proposed->screendata.spaces)
|
||||
{
|
||||
gfxdriver->SetScreen(proposed->screendata.spaces);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const color_map *system_colors(void)
|
||||
{
|
||||
return (const color_map *)&system_palette;
|
||||
}
|
||||
|
||||
status_t set_screen_space(int32 index, uint32 res, bool stick = true)
|
||||
{
|
||||
//printf("set_screen_space(%ld,%lu, %s)\n",index,res,(stick==true)?"true":"false");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t get_scroll_bar_info(scroll_bar_info *info)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t set_scroll_bar_info(scroll_bar_info *info)
|
||||
{
|
||||
//printf("set_scroll_bar_info()\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
bigtime_t idle_time()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void run_select_printer_panel()
|
||||
{
|
||||
}
|
||||
|
||||
void run_add_printer_panel()
|
||||
{
|
||||
}
|
||||
|
||||
void run_be_about()
|
||||
{
|
||||
}
|
||||
|
||||
void set_focus_follows_mouse(bool follow)
|
||||
{
|
||||
//printf("set_focus_follows_mouse(%s)\n",(follow==true)?"true":"false");
|
||||
}
|
||||
|
||||
bool focus_follows_mouse()
|
||||
{
|
||||
return false;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
#ifndef _OBDESKTOP_H_
|
||||
#define _OBDESKTOP_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
class DisplayDriver;
|
||||
|
||||
void init_desktop(int8 workspaces);
|
||||
void shutdown_desktop(void);
|
||||
DisplayDriver *get_gfxdriver(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
color_space mode;
|
||||
BRect frame;
|
||||
uint32 spaces;
|
||||
float min_refresh_rate;
|
||||
float max_refresh_rate;
|
||||
float refresh_rate;
|
||||
uchar h_position;
|
||||
uchar v_position;
|
||||
uchar h_size;
|
||||
uchar v_size;
|
||||
} screen_info;
|
||||
|
||||
|
||||
#endif
|
@ -1,251 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "DirectDriver.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(a) (a<0)?a*-1:a
|
||||
#endif
|
||||
|
||||
OBAppServerScreen::OBAppServerScreen(status_t *error)
|
||||
: BDirectWindow(BRect(100,60,740,540),"OBOS App Server, P3",B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
redraw=true;
|
||||
}
|
||||
|
||||
OBAppServerScreen::~OBAppServerScreen(void)
|
||||
{
|
||||
}
|
||||
|
||||
void OBAppServerScreen::MessageReceived(BMessage *msg)
|
||||
{
|
||||
msg->PrintToStream();
|
||||
switch(msg->what)
|
||||
{
|
||||
case B_KEY_DOWN:
|
||||
// Disconnect();
|
||||
QuitRequested();
|
||||
break;
|
||||
default:
|
||||
BDirectWindow::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OBAppServerScreen::QuitRequested(void)
|
||||
{
|
||||
redraw=false;
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 OBAppServerScreen::Draw(void *data)
|
||||
{
|
||||
OBAppServerScreen *screen=(OBAppServerScreen *)data;
|
||||
for(;;)
|
||||
{
|
||||
if(screen->connected && screen->redraw)
|
||||
{
|
||||
// Draw a sample background
|
||||
screen->redraw=false;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void OBAppServerScreen::DirectConnected(direct_buffer_info *dbinfo)
|
||||
{
|
||||
/* if(ok==true)
|
||||
{
|
||||
connected=true;
|
||||
gcinfo=CardInfo();
|
||||
for(int8 i=0;i<48;i++)
|
||||
gchooks[i]=CardHookAt(i);
|
||||
}
|
||||
else
|
||||
connected=false;
|
||||
*/
|
||||
}
|
||||
|
||||
DirectDriver::DirectDriver(void)
|
||||
{
|
||||
// printf("DirectDriver()\n");
|
||||
// old_space=B_32_BIT_800x600;
|
||||
}
|
||||
|
||||
DirectDriver::~DirectDriver(void)
|
||||
{
|
||||
printf("~DirectDriver()\n");
|
||||
winscreen->Lock();
|
||||
winscreen->Close();
|
||||
}
|
||||
|
||||
void DirectDriver::Initialize(void)
|
||||
{
|
||||
/* printf("DirectDriver::Initialize()\n");
|
||||
status_t stat;
|
||||
winscreen=new OBAppServerScreen(&stat);
|
||||
if(stat==B_OK)
|
||||
winscreen->Show();
|
||||
else
|
||||
delete winscreen;
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::SafeMode(void)
|
||||
{
|
||||
/* printf("DirectDriver::SafeMode()\n");
|
||||
// SetScreen(B_8_BIT_640x480);
|
||||
SetScreen(B_32_BIT_800x600);
|
||||
Reset();
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::Reset(void)
|
||||
{
|
||||
/* printf("DirectDriver::Reset()\n");
|
||||
if(winscreen->connected==true)
|
||||
Clear(51,102,160);
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::SetScreen(uint32 space)
|
||||
{
|
||||
// printf("DirectDriver::SetScreen(%lu)\n",space);
|
||||
// winscreen->SetSpace(space);
|
||||
}
|
||||
|
||||
void DirectDriver::Clear(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
/* // This simply clears the entire screen, utilizing a string and
|
||||
// memcpy to speed things up in a minor way
|
||||
printf("DirectDriver::Clear(%d,%d,%d)\n",red,green,blue);
|
||||
|
||||
if(winscreen->connected==false)
|
||||
return;
|
||||
|
||||
int i,imax,
|
||||
length=winscreen->gcinfo->bytes_per_row;
|
||||
int8 fillstring[length];
|
||||
|
||||
|
||||
switch(winscreen->gcinfo->bits_per_pixel)
|
||||
{
|
||||
case 32:
|
||||
{
|
||||
int32 color,*index32;
|
||||
|
||||
// order is going to be BGRA or ARGB
|
||||
if(winscreen->gcinfo->rgba_order[0]=='B')
|
||||
{
|
||||
// Create the number to quickly create the string
|
||||
|
||||
// BBGG RRAA in RAM => 0xRRAA BBGG
|
||||
color= (int32(red) << 24) + 0xFF0000L + (int32(blue) << 8) + green;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the number to quickly create the string
|
||||
|
||||
// AARR GGBB in RAM
|
||||
color= 0xFF000000L + (int32(red) << 16) + (int32(green) << 8) + blue;
|
||||
}
|
||||
|
||||
// fill the string with the appropriate values
|
||||
index32=(int32 *)fillstring;
|
||||
imax=winscreen->gcinfo->width;
|
||||
|
||||
for(i=0;i<imax;i++)
|
||||
index32[i]=color;
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
/* case 16:
|
||||
{
|
||||
int16 color, *index16;
|
||||
|
||||
if(winscreen->gcinfo->rgba_order[0]=='B')
|
||||
{
|
||||
// Little-endian
|
||||
// G[2:0],B[4:0] R[4:0],G[5:3]
|
||||
|
||||
// Ick. Gotta love all that shifting and masking. :(
|
||||
color= (int16((green & 7)) << 13) +
|
||||
(int16((blue & 31)) << 8) +
|
||||
(int16((red & 31)) << 4) +
|
||||
(int16(green & 56));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Big-endian
|
||||
// R[4:0],G[5:3] G[2:0],B[4:0]
|
||||
color= (int16(red & 31) << 11) +
|
||||
(int16(green & 56) << 8) +
|
||||
(int16(green & 3) << 5) +
|
||||
(blue & 31);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 15:
|
||||
{
|
||||
|
||||
// RGBA_15:
|
||||
// G[2:0],B[4:0] A[0],R[4:0],G[4:3]
|
||||
|
||||
// RGBA_15_BIG:
|
||||
// A[0],R[4:0],G[4:3] G[2:0],B[4:0]
|
||||
break;
|
||||
}
|
||||
*/
|
||||
/* case 8:
|
||||
{
|
||||
// This is both the easiest and hardest:
|
||||
// We fill using memset(), but we have to find the closest match to the
|
||||
// color we've been given. Yuck.
|
||||
|
||||
// Find the closest match by comparing the differences in values for each
|
||||
// color. This function was not intended to be called rapidly, so speed is
|
||||
// not much of an issue at this point.
|
||||
int8 closest=0;
|
||||
int16 closest_delta=765, delta; // (255 * 3)
|
||||
|
||||
// Get the current palette
|
||||
rgb_color *list=winscreen->ColorList();
|
||||
for(i=0;i<256;i++)
|
||||
{
|
||||
delta=ABS(list->red-red)+ABS(list->green-green)+ABS(list->blue-blue);
|
||||
if(delta<closest_delta)
|
||||
{
|
||||
closest=i;
|
||||
closest_delta=delta;
|
||||
}
|
||||
}
|
||||
|
||||
// Theoretically, we now have the closest match, so simply fill the
|
||||
// frame buffer with the index
|
||||
memset(winscreen->gcinfo->frame_buffer,closest,
|
||||
winscreen->gcinfo->bytes_per_row * winscreen->gcinfo->height);
|
||||
|
||||
// Nothing left to do!
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Unsupported bit depth %d in DirectDriver::Clear(r,g,b)!!\n",winscreen->gcinfo->bits_per_pixel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
imax=winscreen->gcinfo->height;
|
||||
|
||||
// a pointer to increment for the screen copy. Faster than doing a multiply
|
||||
// each iteration
|
||||
int8 *pbuffer=(int8*)winscreen->gcinfo->frame_buffer;
|
||||
for(i=0;i<imax;i++)
|
||||
{
|
||||
memcpy(pbuffer,fillstring,length);
|
||||
pbuffer+=length;
|
||||
}
|
||||
*/
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef _DIRECTDRIVER_H_
|
||||
#define _DIRECTDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <DirectWindow.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <Message.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class OBAppServerScreen : public BDirectWindow
|
||||
{
|
||||
public:
|
||||
OBAppServerScreen(status_t *error);
|
||||
~OBAppServerScreen(void);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested(void);
|
||||
static int32 Draw(void *data);
|
||||
virtual void DirectConnected(direct_buffer_info *dbinfo);
|
||||
|
||||
int32 DrawID;
|
||||
bool redraw,connected;
|
||||
graphics_card_info *gcinfo;
|
||||
graphics_card_hook *gchooks;
|
||||
};
|
||||
|
||||
class DirectDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
DirectDriver(void);
|
||||
virtual ~DirectDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
// virtual void SetPixel(int x, int y, rgb_color color);
|
||||
// virtual void StrokeEllipse(BRect rect, rgb_color color);
|
||||
OBAppServerScreen *winscreen;
|
||||
|
||||
protected:
|
||||
// Original screen info
|
||||
uint32 old_space;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,183 +0,0 @@
|
||||
/*
|
||||
DisplayDriver.cpp
|
||||
Modular class to allow the server to not care what the ultimate output is
|
||||
for graphics calls.
|
||||
*/
|
||||
#include "DisplayDriver.h"
|
||||
#include "ServerCursor.h"
|
||||
|
||||
DisplayDriver::DisplayDriver(void)
|
||||
{
|
||||
is_initialized=false;
|
||||
cursor_visible=false;
|
||||
show_on_move=false;
|
||||
locker=new BLocker();
|
||||
}
|
||||
|
||||
DisplayDriver::~DisplayDriver(void)
|
||||
{
|
||||
delete locker;
|
||||
}
|
||||
|
||||
void DisplayDriver::Initialize(void)
|
||||
{ // Loading loop to find proper driver or other setup for the driver
|
||||
}
|
||||
|
||||
void DisplayDriver::Shutdown(void)
|
||||
{ // For use by subclasses
|
||||
}
|
||||
|
||||
bool DisplayDriver::IsInitialized(void)
|
||||
{ // Let us know whether things worked out ok
|
||||
return is_initialized;
|
||||
}
|
||||
|
||||
void DisplayDriver::SafeMode(void)
|
||||
{ // Set video mode to 640x480x256 mode
|
||||
}
|
||||
|
||||
void DisplayDriver::Reset(void)
|
||||
{ // Intended to reload and restart driver. Defaults to a safe mode
|
||||
}
|
||||
|
||||
void DisplayDriver::SetScreen(uint32 space)
|
||||
{ // Set the screen to a particular mode
|
||||
}
|
||||
|
||||
int32 DisplayDriver::GetHeight(void)
|
||||
{ // Gets the height of the current mode
|
||||
return ginfo->height;
|
||||
}
|
||||
|
||||
int32 DisplayDriver::GetWidth(void)
|
||||
{ // Gets the width of the current mode
|
||||
return ginfo->width;
|
||||
}
|
||||
|
||||
int DisplayDriver::GetDepth(void)
|
||||
{ // Gets the color depth of the current mode
|
||||
return ginfo->bytes_per_row;
|
||||
}
|
||||
|
||||
void DisplayDriver::Clear(uint8 red,uint8 green,uint8 blue)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeRect(BRect rect, rgb_color color)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRect(BRect rect, rgb_color color)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeEllipse(BRect rect, rgb_color color)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillEllipse(BRect rect,rgb_color color)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetPixel(int x, int y, rgb_color color)
|
||||
{ // Internal function utilized by other functions to draw to the buffer
|
||||
// Will eventually be an inline function
|
||||
}
|
||||
|
||||
void DisplayDriver::SetCursor(ServerCursor *cursor)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetCursor(int32 value)
|
||||
{ // This is used just to provide an easy way of setting one of the default cursors
|
||||
// Then again, I may just get rid of this thing.
|
||||
}
|
||||
|
||||
void DisplayDriver::ShowCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::HideCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::ObscureCursor(void)
|
||||
{ // Hides cursor until mouse is moved
|
||||
}
|
||||
|
||||
bool DisplayDriver::IsCursorHidden(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void DisplayDriver::MoveCursorTo(int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::Blit(BPoint dest, ServerBitmap *sourcebmp, ServerBitmap *destbmp)
|
||||
{ // Screen-to-screen bitmap copying
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawBitmap(ServerBitmap *bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawChar(char c, int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawString(char *string, int length, int x, int y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeArc(int centerx, int centery, int xradius, int yradius)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillArc(int centerx, int centery, int xradius, int yradius)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokePolygon(int *x, int *y, int numpoints, bool is_closed)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillPolygon(int *x, int *y, int numpoints, bool is_closed)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeRegion(ServerRegion *region)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRegion(ServerRegion *region)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeRoundRect(ServerRect *rect)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRoundRect(ServerRect *rect)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeShape(ServerShape *shape)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillShape(ServerShape *shape)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeTriangle(int *x, int *y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillTriangle(int *x, int *y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::MoveTo(int x, int y)
|
||||
{ // Moves the graphics pen to this position
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
#ifndef _GFX_DRIVER_H_
|
||||
#define _GFX_DRIVER_H_
|
||||
|
||||
#include <GraphicsCard.h>
|
||||
#include <Rect.h>
|
||||
#include <Locker.h>
|
||||
#include "Desktop.h"
|
||||
|
||||
class ServerBitmap;
|
||||
class ServerRegion;
|
||||
class ServerShape;
|
||||
class ServerRect;
|
||||
class ServerCursor;
|
||||
|
||||
#ifndef ROUND
|
||||
#define ROUND(a) ( (a-long(a))>=.5)?(long(a)+1):(long(a))
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uchar *xormask, *andmask;
|
||||
int32 width, height;
|
||||
int32 hotx, hoty;
|
||||
|
||||
} cursor_data;
|
||||
|
||||
#ifndef HOOK_DEFINE_CURSOR
|
||||
|
||||
#define HOOK_DEFINE_CURSOR 0
|
||||
#define HOOK_MOVE_CURSOR 1
|
||||
#define HOOK_SHOW_CURSOR 2
|
||||
#define HOOK_DRAW_LINE_8BIT 3
|
||||
#define HOOK_DRAW_LINE_16BIT 12
|
||||
#define HOOK_DRAW_LINE_32BIT 4
|
||||
#define HOOK_DRAW_RECT_8BIT 5
|
||||
#define HOOK_DRAW_RECT_16BIT 13
|
||||
#define HOOK_DRAW_RECT_32BIT 6
|
||||
#define HOOK_BLIT 7
|
||||
#define HOOK_DRAW_ARRAY_8BIT 8
|
||||
#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers
|
||||
#define HOOK_DRAW_ARRAY_32BIT 9
|
||||
#define HOOK_SYNC 10
|
||||
#define HOOK_INVERT_RECT 11
|
||||
|
||||
#endif
|
||||
|
||||
class ServerCursor;
|
||||
|
||||
class DisplayDriver
|
||||
{
|
||||
public:
|
||||
DisplayDriver(void);
|
||||
virtual ~DisplayDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual void Shutdown(void); // You never know when you'll need this
|
||||
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
|
||||
// Settings functions
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual int32 GetHeight(void);
|
||||
virtual int32 GetWidth(void);
|
||||
virtual int GetDepth(void);
|
||||
|
||||
// Drawing functions
|
||||
virtual void SetPixel(int x, int y, rgb_color color);
|
||||
virtual void DrawBitmap(ServerBitmap *bitmap);
|
||||
virtual void DrawChar(char c, int x, int y);
|
||||
virtual void DrawString(char *string, int length, int x, int y);
|
||||
virtual void StrokeRect(BRect rect,rgb_color color);
|
||||
virtual void FillRect(BRect rect, rgb_color color);
|
||||
virtual void StrokeEllipse(BRect rect,rgb_color color);
|
||||
virtual void FillEllipse(BRect rect,rgb_color color);
|
||||
virtual void StrokeArc(int centerx, int centery, int xradius, int yradius);
|
||||
virtual void FillArc(int centerx, int centery, int xradius, int yradius);
|
||||
virtual void StrokePolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void FillPolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void StrokeRegion(ServerRegion *region);
|
||||
virtual void FillRegion(ServerRegion *region);
|
||||
virtual void StrokeRoundRect(ServerRect *rect);
|
||||
virtual void FillRoundRect(ServerRect *rect);
|
||||
virtual void StrokeShape(ServerShape *shape);
|
||||
virtual void FillShape(ServerShape *shape);
|
||||
virtual void StrokeTriangle(int *x, int *y);
|
||||
virtual void FillTriangle(int *x, int *y);
|
||||
virtual void MoveTo(int x, int y);
|
||||
virtual void Blit(BPoint dest, ServerBitmap *src, ServerBitmap *dest);
|
||||
|
||||
virtual void SetCursor(int32 value);
|
||||
virtual void SetCursor(ServerCursor *cursor);
|
||||
virtual void ShowCursor(void);
|
||||
virtual void MoveCursorTo(int x, int y);
|
||||
virtual void HideCursor(void);
|
||||
virtual void ObscureCursor(void);
|
||||
virtual bool IsCursorHidden(void);
|
||||
|
||||
|
||||
virtual bool IsInitialized(void);
|
||||
graphics_card_hook ghooks[48];
|
||||
graphics_card_info *ginfo;
|
||||
|
||||
protected:
|
||||
bool is_initialized, cursor_visible, show_on_move;
|
||||
ServerCursor *current_cursor;
|
||||
BLocker *locker;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef _SERVER_GLOBALS_H_
|
||||
#define _SERVER_GLOBALS_H_
|
||||
|
||||
#include <List.h>
|
||||
BList *gBitmaplist, *gLayerlist;
|
||||
|
||||
#endif
|
@ -1,74 +0,0 @@
|
||||
#include "Layer.h"
|
||||
|
||||
Layer::Layer(ServerWindow *Win, const char *Name, BRect &Frame, int32 Flags)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::Layer(ServerBitmap *Bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
Layer::~Layer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Show(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Hide(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool Layer::IsVisible(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layer::Update(bool ForceUpdate)
|
||||
{
|
||||
}
|
||||
|
||||
bool Layer::IsBackground(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Layer::SetFrame(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
||||
BRect Layer::Frame(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
BRect Layer::Bounds(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
void Layer::Invalidate(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::AddRegion(BRegion *Region)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::RemoveRegions(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::UpdateRegions(bool ForceUpdate=true, bool Root=true)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Draw(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
#ifndef _LAYER_H_
|
||||
#define _LAYER_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Region.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class ServerBitmap;
|
||||
class ServerWindow;
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
Layer(ServerWindow *Win, const char *Name, BRect &Frame, int32 Flags);
|
||||
Layer(ServerBitmap *Bitmap);
|
||||
virtual ~Layer(void);
|
||||
|
||||
void Initialize(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
bool IsVisible(void);
|
||||
void Update(bool ForceUpdate);
|
||||
|
||||
bool IsBackground(void);
|
||||
|
||||
virtual void SetFrame(const BRect &Rect);
|
||||
BRect Frame(void);
|
||||
BRect Bounds(void);
|
||||
|
||||
void Invalidate(const BRect &Rect);
|
||||
void AddRegion(BRegion *Region);
|
||||
void RemoveRegions(void);
|
||||
void UpdateRegions(bool ForceUpdate=true, bool Root=true);
|
||||
|
||||
// Render functions:
|
||||
virtual void Draw(const BRect &Rect);
|
||||
|
||||
const char *name;
|
||||
int32 handle;
|
||||
ServerWindow *window; // Window associated with this. NULL for background layer
|
||||
ServerBitmap *bitmap; // Blasted to screen on redraw. We render to this
|
||||
|
||||
BRect frame;
|
||||
|
||||
BRegion *visible, // Everything currently visible
|
||||
*full, // The complete region
|
||||
*update; // Area to be updated at next redraw
|
||||
|
||||
int32 flags; // Various flags for behavior
|
||||
|
||||
// Render state:
|
||||
BPoint penpos;
|
||||
rgb_color high, low, erase;
|
||||
|
||||
int32 drawingmode;
|
||||
};
|
||||
|
||||
Layer *FindLayer(int32 Handle);
|
||||
|
||||
#endif
|
@ -1,438 +0,0 @@
|
||||
/*
|
||||
PortLink.cpp:
|
||||
A helper class for port-based messaging
|
||||
|
||||
------------------------------------------------------------------------
|
||||
How it works:
|
||||
The class utilizes a fixed-size array of PortLinkData object pointers. When
|
||||
data is attached, a new PortLinkData object is allocated and a copy of the
|
||||
passed data is created inside it. When the time comes for the message to be sent,
|
||||
the data is pieced together into a flattened array and written to the port.
|
||||
------------------------------------------------------------------------
|
||||
Data members:
|
||||
|
||||
*attachments[] - fixed-size array of pointers used to hold the attached data
|
||||
opcode - message value which is sent along with any data
|
||||
target - port to which the message is sent when Flush() is called
|
||||
replyport - port used with synchronous messaging - FlushWithReply()
|
||||
bufferlength - total bytes taken up by attachments
|
||||
num_attachments - internal variable which is used to track which "slot"
|
||||
will be the next one to receive an attachment object
|
||||
*/
|
||||
|
||||
#include "PortLink.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
//#define PLDEBUG
|
||||
|
||||
// Internal data storage class for holding attached data whilst it is waiting
|
||||
// to be Flattened() and then Flushed(). There is no need for this to be called outside
|
||||
// the PortLink class.
|
||||
class PortLinkData
|
||||
{
|
||||
public:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
bool Set(void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
PortLink::PortLink(port_id port)
|
||||
{
|
||||
// For this class to be useful (and to prevent a lot of init problems)
|
||||
// we require a port in the constructor
|
||||
target=port;
|
||||
|
||||
// We start out without any data attached to the port message
|
||||
num_attachments=0;
|
||||
opcode=0;
|
||||
bufferlength=0;
|
||||
replyport=create_port(30,"PortLink reply port");
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
// If, for some odd reason, this is deleted with something attached,
|
||||
// free the memory used by the attachments. We do not flush the queue
|
||||
// because the port may no longer be valid in cases such as the app
|
||||
// is in the process of quitting
|
||||
MakeEmpty();
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode(int32 code)
|
||||
{
|
||||
// Sets the message code. This does not change once the message is sent.
|
||||
// Another call to SetOpCode() is required for such things.
|
||||
opcode=code;
|
||||
}
|
||||
|
||||
void PortLink::SetPort(port_id port)
|
||||
{
|
||||
// Sets the target port. While not necessary in most uses, this exists
|
||||
// mostly to prevent flexibility problems
|
||||
target=port;
|
||||
}
|
||||
|
||||
port_id PortLink::GetPort(void)
|
||||
{
|
||||
// Simply returns the port at which the object is pointed.
|
||||
return target;
|
||||
}
|
||||
|
||||
void PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message off to the target, complete with attachments. NOTE:
|
||||
// the recipient must delete all attachments, being the PortLink object assumes
|
||||
// no responsiblity for the attachments once the message is sent.
|
||||
int8 *msgbuffer;
|
||||
int32 size;
|
||||
|
||||
if(num_attachments>0)
|
||||
{
|
||||
FlattenData(&msgbuffer,&size);
|
||||
|
||||
// Dump message to port, reset attachments, and clean up
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,msgbuffer,size,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,msgbuffer,size);
|
||||
MakeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,NULL,0,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message to the target and then waits for a reply. The target will
|
||||
// receive a message with the first item being the port_id to reply to.
|
||||
// NOTE: like Flush(), any attached data must be deleted.
|
||||
|
||||
// Effectively, an Attach() call inlined for changes
|
||||
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
{
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&replyport,sizeof(port_id)))
|
||||
{
|
||||
bufferlength+=sizeof(port_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Flatten() inlined to make some necessary changes
|
||||
int8 *buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=buffer;
|
||||
size_t size=0;
|
||||
|
||||
// attach our port_id first
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
|
||||
// attach everything else
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
}
|
||||
|
||||
// Flush the thing....FOOSH! :P
|
||||
write_port(target,opcode,buffer,size);
|
||||
MakeEmpty();
|
||||
delete buffer;
|
||||
|
||||
// Now we wait for the reply
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
*buffersize=port_buffer_size(replyport);
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buffersize=port_buffer_size_etc(replyport,0,timeout);
|
||||
if(*buffersize==B_TIMED_OUT)
|
||||
{
|
||||
*status=*buffersize;
|
||||
return NULL;
|
||||
}
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
|
||||
// We got this far, so we apparently have some data
|
||||
*status=B_OK;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void PortLink::Attach(void *data, size_t size)
|
||||
{
|
||||
// This is the member called to attach data to a message. Attachments are
|
||||
// treated to be in 'Append' mode, tacking on each attached piece of data
|
||||
// to the end of the list.
|
||||
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
if(size==0)
|
||||
return;
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
// These functions were added for a major convenience in passing common types
|
||||
// Eventually, I'd like to templatize these, but for now, this'll do
|
||||
|
||||
void PortLink::Attach(int32 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int32);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int16 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int16);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int8 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int8);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(float data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(float);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(bool data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(bool);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BRect data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BRect);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BPoint data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BPoint);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::FlattenData(int8 **buffer,int32 *size)
|
||||
{
|
||||
// This function is where all the magic happens, but it is strictly internal.
|
||||
// It iterates through each PortLinkData object and copies it to the main buffer
|
||||
// which ends up, ultimately, being written to the PortLink's target port.
|
||||
|
||||
// skip if there aree no attachments
|
||||
if(bufferlength<1)
|
||||
return;
|
||||
|
||||
*buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=*buffer;
|
||||
PortLinkData *pld;
|
||||
*size=0;
|
||||
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
*size+=pld->buffersize;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::MakeEmpty(void)
|
||||
{
|
||||
// Nukes all the attachments currently held by the PortLink class
|
||||
if(num_attachments!=0)
|
||||
{
|
||||
for(int i=0; i<num_attachments; i++)
|
||||
{
|
||||
delete attachments[i];
|
||||
}
|
||||
}
|
||||
num_attachments=0;
|
||||
bufferlength=0;
|
||||
}
|
||||
|
||||
PortLinkData::PortLinkData(void)
|
||||
{
|
||||
// Initialize object to empty
|
||||
buffersize=0;
|
||||
}
|
||||
|
||||
PortLinkData::~PortLinkData(void)
|
||||
{
|
||||
// Frees the buffer if we actually used the class to store data
|
||||
if(buffersize>0)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool PortLinkData::Set(void *data, size_t size)
|
||||
{
|
||||
// Function copies the passed to the internal buffers for storage
|
||||
if(size>0 && buffersize==0 && data!=NULL)
|
||||
{
|
||||
buffer=(char *)malloc(size);
|
||||
if(buffer==NULL)
|
||||
return false;
|
||||
memcpy(buffer, data, size);
|
||||
buffersize=size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef _PORTLINK_H_
|
||||
#define _PORTLINK_H_
|
||||
|
||||
#include <Errors.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
#ifndef _PORTLINK_BUFFERSIZE
|
||||
#define _PORTLINK_MAX_ATTACHMENTS 50
|
||||
#endif
|
||||
|
||||
class PortLinkData;
|
||||
|
||||
class PortLink
|
||||
{
|
||||
public:
|
||||
PortLink(port_id port);
|
||||
~PortLink(void);
|
||||
void SetOpCode(int32 code);
|
||||
void SetPort(port_id port);
|
||||
port_id GetPort(void);
|
||||
void Flush(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
|
||||
bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
void Attach(void *data, size_t size);
|
||||
void Attach(int32 data);
|
||||
void Attach(int16 data);
|
||||
void Attach(int8 data);
|
||||
void Attach(float data);
|
||||
void Attach(bool data);
|
||||
void Attach(BRect data);
|
||||
void Attach(BPoint data);
|
||||
void MakeEmpty(void);
|
||||
protected:
|
||||
void FlattenData(int8 **buffer,int32 *size);
|
||||
port_id target, replyport;
|
||||
int32 opcode, bufferlength;
|
||||
int num_attachments;
|
||||
PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,9 +0,0 @@
|
||||
OpenBeOS App Server Test Prototype #3
|
||||
|
||||
This is an example of both a work in progress and a lot of research at the same time. Many of the concepts used in this prototype will be used in the real server. It doesn't do much, but the fact that it exists and does what it does is the result of a *lot* of work.
|
||||
|
||||
This prototype does everything the second one did PLUS has much of the foundation for graphics in place. Graphics updates are slow and there is a lot of flicker, but this is expected - the driver-access module used also emulates the Input Server and utilizes BeOS' app_server to provide all the drawing.
|
||||
|
||||
The code is reasonably (IMHO) well-commented and should be easy to understand at first glance. Also included are some extra files which I didn't feel like throwing out or are in place for future development. ;D Enjoy.
|
||||
|
||||
--DarkWyrm
|
@ -1,155 +0,0 @@
|
||||
/*
|
||||
ServerApp.cpp
|
||||
Class which works with a BApplication. Handles all messages coming
|
||||
from and going to its application.
|
||||
*/
|
||||
|
||||
#include <AppDefs.h>
|
||||
#include "ServerApp.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
ServerApp::ServerApp(port_id msgport, char *signature)
|
||||
{
|
||||
//printf("New ServerApp %s for app at port %ld\n",signature,msgport);
|
||||
|
||||
// need to copy the signature because the message buffer
|
||||
// owns the copy which we are passed as a parameter.
|
||||
if(signature)
|
||||
{
|
||||
app_sig=new char[strlen(signature)];
|
||||
sprintf(app_sig,signature);
|
||||
}
|
||||
else
|
||||
{
|
||||
app_sig=new char[strlen("Application")];
|
||||
sprintf(app_sig,"Application");
|
||||
}
|
||||
|
||||
// sender is the monitored app's event port
|
||||
sender=msgport;
|
||||
applink=new PortLink(sender);
|
||||
|
||||
// receiver is the port to which the app sends messages for the server
|
||||
receiver=create_port(30,app_sig);
|
||||
//printf("ServerApp port for app %s is at %ld\n",app_sig,receiver);
|
||||
if(receiver==B_NO_MORE_PORTS)
|
||||
{
|
||||
// uh-oh. We have a serious problem. Tell the app to quit
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything checks out, so tell the application
|
||||
// where to send future messages
|
||||
applink->SetOpCode(SET_SERVER_PORT);
|
||||
applink->Attach(&receiver,sizeof(port_id));
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
ServerApp::~ServerApp(void)
|
||||
{
|
||||
//printf("%s::~ServerApp()\n",app_sig);
|
||||
delete app_sig;
|
||||
delete applink;
|
||||
}
|
||||
|
||||
bool ServerApp::Run(void)
|
||||
{
|
||||
// Unlike a BApplication, a ServerApp is *supposed* to return immediately
|
||||
// when its Run function is called.
|
||||
monitor_thread=spawn_thread(MonitorApp,app_sig,B_NORMAL_PRIORITY,this);
|
||||
if(monitor_thread==B_NO_MORE_THREADS || monitor_thread==B_NO_MEMORY)
|
||||
return false;
|
||||
resume_thread(monitor_thread);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 ServerApp::MonitorApp(void *data)
|
||||
{
|
||||
ServerApp *app=(ServerApp *)data;
|
||||
app->Loop();
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ServerApp::Loop(void)
|
||||
{
|
||||
// Message-dispatching loop for the ServerApp
|
||||
|
||||
//printf("%s::MainLoop()\n",app_sig);
|
||||
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(receiver);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are PortLink messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(receiver,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(receiver,&msgcode,NULL,0);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
// Our BApplication sent us this message when it quit.
|
||||
// We need to ask the app_server to delete our monitor
|
||||
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||
if(serverport==B_NAME_NOT_FOUND)
|
||||
{
|
||||
//printf("PANIC: ServerApp %s could not find the app_server port!\n",app_sig);
|
||||
break;
|
||||
}
|
||||
//printf("ServerApp %s quitting\n",app_sig);
|
||||
applink->SetPort(serverport);
|
||||
applink->SetOpCode(DELETE_APP);
|
||||
applink->Attach(&monitor_thread,sizeof(thread_id));
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
case QUIT_APP:
|
||||
{
|
||||
// This message is received from the app_server thread
|
||||
// because the server was asked to quit. Thus, we
|
||||
// ask all apps to quit. This is NOT the same as system
|
||||
// shutdown
|
||||
|
||||
//printf("ServerApp asking %s to quit\n",app_sig);
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//printf("Server received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerApp::DispatchMessage(BMessage *msg)
|
||||
{
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
#ifndef _SRVAPP_H_
|
||||
#define _SRVAPP_H_
|
||||
|
||||
#include <OS.h>
|
||||
class BMessage;
|
||||
class PortLink;
|
||||
|
||||
class ServerApp
|
||||
{
|
||||
public:
|
||||
ServerApp(port_id msgport, char *signature);
|
||||
~ServerApp(void);
|
||||
|
||||
bool Run(void);
|
||||
static int32 MonitorApp(void *data);
|
||||
void Loop(void);
|
||||
void DispatchMessage(BMessage *msg);
|
||||
|
||||
port_id sender,receiver;
|
||||
char *app_sig;
|
||||
thread_id monitor_thread;
|
||||
PortLink *applink;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,214 +0,0 @@
|
||||
/*
|
||||
ServerBitmap.cpp
|
||||
Bitmap class which is intended to provide an easy way to package all the
|
||||
data associated with a picture. It's very low-level, so there's still
|
||||
plenty to do when coding with 'em. Also, they're used to access draw on the
|
||||
frame buffer in a relatively easy way.
|
||||
*/
|
||||
|
||||
// These three includes for ServerBitmap(const char *path_to_image_file) only
|
||||
#include <TranslationUtils.h>
|
||||
#include <string.h>
|
||||
#include <Bitmap.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include "ServerBitmap.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
ServerBitmap::ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0)
|
||||
{
|
||||
width=rect.IntegerWidth()+1;
|
||||
height=rect.IntegerHeight()+1;
|
||||
cspace=space;
|
||||
is_vram=false;
|
||||
|
||||
HandleSpace(space, BytesPerLine);
|
||||
buffer=new uint8[bytesperline*height];
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
ServerBitmap::ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0)
|
||||
{
|
||||
width=w;
|
||||
height=h;
|
||||
cspace=space;
|
||||
is_vram=false;
|
||||
|
||||
HandleSpace(space, BytesPerLine);
|
||||
buffer=new uint8[bytesperline*height];
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
ServerBitmap::ServerBitmap(void)
|
||||
{
|
||||
is_vram=true;
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
// This particular version is not intended for use except for testing purposes.
|
||||
// It loads a BBitmap and copies it to the ServerBitmap. Probably will disappear
|
||||
// when the *real* server is written
|
||||
ServerBitmap::ServerBitmap(const char *path)
|
||||
{
|
||||
BBitmap *bmp=BTranslationUtils::GetBitmap(path);
|
||||
assert(bmp!=NULL);
|
||||
|
||||
if(bmp==NULL)
|
||||
{
|
||||
width=0;
|
||||
height=0;
|
||||
cspace=B_NO_COLOR_SPACE;
|
||||
bytesperline=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
width=bmp->Bounds().IntegerWidth();
|
||||
height=bmp->Bounds().IntegerHeight();
|
||||
cspace=bmp->ColorSpace();
|
||||
bytesperline=bmp->BytesPerRow();
|
||||
buffer=new uint8[bmp->BitsLength()];
|
||||
memcpy(buffer,(void *)bmp->Bits(),bmp->BitsLength());
|
||||
}
|
||||
}
|
||||
|
||||
ServerBitmap::~ServerBitmap(void)
|
||||
{
|
||||
if(!is_vram)
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
void ServerBitmap::UpdateSettings(void)
|
||||
{
|
||||
// This is only used when the object is pointing to the frame buffer
|
||||
driver=get_gfxdriver();
|
||||
bpp=driver->GetDepth();
|
||||
width=driver->GetWidth();
|
||||
height=driver->GetHeight();
|
||||
}
|
||||
|
||||
void ServerBitmap::HandleSpace(color_space space, int32 BytesPerLine)
|
||||
{
|
||||
// Function written to handle color space setup which is required
|
||||
// by the two "normal" constructors
|
||||
|
||||
// Big convoluted mess just to handle every color space and dword align
|
||||
// the buffer
|
||||
switch(space)
|
||||
{
|
||||
// Buffer is dword-aligned, so nothing need be done
|
||||
// aside from allocate the memory
|
||||
case B_RGB32:
|
||||
case B_RGBA32:
|
||||
case B_RGB32_BIG:
|
||||
case B_RGBA32_BIG:
|
||||
case B_UVL32:
|
||||
case B_UVLA32:
|
||||
case B_LAB32:
|
||||
case B_LABA32:
|
||||
case B_HSI32:
|
||||
case B_HSIA32:
|
||||
case B_HSV32:
|
||||
case B_HSVA32:
|
||||
case B_HLS32:
|
||||
case B_HLSA32:
|
||||
case B_CMY32:
|
||||
case B_CMYA32:
|
||||
case B_CMYK32:
|
||||
|
||||
// 24-bit = 32-bit with extra 8 bits ignored
|
||||
case B_RGB24_BIG:
|
||||
case B_RGB24:
|
||||
case B_LAB24:
|
||||
case B_UVL24:
|
||||
case B_HSI24:
|
||||
case B_HSV24:
|
||||
case B_HLS24:
|
||||
case B_CMY24:
|
||||
{
|
||||
if(BytesPerLine<(width*4))
|
||||
bytesperline=width*4;
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=32;
|
||||
break;
|
||||
}
|
||||
// Calculate size and dword-align
|
||||
|
||||
// 1-bit
|
||||
case B_GRAY1:
|
||||
{
|
||||
int32 numbytes=width>>3;
|
||||
if((width % 8) != 0)
|
||||
numbytes++;
|
||||
if(BytesPerLine<numbytes)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (numbytes+i)%4==0)
|
||||
{
|
||||
bytesperline=numbytes+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=1;
|
||||
}
|
||||
|
||||
// 8-bit
|
||||
case B_CMAP8:
|
||||
case B_GRAY8:
|
||||
case B_YUV411:
|
||||
case B_YUV420:
|
||||
case B_YCbCr422:
|
||||
case B_YCbCr411:
|
||||
case B_YCbCr420:
|
||||
case B_YUV422:
|
||||
{
|
||||
if(BytesPerLine<width)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (width+i)%4==0)
|
||||
{
|
||||
bytesperline=width+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=8;
|
||||
break;
|
||||
}
|
||||
|
||||
// 16-bit
|
||||
case B_YUV9:
|
||||
case B_YUV12:
|
||||
case B_RGB15:
|
||||
case B_RGBA15:
|
||||
case B_RGB16:
|
||||
case B_RGB16_BIG:
|
||||
case B_RGB15_BIG:
|
||||
case B_RGBA15_BIG:
|
||||
case B_YCbCr444:
|
||||
case B_YUV444:
|
||||
{
|
||||
if(BytesPerLine<width*2)
|
||||
{
|
||||
if( (width*2) % 4 !=0)
|
||||
bytesperline=(width+1)*2;
|
||||
else
|
||||
bytesperline=width*2;
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=16;
|
||||
break;
|
||||
}
|
||||
case B_NO_COLOR_SPACE:
|
||||
bpp=0;
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
#ifndef _SERVER_BITMAP_H_
|
||||
#define _SERVER_BITMAP_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class ServerBitmap
|
||||
{
|
||||
public:
|
||||
ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0);
|
||||
ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0);
|
||||
ServerBitmap(void);
|
||||
ServerBitmap(const char *path);
|
||||
~ServerBitmap(void);
|
||||
void UpdateSettings(void);
|
||||
|
||||
int32 width,height;
|
||||
int32 bytesperline;
|
||||
color_space cspace;
|
||||
int bpp;
|
||||
uint8 *buffer;
|
||||
|
||||
protected:
|
||||
void HandleSpace(color_space space, int32 BytesPerLine);
|
||||
DisplayDriver *driver;
|
||||
bool is_vram;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
ServerCursor.cpp
|
||||
This is the server-side class used to handle cursors. Note that it
|
||||
will handle the R5 cursors, but it will also handle taking a bitmap.
|
||||
|
||||
This is new code, and there may be changes to the API before it settles
|
||||
in.
|
||||
*/
|
||||
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerBitmap.h"
|
||||
|
||||
ServerCursor::ServerCursor(ServerBitmap *bmp)
|
||||
{
|
||||
is_initialized=false;
|
||||
position.Set(0,0);
|
||||
SetCursor(bmp);
|
||||
}
|
||||
|
||||
ServerCursor::ServerCursor(int8 *data, color_space space)
|
||||
{
|
||||
// For handling the idiot R5 API data format
|
||||
|
||||
is_initialized=false;
|
||||
position.Set(0,0);
|
||||
SetCursor(data,space);
|
||||
}
|
||||
|
||||
ServerCursor::~ServerCursor(void)
|
||||
{
|
||||
if(is_initialized)
|
||||
{
|
||||
delete bitmap;
|
||||
delete mask;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerCursor::SetCursor(int8 *data, color_space space)
|
||||
{
|
||||
// 68-byte array used in R5 for holding cursors.
|
||||
// This API has serious problems and should be deprecated(but supported)
|
||||
// in a future release, perhaps right after the first one
|
||||
if(is_initialized)
|
||||
{
|
||||
delete bitmap;
|
||||
delete mask;
|
||||
}
|
||||
cspace=space;
|
||||
|
||||
bitmap=new ServerBitmap(16,16,B_GRAY1);
|
||||
mask=new ServerBitmap(16,16,B_GRAY1);
|
||||
width=16;
|
||||
height=16;
|
||||
bounds.Set(0,0,15,15);
|
||||
}
|
||||
|
||||
void ServerCursor::SetCursor(ServerBitmap *bmp)
|
||||
{
|
||||
if(is_initialized)
|
||||
{
|
||||
delete bitmap;
|
||||
delete mask;
|
||||
}
|
||||
cspace=bmp->cspace;
|
||||
|
||||
bitmap=new ServerBitmap(16,16,B_GRAY1);
|
||||
mask=new ServerBitmap(16,16,B_GRAY1);
|
||||
width=bmp->width;
|
||||
height=bmp->height;
|
||||
bounds.Set(0,0,bmp->width-1,bmp->height-1);
|
||||
}
|
||||
|
||||
void ServerCursor::MoveTo(int32 x, int32 y)
|
||||
{
|
||||
position.Set(x,y);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#ifndef _SERVER_SPRITE_H
|
||||
#define _SERVER_SPRITE_H
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class ServerBitmap;
|
||||
|
||||
class ServerCursor
|
||||
{
|
||||
public:
|
||||
ServerCursor(ServerBitmap *bmp);
|
||||
ServerCursor(int8 *data,color_space space);
|
||||
~ServerCursor(void);
|
||||
void MoveTo(int32 x, int32 y);
|
||||
void SetCursor(int8 *data, color_space space);
|
||||
void SetCursor(ServerBitmap *bmp);
|
||||
|
||||
ServerBitmap *bitmap,
|
||||
*mask;
|
||||
|
||||
color_space cspace;
|
||||
BRect bounds;
|
||||
int width,height;
|
||||
BPoint position;
|
||||
bool is_initialized;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,13 +0,0 @@
|
||||
#ifndef _APPSERVER_PROTOCOL_
|
||||
#define _APPSERVER_PROTOCOL_
|
||||
|
||||
#define CREATE_APP 'drca'
|
||||
#define DELETE_APP 'drda'
|
||||
|
||||
#define SET_SERVER_PORT 'srsp'
|
||||
#define QUIT_APP 'srqa'
|
||||
|
||||
#define SERVER_PORT_NAME "OBappserver"
|
||||
#define SERVER_INPUT_PORT "OBinputport"
|
||||
|
||||
#endif
|
@ -1,35 +0,0 @@
|
||||
#ifndef _SERVER_RECT_H_
|
||||
#define _SERVER_RECT_H_
|
||||
|
||||
class ServerRect
|
||||
{
|
||||
public:
|
||||
ServerRect(int32 l, int32 t, int32 r, int32 b)
|
||||
{ left=l; top=t; right=r; bottom=b; }
|
||||
ServerRect(void)
|
||||
{ left=top=0; right=bottom=0; }
|
||||
ServerRect(const ServerRect &rect);
|
||||
ServerRect Bounds(void) const
|
||||
{ return( ServerRect( 0, 0, right - left, bottom - top ) );}
|
||||
|
||||
virtual ~ServerRect(void);
|
||||
bool Intersect(const ServerRect &rect ) const
|
||||
{ return( !( rect.right < left || rect.left > right || rect.bottom < top || rect.top > bottom ) ); }
|
||||
|
||||
|
||||
int32 left,top,right,bottom;
|
||||
};
|
||||
|
||||
ServerRect::ServerRect( const ServerRect& rect )
|
||||
{
|
||||
left = rect.left;
|
||||
top = rect.top;
|
||||
right = rect.right;
|
||||
bottom = rect.bottom;
|
||||
}
|
||||
|
||||
ServerRect::~ServerRect(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
@ -1,21 +0,0 @@
|
||||
#ifndef _SERVER_REGION_H_
|
||||
#define _SERVER_REGION_H_
|
||||
|
||||
#include "ServerRect.h"
|
||||
|
||||
class ServerRegion
|
||||
{
|
||||
public:
|
||||
ServerRegion(void);
|
||||
ServerRegion(const ServerRect rect);
|
||||
ServerRegion(const ServerRegion ®);
|
||||
virtual ~ServerRegion(void);
|
||||
bool Intersects(ServerRect rect);
|
||||
void Set(ServerRect rect);
|
||||
void Include(ServerRect rect);
|
||||
void Exclude(ServerRect rect);
|
||||
void IntersectWith(ServerRect rect);
|
||||
void MakeEmpty(void);
|
||||
void Optimize(void);
|
||||
};
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerBitmap.h"
|
||||
|
||||
ServerCursor::ServerCursor(ServerBitmap *bmp)
|
||||
{
|
||||
}
|
||||
|
||||
ServerCursor::~ServerCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
ServerCursor::SetCursor(int8 *data)
|
||||
{
|
||||
// 68-byte array used in R5 for holding cursors.
|
||||
// This API has serious problems and should be deprecated(but supported)
|
||||
// in a future release, perhaps the first one(?)
|
||||
}
|
||||
|
||||
void ServerCursor::SaveClientData(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerCursor::MoveTo(int32 x, int32 y)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerCursor::SetClient(ServerBitmap *bmp)
|
||||
{
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
#include <Rect.h>
|
||||
#include "ServerWindow.h"
|
||||
|
||||
ServerWindow::ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort)
|
||||
{
|
||||
}
|
||||
|
||||
ServerWindow::ServerWindow(ServerApp *App, ServerBitmap *Bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
ServerWindow::~ServerWindow(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::PostMessage(BMessage *msg)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ReplaceDecorator(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Quit(void)
|
||||
{
|
||||
}
|
||||
|
||||
const char *ServerWindow::GetTitle(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ServerApp *ServerWindow::GetApp(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMessenger *ServerWindow::GetAppTarget(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ServerWindow::Show(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Hide(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::SetFocus(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ServerWindow::HasFocus(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerWindow::DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::WindowActivated(bool Active)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ScreenModeChanged(const BPoint Resolustion, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::SetFrame(const BRect &Frame)
|
||||
{
|
||||
}
|
||||
|
||||
BRect ServerWindow::Frame(void)
|
||||
{
|
||||
return BRect(0,0,0,0);
|
||||
}
|
||||
|
||||
thread_id ServerWindow::Run(void)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
status_t ServerWindow::Lock(void)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t ServerWindow::Unlock(void)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
bool ServerWindow::IsLocked(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerWindow::DispatchMessage(BMessage *msg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerWindow::DispatchMessage(const void *msg, int nCode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerWindow::Loop(void)
|
||||
{
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
#ifndef _SERVERWIN_H_
|
||||
#define _SERVERWIN_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
|
||||
class BString;
|
||||
class BMessenger;
|
||||
class BRect;
|
||||
class BPoint;
|
||||
class ServerApp;
|
||||
class ServerBitmap;
|
||||
class WindowDecorator;
|
||||
|
||||
class ServerWindow
|
||||
{
|
||||
public:
|
||||
ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort);
|
||||
ServerWindow(ServerApp *App, ServerBitmap *Bitmap);
|
||||
virtual ~ServerWindow(void);
|
||||
|
||||
void PostMessage(BMessage *msg);
|
||||
void ReplaceDecorator(void);
|
||||
virtual void Quit(void);
|
||||
const char *GetTitle(void);
|
||||
ServerApp *GetApp(void);
|
||||
BMessenger *GetAppTarget(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
void SetFocus(void);
|
||||
bool HasFocus(void);
|
||||
|
||||
void DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace);
|
||||
void WindowActivated(bool Active);
|
||||
void ScreenModeChanged(const BPoint Resolustion, color_space CSpace);
|
||||
|
||||
void SetFrame(const BRect &Frame);
|
||||
BRect Frame(void);
|
||||
|
||||
thread_id Run(void);
|
||||
status_t Lock(void);
|
||||
status_t Unlock(void);
|
||||
bool IsLocked(void);
|
||||
|
||||
bool DispatchMessage(BMessage *msg);
|
||||
bool DispatchMessage(const void *msg, int nCode);
|
||||
|
||||
void Loop(void);
|
||||
|
||||
const char *title;
|
||||
int32 flags;
|
||||
int32 desktop;
|
||||
|
||||
ServerBitmap *userbitmap;
|
||||
ServerApp *app;
|
||||
|
||||
WindowDecorator *decorator;
|
||||
bigtime_t lasthit; // Time of last mouse click
|
||||
|
||||
thread_id thread;
|
||||
port_id rcvport; // Messages from application
|
||||
port_id sendport; // Messages to application
|
||||
BLocker mutex;
|
||||
BMessenger *apptarget;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,327 +0,0 @@
|
||||
/*
|
||||
SystemPalette.cpp
|
||||
One global function to generate the palette which is the default BeOS
|
||||
System palette and the variable to go with it
|
||||
*/
|
||||
|
||||
#include "SystemPalette.h"
|
||||
|
||||
rgb_color SystemPalette[256];
|
||||
|
||||
void GenerateSystemPalette(rgb_color *palette)
|
||||
{
|
||||
int i,j,index=0;
|
||||
int indexvals1[]={ 255,229,204,179,154,129,105,80,55,30 },
|
||||
indexvals2[]={ 255,203,152,102,51,0 };
|
||||
rgb_color *currentcol;
|
||||
|
||||
// Grays 0,0,0 -> 248,248,248 by 8's
|
||||
for(i=0; i<=248; i+=8,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=i;
|
||||
currentcol->green=i;
|
||||
currentcol->blue=i;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Blues, following indexvals1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals1[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Reds, following indexvals1 - 1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals1[i] - 1;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=0;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Greens, following indexvals1 - 1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=indexvals1[i] - 1;
|
||||
currentcol->blue=0;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=152;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<4;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=152;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=203;
|
||||
index++;
|
||||
|
||||
// Mostly array runs from here on out
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=203;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=152;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=102;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=51;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=152;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=102;
|
||||
index++;
|
||||
|
||||
// knocks out 4 assignment loops at once :)
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=152;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=230;
|
||||
currentcol->green=134;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(i=1;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=102;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=175;
|
||||
currentcol->blue=19;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=203;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=3;i>=0;i--,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
for(i=2;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
for(i=0;i<5;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=203;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=227;
|
||||
currentcol->blue=70;
|
||||
index++;
|
||||
|
||||
for(j=2;j<6;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(i=5;i<=0;i--,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#ifndef _SYSTEM_PALETTE_H_
|
||||
#define _SYSTEM_PALETTE_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
void GenerateSystemPalette(rgb_color *palette);
|
||||
extern rgb_color SystemPalette[];
|
||||
|
||||
#endif
|
@ -1,555 +0,0 @@
|
||||
/*
|
||||
ViewDriver:
|
||||
First, slowest, and easiest driver class in the app_server which is designed
|
||||
to utilize the BeOS graphics functions to cut out a lot of junk in getting the
|
||||
drawing infrastructure in this server.
|
||||
|
||||
The concept is to have VDView::Draw() draw a bitmap, which is a "frame buffer"
|
||||
of sorts, utilize a second view to write to it. This cuts out
|
||||
the most problems with having a crapload of code to get just right without
|
||||
having to write a bunch of unit tests
|
||||
|
||||
Components: 3 classes, VDView, VDWindow, and ViewDriver
|
||||
|
||||
ViewDriver - a wrapper class which mostly posts messages to the VDWindow
|
||||
VDWindow - does most of the work.
|
||||
VDView - doesn't do all that much except display the rendered bitmap
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Message.h>
|
||||
#include <Bitmap.h>
|
||||
#include <OS.h>
|
||||
#include "PortLink.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "ServerBitmap.h"
|
||||
#include "ViewDriver.h"
|
||||
#include "ServerCursor.h"
|
||||
#include "DebugTools.h"
|
||||
|
||||
// Message defines for internal use only
|
||||
#define VDWIN_CLEAR 'vwcl'
|
||||
#define VDWIN_SAFEMODE 'vwsm'
|
||||
#define VDWIN_RESET 'vwrs'
|
||||
#define VDWIN_SETSCREEN 'vwss'
|
||||
#define VDWIN_FILLRECT 'vwfr'
|
||||
#define VDWIN_STROKERECT 'vwsr'
|
||||
#define VDWIN_FILLELLIPSE 'vwfe'
|
||||
#define VDWIN_STROKEELLIPSE 'vwse'
|
||||
#define VDWIN_SHOWCURSOR 'vscr'
|
||||
#define VDWIN_HIDECURSOR 'vhcr'
|
||||
#define VDWIN_MOVECURSOR 'vmcr'
|
||||
|
||||
static uint8 pickcursor[] = {16,1,2,1,
|
||||
0,0,64,0,160,0,88,0,36,0,34,0,17,0,8,128,
|
||||
4,88,2,60,1,120,0,240,1,248,1,220,0,140,0,0,
|
||||
0,0,64,0,224,0,120,0,60,0,62,0,31,0,15,128,
|
||||
7,216,3,252,1,248,0,240,1,248,1,220,0,140,0,0
|
||||
};
|
||||
static uint8 crosscursor[] = {16,1,5,5,
|
||||
14,0,4,0,4,0,4,0,128,32,241,224,128,32,4,0,
|
||||
4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0,
|
||||
14,0,4,0,4,0,4,0,128,32,245,224,128,32,4,0,
|
||||
4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
VDView::VDView(BRect bounds)
|
||||
: BView(bounds,"viewdriver_view",B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
{
|
||||
viewbmp=new BBitmap(bounds,B_RGB32,true);
|
||||
drawview=new BView(viewbmp->Bounds(),"drawview",B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
|
||||
// This link for sending mouse messages to the OBAppServer.
|
||||
// This is only to take the place of the Input Server. I suppose I could write
|
||||
// an addon filter to be more like the Input Server, but then I wouldn't be working
|
||||
// on this thing! :P
|
||||
serverlink=new PortLink(find_port(SERVER_INPUT_PORT));
|
||||
// printf("VDView: app_server input port: %ld\n",serverlink->GetPort());
|
||||
|
||||
hide_cursor=0;
|
||||
|
||||
// Create a cursor which isn't just a box
|
||||
cursor=new BBitmap(BRect(0,0,20,20),B_RGBA32,true);
|
||||
BView *v=new BView(cursor->Bounds(),"v", B_FOLLOW_NONE, B_WILL_DRAW);
|
||||
cursor->Lock();
|
||||
cursor->AddChild(v);
|
||||
v->SetHighColor(255,255,255,0);
|
||||
v->FillRect(cursor->Bounds());
|
||||
v->SetHighColor(255,0,0,255);
|
||||
v->FillTriangle(cursor->Bounds().LeftTop(),cursor->Bounds().RightTop(),cursor->Bounds().LeftBottom());
|
||||
cursor->RemoveChild(v);
|
||||
cursor->Unlock();
|
||||
|
||||
cursorframe=cursor->Bounds();
|
||||
oldcursorframe=cursor->Bounds();
|
||||
}
|
||||
|
||||
VDView::~VDView(void)
|
||||
{
|
||||
delete viewbmp;
|
||||
delete serverlink;
|
||||
delete cursor;
|
||||
}
|
||||
|
||||
void VDView::AttachedToWindow(void)
|
||||
{
|
||||
// printf("VDView::AttachedToWindow()\n");
|
||||
}
|
||||
|
||||
void VDView::Draw(BRect rect)
|
||||
{
|
||||
DrawBitmapAsync(viewbmp,oldcursorframe,oldcursorframe);
|
||||
DrawBitmapAsync(viewbmp,rect,rect);
|
||||
SetDrawingMode(B_OP_ALPHA);
|
||||
DrawBitmapAsync(cursor,cursor->Bounds(),cursorframe);
|
||||
SetDrawingMode(B_OP_COPY);
|
||||
Sync();
|
||||
|
||||
// oldcursorframe.PrintToStream();
|
||||
// cursorframe.PrintToStream();
|
||||
// printf("\n");
|
||||
}
|
||||
|
||||
void VDView::MouseDown(BPoint pt)
|
||||
{
|
||||
// printf("VDView::MouseDown()\n");
|
||||
// serverlink->SetOpCode(B_MOUSE_DOWN);
|
||||
// serverlink->Flush();
|
||||
}
|
||||
|
||||
void VDView::MouseMoved(BPoint pt, uint32 transit, const BMessage *msg)
|
||||
{
|
||||
// This emulates an Input Server by sending the same kind of messages to the
|
||||
// server's port. Being we're using a regular window, it would make little sense
|
||||
// to do anything else.
|
||||
|
||||
// Attach data:
|
||||
// 1) int64 - time of mouse click
|
||||
// 2) float - x coordinate of mouse click
|
||||
// 3) float - y coordinate of mouse click
|
||||
// 4) int32 - buttons down
|
||||
BPoint p;
|
||||
uint32 buttons;
|
||||
int64 time=(int64)real_time_clock();
|
||||
|
||||
serverlink->SetOpCode(B_MOUSE_MOVED);
|
||||
serverlink->Attach(&time,sizeof(int64));
|
||||
serverlink->Attach(&pt.x,sizeof(float));
|
||||
serverlink->Attach(&pt.y,sizeof(float));
|
||||
GetMouse(&p,&buttons);
|
||||
serverlink->Attach(&buttons,sizeof(int32));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void VDView::MouseUp(BPoint pt)
|
||||
{
|
||||
// printf("VDView::MouseUp()\n");
|
||||
// serverlink->SetOpCode(B_MOUSE_UP);
|
||||
// serverlink->Flush();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
VDWindow::VDWindow(void)
|
||||
: BWindow(BRect(100,60,740,540),"OBOS App Server, P3",B_TITLED_WINDOW,
|
||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
|
||||
{
|
||||
view=new VDView(Bounds());
|
||||
AddChild(view);
|
||||
pick=new BCursor(pickcursor);
|
||||
cross=new BCursor(crosscursor);
|
||||
}
|
||||
|
||||
VDWindow::~VDWindow(void)
|
||||
{
|
||||
delete pick;
|
||||
delete cross;
|
||||
}
|
||||
|
||||
void VDWindow::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch(msg->what)
|
||||
{
|
||||
case VDWIN_CLEAR:
|
||||
{
|
||||
// printf("ViewDriver: Clear\n");
|
||||
int8 red=0,green=0,blue=0;
|
||||
msg->FindInt8("red",&red);
|
||||
msg->FindInt8("green",&green);
|
||||
msg->FindInt8("blue",&blue);
|
||||
Clear(red,green,blue);
|
||||
break;
|
||||
}
|
||||
case VDWIN_SETSCREEN:
|
||||
{
|
||||
// debug printing done in SetScreen()
|
||||
int32 space=0;
|
||||
msg->FindInt32("screenmode",&space);
|
||||
SetScreen(space);
|
||||
break;
|
||||
}
|
||||
case VDWIN_RESET:
|
||||
{
|
||||
// printf("ViewDriver: Reset\n");
|
||||
Reset();
|
||||
break;
|
||||
}
|
||||
case VDWIN_SAFEMODE:
|
||||
{
|
||||
// printf("ViewDriver: Safemode\n");
|
||||
SafeMode();
|
||||
break;
|
||||
}
|
||||
case VDWIN_FILLRECT:
|
||||
{
|
||||
// printf("ViewDriver: FillRect\n");
|
||||
BRect rect(0,0,0,0);
|
||||
rgb_color color;
|
||||
|
||||
msg->FindRect("rect",&rect);
|
||||
msg->FindInt8("red",(int8 *)&color.red);
|
||||
msg->FindInt8("green",(int8 *)&color.green);
|
||||
msg->FindInt8("blue",(int8 *)&color.blue);
|
||||
|
||||
view->viewbmp->Lock();
|
||||
view->viewbmp->AddChild(view->drawview);
|
||||
view->drawview->SetHighColor(color);
|
||||
view->drawview->FillRect(rect);
|
||||
view->viewbmp->RemoveChild(view->drawview);
|
||||
view->viewbmp->Unlock();
|
||||
break;
|
||||
}
|
||||
case VDWIN_STROKERECT:
|
||||
{
|
||||
// printf("ViewDriver: StrokeRect\n");
|
||||
BRect rect(0,0,0,0);
|
||||
rgb_color color;
|
||||
|
||||
msg->FindRect("rect",&rect);
|
||||
msg->FindInt8("red",(int8 *)&color.red);
|
||||
msg->FindInt8("green",(int8 *)&color.green);
|
||||
msg->FindInt8("blue",(int8 *)&color.blue);
|
||||
|
||||
view->viewbmp->Lock();
|
||||
view->viewbmp->AddChild(view->drawview);
|
||||
view->drawview->SetHighColor(color);
|
||||
view->drawview->StrokeRect(rect);
|
||||
view->viewbmp->RemoveChild(view->drawview);
|
||||
view->viewbmp->Unlock();
|
||||
break;
|
||||
}
|
||||
case VDWIN_FILLELLIPSE:
|
||||
{
|
||||
// printf("ViewDriver: FillEllipse\n");
|
||||
BRect rect(0,0,0,0);
|
||||
rgb_color color;
|
||||
|
||||
msg->FindRect("rect",&rect);
|
||||
msg->FindInt8("red",(int8 *)&color.red);
|
||||
msg->FindInt8("green",(int8 *)&color.green);
|
||||
msg->FindInt8("blue",(int8 *)&color.blue);
|
||||
|
||||
view->viewbmp->Lock();
|
||||
view->viewbmp->AddChild(view->drawview);
|
||||
view->drawview->SetHighColor(color);
|
||||
view->drawview->FillEllipse(rect);
|
||||
view->viewbmp->RemoveChild(view->drawview);
|
||||
view->viewbmp->Unlock();
|
||||
break;
|
||||
}
|
||||
case VDWIN_STROKEELLIPSE:
|
||||
{
|
||||
// printf("ViewDriver: StrokeEllipse\n");
|
||||
BRect rect(0,0,0,0);
|
||||
rgb_color color;
|
||||
|
||||
msg->FindRect("rect",&rect);
|
||||
msg->FindInt8("red",(int8 *)&color.red);
|
||||
msg->FindInt8("green",(int8 *)&color.green);
|
||||
msg->FindInt8("blue",(int8 *)&color.blue);
|
||||
|
||||
view->viewbmp->Lock();
|
||||
view->viewbmp->AddChild(view->drawview);
|
||||
view->drawview->SetHighColor(color);
|
||||
view->drawview->StrokeEllipse(rect);
|
||||
view->viewbmp->RemoveChild(view->drawview);
|
||||
view->viewbmp->Unlock();
|
||||
break;
|
||||
}
|
||||
case VDWIN_SHOWCURSOR:
|
||||
{
|
||||
if(view->hide_cursor>0)
|
||||
view->hide_cursor--;
|
||||
break;
|
||||
}
|
||||
case VDWIN_HIDECURSOR:
|
||||
{
|
||||
view->hide_cursor++;
|
||||
break;
|
||||
}
|
||||
case VDWIN_MOVECURSOR:
|
||||
{
|
||||
view->oldcursorframe=view->cursorframe;
|
||||
|
||||
int16 x,y;
|
||||
msg->FindInt16("x",&x);
|
||||
msg->FindInt16("y",&y);
|
||||
view->cursorframe.OffsetTo(x,y);
|
||||
view->Invalidate(view->oldcursorframe);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
BWindow::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VDWindow::SafeMode(void)
|
||||
{
|
||||
SetScreen(B_32_BIT_640x480);
|
||||
}
|
||||
|
||||
void VDWindow::Reset(void)
|
||||
{
|
||||
SafeMode();
|
||||
Clear(255,255,255);
|
||||
}
|
||||
|
||||
void VDWindow::SetScreen(uint32 space)
|
||||
{
|
||||
switch(space)
|
||||
{
|
||||
case B_32_BIT_640x480:
|
||||
case B_16_BIT_640x480:
|
||||
case B_8_BIT_640x480:
|
||||
{
|
||||
ResizeTo(640.0,480.0);
|
||||
//printf("SetScreen(): 640x480\n");
|
||||
break;
|
||||
}
|
||||
case B_32_BIT_800x600:
|
||||
case B_16_BIT_800x600:
|
||||
case B_8_BIT_800x600:
|
||||
{
|
||||
ResizeTo(800.0,600.0);
|
||||
//printf("SetScreen(): 800x600\n");
|
||||
break;
|
||||
}
|
||||
case B_32_BIT_1024x768:
|
||||
case B_16_BIT_1024x768:
|
||||
case B_8_BIT_1024x768:
|
||||
{
|
||||
ResizeTo(1024.0,768.0);
|
||||
//printf("SetScreen(): 1024x768\n");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void VDWindow::Clear(uint8 red,uint8 green,uint8 blue)
|
||||
{
|
||||
//printf("Clear: (%d,%d,%d)\n",red,green,blue);
|
||||
view->viewbmp->Lock();
|
||||
view->viewbmp->AddChild(view->drawview);
|
||||
view->drawview->SetHighColor(red,green,blue);
|
||||
view->drawview->FillRect(view->drawview->Bounds());
|
||||
view->viewbmp->RemoveChild(view->drawview);
|
||||
view->viewbmp->Unlock();
|
||||
view->Invalidate();
|
||||
}
|
||||
|
||||
bool VDWindow::QuitRequested(void)
|
||||
{
|
||||
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||
if(serverport!=B_NAME_NOT_FOUND)
|
||||
{
|
||||
write_port(serverport,B_QUIT_REQUESTED,NULL,0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void VDWindow::WindowActivated(bool active)
|
||||
{
|
||||
// This is just to hide the regular system cursor so we can see our own
|
||||
if(active)
|
||||
be_app->HideCursor();
|
||||
else
|
||||
be_app->ShowCursor();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
Posting messages to the rendering window helps run right around a whole
|
||||
migraine's worth of multithreaded code
|
||||
*/
|
||||
|
||||
ViewDriver::ViewDriver(void)
|
||||
{
|
||||
screenwin=new VDWindow();
|
||||
hide_cursor=0;
|
||||
}
|
||||
|
||||
ViewDriver::~ViewDriver(void)
|
||||
{
|
||||
if(is_initialized)
|
||||
{
|
||||
screenwin->Lock();
|
||||
screenwin->Quit();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewDriver::Initialize(void)
|
||||
{
|
||||
locker->Lock();
|
||||
screenwin->Show();
|
||||
is_initialized=true;
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::Shutdown(void)
|
||||
{
|
||||
locker->Lock();
|
||||
screenwin->Lock();
|
||||
screenwin->Close();
|
||||
is_initialized=false;
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::SafeMode(void)
|
||||
{
|
||||
locker->Lock();
|
||||
screenwin->PostMessage(VDWIN_SAFEMODE);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::Reset(void)
|
||||
{
|
||||
locker->Lock();
|
||||
screenwin->PostMessage(VDWIN_RESET);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::SetScreen(uint32 space)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_SETSCREEN);
|
||||
msg->AddInt32("screenmode",space);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::Clear(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_CLEAR);
|
||||
msg->AddInt8("red",red);
|
||||
msg->AddInt8("green",green);
|
||||
msg->AddInt8("blue",blue);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::StrokeRect(BRect rect,rgb_color color)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_STROKERECT);
|
||||
msg->AddRect("rect",rect);
|
||||
msg->AddInt8("red",color.red);
|
||||
msg->AddInt8("green",color.green);
|
||||
msg->AddInt8("blue",color.blue);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::FillRect(BRect rect, rgb_color color)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_FILLRECT);
|
||||
msg->AddRect("rect",rect);
|
||||
msg->AddInt8("red",color.red);
|
||||
msg->AddInt8("green",color.green);
|
||||
msg->AddInt8("blue",color.blue);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::StrokeEllipse(BRect rect,rgb_color color)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_STROKEELLIPSE);
|
||||
msg->AddRect("rect",rect);
|
||||
msg->AddInt8("red",color.red);
|
||||
msg->AddInt8("green",color.green);
|
||||
msg->AddInt8("blue",color.blue);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::FillEllipse(BRect rect,rgb_color color)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_FILLELLIPSE);
|
||||
msg->AddRect("rect",rect);
|
||||
msg->AddInt8("red",color.red);
|
||||
msg->AddInt8("green",color.green);
|
||||
msg->AddInt8("blue",color.blue);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::Blit(BPoint dest, ServerBitmap *sourcebmp, ServerBitmap *destbmp)
|
||||
{
|
||||
}
|
||||
|
||||
void ViewDriver::SetCursor(int32 value)
|
||||
{
|
||||
}
|
||||
|
||||
void ViewDriver::SetCursor(ServerCursor *cursor)
|
||||
{
|
||||
}
|
||||
|
||||
void ViewDriver::ShowCursor(void)
|
||||
{
|
||||
locker->Lock();
|
||||
if(hide_cursor>0)
|
||||
{
|
||||
hide_cursor--;
|
||||
screenwin->PostMessage(VDWIN_SHOWCURSOR);
|
||||
}
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
void ViewDriver::HideCursor(void)
|
||||
{
|
||||
locker->Lock();
|
||||
hide_cursor++;
|
||||
screenwin->PostMessage(VDWIN_HIDECURSOR);
|
||||
locker->Unlock();
|
||||
}
|
||||
|
||||
bool ViewDriver::IsCursorHidden(void)
|
||||
{
|
||||
locker->Lock();
|
||||
bool value=(hide_cursor>0)?true:false;
|
||||
locker->Unlock();
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void ViewDriver::MoveCursorTo(int x, int y)
|
||||
{
|
||||
locker->Lock();
|
||||
BMessage *msg=new BMessage(VDWIN_MOVECURSOR);
|
||||
msg->AddInt16("x",x);
|
||||
msg->AddInt16("y",y);
|
||||
screenwin->PostMessage(msg);
|
||||
locker->Unlock();
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
#ifndef _VIEWDRIVER_H_
|
||||
#define _VIEWDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <Cursor.h>
|
||||
#include <Message.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class BBitmap;
|
||||
class PortLink;
|
||||
class VDWindow;
|
||||
class ServerCursor;
|
||||
|
||||
class VDView : public BView
|
||||
{
|
||||
public:
|
||||
VDView(BRect bounds);
|
||||
~VDView(void);
|
||||
void AttachedToWindow(void);
|
||||
void Draw(BRect rect);
|
||||
void MouseDown(BPoint pt);
|
||||
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
|
||||
void MouseUp(BPoint pt);
|
||||
|
||||
BBitmap *viewbmp;
|
||||
BView *drawview;
|
||||
PortLink *serverlink;
|
||||
|
||||
protected:
|
||||
friend VDWindow;
|
||||
|
||||
int hide_cursor;
|
||||
BBitmap *cursor;
|
||||
|
||||
BRect cursorframe, oldcursorframe;
|
||||
};
|
||||
|
||||
class VDWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
VDWindow(void);
|
||||
~VDWindow(void);
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool QuitRequested(void);
|
||||
void WindowActivated(bool active);
|
||||
|
||||
void SafeMode(void);
|
||||
void Reset(void);
|
||||
void SetScreen(uint32 space);
|
||||
void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
|
||||
VDView *view;
|
||||
BCursor *pick, *cross;
|
||||
};
|
||||
|
||||
class ViewDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
ViewDriver(void);
|
||||
virtual ~ViewDriver(void);
|
||||
|
||||
virtual void Initialize(void);
|
||||
virtual void Shutdown(void);
|
||||
virtual void SafeMode(void);
|
||||
virtual void Reset(void);
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
|
||||
virtual void StrokeRect(BRect rect,rgb_color color);
|
||||
virtual void FillRect(BRect rect, rgb_color color);
|
||||
virtual void StrokeEllipse(BRect rect,rgb_color color);
|
||||
virtual void FillEllipse(BRect rect,rgb_color color);
|
||||
virtual void Blit(BPoint dest, ServerBitmap *sourcebmp, ServerBitmap *destbmp);
|
||||
|
||||
virtual void SetCursor(int32 value);
|
||||
virtual void SetCursor(ServerCursor *cursor);
|
||||
virtual void ShowCursor(void);
|
||||
virtual void HideCursor(void);
|
||||
virtual bool IsCursorHidden(void);
|
||||
virtual void MoveCursorTo(int x, int y);
|
||||
VDWindow *screenwin;
|
||||
protected:
|
||||
int hide_cursor;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,323 +0,0 @@
|
||||
#include <Message.h>
|
||||
#include <AppDefs.h>
|
||||
#include "scheduler.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
#include "AppServer.h"
|
||||
#include "ServerApp.h"
|
||||
#include "Desktop.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
#include "DisplayDriver.h"
|
||||
#include "DebugTools.h"
|
||||
|
||||
AppServer::AppServer(void) : BApplication("application/x-vnd.obe-OBAppServer")
|
||||
{
|
||||
// printf("AppServer()\n");
|
||||
|
||||
mouseport=create_port(30,SERVER_INPUT_PORT);
|
||||
messageport=create_port(20,SERVER_PORT_NAME);
|
||||
// printf("Server message port: %ld\n",messageport);
|
||||
// printf("Server input port: %ld\n",mouseport);
|
||||
applist=new BList(0);
|
||||
quitting_server=false;
|
||||
exit_poller=false;
|
||||
|
||||
// Set up the Desktop
|
||||
init_desktop(3);
|
||||
|
||||
// Spawn our input-polling thread
|
||||
poller_id = spawn_thread(PollerThread, "Poller", B_NORMAL_PRIORITY, this);
|
||||
if (poller_id >= 0)
|
||||
resume_thread(poller_id);
|
||||
driver=get_gfxdriver();
|
||||
|
||||
active_app=-1;
|
||||
p_active_app=NULL;
|
||||
|
||||
// This is necessary to mediate access between the Poller and app_server threads
|
||||
active_lock=new BLocker;
|
||||
}
|
||||
|
||||
AppServer::~AppServer(void)
|
||||
{
|
||||
shutdown_desktop();
|
||||
|
||||
ServerApp *temp;
|
||||
for(int32 i=0;i<applist->CountItems();i++)
|
||||
{
|
||||
temp=(ServerApp *)applist->ItemAt(i);
|
||||
if(temp!=NULL)
|
||||
delete temp;
|
||||
}
|
||||
delete applist;
|
||||
delete active_lock;
|
||||
}
|
||||
|
||||
thread_id AppServer::Run(void)
|
||||
{
|
||||
//printf("AppServer::Run()\n");
|
||||
|
||||
MainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AppServer::MainLoop(void)
|
||||
{
|
||||
// Main loop (duh). Monitors the message queue and dispatches as appropriate.
|
||||
// Input messages are handled by the poller, however.
|
||||
|
||||
//printf("AppServer::MainLoop()\n");
|
||||
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(messageport);
|
||||
if(buffersize>0)
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(messageport,&msgcode,msgbuffer,buffersize);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case CREATE_APP:
|
||||
case DELETE_APP:
|
||||
case B_QUIT_REQUESTED:
|
||||
DispatchMessage(msgcode,msgbuffer);
|
||||
break;
|
||||
default:
|
||||
//printf("Server received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
if(msgcode==DELETE_APP || msgcode==B_QUIT_REQUESTED)
|
||||
{
|
||||
if(quitting_server==true && applist->CountItems()==0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Make sure our polling thread has exited
|
||||
if(find_thread("Poller")!=B_NAME_NOT_FOUND)
|
||||
kill_thread(poller_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AppServer::DispatchMessage(int32 code, int8 *buffer)
|
||||
{
|
||||
int8 *index=buffer;
|
||||
switch(code)
|
||||
{
|
||||
case CREATE_APP:
|
||||
{
|
||||
// Create the ServerApp to node monitor a new BApplication
|
||||
|
||||
//printf("AppServer: Create App\n");
|
||||
|
||||
// Attached data:
|
||||
// 1) port_id - receiver port of a regular app
|
||||
// 2) char * - signature of the regular app
|
||||
|
||||
// Find the necessary data
|
||||
port_id app_port=*((port_id*)index);
|
||||
index+=sizeof(port_id);
|
||||
|
||||
char *app_signature=(char *)index;
|
||||
|
||||
// Create the ServerApp subthread for this app
|
||||
ServerApp *newapp=new ServerApp(app_port,app_signature);
|
||||
applist->AddItem(newapp);
|
||||
|
||||
active_lock->Lock();
|
||||
p_active_app=newapp;
|
||||
active_app=applist->CountItems()-1;
|
||||
active_lock->Unlock();
|
||||
|
||||
newapp->Run();
|
||||
|
||||
break;
|
||||
}
|
||||
case DELETE_APP:
|
||||
{
|
||||
// Delete a ServerApp. Received only from the respective ServerApp when a
|
||||
// BApplication asks it to quit.
|
||||
|
||||
//printf("AppServer: Delete App\n");
|
||||
|
||||
// Attached Data:
|
||||
// 1) thread_id - thread ID of the ServerApp to be deleted
|
||||
|
||||
int32 i, appnum=applist->CountItems();
|
||||
ServerApp *srvapp;
|
||||
thread_id srvapp_id=*((thread_id*)buffer);
|
||||
|
||||
// Run through the list of apps and nuke the proper one
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL && srvapp->monitor_thread==srvapp_id)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->RemoveItem(i);
|
||||
delete srvapp;
|
||||
active_lock->Lock();
|
||||
|
||||
if(applist->CountItems()==0)
|
||||
{
|
||||
// active==-1 signifies that no other apps are running - NOT good
|
||||
active_app=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we actually still have apps running, so make a new one active
|
||||
if(active_app>0)
|
||||
active_app--;
|
||||
else
|
||||
active_app=0;
|
||||
}
|
||||
p_active_app=(active_app>-1)?(ServerApp*)applist->ItemAt(active_app):NULL;
|
||||
active_lock->Unlock();
|
||||
break; // jump out of the loop
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
//printf("Shutdown sequence initiated.\n");
|
||||
|
||||
// Attached Data:
|
||||
// none
|
||||
|
||||
// We've been asked to quit, so (for now) broadcast to all
|
||||
// test apps to quit. This situation will occur only when the server
|
||||
// is compiled as a regular Be application.
|
||||
PortLink *applink=new PortLink(0);
|
||||
ServerApp *srvapp;
|
||||
int32 i,appnum=applist->CountItems();
|
||||
|
||||
applink->SetOpCode(QUIT_APP);
|
||||
for(i=0;i<appnum;i++)
|
||||
{
|
||||
srvapp=(ServerApp *)applist->ItemAt(i);
|
||||
if(srvapp!=NULL)
|
||||
{
|
||||
applink->SetPort(srvapp->receiver);
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
delete applink;
|
||||
// So when we delete the last ServerApp, we can exit the server
|
||||
quitting_server=true;
|
||||
exit_poller=true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//printf("Unexpected message %ld (%lx) in AppServer::DispatchMessage()\n",code,code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void AppServer::Poller(void)
|
||||
{
|
||||
// This thread handles nothing but input messages for mouse and keyboard
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL,*index;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(mouseport);
|
||||
if(buffersize>0)
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(mouseport,&msgcode,msgbuffer,buffersize);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
// We don't need to do anything with these two, so just pass them
|
||||
// onto the active application. Eventually, we will pass them onto
|
||||
// the window which is currently under the cursor.
|
||||
case B_MOUSE_DOWN:
|
||||
case B_MOUSE_UP:
|
||||
{
|
||||
active_lock->Lock();
|
||||
if(active_app>-1)
|
||||
write_port(p_active_app->receiver, msgcode,msgbuffer,buffersize);
|
||||
active_lock->Unlock();
|
||||
break;
|
||||
}
|
||||
|
||||
// Process the cursor and then pass it on
|
||||
case B_MOUSE_MOVED:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) int64 - time of mouse click
|
||||
// 2) float - x coordinate of mouse click
|
||||
// 3) float - y coordinate of mouse click
|
||||
// 4) int32 - buttons down
|
||||
|
||||
index=msgbuffer;
|
||||
|
||||
// Time sent is not necessary for cursor processing.
|
||||
index += sizeof(int64);
|
||||
|
||||
float tempx=0,tempy=0;
|
||||
tempx=*((float*)index);
|
||||
index+=sizeof(float);
|
||||
tempy=*((float*)index);
|
||||
index+=sizeof(float);
|
||||
|
||||
driver->MoveCursorTo(tempx,tempy);
|
||||
|
||||
active_lock->Lock();
|
||||
if(active_app>-1)
|
||||
write_port(p_active_app->receiver, msgcode,msgbuffer,buffersize);
|
||||
active_lock->Unlock();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//printf("Server::Poller received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(exit_poller)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32 AppServer::PollerThread(void *data)
|
||||
{
|
||||
//printf("Starting Poller thread...\n");
|
||||
AppServer *server=(AppServer *)data;
|
||||
|
||||
server->Poller(); // This won't return until it's told to
|
||||
|
||||
//printf("Exiting Poller thread...\n");
|
||||
exit_thread(B_OK);
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
AppServer *obas = new AppServer();
|
||||
obas->Run();
|
||||
delete obas;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
#ifndef _OPENBEOS_APP_SERVER_H_
|
||||
#define _OPENBEOS_APP_SERVER_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
#include <Application.h>
|
||||
#include <List.h>
|
||||
|
||||
class BMessage;
|
||||
class ServerApp;
|
||||
class DisplayDriver;
|
||||
|
||||
class AppServer : public BApplication
|
||||
{
|
||||
public:
|
||||
AppServer(void);
|
||||
~AppServer(void);
|
||||
thread_id Run(void);
|
||||
void MainLoop(void);
|
||||
port_id messageport,mouseport;
|
||||
void Poller(void);
|
||||
|
||||
private:
|
||||
void DispatchMessage(int32 code, int8 *buffer);
|
||||
static int32 PollerThread(void *data);
|
||||
|
||||
bool quitting_server;
|
||||
BList *applist;
|
||||
int32 active_app;
|
||||
ServerApp *p_active_app;
|
||||
thread_id poller_id;
|
||||
BLocker *active_lock;
|
||||
bool exit_poller;
|
||||
DisplayDriver *driver;
|
||||
};
|
||||
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
Cursor display is just a little bit funky (try moving cursor by 1 pixel)
|
@ -1,19 +0,0 @@
|
||||
Prototype 4
|
||||
|
||||
Serious DisplayDriver API changes
|
||||
Support of cursordata-based SetCursor calls by test app (ServerCursor translates them to 32-bit bitmaps)
|
||||
TestApp has been modified to test the graphics access module
|
||||
Implemented many, many BView graphics calls and appropriate protocols
|
||||
BShape, BRegion, and BPolygon graphics calls not implemented.
|
||||
BFont-based calls, save DrawString and SetFontSize, are unimplemented.
|
||||
Partial foundation laid for BBitmap support
|
||||
|
||||
Prototype 3
|
||||
|
||||
Added GUI and hardcoded cursor
|
||||
|
||||
|
||||
Prototype 2
|
||||
|
||||
Adding and removing test applications
|
||||
Quitting server causes all test apps to quit also
|
@ -1,205 +0,0 @@
|
||||
#include <iostream.h>
|
||||
#include <String.h>
|
||||
#include "DebugTools.h"
|
||||
|
||||
void PrintStatusToStream(status_t value)
|
||||
{
|
||||
// Function which simply translates a returned status code into a string
|
||||
// and dumps it to stdout
|
||||
BString outstr;
|
||||
switch(value)
|
||||
{
|
||||
case B_OK:
|
||||
outstr="B_OK ";
|
||||
break;
|
||||
case B_NAME_NOT_FOUND:
|
||||
outstr="B_NAME_NOT_FOUND ";
|
||||
break;
|
||||
case B_BAD_VALUE:
|
||||
outstr="B_BAD_VALUE ";
|
||||
break;
|
||||
case B_ERROR:
|
||||
outstr="B_ERROR ";
|
||||
break;
|
||||
case B_TIMED_OUT:
|
||||
outstr="B_TIMED_OUT ";
|
||||
break;
|
||||
case B_NO_MORE_PORTS:
|
||||
outstr="B_NO_MORE_PORTS ";
|
||||
break;
|
||||
case B_WOULD_BLOCK:
|
||||
outstr="B_WOULD_BLOCK ";
|
||||
break;
|
||||
case B_BAD_PORT_ID:
|
||||
outstr="B_BAD_PORT_ID ";
|
||||
break;
|
||||
case B_BAD_TEAM_ID:
|
||||
outstr="B_BAD_TEAM_ID ";
|
||||
break;
|
||||
default:
|
||||
outstr="undefined status value in debugtools::PrintStatusToStream() ";
|
||||
break;
|
||||
}
|
||||
cout << "Status: " << outstr.String() << endl << flush;
|
||||
|
||||
}
|
||||
|
||||
void PrintColorSpaceToStream(color_space value)
|
||||
{
|
||||
// Dump a color space to cout
|
||||
BString outstr;
|
||||
switch(value)
|
||||
{
|
||||
case B_RGB32:
|
||||
outstr="B_RGB32 ";
|
||||
break;
|
||||
case B_RGBA32:
|
||||
outstr="B_RGBA32 ";
|
||||
break;
|
||||
case B_RGB32_BIG:
|
||||
outstr="B_RGB32_BIG ";
|
||||
break;
|
||||
case B_RGBA32_BIG:
|
||||
outstr=" ";
|
||||
break;
|
||||
case B_UVL32:
|
||||
outstr="B_UVL32 ";
|
||||
break;
|
||||
case B_UVLA32:
|
||||
outstr="B_UVLA32 ";
|
||||
break;
|
||||
case B_LAB32:
|
||||
outstr="B_LAB32 ";
|
||||
break;
|
||||
case B_LABA32:
|
||||
outstr="B_LABA32 ";
|
||||
break;
|
||||
case B_HSI32:
|
||||
outstr="B_HSI32 ";
|
||||
break;
|
||||
case B_HSIA32:
|
||||
outstr="B_HSIA32 ";
|
||||
break;
|
||||
case B_HSV32:
|
||||
outstr="B_HSV32 ";
|
||||
break;
|
||||
case B_HSVA32:
|
||||
outstr="B_HSVA32 ";
|
||||
break;
|
||||
case B_HLS32:
|
||||
outstr="B_HLS32 ";
|
||||
break;
|
||||
case B_HLSA32:
|
||||
outstr="B_HLSA32 ";
|
||||
break;
|
||||
case B_CMY32:
|
||||
outstr="B_CMY32";
|
||||
break;
|
||||
case B_CMYA32:
|
||||
outstr="B_CMYA32 ";
|
||||
break;
|
||||
case B_CMYK32:
|
||||
outstr="B_CMYK32 ";
|
||||
break;
|
||||
case B_RGB24_BIG:
|
||||
outstr="B_RGB24_BIG ";
|
||||
break;
|
||||
case B_RGB24:
|
||||
outstr="B_RGB24 ";
|
||||
break;
|
||||
case B_LAB24:
|
||||
outstr="B_LAB24 ";
|
||||
break;
|
||||
case B_UVL24:
|
||||
outstr="B_UVL24 ";
|
||||
break;
|
||||
case B_HSI24:
|
||||
outstr="B_HSI24 ";
|
||||
break;
|
||||
case B_HSV24:
|
||||
outstr="B_HSV24 ";
|
||||
break;
|
||||
case B_HLS24:
|
||||
outstr="B_HLS24 ";
|
||||
break;
|
||||
case B_CMY24:
|
||||
outstr="B_CMY24 ";
|
||||
break;
|
||||
case B_GRAY1:
|
||||
outstr="B_GRAY1 ";
|
||||
break;
|
||||
case B_CMAP8:
|
||||
outstr="B_CMAP8 ";
|
||||
break;
|
||||
case B_GRAY8:
|
||||
outstr="B_GRAY8 ";
|
||||
break;
|
||||
case B_YUV411:
|
||||
outstr="B_YUV411 ";
|
||||
break;
|
||||
case B_YUV420:
|
||||
outstr="B_YUV420 ";
|
||||
break;
|
||||
case B_YCbCr422:
|
||||
outstr="B_YCbCr422 ";
|
||||
break;
|
||||
case B_YCbCr411:
|
||||
outstr="B_YCbCr411 ";
|
||||
break;
|
||||
case B_YCbCr420:
|
||||
outstr="B_YCbCr420 ";
|
||||
break;
|
||||
case B_YUV422:
|
||||
outstr="B_YUV422 ";
|
||||
break;
|
||||
case B_YUV9:
|
||||
outstr="B_YUV9 ";
|
||||
break;
|
||||
case B_YUV12:
|
||||
outstr="B_YUV12 ";
|
||||
break;
|
||||
case B_RGB15:
|
||||
outstr="B_RGB15 ";
|
||||
break;
|
||||
case B_RGBA15:
|
||||
outstr="B_RGBA15 ";
|
||||
break;
|
||||
case B_RGB16:
|
||||
outstr="B_RGB16 ";
|
||||
break;
|
||||
case B_RGB16_BIG:
|
||||
outstr="B_RGB16_BIG ";
|
||||
break;
|
||||
case B_RGB15_BIG:
|
||||
outstr="B_RGB15_BIG ";
|
||||
break;
|
||||
case B_RGBA15_BIG:
|
||||
outstr="B_RGBA15_BIG ";
|
||||
break;
|
||||
case B_YCbCr444:
|
||||
outstr="B_YCbCr444 ";
|
||||
break;
|
||||
case B_YUV444:
|
||||
outstr="B_YUV444 ";
|
||||
break;
|
||||
case B_NO_COLOR_SPACE:
|
||||
outstr="B_NO_COLOR_SPACE ";
|
||||
break;
|
||||
default:
|
||||
outstr="Undefined color space ";
|
||||
break;
|
||||
}
|
||||
cout << "Color Space: " << outstr.String() << flush;
|
||||
}
|
||||
|
||||
void TranslateMessageCodeToStream(int32 code)
|
||||
{
|
||||
// Used to translate BMessage message codes back to a character
|
||||
// format
|
||||
|
||||
cout << "'"
|
||||
<< (char)((code & 0xFF000000) >> 24)
|
||||
<< (char)((code & 0x00FF0000) >> 16)
|
||||
<< (char)((code & 0x0000FF00) >> 8)
|
||||
<< (char)((code & 0x000000FF)) << "' ";
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
#ifndef _DEBUGTOOLS_H_
|
||||
#define _DEBUGTOOLS_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
void PrintStatusToStream(status_t value);
|
||||
void PrintColorSpaceToStream(color_space value);
|
||||
void TranslateMessageCodeToStream(int32 code);
|
||||
|
||||
#endif
|
@ -1,338 +0,0 @@
|
||||
/*
|
||||
Desktop.cpp:
|
||||
Code necessary to handle the Desktop, defined as the collection of workspaces.
|
||||
*/
|
||||
|
||||
//#define DEBUG_WORKSPACES
|
||||
|
||||
#include <List.h>
|
||||
#include <Path.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <stdio.h>
|
||||
#include "DisplayDriver.h"
|
||||
#include "ViewDriver.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
class ServerWindow;
|
||||
class ServerBitmap;
|
||||
class Workspace;
|
||||
|
||||
// Quick hack to make setting rgb_colors much easier to live with
|
||||
void set_rgb_color(rgb_color *col,uint8 red, uint8 green, uint8 blue, uint8 alpha=255)
|
||||
{
|
||||
col->red=red;
|
||||
col->green=green;
|
||||
col->blue=blue;
|
||||
col->alpha=alpha;
|
||||
}
|
||||
|
||||
//--------------------GLOBALS-------------------------
|
||||
int32 workspace_count, active_workspace;
|
||||
BList *desktop;
|
||||
Workspace *pactive_workspace;
|
||||
color_map system_palette;
|
||||
ViewDriver *gfxdriver;
|
||||
//----------------------------------------------------
|
||||
|
||||
|
||||
//-------------------INTERNAL CLASS DEFS--------------
|
||||
class Workspace
|
||||
{
|
||||
public:
|
||||
Workspace(void);
|
||||
Workspace(BPath imagepath);
|
||||
~Workspace();
|
||||
|
||||
BList layerlist;
|
||||
BList focuslist;
|
||||
rgb_color bgcolor;
|
||||
screen_info screendata,
|
||||
olddata;
|
||||
};
|
||||
|
||||
DisplayDriver *get_gfxdriver(void)
|
||||
{
|
||||
return gfxdriver;
|
||||
}
|
||||
|
||||
Workspace::Workspace(void)
|
||||
{
|
||||
workspace_count++;
|
||||
|
||||
// default values
|
||||
layerlist.MakeEmpty();
|
||||
focuslist.MakeEmpty();
|
||||
bgcolor.red=51;
|
||||
bgcolor.green=102;
|
||||
bgcolor.blue=160;
|
||||
screendata.mode=B_CMAP8;
|
||||
screendata.spaces=B_8_BIT_640x480;
|
||||
screendata.refresh_rate=60.0;
|
||||
screendata.min_refresh_rate=60.0;
|
||||
screendata.max_refresh_rate=60.0;
|
||||
screendata.h_position=(uchar)50;
|
||||
screendata.v_position=(uchar)50;
|
||||
screendata.h_size=(uchar)50;
|
||||
screendata.v_size=(uchar)50;
|
||||
olddata=screendata;
|
||||
}
|
||||
|
||||
Workspace::~Workspace(void)
|
||||
{
|
||||
workspace_count--;
|
||||
}
|
||||
//---------------------------------------------------
|
||||
|
||||
|
||||
//-----------------GLOBAL FUNCTION DEFS---------------
|
||||
|
||||
void init_desktop(int8 workspaces)
|
||||
{
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("init_desktop(%d)\n",workspaces);
|
||||
#endif
|
||||
workspace_count=workspaces;
|
||||
if(workspace_count==0)
|
||||
workspace_count++;
|
||||
|
||||
// Instantiate and initialize display driver
|
||||
gfxdriver=new ViewDriver();
|
||||
gfxdriver->Initialize();
|
||||
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("Driver %s\n", (gfxdriver->IsInitialized()==true)?"initialized":"NOT initialized");
|
||||
#endif
|
||||
|
||||
desktop=new BList(0);
|
||||
|
||||
// Create the workspaces we're supposed to have
|
||||
for(int8 i=0; i<workspaces; i++)
|
||||
{
|
||||
desktop->AddItem(new Workspace());
|
||||
}
|
||||
|
||||
// Load workspace preferences here
|
||||
|
||||
// We're going to punch in some hardcoded settings for testing purposes.
|
||||
// There are 3 workspaces hardcoded in for now, but we'll only use the
|
||||
// second one.
|
||||
Workspace *wksp=(Workspace*)desktop->ItemAt(1);
|
||||
if(wksp!=NULL) // in case I forgot something
|
||||
{
|
||||
set_rgb_color(&(wksp->bgcolor),0,200,236);
|
||||
screen_info *tempsd=&(wksp->screendata);
|
||||
tempsd->mode=B_CMAP8;
|
||||
tempsd->spaces=B_8_BIT_800x600;
|
||||
tempsd->frame.Set(0,0,799,599);
|
||||
}
|
||||
else
|
||||
printf("DW goofed on the workspace index :P\n");
|
||||
|
||||
|
||||
// Activate workspace 0
|
||||
pactive_workspace=(Workspace *)desktop->ItemAt(0);
|
||||
gfxdriver->SetScreen(pactive_workspace->screendata.spaces);
|
||||
|
||||
// Clear the screen
|
||||
set_rgb_color(&(pactive_workspace->bgcolor),80,85,152);
|
||||
gfxdriver->Clear(pactive_workspace->bgcolor);
|
||||
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("Desktop initialized\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void shutdown_desktop(void)
|
||||
{
|
||||
int32 i,count=desktop->CountItems();
|
||||
for(i=0;i<count;i++)
|
||||
{
|
||||
if(desktop->ItemAt(i)!=NULL)
|
||||
delete desktop->ItemAt(i);
|
||||
}
|
||||
desktop->MakeEmpty();
|
||||
delete desktop;
|
||||
gfxdriver->Shutdown();
|
||||
delete gfxdriver;
|
||||
}
|
||||
|
||||
|
||||
int32 CountWorkspaces(void)
|
||||
{
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("CountWorkspaces() returned %ld\n",workspace_count);
|
||||
#endif
|
||||
return workspace_count;
|
||||
}
|
||||
|
||||
void SetWorkspaceCount(int32 count)
|
||||
{
|
||||
if(count<0)
|
||||
{
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("SetWorkspaceCount(value<0) - DOH!\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if(count==workspace_count)
|
||||
return;
|
||||
|
||||
// Activate last workspace in new set if we're using one to be nuked
|
||||
if(count<active_workspace)
|
||||
activate_workspace(count);
|
||||
|
||||
if(count < workspace_count)
|
||||
{
|
||||
for(int32 i=count;i<workspace_count;i++)
|
||||
{
|
||||
if(desktop->ItemAt(i)!=NULL)
|
||||
{
|
||||
delete (Workspace*)desktop->ItemAt(i);
|
||||
desktop->RemoveItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// count > workspace_count here
|
||||
|
||||
// Once we have default workspace preferences which can be set by the
|
||||
// user, we'll end up having to initialize newly-added workspaces to that
|
||||
// data. In the mean time, the defaults in the constructor will do. :)
|
||||
for(int32 i=count;i<workspace_count;i++)
|
||||
{
|
||||
desktop->AddItem(new Workspace());
|
||||
}
|
||||
}
|
||||
|
||||
// don't forget to update our global!
|
||||
workspace_count=desktop->CountItems();
|
||||
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("SetWorkspaceCount(%ld)\n",workspace_count);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int32 CurrentWorkspace(void)
|
||||
{
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("CurrentWorkspace() returned %ld\n",active_workspace);
|
||||
#endif
|
||||
return active_workspace;
|
||||
}
|
||||
|
||||
void ActivateWorkspace(int32 workspace)
|
||||
{
|
||||
// In order to change workspaces, we'll need to make all the necessary
|
||||
// changes to the screen to fit the new one, such as resolution,
|
||||
// background color, color depth, refresh rate, etc.
|
||||
|
||||
if(workspace>workspace_count || workspace<0)
|
||||
return;
|
||||
|
||||
Workspace *proposed=(Workspace *)desktop->ItemAt(workspace);
|
||||
|
||||
if(proposed==NULL)
|
||||
return;
|
||||
|
||||
// Here's where we update all the screen stuff
|
||||
if(pactive_workspace->screendata.spaces != proposed->screendata.spaces)
|
||||
{
|
||||
gfxdriver->SetScreen(proposed->screendata.spaces);
|
||||
gfxdriver->Clear(proposed->bgcolor);
|
||||
}
|
||||
// more if != then change code goes here. Currently, a lot of the code which
|
||||
// uses this stuff is not implemented, so it's kind of moot. However, when we
|
||||
// use the real graphics HW, it'll become important.
|
||||
|
||||
// actually set our active workspace data to reflect the change in workspaces
|
||||
pactive_workspace=proposed;
|
||||
active_workspace=workspace;
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("ActivateWorkspace(%ld)\n",active_workspace);
|
||||
#endif
|
||||
}
|
||||
|
||||
const color_map *SystemColors(void)
|
||||
{
|
||||
return (const color_map *)&system_palette;
|
||||
}
|
||||
|
||||
status_t SetScreenSpace(int32 index, uint32 res, bool stick = true)
|
||||
{
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
printf("SetScreenSpace(%ld,%lu, %s)\n",index,res,(stick==true)?"true":"false");
|
||||
#endif
|
||||
|
||||
if(index>workspace_count-1)
|
||||
{
|
||||
printf("SetScreenSpace was passed invalid workspace value %ld\n",index);
|
||||
return B_ERROR;
|
||||
}
|
||||
if(res>0x800000) // the last "normal" screen mode defined in GraphicsDefs.h
|
||||
{
|
||||
printf("SetScreenSpace was passed invalid screen value %lu\n",res);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
// When we actually use app_server preferences, we'll save the screen mode to
|
||||
// the preferences so that we use this mode next boot. For now, we treat stick==false
|
||||
if(stick==true)
|
||||
{
|
||||
// save the screen data here
|
||||
}
|
||||
if(index==active_workspace)
|
||||
{
|
||||
gfxdriver->SetScreen(res);
|
||||
gfxdriver->Clear(pactive_workspace->bgcolor);
|
||||
}
|
||||
else
|
||||
{
|
||||
// just set the workspace's data here. right now, do nothing.
|
||||
}
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
status_t GetScrollBarInfo(scroll_bar_info *info)
|
||||
{
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status_t SetScrollBarInfo(scroll_bar_info *info)
|
||||
{
|
||||
//printf("set_scroll_bar_info()\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
bigtime_t IdleTime()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RunSelectPrinterPanel()
|
||||
{ // Not sure what to do with this guy just yet
|
||||
}
|
||||
|
||||
void RunAddPrinterPanel()
|
||||
{ // Not sure what to do with this guy just yet
|
||||
}
|
||||
|
||||
void RunBeAbout()
|
||||
{ // the BeOS About Window belongs to Tracker....
|
||||
}
|
||||
|
||||
void SetFocusFollowsMouse(bool follow)
|
||||
{
|
||||
//printf("set_focus_follows_mouse(%s)\n",(follow==true)?"true":"false");
|
||||
}
|
||||
|
||||
bool FocusFollowsMouse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Another "just in case DW screws up again" section
|
||||
#ifdef DEBUG_WORKSPACES
|
||||
#undef DEBUG_WORKSPACES
|
||||
#endif
|
@ -1,37 +0,0 @@
|
||||
#ifndef _OBDESKTOP_H_
|
||||
#define _OBDESKTOP_H_
|
||||
|
||||
|
||||
#include <InterfaceDefs.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
class DisplayDriver;
|
||||
|
||||
void init_desktop(int8 workspaces);
|
||||
void shutdown_desktop(void);
|
||||
DisplayDriver *get_gfxdriver(void);
|
||||
|
||||
// Workspace access functions
|
||||
int32 CountWorkspaces(void);
|
||||
void SetWorkspaceCount(int32 count);
|
||||
int32 CurrentWorkspace(void);
|
||||
void ActivateWorkspace(int32 workspace);
|
||||
const color_map *SystemColors(void);
|
||||
status_t SetScreenSpace(int32 index, uint32 res, bool stick = true);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
color_space mode;
|
||||
BRect frame;
|
||||
uint32 spaces;
|
||||
float min_refresh_rate;
|
||||
float max_refresh_rate;
|
||||
float refresh_rate;
|
||||
uchar h_position;
|
||||
uchar v_position;
|
||||
uchar h_size;
|
||||
uchar v_size;
|
||||
} screen_info;
|
||||
|
||||
|
||||
#endif
|
@ -1,251 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include "DirectDriver.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifndef ABS
|
||||
#define ABS(a) (a<0)?a*-1:a
|
||||
#endif
|
||||
|
||||
OBAppServerScreen::OBAppServerScreen(status_t *error)
|
||||
: BDirectWindow(BRect(100,60,740,540),"OBOS App Server, P3",B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE)
|
||||
{
|
||||
redraw=true;
|
||||
}
|
||||
|
||||
OBAppServerScreen::~OBAppServerScreen(void)
|
||||
{
|
||||
}
|
||||
|
||||
void OBAppServerScreen::MessageReceived(BMessage *msg)
|
||||
{
|
||||
msg->PrintToStream();
|
||||
switch(msg->what)
|
||||
{
|
||||
case B_KEY_DOWN:
|
||||
// Disconnect();
|
||||
QuitRequested();
|
||||
break;
|
||||
default:
|
||||
BDirectWindow::MessageReceived(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool OBAppServerScreen::QuitRequested(void)
|
||||
{
|
||||
redraw=false;
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 OBAppServerScreen::Draw(void *data)
|
||||
{
|
||||
OBAppServerScreen *screen=(OBAppServerScreen *)data;
|
||||
for(;;)
|
||||
{
|
||||
if(screen->connected && screen->redraw)
|
||||
{
|
||||
// Draw a sample background
|
||||
screen->redraw=false;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void OBAppServerScreen::DirectConnected(direct_buffer_info *dbinfo)
|
||||
{
|
||||
/* if(ok==true)
|
||||
{
|
||||
connected=true;
|
||||
gcinfo=CardInfo();
|
||||
for(int8 i=0;i<48;i++)
|
||||
gchooks[i]=CardHookAt(i);
|
||||
}
|
||||
else
|
||||
connected=false;
|
||||
*/
|
||||
}
|
||||
|
||||
DirectDriver::DirectDriver(void)
|
||||
{
|
||||
// printf("DirectDriver()\n");
|
||||
// old_space=B_32_BIT_800x600;
|
||||
}
|
||||
|
||||
DirectDriver::~DirectDriver(void)
|
||||
{
|
||||
printf("~DirectDriver()\n");
|
||||
winscreen->Lock();
|
||||
winscreen->Close();
|
||||
}
|
||||
|
||||
void DirectDriver::Initialize(void)
|
||||
{
|
||||
/* printf("DirectDriver::Initialize()\n");
|
||||
status_t stat;
|
||||
winscreen=new OBAppServerScreen(&stat);
|
||||
if(stat==B_OK)
|
||||
winscreen->Show();
|
||||
else
|
||||
delete winscreen;
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::SafeMode(void)
|
||||
{
|
||||
/* printf("DirectDriver::SafeMode()\n");
|
||||
// SetScreen(B_8_BIT_640x480);
|
||||
SetScreen(B_32_BIT_800x600);
|
||||
Reset();
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::Reset(void)
|
||||
{
|
||||
/* printf("DirectDriver::Reset()\n");
|
||||
if(winscreen->connected==true)
|
||||
Clear(51,102,160);
|
||||
*/
|
||||
}
|
||||
|
||||
void DirectDriver::SetScreen(uint32 space)
|
||||
{
|
||||
// printf("DirectDriver::SetScreen(%lu)\n",space);
|
||||
// winscreen->SetSpace(space);
|
||||
}
|
||||
|
||||
void DirectDriver::Clear(uint8 red, uint8 green, uint8 blue)
|
||||
{
|
||||
/* // This simply clears the entire screen, utilizing a string and
|
||||
// memcpy to speed things up in a minor way
|
||||
printf("DirectDriver::Clear(%d,%d,%d)\n",red,green,blue);
|
||||
|
||||
if(winscreen->connected==false)
|
||||
return;
|
||||
|
||||
int i,imax,
|
||||
length=winscreen->gcinfo->bytes_per_row;
|
||||
int8 fillstring[length];
|
||||
|
||||
|
||||
switch(winscreen->gcinfo->bits_per_pixel)
|
||||
{
|
||||
case 32:
|
||||
{
|
||||
int32 color,*index32;
|
||||
|
||||
// order is going to be BGRA or ARGB
|
||||
if(winscreen->gcinfo->rgba_order[0]=='B')
|
||||
{
|
||||
// Create the number to quickly create the string
|
||||
|
||||
// BBGG RRAA in RAM => 0xRRAA BBGG
|
||||
color= (int32(red) << 24) + 0xFF0000L + (int32(blue) << 8) + green;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create the number to quickly create the string
|
||||
|
||||
// AARR GGBB in RAM
|
||||
color= 0xFF000000L + (int32(red) << 16) + (int32(green) << 8) + blue;
|
||||
}
|
||||
|
||||
// fill the string with the appropriate values
|
||||
index32=(int32 *)fillstring;
|
||||
imax=winscreen->gcinfo->width;
|
||||
|
||||
for(i=0;i<imax;i++)
|
||||
index32[i]=color;
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
/* case 16:
|
||||
{
|
||||
int16 color, *index16;
|
||||
|
||||
if(winscreen->gcinfo->rgba_order[0]=='B')
|
||||
{
|
||||
// Little-endian
|
||||
// G[2:0],B[4:0] R[4:0],G[5:3]
|
||||
|
||||
// Ick. Gotta love all that shifting and masking. :(
|
||||
color= (int16((green & 7)) << 13) +
|
||||
(int16((blue & 31)) << 8) +
|
||||
(int16((red & 31)) << 4) +
|
||||
(int16(green & 56));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Big-endian
|
||||
// R[4:0],G[5:3] G[2:0],B[4:0]
|
||||
color= (int16(red & 31) << 11) +
|
||||
(int16(green & 56) << 8) +
|
||||
(int16(green & 3) << 5) +
|
||||
(blue & 31);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 15:
|
||||
{
|
||||
|
||||
// RGBA_15:
|
||||
// G[2:0],B[4:0] A[0],R[4:0],G[4:3]
|
||||
|
||||
// RGBA_15_BIG:
|
||||
// A[0],R[4:0],G[4:3] G[2:0],B[4:0]
|
||||
break;
|
||||
}
|
||||
*/
|
||||
/* case 8:
|
||||
{
|
||||
// This is both the easiest and hardest:
|
||||
// We fill using memset(), but we have to find the closest match to the
|
||||
// color we've been given. Yuck.
|
||||
|
||||
// Find the closest match by comparing the differences in values for each
|
||||
// color. This function was not intended to be called rapidly, so speed is
|
||||
// not much of an issue at this point.
|
||||
int8 closest=0;
|
||||
int16 closest_delta=765, delta; // (255 * 3)
|
||||
|
||||
// Get the current palette
|
||||
rgb_color *list=winscreen->ColorList();
|
||||
for(i=0;i<256;i++)
|
||||
{
|
||||
delta=ABS(list->red-red)+ABS(list->green-green)+ABS(list->blue-blue);
|
||||
if(delta<closest_delta)
|
||||
{
|
||||
closest=i;
|
||||
closest_delta=delta;
|
||||
}
|
||||
}
|
||||
|
||||
// Theoretically, we now have the closest match, so simply fill the
|
||||
// frame buffer with the index
|
||||
memset(winscreen->gcinfo->frame_buffer,closest,
|
||||
winscreen->gcinfo->bytes_per_row * winscreen->gcinfo->height);
|
||||
|
||||
// Nothing left to do!
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Unsupported bit depth %d in DirectDriver::Clear(r,g,b)!!\n",winscreen->gcinfo->bits_per_pixel);
|
||||
return;
|
||||
}
|
||||
}
|
||||
imax=winscreen->gcinfo->height;
|
||||
|
||||
// a pointer to increment for the screen copy. Faster than doing a multiply
|
||||
// each iteration
|
||||
int8 *pbuffer=(int8*)winscreen->gcinfo->frame_buffer;
|
||||
for(i=0;i<imax;i++)
|
||||
{
|
||||
memcpy(pbuffer,fillstring,length);
|
||||
pbuffer+=length;
|
||||
}
|
||||
*/
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
#ifndef _DIRECTDRIVER_H_
|
||||
#define _DIRECTDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <DirectWindow.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <Message.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class OBAppServerScreen : public BDirectWindow
|
||||
{
|
||||
public:
|
||||
OBAppServerScreen(status_t *error);
|
||||
~OBAppServerScreen(void);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual bool QuitRequested(void);
|
||||
static int32 Draw(void *data);
|
||||
virtual void DirectConnected(direct_buffer_info *dbinfo);
|
||||
|
||||
int32 DrawID;
|
||||
bool redraw,connected;
|
||||
graphics_card_info *gcinfo;
|
||||
graphics_card_hook *gchooks;
|
||||
};
|
||||
|
||||
class DirectDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
DirectDriver(void);
|
||||
virtual ~DirectDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
// virtual void SetPixel(int x, int y, rgb_color color);
|
||||
// virtual void StrokeEllipse(BRect rect, rgb_color color);
|
||||
OBAppServerScreen *winscreen;
|
||||
|
||||
protected:
|
||||
// Original screen info
|
||||
uint32 old_space;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,230 +0,0 @@
|
||||
/*
|
||||
DisplayDriver.cpp
|
||||
Modular class to allow the server to not care what the ultimate output is
|
||||
for graphics calls.
|
||||
*/
|
||||
#include "DisplayDriver.h"
|
||||
#include "ServerCursor.h"
|
||||
|
||||
DisplayDriver::DisplayDriver(void)
|
||||
{
|
||||
is_initialized=false;
|
||||
cursor_visible=false;
|
||||
show_on_move=false;
|
||||
locker=new BLocker();
|
||||
|
||||
penpos.Set(0,0);
|
||||
pensize=0.0;
|
||||
|
||||
// initialize to BView defaults
|
||||
highcol.red=0;
|
||||
highcol.green=0;
|
||||
highcol.blue=0;
|
||||
highcol.alpha=0;
|
||||
lowcol.red=255;
|
||||
lowcol.green=255;
|
||||
lowcol.blue=255;
|
||||
lowcol.alpha=255;
|
||||
}
|
||||
|
||||
DisplayDriver::~DisplayDriver(void)
|
||||
{
|
||||
delete locker;
|
||||
}
|
||||
|
||||
void DisplayDriver::Initialize(void)
|
||||
{ // Loading loop to find proper driver or other setup for the driver
|
||||
}
|
||||
|
||||
bool DisplayDriver::IsInitialized(void)
|
||||
{ // Let us know whether things worked out ok
|
||||
return is_initialized;
|
||||
}
|
||||
|
||||
void DisplayDriver::Shutdown(void)
|
||||
{ // For use by subclasses
|
||||
}
|
||||
|
||||
void DisplayDriver::SafeMode(void)
|
||||
{ // Set video mode to 640x480x256 mode
|
||||
}
|
||||
|
||||
void DisplayDriver::Reset(void)
|
||||
{ // Intended to reload and restart driver. Defaults to a safe mode
|
||||
}
|
||||
|
||||
void DisplayDriver::Clear(uint8 red,uint8 green,uint8 blue)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::Clear(rgb_color col)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetScreen(uint32 space)
|
||||
{ // Set the screen to a particular mode
|
||||
}
|
||||
|
||||
int32 DisplayDriver::GetHeight(void)
|
||||
{ // Gets the height of the current mode
|
||||
return ginfo->height;
|
||||
}
|
||||
|
||||
int32 DisplayDriver::GetWidth(void)
|
||||
{ // Gets the width of the current mode
|
||||
return ginfo->width;
|
||||
}
|
||||
|
||||
int DisplayDriver::GetDepth(void)
|
||||
{ // Gets the color depth of the current mode
|
||||
return ginfo->bytes_per_row;
|
||||
}
|
||||
|
||||
void DisplayDriver::Blit(BPoint dest, ServerBitmap *sourcebmp, ServerBitmap *destbmp)
|
||||
{ // Screen-to-screen bitmap copying
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawBitmap(ServerBitmap *bitmap)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawChar(char c, BPoint point)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::DrawString(char *string, int length, BPoint point)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillBezier(BPoint *points, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillPolygon(int *x, int *y, int numpoints, bool is_closed)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRect(BRect rect, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRegion(BRegion *region)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillShape(BShape *shape)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::FillTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::HideCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool DisplayDriver::IsCursorHidden(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void DisplayDriver::ObscureCursor(void)
|
||||
{ // Hides cursor until mouse is moved
|
||||
}
|
||||
|
||||
void DisplayDriver::MoveCursorTo(float x, float y)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::MovePenTo(BPoint pt)
|
||||
{ // Moves the graphics pen to this position
|
||||
}
|
||||
|
||||
BPoint DisplayDriver::PenPosition(void)
|
||||
{
|
||||
return penpos;
|
||||
}
|
||||
|
||||
float DisplayDriver::PenSize(void)
|
||||
{
|
||||
return pensize;
|
||||
}
|
||||
|
||||
void DisplayDriver::SetCursor(ServerCursor *cursor)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetCursor(int32 value)
|
||||
{ // This is used just to provide an easy way of setting one of the default cursors
|
||||
// Then again, I may just get rid of this thing.
|
||||
}
|
||||
|
||||
void DisplayDriver::SetHighColor(uint8 r,uint8 g,uint8 b,uint8 a=255)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetLowColor(uint8 r,uint8 g,uint8 b,uint8 a=255)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetPenSize(float size)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::SetPixel(int x, int y, uint8 *pattern)
|
||||
{ // Internal function utilized by other functions to draw to the buffer
|
||||
// Will eventually be an inline function
|
||||
}
|
||||
|
||||
void DisplayDriver::ShowCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeBezier(BPoint *points, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeLine(BPoint point, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokePolygon(int *x, int *y, int numpoints, bool is_closed)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeRect(BRect rect, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeShape(BShape *shape)
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayDriver::StrokeTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern)
|
||||
{
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
#ifndef _GFX_DRIVER_H_
|
||||
#define _GFX_DRIVER_H_
|
||||
|
||||
#include <GraphicsCard.h>
|
||||
#include <Rect.h>
|
||||
#include <Locker.h>
|
||||
#include "Desktop.h"
|
||||
|
||||
class ServerBitmap;
|
||||
class ServerCursor;
|
||||
|
||||
#ifndef ROUND
|
||||
#define ROUND(a) ( (a-long(a))>=.5)?(long(a)+1):(long(a))
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uchar *xormask, *andmask;
|
||||
int32 width, height;
|
||||
int32 hotx, hoty;
|
||||
|
||||
} cursor_data;
|
||||
|
||||
#ifndef HOOK_DEFINE_CURSOR
|
||||
|
||||
#define HOOK_DEFINE_CURSOR 0
|
||||
#define HOOK_MOVE_CURSOR 1
|
||||
#define HOOK_SHOW_CURSOR 2
|
||||
#define HOOK_DRAW_LINE_8BIT 3
|
||||
#define HOOK_DRAW_LINE_16BIT 12
|
||||
#define HOOK_DRAW_LINE_32BIT 4
|
||||
#define HOOK_DRAW_RECT_8BIT 5
|
||||
#define HOOK_DRAW_RECT_16BIT 13
|
||||
#define HOOK_DRAW_RECT_32BIT 6
|
||||
#define HOOK_BLIT 7
|
||||
#define HOOK_DRAW_ARRAY_8BIT 8
|
||||
#define HOOK_DRAW_ARRAY_16BIT 14 // Not implemented in current R5 drivers
|
||||
#define HOOK_DRAW_ARRAY_32BIT 9
|
||||
#define HOOK_SYNC 10
|
||||
#define HOOK_INVERT_RECT 11
|
||||
|
||||
#endif
|
||||
|
||||
class ServerCursor;
|
||||
|
||||
class DisplayDriver
|
||||
{
|
||||
public:
|
||||
DisplayDriver(void);
|
||||
virtual ~DisplayDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual bool IsInitialized(void);
|
||||
virtual void Shutdown(void); // You never know when you'll need this
|
||||
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
virtual void Clear(rgb_color col);
|
||||
|
||||
// Settings functions
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual int32 GetHeight(void);
|
||||
virtual int32 GetWidth(void);
|
||||
virtual int GetDepth(void);
|
||||
|
||||
// Drawing functions
|
||||
virtual void Blit(BPoint dest, ServerBitmap *src, ServerBitmap *dest);
|
||||
virtual void DrawBitmap(ServerBitmap *bitmap);
|
||||
virtual void DrawChar(char c, BPoint point);
|
||||
virtual void DrawString(char *string, int length, BPoint point);
|
||||
|
||||
virtual void FillArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern);
|
||||
virtual void FillBezier(BPoint *points, uint8 *pattern);
|
||||
virtual void FillEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern);
|
||||
virtual void FillPolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void FillRect(BRect rect, uint8 *pattern);
|
||||
virtual void FillRegion(BRegion *region);
|
||||
virtual void FillRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern);
|
||||
virtual void FillShape(BShape *shape);
|
||||
virtual void FillTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern);
|
||||
|
||||
// virtual void GetBlendingMode(source_alpha *srcmode, alpha_function *funcmode);
|
||||
// virtual drawing_mode GetDrawingMode(void);
|
||||
virtual void HideCursor(void);
|
||||
virtual bool IsCursorHidden(void);
|
||||
virtual void MoveCursorTo(float x, float y);
|
||||
virtual void MovePenTo(BPoint pt);
|
||||
virtual void ObscureCursor(void);
|
||||
virtual BPoint PenPosition(void);
|
||||
virtual float PenSize(void);
|
||||
// virtual void SetBlendingMode(source_alpha srcmode, alpha_function funcmode);
|
||||
virtual void SetCursor(int32 value);
|
||||
virtual void SetCursor(ServerCursor *cursor);
|
||||
// virtual void SetDrawingMode(drawing_mode mode);
|
||||
virtual void ShowCursor(void);
|
||||
virtual void SetHighColor(uint8 r,uint8 g,uint8 b,uint8 a=255);
|
||||
virtual void SetLowColor(uint8 r,uint8 g,uint8 b,uint8 a=255);
|
||||
virtual void SetPenSize(float size);
|
||||
virtual void SetPixel(int x, int y, uint8 *pattern);
|
||||
|
||||
virtual void StrokeArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern);
|
||||
virtual void StrokeBezier(BPoint *points, uint8 *pattern);
|
||||
virtual void StrokeEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern);
|
||||
virtual void StrokeLine(BPoint point, uint8 *pattern);
|
||||
virtual void StrokePolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void StrokeRect(BRect rect,uint8 *pattern);
|
||||
virtual void StrokeRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern);
|
||||
virtual void StrokeShape(BShape *shape);
|
||||
virtual void StrokeTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern);
|
||||
|
||||
graphics_card_hook ghooks[48];
|
||||
graphics_card_info *ginfo;
|
||||
|
||||
protected:
|
||||
bool is_initialized, cursor_visible, show_on_move;
|
||||
ServerCursor *current_cursor;
|
||||
BLocker *locker;
|
||||
rgb_color highcol, lowcol;
|
||||
BPoint penpos;
|
||||
float pensize;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,7 +0,0 @@
|
||||
#ifndef _SERVER_GLOBALS_H_
|
||||
#define _SERVER_GLOBALS_H_
|
||||
|
||||
#include <List.h>
|
||||
BList *gBitmaplist, *gLayerlist;
|
||||
|
||||
#endif
|
@ -1,281 +0,0 @@
|
||||
/*
|
||||
Layer.cpp:
|
||||
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <iostream.h>
|
||||
#include "ServerWindow.h"
|
||||
#include "Layer.h"
|
||||
|
||||
Layer::Layer(ServerWindow *Win, const char *Name, Layer *Parent,
|
||||
BRect &Frame, int32 Flags)
|
||||
{
|
||||
Initialize();
|
||||
flags=Flags;
|
||||
frame=Frame;
|
||||
if(Name!=NULL)
|
||||
{
|
||||
name=new char[strlen(Name)];
|
||||
cout << "Layer::Layer name=" << strcpy((char *)name, Name) << endl;
|
||||
}
|
||||
else
|
||||
name=NULL;
|
||||
if(Parent!=NULL)
|
||||
Parent->AddChild(this);
|
||||
}
|
||||
|
||||
Layer::~Layer(void)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::Initialize(void)
|
||||
{
|
||||
visible=NULL;
|
||||
full=NULL;
|
||||
update=NULL;
|
||||
high.red=255; high.green=255; high.blue=255; high.alpha=255;
|
||||
low.red=255; low.green=255; low.blue=255; low.alpha=255;
|
||||
erase.red=255; erase.green=255; erase.blue=255; erase.alpha=255;
|
||||
drawingmode=B_OP_COPY;
|
||||
parent=NULL;
|
||||
uppersibling=NULL;
|
||||
lowersibling=NULL;
|
||||
topchild=NULL;
|
||||
bottomchild=NULL;
|
||||
hidecount=0;
|
||||
}
|
||||
|
||||
void Layer::AddChild(Layer *child, bool topmost=true)
|
||||
{
|
||||
// If we don't have any children, simply add the thing.
|
||||
if (bottomchild==NULL && topchild==NULL)
|
||||
{
|
||||
bottomchild=child;
|
||||
topchild=child;
|
||||
child->lowersibling=NULL;
|
||||
child->uppersibling=NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (topmost)
|
||||
{
|
||||
// "Move" the top child if there is one already and add to the
|
||||
// top of the tree
|
||||
if (topchild!=NULL)
|
||||
topchild->uppersibling = child;
|
||||
|
||||
topchild=child;
|
||||
child->uppersibling= NULL;
|
||||
child->lowersibling = topchild;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add layer to bottom of tree unless there are no other
|
||||
// children
|
||||
Layer *lay=bottomchild;
|
||||
if (lay!=NULL)
|
||||
{
|
||||
child->uppersibling=lay;
|
||||
child->lowersibling=lay->lowersibling;
|
||||
lay->lowersibling=child;
|
||||
|
||||
if(child->lowersibling!=NULL)
|
||||
child->lowersibling->uppersibling=child;
|
||||
else
|
||||
bottomchild=child;
|
||||
}
|
||||
else
|
||||
{
|
||||
topchild=child;
|
||||
topchild->uppersibling=child;
|
||||
child->lowersibling=topchild;
|
||||
child->uppersibling=NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
child->parent = this;
|
||||
child->SetAddedData(hidecount);
|
||||
}
|
||||
|
||||
void Layer::RemoveChild(Layer *child)
|
||||
{
|
||||
if(child->parent!=this)
|
||||
{
|
||||
cout << "DEBUG: attempt to remove a non-child layer\n" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (child==bottomchild)
|
||||
bottomchild=child->uppersibling;
|
||||
|
||||
if (child==bottomchild)
|
||||
bottomchild=child->uppersibling;
|
||||
|
||||
if (child->lowersibling!=NULL)
|
||||
child->lowersibling->uppersibling=child->uppersibling;
|
||||
|
||||
if (child->uppersibling!=NULL)
|
||||
child->uppersibling->lowersibling=child->lowersibling;
|
||||
|
||||
child->parent=NULL;
|
||||
child->lowersibling=NULL;
|
||||
child->uppersibling=NULL;
|
||||
}
|
||||
|
||||
void Layer::RemoveSelf(void)
|
||||
{
|
||||
if (parent!=NULL)
|
||||
parent->RemoveChild(this);
|
||||
}
|
||||
|
||||
void Layer::SetAddedData(uint8 count)
|
||||
{
|
||||
hidecount+=count;
|
||||
Layer *lay;
|
||||
for (lay=topchild; lay!=NULL; lay=lay->lowersibling)
|
||||
lay->SetAddedData(count);
|
||||
}
|
||||
|
||||
void Layer::Show(void)
|
||||
{
|
||||
hidecount--;
|
||||
if(hidecount==0)
|
||||
SetDirty(true);
|
||||
}
|
||||
|
||||
void Layer::Hide(void)
|
||||
{
|
||||
if(parent==NULL)
|
||||
{
|
||||
cout << "DEBUG: attempt to hide an orphan layer" << endl;
|
||||
return;
|
||||
}
|
||||
if(hidecount==0)
|
||||
{
|
||||
// Invalidate any sibling layers when this gets hidden so that
|
||||
// we see what's left. This is a slower way to do things, but it
|
||||
// works
|
||||
Layer *sibling;
|
||||
for (sibling=parent->bottomchild; sibling!=NULL; sibling=sibling->uppersibling)
|
||||
{
|
||||
if (sibling->frame.Intersects(frame))
|
||||
{
|
||||
sibling->MarkModified(frame & sibling->frame);
|
||||
}
|
||||
}
|
||||
|
||||
// Hide all child layers
|
||||
Layer *child;
|
||||
for (child=topchild; child!=NULL; child=child->lowersibling)
|
||||
{
|
||||
child->Hide();
|
||||
}
|
||||
}
|
||||
hidecount++;
|
||||
}
|
||||
|
||||
bool Layer::IsVisible(void)
|
||||
{
|
||||
return (hidecount==0)?true:false;
|
||||
}
|
||||
|
||||
void Layer::Update(bool ForceUpdate)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::SetFrame(const BRect &Rect)
|
||||
{
|
||||
}
|
||||
|
||||
BRect Layer::Frame(void)
|
||||
{
|
||||
return frame;
|
||||
}
|
||||
|
||||
BRect Layer::Bounds(void)
|
||||
{
|
||||
BRect r=frame;
|
||||
r.OffsetTo(0,0);
|
||||
return r;
|
||||
}
|
||||
|
||||
void Layer::Invalidate(const BRect &rect)
|
||||
{
|
||||
if (hidecount==0)
|
||||
{
|
||||
if (update==NULL)
|
||||
update=new BRegion(rect);
|
||||
else
|
||||
update->Include(rect);
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidates the entire layer, possibly including the child layers
|
||||
void Layer::Invalidate(bool recursive)
|
||||
{
|
||||
if (hidecount==0)
|
||||
{
|
||||
delete update;
|
||||
update = new BRegion(frame);
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
for (Layer *lay=bottomchild; lay!=NULL; lay=lay->uppersibling)
|
||||
lay->Invalidate(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This invalidates the layer and all its child layers
|
||||
void Layer::SetDirty(bool flag)
|
||||
{
|
||||
isdirty=flag;
|
||||
|
||||
Layer *lay;
|
||||
for (lay=bottomchild; lay!=NULL; lay=lay->uppersibling )
|
||||
{
|
||||
lay->SetDirty(flag);
|
||||
}
|
||||
}
|
||||
|
||||
void Layer::AddRegion(BRegion *Region)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::RemoveRegions(void)
|
||||
{
|
||||
/* delete visible;
|
||||
delete full;
|
||||
delete update;
|
||||
|
||||
visible=NULL;
|
||||
full=NULL;
|
||||
update=NULL;
|
||||
|
||||
Layer *lay;
|
||||
for (lay=topchild; lay!=NULL; lay=lay->lowersibling )
|
||||
lay->DeleteRegions();
|
||||
*/
|
||||
}
|
||||
|
||||
void Layer::UpdateRegions(bool ForceUpdate=true, bool Root=true)
|
||||
{
|
||||
}
|
||||
|
||||
void Layer::MarkModified(BRect rect)
|
||||
{
|
||||
if (frame.Intersects(rect))
|
||||
{
|
||||
BRect r=rect & frame;
|
||||
isdirty=true;
|
||||
|
||||
Layer* lay;
|
||||
for (lay=bottomchild; lay!=NULL; lay=lay->uppersibling )
|
||||
lay->MarkModified(r);
|
||||
}
|
||||
}
|
||||
|
||||
// virtual function to be defined by child classes
|
||||
void Layer::Draw(const BRect &Rect)
|
||||
{
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
#ifndef _LAYER_H_
|
||||
#define _LAYER_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Region.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class ServerWindow;
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
Layer(ServerWindow *Win, const char *Name, Layer *Parent, BRect &Frame, int32 Flags);
|
||||
virtual ~Layer(void);
|
||||
|
||||
void Initialize(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
bool IsVisible(void);
|
||||
void Update(bool ForceUpdate);
|
||||
|
||||
void AddChild(Layer *child, bool topmost=true);
|
||||
void RemoveChild(Layer *child);
|
||||
void RemoveSelf(void);
|
||||
void SetAddedData(uint8 count);
|
||||
|
||||
virtual void SetFrame(const BRect &Rect);
|
||||
BRect Frame(void);
|
||||
BRect Bounds(void);
|
||||
|
||||
void Invalidate(const BRect &rect);
|
||||
void Invalidate(bool recursive);
|
||||
void AddRegion(BRegion *Region);
|
||||
void RemoveRegions(void);
|
||||
void UpdateRegions(bool ForceUpdate=true, bool Root=true);
|
||||
void SetDirty(bool flag);
|
||||
void MarkModified(BRect rect);
|
||||
|
||||
// Render functions:
|
||||
virtual void Draw(const BRect &Rect);
|
||||
|
||||
const char *name;
|
||||
int32 handle;
|
||||
ServerWindow *window; // Window associated with this. NULL for background layer
|
||||
|
||||
BRect frame;
|
||||
|
||||
BRegion *visible, // Everything currently visible
|
||||
*full, // The complete region
|
||||
*update; // Area to be updated at next redraw
|
||||
|
||||
int32 flags; // Various flags for behavior
|
||||
uint8 hidecount; // tracks the number of hide calls
|
||||
bool isdirty; // has regions which are invalid
|
||||
|
||||
// The whole set of layers is actually a tree
|
||||
Layer *topchild, *bottomchild;
|
||||
Layer *uppersibling, *lowersibling;
|
||||
Layer *parent;
|
||||
|
||||
// Render state:
|
||||
BPoint penpos;
|
||||
rgb_color high, low, erase;
|
||||
|
||||
int32 drawingmode;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,438 +0,0 @@
|
||||
/*
|
||||
PortLink.cpp:
|
||||
A helper class for port-based messaging
|
||||
|
||||
------------------------------------------------------------------------
|
||||
How it works:
|
||||
The class utilizes a fixed-size array of PortLinkData object pointers. When
|
||||
data is attached, a new PortLinkData object is allocated and a copy of the
|
||||
passed data is created inside it. When the time comes for the message to be sent,
|
||||
the data is pieced together into a flattened array and written to the port.
|
||||
------------------------------------------------------------------------
|
||||
Data members:
|
||||
|
||||
*attachments[] - fixed-size array of pointers used to hold the attached data
|
||||
opcode - message value which is sent along with any data
|
||||
target - port to which the message is sent when Flush() is called
|
||||
replyport - port used with synchronous messaging - FlushWithReply()
|
||||
bufferlength - total bytes taken up by attachments
|
||||
num_attachments - internal variable which is used to track which "slot"
|
||||
will be the next one to receive an attachment object
|
||||
*/
|
||||
|
||||
#include "PortLink.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
//#define PLDEBUG
|
||||
|
||||
// Internal data storage class for holding attached data whilst it is waiting
|
||||
// to be Flattened() and then Flushed(). There is no need for this to be called outside
|
||||
// the PortLink class.
|
||||
class PortLinkData
|
||||
{
|
||||
public:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
bool Set(void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
PortLink::PortLink(port_id port)
|
||||
{
|
||||
// For this class to be useful (and to prevent a lot of init problems)
|
||||
// we require a port in the constructor
|
||||
target=port;
|
||||
|
||||
// We start out without any data attached to the port message
|
||||
num_attachments=0;
|
||||
opcode=0;
|
||||
bufferlength=0;
|
||||
replyport=create_port(30,"PortLink reply port");
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
// If, for some odd reason, this is deleted with something attached,
|
||||
// free the memory used by the attachments. We do not flush the queue
|
||||
// because the port may no longer be valid in cases such as the app
|
||||
// is in the process of quitting
|
||||
MakeEmpty();
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode(int32 code)
|
||||
{
|
||||
// Sets the message code. This does not change once the message is sent.
|
||||
// Another call to SetOpCode() is required for such things.
|
||||
opcode=code;
|
||||
}
|
||||
|
||||
void PortLink::SetPort(port_id port)
|
||||
{
|
||||
// Sets the target port. While not necessary in most uses, this exists
|
||||
// mostly to prevent flexibility problems
|
||||
target=port;
|
||||
}
|
||||
|
||||
port_id PortLink::GetPort(void)
|
||||
{
|
||||
// Simply returns the port at which the object is pointed.
|
||||
return target;
|
||||
}
|
||||
|
||||
void PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message off to the target, complete with attachments. NOTE:
|
||||
// the recipient must delete all attachments, being the PortLink object assumes
|
||||
// no responsiblity for the attachments once the message is sent.
|
||||
int8 *msgbuffer;
|
||||
int32 size;
|
||||
|
||||
if(num_attachments>0)
|
||||
{
|
||||
FlattenData(&msgbuffer,&size);
|
||||
|
||||
// Dump message to port, reset attachments, and clean up
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,msgbuffer,size,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,msgbuffer,size);
|
||||
MakeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,NULL,0,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message to the target and then waits for a reply. The target will
|
||||
// receive a message with the first item being the port_id to reply to.
|
||||
// NOTE: like Flush(), any attached data must be deleted.
|
||||
|
||||
// Effectively, an Attach() call inlined for changes
|
||||
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
{
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&replyport,sizeof(port_id)))
|
||||
{
|
||||
bufferlength+=sizeof(port_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Flatten() inlined to make some necessary changes
|
||||
int8 *buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=buffer;
|
||||
size_t size=0;
|
||||
|
||||
// attach our port_id first
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
|
||||
// attach everything else
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
}
|
||||
|
||||
// Flush the thing....FOOSH! :P
|
||||
write_port(target,opcode,buffer,size);
|
||||
MakeEmpty();
|
||||
delete buffer;
|
||||
|
||||
// Now we wait for the reply
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
*buffersize=port_buffer_size(replyport);
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buffersize=port_buffer_size_etc(replyport,0,timeout);
|
||||
if(*buffersize==B_TIMED_OUT)
|
||||
{
|
||||
*status=*buffersize;
|
||||
return NULL;
|
||||
}
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
|
||||
// We got this far, so we apparently have some data
|
||||
*status=B_OK;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void PortLink::Attach(void *data, size_t size)
|
||||
{
|
||||
// This is the member called to attach data to a message. Attachments are
|
||||
// treated to be in 'Append' mode, tacking on each attached piece of data
|
||||
// to the end of the list.
|
||||
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
if(size==0)
|
||||
return;
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
// These functions were added for a major convenience in passing common types
|
||||
// Eventually, I'd like to templatize these, but for now, this'll do
|
||||
|
||||
void PortLink::Attach(int32 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int32);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int16 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int16);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int8 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int8);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(float data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(float);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(bool data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(bool);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BRect data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BRect);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BPoint data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BPoint);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::FlattenData(int8 **buffer,int32 *size)
|
||||
{
|
||||
// This function is where all the magic happens, but it is strictly internal.
|
||||
// It iterates through each PortLinkData object and copies it to the main buffer
|
||||
// which ends up, ultimately, being written to the PortLink's target port.
|
||||
|
||||
// skip if there aree no attachments
|
||||
if(bufferlength<1)
|
||||
return;
|
||||
|
||||
*buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=*buffer;
|
||||
PortLinkData *pld;
|
||||
*size=0;
|
||||
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
*size+=pld->buffersize;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::MakeEmpty(void)
|
||||
{
|
||||
// Nukes all the attachments currently held by the PortLink class
|
||||
if(num_attachments!=0)
|
||||
{
|
||||
for(int i=0; i<num_attachments; i++)
|
||||
{
|
||||
delete attachments[i];
|
||||
}
|
||||
}
|
||||
num_attachments=0;
|
||||
bufferlength=0;
|
||||
}
|
||||
|
||||
PortLinkData::PortLinkData(void)
|
||||
{
|
||||
// Initialize object to empty
|
||||
buffersize=0;
|
||||
}
|
||||
|
||||
PortLinkData::~PortLinkData(void)
|
||||
{
|
||||
// Frees the buffer if we actually used the class to store data
|
||||
if(buffersize>0)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool PortLinkData::Set(void *data, size_t size)
|
||||
{
|
||||
// Function copies the passed to the internal buffers for storage
|
||||
if(size>0 && buffersize==0 && data!=NULL)
|
||||
{
|
||||
buffer=(char *)malloc(size);
|
||||
if(buffer==NULL)
|
||||
return false;
|
||||
memcpy(buffer, data, size);
|
||||
buffersize=size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
#ifndef _PORTLINK_H_
|
||||
#define _PORTLINK_H_
|
||||
|
||||
#include <Errors.h>
|
||||
#include <OS.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
#ifndef _PORTLINK_BUFFERSIZE
|
||||
#define _PORTLINK_MAX_ATTACHMENTS 50
|
||||
#endif
|
||||
|
||||
class PortLinkData;
|
||||
|
||||
class PortLink
|
||||
{
|
||||
public:
|
||||
PortLink(port_id port);
|
||||
~PortLink(void);
|
||||
void SetOpCode(int32 code);
|
||||
void SetPort(port_id port);
|
||||
port_id GetPort(void);
|
||||
void Flush(bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
int8* FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize,
|
||||
bigtime_t timeout=B_INFINITE_TIMEOUT);
|
||||
void Attach(void *data, size_t size);
|
||||
void Attach(int32 data);
|
||||
void Attach(int16 data);
|
||||
void Attach(int8 data);
|
||||
void Attach(float data);
|
||||
void Attach(bool data);
|
||||
void Attach(BRect data);
|
||||
void Attach(BPoint data);
|
||||
void MakeEmpty(void);
|
||||
protected:
|
||||
void FlattenData(int8 **buffer,int32 *size);
|
||||
port_id target, replyport;
|
||||
int32 opcode, bufferlength;
|
||||
int num_attachments;
|
||||
PortLinkData *attachments[_PORTLINK_MAX_ATTACHMENTS];
|
||||
};
|
||||
|
||||
#endif
|
@ -1,9 +0,0 @@
|
||||
OpenBeOS App Server Test Prototype #4
|
||||
|
||||
This prototype is an extension of the third one, where the TestApp has become a test bed for graphics functions. The graphics-access object used, ViewDriver, has most of the useful BView calls implemented and tested. Such was necessary to proceed to the next steps. The functions not implemented were not done either because it was way too much work or simply not possible to do with the current test application. They will have to wait until BView is done. In any event, not bad for 2 weeks' work.
|
||||
|
||||
This is an example of both a work in progress and a lot of research at the same time. Many of the concepts used in this prototype will be used in the real server. It doesn't do much, but the fact that it exists and does what it does is the result of a *lot* of work.
|
||||
|
||||
The code is reasonably (IMHO) well-commented and should be easy to understand at first glance. Also included are some extra files which I didn't feel like throwing out or are in place for future development. ;D Enjoy.
|
||||
|
||||
--DarkWyrm
|
@ -1,759 +0,0 @@
|
||||
/*
|
||||
ServerApp.cpp
|
||||
Class which works with a BApplication. Handles all messages coming
|
||||
from and going to its application.
|
||||
*/
|
||||
//#define DEBUG_SERVERAPP_MSGS
|
||||
//#define DEBUG_SERVERAPP_CURSORS
|
||||
|
||||
#include <AppDefs.h>
|
||||
#include <Cursor.h>
|
||||
#include <List.h>
|
||||
#include "Desktop.h"
|
||||
#include "DisplayDriver.h"
|
||||
#include "ServerApp.h"
|
||||
#include "ServerWindow.h"
|
||||
#include "ServerBitmap.h"
|
||||
#include "ServerProtocol.h"
|
||||
#include "ServerCursor.h"
|
||||
#include "PortLink.h"
|
||||
#include <stdio.h>
|
||||
#include <iostream.h>
|
||||
#include <string.h>
|
||||
#include "DebugTools.h"
|
||||
|
||||
ServerApp::ServerApp(port_id msgport, char *signature)
|
||||
{
|
||||
// need to copy the signature because the message buffer
|
||||
// owns the copy which we are passed as a parameter.
|
||||
if(signature)
|
||||
{
|
||||
app_sig=new char[strlen(signature)];
|
||||
sprintf(app_sig,signature);
|
||||
}
|
||||
else
|
||||
{
|
||||
app_sig=new char[strlen("Application")];
|
||||
sprintf(app_sig,"Application");
|
||||
}
|
||||
|
||||
// sender is the monitored app's event port
|
||||
sender=msgport;
|
||||
applink=new PortLink(sender);
|
||||
|
||||
// receiver is the port to which the app sends messages for the server
|
||||
receiver=create_port(30,app_sig);
|
||||
//printf("ServerApp port for app %s is at %ld\n",app_sig,receiver);
|
||||
if(receiver==B_NO_MORE_PORTS)
|
||||
{
|
||||
// uh-oh. We have a serious problem. Tell the app to quit
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything checks out, so tell the application
|
||||
// where to send future messages
|
||||
applink->SetOpCode(SET_SERVER_PORT);
|
||||
applink->Attach(&receiver,sizeof(port_id));
|
||||
applink->Flush();
|
||||
}
|
||||
winlist=new BList(0);
|
||||
bmplist=new BList(0);
|
||||
driver=get_gfxdriver();
|
||||
isactive=false;
|
||||
cursor=new ServerCursor();
|
||||
|
||||
// This exists for testing the graphics access module and will disappear
|
||||
// when layers are implemented
|
||||
high.red=255;
|
||||
high.green=255;
|
||||
high.blue=255;
|
||||
high.alpha=255;
|
||||
low.red=0;
|
||||
low.green=0;
|
||||
low.blue=0;
|
||||
low.alpha=255;
|
||||
}
|
||||
|
||||
ServerApp::~ServerApp(void)
|
||||
{
|
||||
int32 i;
|
||||
ServerWindow *tempwin;
|
||||
for(i=0;i<winlist->CountItems();i++)
|
||||
{
|
||||
tempwin=(ServerWindow*)winlist->ItemAt(i);
|
||||
delete tempwin;
|
||||
}
|
||||
winlist->MakeEmpty();
|
||||
delete winlist;
|
||||
|
||||
ServerBitmap *tempbmp;
|
||||
for(i=0;i<bmplist->CountItems();i++)
|
||||
{
|
||||
tempbmp=(ServerBitmap*)bmplist->ItemAt(i);
|
||||
delete tempbmp;
|
||||
}
|
||||
bmplist->MakeEmpty();
|
||||
delete bmplist;
|
||||
|
||||
delete app_sig;
|
||||
delete applink;
|
||||
delete cursor;
|
||||
}
|
||||
|
||||
bool ServerApp::Run(void)
|
||||
{
|
||||
// Unlike a BApplication, a ServerApp is *supposed* to return immediately
|
||||
// when its Run function is called.
|
||||
monitor_thread=spawn_thread(MonitorApp,app_sig,B_NORMAL_PRIORITY,this);
|
||||
if(monitor_thread==B_NO_MORE_THREADS || monitor_thread==B_NO_MEMORY)
|
||||
return false;
|
||||
resume_thread(monitor_thread);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32 ServerApp::MonitorApp(void *data)
|
||||
{
|
||||
ServerApp *app=(ServerApp *)data;
|
||||
app->Loop();
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ServerApp::Loop(void)
|
||||
{
|
||||
// Message-dispatching loop for the ServerApp
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(receiver);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are PortLink messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(receiver,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(receiver,&msgcode,NULL,0);
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
// -------------- Messages received from the Application ------------------
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
// Our BApplication sent us this message when it quit.
|
||||
// We need to ask the app_server to delete our monitor
|
||||
port_id serverport=find_port(SERVER_PORT_NAME);
|
||||
if(serverport==B_NAME_NOT_FOUND)
|
||||
{
|
||||
printf("PANIC: ServerApp %s could not find the app_server port!\n",app_sig);
|
||||
break;
|
||||
}
|
||||
|
||||
applink->SetPort(serverport);
|
||||
applink->SetOpCode(DELETE_APP);
|
||||
applink->Attach(&monitor_thread,sizeof(thread_id));
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
case CREATE_WINDOW:
|
||||
case DELETE_WINDOW:
|
||||
case SHOW_CURSOR:
|
||||
case HIDE_CURSOR:
|
||||
case OBSCURE_CURSOR:
|
||||
case SET_CURSOR_BCURSOR:
|
||||
case SET_CURSOR_DATA:
|
||||
case SET_CURSOR_BBITMAP:
|
||||
case GFX_MOVEPENBY:
|
||||
case GFX_MOVEPENTO:
|
||||
case GFX_SETPENSIZE:
|
||||
case GFX_COUNT_WORKSPACES:
|
||||
case GFX_SET_WORKSPACE_COUNT:
|
||||
case GFX_CURRENT_WORKSPACE:
|
||||
case GFX_ACTIVATE_WORKSPACE:
|
||||
case GFX_SYSTEM_COLORS:
|
||||
case GFX_SET_SCREEN_MODE:
|
||||
case GFX_GET_SCROLLBAR_INFO:
|
||||
case GFX_SET_SCROLLBAR_INFO:
|
||||
case GFX_IDLE_TIME:
|
||||
case GFX_SELECT_PRINTER_PANEL:
|
||||
case GFX_ADD_PRINTER_PANEL:
|
||||
case GFX_RUN_BE_ABOUT:
|
||||
case GFX_SET_FOCUS_FOLLOWS_MOUSE:
|
||||
case GFX_FOCUS_FOLLOWS_MOUSE:
|
||||
|
||||
// Graphics messages
|
||||
case GFX_SET_HIGH_COLOR:
|
||||
case GFX_SET_LOW_COLOR:
|
||||
case GFX_DRAW_STRING:
|
||||
case GFX_SET_FONT_SIZE:
|
||||
case GFX_STROKE_ARC:
|
||||
case GFX_STROKE_BEZIER:
|
||||
case GFX_STROKE_ELLIPSE:
|
||||
case GFX_STROKE_LINE:
|
||||
case GFX_STROKE_POLYGON:
|
||||
case GFX_STROKE_RECT:
|
||||
case GFX_STROKE_ROUNDRECT:
|
||||
case GFX_STROKE_SHAPE:
|
||||
case GFX_STROKE_TRIANGLE:
|
||||
case GFX_FILL_ARC:
|
||||
case GFX_FILL_BEZIER:
|
||||
case GFX_FILL_ELLIPSE:
|
||||
case GFX_FILL_POLYGON:
|
||||
case GFX_FILL_RECT:
|
||||
case GFX_FILL_REGION:
|
||||
case GFX_FILL_ROUNDRECT:
|
||||
case GFX_FILL_SHAPE:
|
||||
case GFX_FILL_TRIANGLE:
|
||||
DispatchMessage(msgcode, msgbuffer);
|
||||
break;
|
||||
|
||||
// -------------- Messages received from the Server ------------------------
|
||||
// Mouse messages simply get passed onto the active app for now
|
||||
case B_MOUSE_UP:
|
||||
case B_MOUSE_DOWN:
|
||||
case B_MOUSE_MOVED:
|
||||
{
|
||||
// everything is formatted as it should be, so just call
|
||||
// write_port. Eventually, this will be replaced by a
|
||||
// BMessage
|
||||
write_port(sender, msgcode, msgbuffer, buffersize);
|
||||
break;
|
||||
}
|
||||
case QUIT_APP:
|
||||
{
|
||||
// This message is received from the app_server thread
|
||||
// because the server was asked to quit. Thus, we
|
||||
// ask all apps to quit. This is NOT the same as system
|
||||
// shutdown and will happen only in testing
|
||||
|
||||
//printf("ServerApp asking %s to quit\n",app_sig);
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
cout << "ServerApp received unrecognized code: ";
|
||||
TranslateMessageCodeToStream(msgcode);
|
||||
cout << endl << flush;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerApp::DispatchMessage(int32 code, int8 *buffer)
|
||||
{
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
cout << "ServerApp Message: ";
|
||||
TranslateMessageCodeToStream(code);
|
||||
cout << endl << flush;
|
||||
#endif
|
||||
|
||||
int8 *index=buffer;
|
||||
switch(code)
|
||||
{
|
||||
case CREATE_WINDOW:
|
||||
{
|
||||
// Attached data
|
||||
//
|
||||
break;
|
||||
}
|
||||
case DELETE_WINDOW:
|
||||
{
|
||||
// Attached data
|
||||
break;
|
||||
}
|
||||
case GFX_SET_SCREEN_MODE:
|
||||
{
|
||||
// Attached data
|
||||
// 1) int32 workspace #
|
||||
// 2) uint32 screen mode
|
||||
// 3) bool make default
|
||||
int32 workspace=*((int32*)index); index+=sizeof(int32);
|
||||
uint32 mode=*((uint32*)index); index+=sizeof(uint32);
|
||||
|
||||
SetScreenSpace(workspace,mode,*((bool*)index));
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp: SetScreenMode(%ld,%lu,%s)\n",workspace,
|
||||
mode,(*((bool*)index)==true)?"true":"false");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case GFX_ACTIVATE_WORKSPACE:
|
||||
{
|
||||
// Attached data
|
||||
// 1) int32 workspace index
|
||||
ActivateWorkspace(*((int32*)index));
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp: ActivateWorkspace(%ld)\n",*((int32*)index));
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case SHOW_CURSOR:
|
||||
{
|
||||
driver->ShowCursor();
|
||||
break;
|
||||
}
|
||||
case HIDE_CURSOR:
|
||||
{
|
||||
driver->HideCursor();
|
||||
break;
|
||||
}
|
||||
case OBSCURE_CURSOR:
|
||||
{
|
||||
driver->ObscureCursor();
|
||||
break;
|
||||
}
|
||||
case SET_CURSOR_DATA:
|
||||
{
|
||||
// Attached data: 68 bytes of cursor data
|
||||
|
||||
// Get the data, update the app's cursor, and update the
|
||||
// app's cursor if active.
|
||||
int8 cdata[68];
|
||||
memcpy(cdata, buffer, 68);
|
||||
cursor->SetCursor(cdata);
|
||||
driver->SetCursor(cursor);
|
||||
#ifdef DEBUG_SERVERAPP_CURSOR
|
||||
printf("ServerApp: SetCursor(%d,%d,%d,%d)\n",r,g,b,a);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case SET_CURSOR_BCURSOR:
|
||||
// Not yet implemented
|
||||
break;
|
||||
|
||||
case SET_CURSOR_BBITMAP:
|
||||
// Not yet implemented
|
||||
break;
|
||||
|
||||
// Graphics messages
|
||||
case GFX_SET_HIGH_COLOR:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) uint8 red
|
||||
// 2) uint8 green
|
||||
// 3) uint8 blue
|
||||
// 4) uint8 alpha
|
||||
|
||||
uint8 r,g,b,a;
|
||||
r=*((uint8*)index); index+=sizeof(uint8);
|
||||
g=*((uint8*)index); index+=sizeof(uint8);
|
||||
b=*((uint8*)index); index+=sizeof(uint8);
|
||||
a=*((uint8*)index);
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp: SetHighColor(%d,%d,%d,%d)\n",r,g,b,a);
|
||||
#endif
|
||||
driver->SetHighColor(r,g,b,a);
|
||||
break;
|
||||
}
|
||||
case GFX_SET_LOW_COLOR:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) uint8 red
|
||||
// 2) uint8 green
|
||||
// 3) uint8 blue
|
||||
// 4) uint8 alpha
|
||||
|
||||
uint8 r,g,b,a;
|
||||
r=*((uint8*)index); index+=sizeof(uint8);
|
||||
g=*((uint8*)index); index+=sizeof(uint8);
|
||||
b=*((uint8*)index); index+=sizeof(uint8);
|
||||
a=*((uint8*)index);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp: SetHighColor(%d,%d,%d,%d)\n",r,g,b,a);
|
||||
#endif
|
||||
driver->SetLowColor(r,g,b,a);
|
||||
break;
|
||||
}
|
||||
case GFX_MOVEPENBY:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BPoint pt
|
||||
|
||||
// Default functionality is MoveTo, so get the current position
|
||||
// from the driver and compensate
|
||||
BPoint *ptindex,passed_pt;
|
||||
|
||||
ptindex=(BPoint*)index;
|
||||
passed_pt=driver->PenPosition();
|
||||
passed_pt+=*ptindex;
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp MovePenBy: (%f,%f)\n",ptindex->x,ptindex->y);
|
||||
printf("Pen moved to (%f,%f)\n",passed_pt.x,passed_pt.y);
|
||||
#endif
|
||||
driver->MovePenTo(passed_pt);
|
||||
break;
|
||||
}
|
||||
case GFX_MOVEPENTO:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BPoint pt
|
||||
BPoint *pt;
|
||||
pt=(BPoint*)index;
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp MovePenTo: (%f,%f)\n",pt->x,pt->y);
|
||||
#endif
|
||||
driver->MovePenTo(*pt);
|
||||
break;
|
||||
}
|
||||
case GFX_SETPENSIZE:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) float pen size
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp SetPenSize(%f)\n",*((float*)index));
|
||||
#endif
|
||||
driver->SetPenSize(*((float*)index));
|
||||
break;
|
||||
}
|
||||
case GFX_DRAW_STRING:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) uint16 string length
|
||||
// 2) char * string
|
||||
// 3) BPoint point
|
||||
|
||||
uint16 length=*((uint16*)index); index+=sizeof(uint16);
|
||||
char *string=new char[length];
|
||||
strcpy(string, (const char *)index); index+=length;
|
||||
BPoint point=*((BPoint*)index);
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp DrawString(%s, %d, BPoint(%f,%f))\n",string,length,point.x,point.y);
|
||||
#endif
|
||||
driver->DrawString(string, length, point);
|
||||
delete string;
|
||||
break;
|
||||
}
|
||||
case GFX_SET_FONT_SIZE:
|
||||
break;
|
||||
case GFX_STROKE_ARC:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) float center x
|
||||
// 2) float center y
|
||||
// 3) float x radius
|
||||
// 4) float y radius
|
||||
// 5) float starting angle
|
||||
// 6) float span (arc length in degrees)
|
||||
// 7) uint8[8] pattern
|
||||
float cx,cy,rx,ry,angle,span;
|
||||
|
||||
cx=*((float*)index); index+=sizeof(float);
|
||||
cy=*((float*)index); index+=sizeof(float);
|
||||
rx=*((float*)index); index+=sizeof(float);
|
||||
ry=*((float*)index); index+=sizeof(float);
|
||||
angle=*((float*)index); index+=sizeof(float);
|
||||
span=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeArc: ");
|
||||
printf("Center: %f,%f\n",cx,cy);
|
||||
printf("Radii: %f,%f\n",rx,ry);
|
||||
printf("Angle, Span: %f,%f\n",angle, span);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeArc(cx,cy,rx,ry,angle,span,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_BEZIER:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BPoint #1
|
||||
// 2) BPoint #2
|
||||
// 3) BPoint #3
|
||||
// 4) BPoint #4
|
||||
// 5) uint8[8] pattern
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
BPoint *pt=(BPoint*)index;
|
||||
printf("ServerApp StrokeBezier:\n");
|
||||
printf("Point 1: "); pt[0].PrintToStream();
|
||||
printf("Point 2: "); pt[1].PrintToStream();
|
||||
printf("Point 3: "); pt[2].PrintToStream();
|
||||
printf("Point 4: "); pt[3].PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeBezier((BPoint*)index,(uint8*)(index+(sizeof(BPoint)*4)));
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_ELLIPSE:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) float center x
|
||||
// 2) float center y
|
||||
// 3) float x radius
|
||||
// 4) float y radius
|
||||
// 5) uint8[8] pattern
|
||||
float cx,cy,rx,ry;
|
||||
|
||||
cx=*((float*)index); index+=sizeof(float);
|
||||
cy=*((float*)index); index+=sizeof(float);
|
||||
rx=*((float*)index); index+=sizeof(float);
|
||||
ry=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeEllipse: ");
|
||||
printf("Center: %f,%f\n",cx,cy);
|
||||
printf("Radii: %f,%f\n",rx,ry);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeEllipse(cx,cy,rx,ry,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_LINE:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BPoint endpoint
|
||||
// 2) uint8[8] pattern
|
||||
BPoint *pt;
|
||||
pt=(BPoint*)index; index+=sizeof(BPoint);
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeLineTo: (%f,%f)\n",pt->x,pt->y);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeLine(*pt,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_POLYGON:
|
||||
break;
|
||||
case GFX_STROKE_RECT:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BRect rect
|
||||
// 2) uint8[8] pattern
|
||||
BRect rect;
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeRect: "); rect.PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeRect(rect, (uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_ROUNDRECT:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BRect rect
|
||||
// 2) float x_radius
|
||||
// 3) float y_radius
|
||||
// 4) uint8[8] pattern
|
||||
BRect rect;
|
||||
float x,y;
|
||||
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
x=*((float*)index); index+=sizeof(float);
|
||||
y=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeRoundRect: "); rect.PrintToStream();
|
||||
printf("Radii: %f,%f\n",x,y);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeRoundRect(rect, x,y,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_STROKE_SHAPE:
|
||||
break;
|
||||
case GFX_STROKE_TRIANGLE:
|
||||
{
|
||||
// Attached data
|
||||
// 1) BPoint #1
|
||||
// 2) BPoint #2
|
||||
// 3) BPoint #3
|
||||
// 4) BRect invalid rect
|
||||
// 5) uint8[8] pattern
|
||||
BPoint pt1,pt2,pt3;
|
||||
BRect rect;
|
||||
pt1=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
pt2=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
pt3=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp StrokeTriangle: ");
|
||||
printf("Point 1: "); pt1.PrintToStream();
|
||||
printf("Point 2: "); pt2.PrintToStream();
|
||||
printf("Point 3: "); pt3.PrintToStream();
|
||||
printf("Rectangle: "); rect.PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->StrokeTriangle(pt1,pt2,pt3,rect,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_ARC:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) float center x
|
||||
// 2) float center y
|
||||
// 3) float x radius
|
||||
// 4) float y radius
|
||||
// 5) float starting angle
|
||||
// 6) float span (arc length in degrees)
|
||||
// 7) uint8[8] pattern
|
||||
float cx,cy,rx,ry,angle,span;
|
||||
|
||||
cx=*((float*)index); index+=sizeof(float);
|
||||
cy=*((float*)index); index+=sizeof(float);
|
||||
rx=*((float*)index); index+=sizeof(float);
|
||||
ry=*((float*)index); index+=sizeof(float);
|
||||
angle=*((float*)index); index+=sizeof(float);
|
||||
span=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp FillArc: ");
|
||||
printf("Center: %f,%f\n",cx,cy);
|
||||
printf("Radii: %f,%f\n",rx,ry);
|
||||
printf("Angle, Span: %f,%f\n",angle, span);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillArc(cx,cy,rx,ry,angle,span,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_BEZIER:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BPoint #1
|
||||
// 2) BPoint #2
|
||||
// 3) BPoint #3
|
||||
// 4) BPoint #4
|
||||
// 5) uint8[8] pattern
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
BPoint *pt=(BPoint*)index;
|
||||
printf("ServerApp FillBezier:\n");
|
||||
printf("Point 1: "); pt[0].PrintToStream();
|
||||
printf("Point 2: "); pt[1].PrintToStream();
|
||||
printf("Point 3: "); pt[2].PrintToStream();
|
||||
printf("Point 4: "); pt[3].PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillBezier((BPoint*)index,(uint8*)(index+(sizeof(BPoint)*4)));
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_ELLIPSE:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) float center x
|
||||
// 2) float center y
|
||||
// 3) float x radius
|
||||
// 4) float y radius
|
||||
// 5) uint8[8] pattern
|
||||
float cx,cy,rx,ry;
|
||||
|
||||
cx=*((float*)index); index+=sizeof(float);
|
||||
cy=*((float*)index); index+=sizeof(float);
|
||||
rx=*((float*)index); index+=sizeof(float);
|
||||
ry=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp FillEllipse: ");
|
||||
printf("Center: %f,%f\n",cx,cy);
|
||||
printf("Radii: %f,%f\n",rx,ry);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillEllipse(cx,cy,rx,ry,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_POLYGON:
|
||||
break;
|
||||
case GFX_FILL_RECT:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BRect rect
|
||||
// 2) uint8[8] pattern
|
||||
BRect rect;
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp FillRect: "); rect.PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillRect(rect, (uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_REGION:
|
||||
break;
|
||||
case GFX_FILL_ROUNDRECT:
|
||||
{
|
||||
// Attached data:
|
||||
// 1) BRect rect
|
||||
// 2) float x_radius
|
||||
// 3) float y_radius
|
||||
// 4) uint8[8] pattern
|
||||
BRect rect;
|
||||
float x,y;
|
||||
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
x=*((float*)index); index+=sizeof(float);
|
||||
y=*((float*)index); index+=sizeof(float);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp FillRoundRect: "); rect.PrintToStream();
|
||||
printf("Radii: %f,%f\n",x,y);
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillRoundRect(rect, x,y,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
case GFX_FILL_SHAPE:
|
||||
break;
|
||||
case GFX_FILL_TRIANGLE:
|
||||
{
|
||||
// Attached data
|
||||
// 1) BPoint #1
|
||||
// 2) BPoint #2
|
||||
// 3) BPoint #3
|
||||
// 4) BRect invalid rect
|
||||
// 5) uint8[8] pattern
|
||||
BPoint pt1,pt2,pt3;
|
||||
BRect rect;
|
||||
pt1=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
pt2=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
pt3=*((BPoint*)index); index+=sizeof(BPoint);
|
||||
rect=*((BRect*)index); index+=sizeof(BRect);
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
printf("ServerApp FillTriangle: ");
|
||||
printf("Point 1: "); pt1.PrintToStream();
|
||||
printf("Point 2: "); pt2.PrintToStream();
|
||||
printf("Point 3: "); pt3.PrintToStream();
|
||||
printf("Rectangle: "); rect.PrintToStream();
|
||||
printf("pattern: {%d,%d,%d,%d,%d,%d,%d,%d}\n",index[0],index[1],index[2],index[3],index[4],index[5],index[6],index[7]);
|
||||
#endif
|
||||
driver->FillTriangle(pt1,pt2,pt3,rect,(uint8*)index);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
cout << "DispatchMessage::Unrecognized code: ";
|
||||
TranslateMessageCodeToStream(code);
|
||||
cout << endl << flush;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent any preprocessor problems in case I screw something up
|
||||
#ifdef DEBUG_SERVERAPP_MSGS
|
||||
#undef DEBUG_SERVERAPP_MSGS
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_SERVERAPP_CURSORS
|
||||
#undef DEBUG_SERVERAPP_CURSORS
|
||||
#endif
|
@ -1,35 +0,0 @@
|
||||
#ifndef _SRVAPP_H_
|
||||
#define _SRVAPP_H_
|
||||
|
||||
#include <OS.h>
|
||||
class BMessage;
|
||||
class PortLink;
|
||||
class BList;
|
||||
class ServerCursor;
|
||||
class DisplayDriver;
|
||||
|
||||
class ServerApp
|
||||
{
|
||||
public:
|
||||
ServerApp(port_id msgport, char *signature);
|
||||
~ServerApp(void);
|
||||
|
||||
bool Run(void);
|
||||
static int32 MonitorApp(void *data);
|
||||
void Loop(void);
|
||||
void DispatchMessage(int32 code, int8 *buffer);
|
||||
bool IsActive(void) { return isactive; }
|
||||
void Activate(bool value) { isactive=value; }
|
||||
|
||||
port_id sender,receiver;
|
||||
char *app_sig;
|
||||
thread_id monitor_thread;
|
||||
PortLink *applink;
|
||||
BList *winlist, *bmplist;
|
||||
ServerCursor *cursor;
|
||||
DisplayDriver *driver;
|
||||
bool isactive;
|
||||
rgb_color high, low; // just for testing until layers are implemented
|
||||
};
|
||||
|
||||
#endif
|
@ -1,252 +0,0 @@
|
||||
/*
|
||||
ServerBitmap.cpp
|
||||
Bitmap class which is intended to provide an easy way to package all the
|
||||
data associated with a picture. It's very low-level, so there's still
|
||||
plenty to do when coding with 'em. Also, they're used to access draw on the
|
||||
frame buffer in a relatively easy way, although it is currently unclear
|
||||
whether this functionality will even be necessary.
|
||||
*/
|
||||
|
||||
// These three includes for ServerBitmap(const char *path_to_image_file) only
|
||||
#include <TranslationUtils.h>
|
||||
#include <string.h>
|
||||
#include <Bitmap.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include "ServerBitmap.h"
|
||||
#include "Desktop.h"
|
||||
|
||||
ServerBitmap::ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0)
|
||||
{
|
||||
width=rect.IntegerWidth()+1;
|
||||
height=rect.IntegerHeight()+1;
|
||||
cspace=space;
|
||||
is_vram=false;
|
||||
is_area=false;
|
||||
areaid=B_ERROR;
|
||||
|
||||
HandleSpace(space, BytesPerLine);
|
||||
buffer=new uint8[bytesperline*height];
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
ServerBitmap::ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0)
|
||||
{
|
||||
width=w;
|
||||
height=h;
|
||||
cspace=space;
|
||||
is_vram=false;
|
||||
is_area=false;
|
||||
areaid=B_ERROR;
|
||||
|
||||
HandleSpace(space, BytesPerLine);
|
||||
buffer=new uint8[bytesperline*height];
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
ServerBitmap::ServerBitmap(int32 w,int32 h,color_space space, area_id areaID, int32 BytesPerLine=0)
|
||||
{
|
||||
// This version is used for holding BBitmaps as one of the undocumented BBitmap
|
||||
// constructors allows - it creates an area on the server's side.
|
||||
width=w;
|
||||
height=h;
|
||||
cspace=space;
|
||||
is_vram=false;
|
||||
is_area=true;
|
||||
|
||||
HandleSpace(space, BytesPerLine);
|
||||
area_info ainfo;
|
||||
areaid=areaID;
|
||||
get_area_info(areaid, &ainfo);
|
||||
buffer=(uint8*)ainfo.address;
|
||||
driver=get_gfxdriver();
|
||||
}
|
||||
|
||||
ServerBitmap::ServerBitmap(void)
|
||||
{
|
||||
// This version is obviously intended for use as an easy-access class for the
|
||||
// frame buffer. AtheOS does it and it's small, so why not? Worst case, this
|
||||
// can disappear if not necessary.
|
||||
is_vram=true;
|
||||
is_area=false;
|
||||
areaid=B_ERROR;
|
||||
UpdateSettings();
|
||||
}
|
||||
|
||||
// This particular version is not intended for use except for testing purposes.
|
||||
// It loads a BBitmap and copies it to the ServerBitmap. Probably will disappear
|
||||
// when the *real* server is written
|
||||
ServerBitmap::ServerBitmap(const char *path)
|
||||
{
|
||||
BBitmap *bmp=BTranslationUtils::GetBitmap(path);
|
||||
assert(bmp!=NULL);
|
||||
|
||||
if(bmp==NULL)
|
||||
{
|
||||
width=0;
|
||||
height=0;
|
||||
cspace=B_NO_COLOR_SPACE;
|
||||
bytesperline=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
width=bmp->Bounds().IntegerWidth();
|
||||
height=bmp->Bounds().IntegerHeight();
|
||||
cspace=bmp->ColorSpace();
|
||||
bytesperline=bmp->BytesPerRow();
|
||||
buffer=new uint8[bmp->BitsLength()];
|
||||
memcpy(buffer,(void *)bmp->Bits(),bmp->BitsLength());
|
||||
}
|
||||
}
|
||||
|
||||
ServerBitmap::~ServerBitmap(void)
|
||||
{
|
||||
if(!is_vram)
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
void ServerBitmap::UpdateSettings(void)
|
||||
{
|
||||
// This is only used when the object is pointing to the frame buffer
|
||||
driver=get_gfxdriver();
|
||||
bpp=driver->GetDepth();
|
||||
width=driver->GetWidth();
|
||||
height=driver->GetHeight();
|
||||
}
|
||||
|
||||
void ServerBitmap::SetBuffer(void *buffer)
|
||||
{
|
||||
buffer=(uint8 *)buffer;
|
||||
}
|
||||
|
||||
uint8 *ServerBitmap::Buffer(void)
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void ServerBitmap::HandleSpace(color_space space, int32 BytesPerLine)
|
||||
{
|
||||
// Function written to handle color space setup which is required
|
||||
// by the two "normal" constructors
|
||||
|
||||
// Big convoluted mess just to handle every color space and dword align
|
||||
// the buffer
|
||||
switch(space)
|
||||
{
|
||||
// Buffer is dword-aligned, so nothing need be done
|
||||
// aside from allocate the memory
|
||||
case B_RGB32:
|
||||
case B_RGBA32:
|
||||
case B_RGB32_BIG:
|
||||
case B_RGBA32_BIG:
|
||||
case B_UVL32:
|
||||
case B_UVLA32:
|
||||
case B_LAB32:
|
||||
case B_LABA32:
|
||||
case B_HSI32:
|
||||
case B_HSIA32:
|
||||
case B_HSV32:
|
||||
case B_HSVA32:
|
||||
case B_HLS32:
|
||||
case B_HLSA32:
|
||||
case B_CMY32:
|
||||
case B_CMYA32:
|
||||
case B_CMYK32:
|
||||
|
||||
// 24-bit = 32-bit with extra 8 bits ignored
|
||||
case B_RGB24_BIG:
|
||||
case B_RGB24:
|
||||
case B_LAB24:
|
||||
case B_UVL24:
|
||||
case B_HSI24:
|
||||
case B_HSV24:
|
||||
case B_HLS24:
|
||||
case B_CMY24:
|
||||
{
|
||||
if(BytesPerLine<(width*4))
|
||||
bytesperline=width*4;
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=32;
|
||||
break;
|
||||
}
|
||||
// Calculate size and dword-align
|
||||
|
||||
// 1-bit
|
||||
case B_GRAY1:
|
||||
{
|
||||
int32 numbytes=width>>3;
|
||||
if((width % 8) != 0)
|
||||
numbytes++;
|
||||
if(BytesPerLine<numbytes)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (numbytes+i)%4==0)
|
||||
{
|
||||
bytesperline=numbytes+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=1;
|
||||
}
|
||||
|
||||
// 8-bit
|
||||
case B_CMAP8:
|
||||
case B_GRAY8:
|
||||
case B_YUV411:
|
||||
case B_YUV420:
|
||||
case B_YCbCr422:
|
||||
case B_YCbCr411:
|
||||
case B_YCbCr420:
|
||||
case B_YUV422:
|
||||
{
|
||||
if(BytesPerLine<width)
|
||||
{
|
||||
for(int8 i=0;i<4;i++)
|
||||
{
|
||||
if( (width+i)%4==0)
|
||||
{
|
||||
bytesperline=width+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=8;
|
||||
break;
|
||||
}
|
||||
|
||||
// 16-bit
|
||||
case B_YUV9:
|
||||
case B_YUV12:
|
||||
case B_RGB15:
|
||||
case B_RGBA15:
|
||||
case B_RGB16:
|
||||
case B_RGB16_BIG:
|
||||
case B_RGB15_BIG:
|
||||
case B_RGBA15_BIG:
|
||||
case B_YCbCr444:
|
||||
case B_YUV444:
|
||||
{
|
||||
if(BytesPerLine<width*2)
|
||||
{
|
||||
if( (width*2) % 4 !=0)
|
||||
bytesperline=(width+1)*2;
|
||||
else
|
||||
bytesperline=width*2;
|
||||
}
|
||||
else
|
||||
bytesperline=BytesPerLine;
|
||||
bpp=16;
|
||||
break;
|
||||
}
|
||||
case B_NO_COLOR_SPACE:
|
||||
bpp=0;
|
||||
break;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
#ifndef _SERVER_BITMAP_H_
|
||||
#define _SERVER_BITMAP_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
#include <OS.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class ServerBitmap
|
||||
{
|
||||
public:
|
||||
ServerBitmap(BRect rect,color_space space,int32 BytesPerLine=0);
|
||||
ServerBitmap(int32 w,int32 h,color_space space,int32 BytesPerLine=0);
|
||||
ServerBitmap(int32 w,int32 h,color_space space, area_id areaID, int32 BytesPerLine=0);
|
||||
ServerBitmap(void);
|
||||
ServerBitmap(const char *path);
|
||||
~ServerBitmap(void);
|
||||
void UpdateSettings(void);
|
||||
void SetBuffer(void *buffer);
|
||||
uint8 *Buffer(void);
|
||||
void SetArea(area_id ID);
|
||||
area_id Area(void);
|
||||
|
||||
int32 width,height;
|
||||
int32 bytesperline;
|
||||
color_space cspace;
|
||||
int bpp;
|
||||
|
||||
protected:
|
||||
void HandleSpace(color_space space, int32 BytesPerLine);
|
||||
DisplayDriver *driver;
|
||||
bool is_vram,is_area;
|
||||
area_id areaid;
|
||||
uint8 *buffer;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
ServerCursor.cpp
|
||||
This is the server-side class used to handle cursors. Note that it
|
||||
will handle the R5 cursor API, but it will also handle taking a bitmap.
|
||||
|
||||
ServerCursors are 32-bit. Eventually, we will be mapping colors to fit
|
||||
when the set is called.
|
||||
|
||||
This is new code, and there may be changes to the API before it settles
|
||||
in.
|
||||
*/
|
||||
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerBitmap.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
long pow2(int power)
|
||||
{
|
||||
if(power==0)
|
||||
return 1;
|
||||
return long(2 << (power-1));
|
||||
}
|
||||
|
||||
ServerCursor::ServerCursor(void)
|
||||
{
|
||||
// For when an application is started. This will probably disappear once I
|
||||
// get the stuff for default cursors established
|
||||
is_initialized=false;
|
||||
position.Set(0,0);
|
||||
}
|
||||
|
||||
ServerCursor::ServerCursor(ServerBitmap *bmp, ServerBitmap *cmask=NULL)
|
||||
{
|
||||
// The OpenBeOS R1 API uses Bitmaps to create cursors - more flexibility that way.
|
||||
is_initialized=false;
|
||||
position.Set(0,0);
|
||||
SetCursor(bmp);
|
||||
}
|
||||
|
||||
ServerCursor::ServerCursor(int8 *data)
|
||||
{
|
||||
// For handling the idiot R5 API data format
|
||||
is_initialized=false;
|
||||
position.Set(0,0);
|
||||
SetCursor(data);
|
||||
}
|
||||
|
||||
ServerCursor::~ServerCursor(void)
|
||||
{
|
||||
if(is_initialized)
|
||||
delete bitmap;
|
||||
}
|
||||
|
||||
void ServerCursor::SetCursor(int8 *data)
|
||||
{
|
||||
// 68-byte array used in R5 for holding cursors.
|
||||
// This API has serious problems and should be deprecated(but supported)
|
||||
// in a future release, perhaps right after the first one
|
||||
|
||||
if(is_initialized)
|
||||
{
|
||||
delete bitmap;
|
||||
}
|
||||
cspace=B_RGBA32;
|
||||
|
||||
bitmap=new ServerBitmap(16,16,B_RGBA32);
|
||||
width=16;
|
||||
height=16;
|
||||
bounds.Set(0,0,15,15);
|
||||
|
||||
// Now that we have all the setup, we're going to map (for now) the cursor
|
||||
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths
|
||||
uint32 black=0xFF000000,
|
||||
white=0xFFFFFFFF,
|
||||
*bmppos;
|
||||
uint16 *cursorpos, *maskpos,cursorflip, maskflip,
|
||||
cursorval, maskval;
|
||||
uint8 i,j;
|
||||
|
||||
cursorpos=(uint16*)(data+4);
|
||||
maskpos=(uint16*)(data+36);
|
||||
|
||||
// for each row in the cursor data
|
||||
for(j=0;j<16;j++)
|
||||
{
|
||||
bmppos=(uint32*)(bitmap->Buffer()+ (j*bitmap->bytesperline) );
|
||||
|
||||
// On intel, our bytes end up swapped, so we must swap them back
|
||||
cursorflip=(cursorpos[j] & 0xFF) << 8;
|
||||
cursorflip |= (cursorpos[j] & 0xFF00) >> 8;
|
||||
maskflip=(maskpos[j] & 0xFF) << 8;
|
||||
maskflip |= (maskpos[j] & 0xFF00) >> 8;
|
||||
|
||||
// for each column in each row of cursor data
|
||||
for(i=0;i<16;i++)
|
||||
{
|
||||
// Get the values and dump them to the bitmap
|
||||
cursorval=cursorflip & pow2(15-i);
|
||||
maskval=maskflip & pow2(15-i);
|
||||
bmppos[i]=((cursorval!=0)?black:white) & ((maskval>0)?0xFFFFFFFF:0x00FFFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Currently unimplemented
|
||||
void ServerCursor::SetCursor(ServerBitmap *bmp, ServerBitmap *cmask=NULL)
|
||||
{
|
||||
/* if(is_initialized)
|
||||
delete bitmap;
|
||||
cspace=bmp->cspace;
|
||||
|
||||
bitmap=new ServerBitmap(bmp->width,bmp->height,cspace);
|
||||
|
||||
width=bmp->width;
|
||||
height=bmp->height;
|
||||
bounds.Set(0,0,bmp->width-1,bmp->height-1);
|
||||
*/
|
||||
}
|
||||
|
||||
void ServerCursor::MoveTo(int32 x, int32 y)
|
||||
{
|
||||
position.Set(x,y);
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#ifndef _SERVER_SPRITE_H
|
||||
#define _SERVER_SPRITE_H
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class ServerBitmap;
|
||||
|
||||
class ServerCursor
|
||||
{
|
||||
public:
|
||||
ServerCursor(ServerBitmap *bmp,ServerBitmap *cmask=NULL);
|
||||
ServerCursor(int8 *data);
|
||||
ServerCursor(void);
|
||||
~ServerCursor(void);
|
||||
void MoveTo(int32 x, int32 y);
|
||||
void SetCursor(int8 *data);
|
||||
void SetCursor(ServerBitmap *bmp, ServerBitmap *cmask=NULL);
|
||||
|
||||
ServerBitmap *bitmap;
|
||||
|
||||
color_space cspace;
|
||||
BRect bounds;
|
||||
int width,height;
|
||||
BPoint position,hotspot;
|
||||
bool is_initialized;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,69 +0,0 @@
|
||||
#ifndef _APPSERVER_PROTOCOL_
|
||||
#define _APPSERVER_PROTOCOL_
|
||||
|
||||
#define CREATE_APP 'drca'
|
||||
#define DELETE_APP 'drda'
|
||||
#define QUIT_APP 'srqa'
|
||||
|
||||
#define SET_SERVER_PORT 'srsp'
|
||||
|
||||
#define CREATE_WINDOW 'drcw'
|
||||
#define DELETE_WINDOW 'drdw'
|
||||
#define QUIT_WINDOW 'srqw'
|
||||
|
||||
#define SERVER_PORT_NAME "OBappserver"
|
||||
#define SERVER_INPUT_PORT "OBinputport"
|
||||
|
||||
#define SET_CURSOR_DATA 'sscd'
|
||||
#define SET_CURSOR_BCURSOR 'sscb'
|
||||
#define SET_CURSOR_BBITMAP 'sscB'
|
||||
#define SHOW_CURSOR 'srsc'
|
||||
#define HIDE_CURSOR 'srhc'
|
||||
#define OBSCURE_CURSOR 'sroc'
|
||||
|
||||
#define GFX_COUNT_WORKSPACES 'gcws'
|
||||
#define GFX_SET_WORKSPACE_COUNT 'ggwc'
|
||||
#define GFX_CURRENT_WORKSPACE 'ggcw'
|
||||
#define GFX_ACTIVATE_WORKSPACE 'gaws'
|
||||
#define GFX_SYSTEM_COLORS 'gsyc'
|
||||
#define GFX_SET_SCREEN_MODE 'gssm'
|
||||
#define GFX_GET_SCROLLBAR_INFO 'ggsi'
|
||||
#define GFX_SET_SCROLLBAR_INFO 'gssi'
|
||||
#define GFX_IDLE_TIME 'gidt'
|
||||
#define GFX_SELECT_PRINTER_PANEL 'gspp'
|
||||
#define GFX_ADD_PRINTER_PANEL 'gapp'
|
||||
#define GFX_RUN_BE_ABOUT 'grba'
|
||||
#define GFX_SET_FOCUS_FOLLOWS_MOUSE 'gsfm'
|
||||
#define GFX_FOCUS_FOLLOWS_MOUSE 'gffm'
|
||||
|
||||
#define GFX_SET_HIGH_COLOR 'gshc'
|
||||
#define GFX_SET_LOW_COLOR 'gslc'
|
||||
|
||||
#define GFX_STROKE_ARC 'gsar'
|
||||
#define GFX_STROKE_BEZIER 'gsbz'
|
||||
#define GFX_STROKE_ELLIPSE 'gsel'
|
||||
#define GFX_STROKE_LINE 'gsln'
|
||||
#define GFX_STROKE_POLYGON 'gspy'
|
||||
#define GFX_STROKE_RECT 'gsrc'
|
||||
#define GFX_STROKE_ROUNDRECT 'gsrr'
|
||||
#define GFX_STROKE_SHAPE 'gssh'
|
||||
#define GFX_STROKE_TRIANGLE 'gstr'
|
||||
|
||||
#define GFX_FILL_ARC 'gfar'
|
||||
#define GFX_FILL_BEZIER 'gfbz'
|
||||
#define GFX_FILL_ELLIPSE 'gfel'
|
||||
#define GFX_FILL_POLYGON 'gfpy'
|
||||
#define GFX_FILL_RECT 'gfrc'
|
||||
#define GFX_FILL_REGION 'gfrg'
|
||||
#define GFX_FILL_ROUNDRECT 'gfrr'
|
||||
#define GFX_FILL_SHAPE 'gfsh'
|
||||
#define GFX_FILL_TRIANGLE 'gftr'
|
||||
|
||||
#define GFX_MOVEPENBY 'gmpb'
|
||||
#define GFX_MOVEPENTO 'gmpt'
|
||||
#define GFX_SETPENSIZE 'gsps'
|
||||
|
||||
#define GFX_DRAW_STRING 'gdst'
|
||||
#define GFX_SET_FONT 'gsft'
|
||||
#define GFX_SET_FONT_SIZE 'gsfs'
|
||||
#endif
|
@ -1,29 +0,0 @@
|
||||
#include "ServerCursor.h"
|
||||
#include "ServerBitmap.h"
|
||||
|
||||
ServerCursor::ServerCursor(ServerBitmap *bmp)
|
||||
{
|
||||
}
|
||||
|
||||
ServerCursor::~ServerCursor(void)
|
||||
{
|
||||
}
|
||||
|
||||
ServerCursor::SetCursor(int8 *data)
|
||||
{
|
||||
// 68-byte array used in R5 for holding cursors.
|
||||
// This API has serious problems and should be deprecated(but supported)
|
||||
// in a future release, perhaps the first one(?)
|
||||
}
|
||||
|
||||
void ServerCursor::SaveClientData(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerCursor::MoveTo(int32 x, int32 y)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerCursor::SetClient(ServerBitmap *bmp)
|
||||
{
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
#include <AppDefs.h>
|
||||
#include <iostream.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "PortLink.h"
|
||||
#include "ServerWindow.h"
|
||||
#include "ServerApp.h"
|
||||
#include "ServerProtocol.h"
|
||||
|
||||
ServerWindow::ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort)
|
||||
{
|
||||
cout << "ServerWindow " << Title << endl;
|
||||
|
||||
if(Title)
|
||||
{
|
||||
title=new char[strlen(Title)];
|
||||
sprintf((char *)title,Title);
|
||||
}
|
||||
else
|
||||
{
|
||||
title=new char[strlen("Window")];
|
||||
sprintf((char *)title,"Window");
|
||||
}
|
||||
|
||||
// sender is the monitored app's event port
|
||||
sender=SendPort;
|
||||
winlink=new PortLink(sender);
|
||||
|
||||
if(App!=NULL)
|
||||
applink=new PortLink(App->receiver);
|
||||
else
|
||||
applink=NULL;
|
||||
|
||||
// receiver is the port to which the app sends messages for the server
|
||||
receiver=create_port(30,title);
|
||||
|
||||
cout << "ServerWin port for window " << title << "is at " << (int32)receiver << endl;
|
||||
if(receiver==B_NO_MORE_PORTS)
|
||||
{
|
||||
// uh-oh. We have a serious problem. Tell the app to quit
|
||||
if(applink!=NULL)
|
||||
{
|
||||
applink->SetOpCode(B_QUIT_REQUESTED);
|
||||
applink->Flush();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Everything checks out, so tell the application
|
||||
// where to send future messages
|
||||
winlink->SetOpCode(SET_SERVER_PORT);
|
||||
winlink->Attach(&receiver,sizeof(port_id));
|
||||
winlink->Flush();
|
||||
}
|
||||
active=false;
|
||||
frame.Set(0,0,0,0);
|
||||
hidecount=0;
|
||||
|
||||
// Spawn our message monitoring thread
|
||||
thread=spawn_thread(MonitorWin,title,B_NORMAL_PRIORITY,this);
|
||||
if(thread!=B_NO_MORE_THREADS && thread!=B_NO_MEMORY)
|
||||
resume_thread(thread);
|
||||
|
||||
}
|
||||
|
||||
ServerWindow::~ServerWindow(void)
|
||||
{
|
||||
if(applink!=NULL)
|
||||
delete applink;
|
||||
delete title;
|
||||
delete winlink;
|
||||
}
|
||||
|
||||
void ServerWindow::PostMessage(BMessage *msg)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ReplaceDecorator(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Quit(void)
|
||||
{
|
||||
}
|
||||
|
||||
const char *ServerWindow::GetTitle(void)
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
ServerApp *ServerWindow::GetApp(void)
|
||||
{
|
||||
return app;
|
||||
}
|
||||
|
||||
void ServerWindow::Show(void)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Hide(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool ServerWindow::IsHidden(void)
|
||||
{
|
||||
return (hidecount==0)?true:false;
|
||||
}
|
||||
|
||||
void ServerWindow::SetFocus(bool value)
|
||||
{
|
||||
active=value;
|
||||
}
|
||||
|
||||
bool ServerWindow::HasFocus(void)
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
void ServerWindow::DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::WindowActivated(bool Active)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::ScreenModeChanged(const BPoint Resolustion, color_space CSpace)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::SetFrame(const BRect &rect)
|
||||
{
|
||||
frame=rect;
|
||||
}
|
||||
|
||||
BRect ServerWindow::Frame(void)
|
||||
{
|
||||
return frame;
|
||||
}
|
||||
|
||||
status_t ServerWindow::Lock(void)
|
||||
{
|
||||
return locker.Lock();
|
||||
}
|
||||
|
||||
void ServerWindow::Unlock(void)
|
||||
{
|
||||
locker.Unlock();
|
||||
}
|
||||
|
||||
bool ServerWindow::IsLocked(void)
|
||||
{
|
||||
return locker.IsLocked();
|
||||
}
|
||||
|
||||
void ServerWindow::DispatchMessage(const void *msg, int nCode)
|
||||
{
|
||||
}
|
||||
|
||||
void ServerWindow::Loop(void)
|
||||
{
|
||||
// Message-dispatching loop for the ServerWindow
|
||||
|
||||
cout << "Main message loop for " << title << endl;
|
||||
|
||||
int32 msgcode;
|
||||
int8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(receiver);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are PortLink messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new int8[buffersize];
|
||||
bytesread=read_port(receiver,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(receiver,&msgcode,NULL,0);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
default:
|
||||
cout << "ServerWin received unexpected code " << (int32)msgcode << endl;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32 ServerWindow::MonitorWin(void *data)
|
||||
{
|
||||
ServerWindow *win=(ServerWindow *)data;
|
||||
win->Loop();
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
#ifndef _SERVERWIN_H_
|
||||
#define _SERVERWIN_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <GraphicsDefs.h>
|
||||
#include <OS.h>
|
||||
#include <Locker.h>
|
||||
#include <Rect.h>
|
||||
|
||||
class BString;
|
||||
class BMessenger;
|
||||
class BPoint;
|
||||
class ServerApp;
|
||||
class WindowDecorator;
|
||||
class PortLink;
|
||||
|
||||
class ServerWindow
|
||||
{
|
||||
public:
|
||||
ServerWindow(const char *Title, uint32 Flags, uint32 Desktop,
|
||||
const BRect &Rect, ServerApp *App, port_id SendPort);
|
||||
~ServerWindow(void);
|
||||
|
||||
void PostMessage(BMessage *msg);
|
||||
void ReplaceDecorator(void);
|
||||
void Quit(void);
|
||||
const char *GetTitle(void);
|
||||
ServerApp *GetApp(void);
|
||||
void Show(void);
|
||||
void Hide(void);
|
||||
bool IsHidden(void);
|
||||
void SetFocus(bool value);
|
||||
bool HasFocus(void);
|
||||
|
||||
void DesktopActivated(int32 NewDesktop, const BPoint Resolution, color_space CSpace);
|
||||
void WindowActivated(bool Active);
|
||||
void ScreenModeChanged(const BPoint Resolution, color_space CSpace);
|
||||
|
||||
void SetFrame(const BRect &rect);
|
||||
BRect Frame(void);
|
||||
|
||||
status_t Lock(void);
|
||||
void Unlock(void);
|
||||
bool IsLocked(void);
|
||||
|
||||
void DispatchMessage(const void *msg, int nCode);
|
||||
static int32 MonitorWin(void *data);
|
||||
void Loop(void);
|
||||
|
||||
const char *title;
|
||||
int32 flags;
|
||||
int32 desktop;
|
||||
bool active;
|
||||
|
||||
ServerApp *app;
|
||||
|
||||
WindowDecorator *decorator;
|
||||
bigtime_t lasthit; // Time of last mouse click
|
||||
|
||||
thread_id thread;
|
||||
port_id receiver; // Messages from window
|
||||
port_id sender; // Messages to window
|
||||
PortLink *winlink,*applink;
|
||||
BLocker locker;
|
||||
BRect frame;
|
||||
uint8 hidecount;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,327 +0,0 @@
|
||||
/*
|
||||
SystemPalette.cpp
|
||||
One global function to generate the palette which is the default BeOS
|
||||
System palette and the variable to go with it
|
||||
*/
|
||||
|
||||
#include "SystemPalette.h"
|
||||
|
||||
rgb_color SystemPalette[256];
|
||||
|
||||
void GenerateSystemPalette(rgb_color *palette)
|
||||
{
|
||||
int i,j,index=0;
|
||||
int indexvals1[]={ 255,229,204,179,154,129,105,80,55,30 },
|
||||
indexvals2[]={ 255,203,152,102,51,0 };
|
||||
rgb_color *currentcol;
|
||||
|
||||
// Grays 0,0,0 -> 248,248,248 by 8's
|
||||
for(i=0; i<=248; i+=8,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=i;
|
||||
currentcol->green=i;
|
||||
currentcol->blue=i;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Blues, following indexvals1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals1[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Reds, following indexvals1 - 1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals1[i] - 1;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=0;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
// Greens, following indexvals1 - 1
|
||||
for(i=0; i<10; i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=indexvals1[i] - 1;
|
||||
currentcol->blue=0;
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=152;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<4;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=152;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=203;
|
||||
index++;
|
||||
|
||||
// Mostly array runs from here on out
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=203;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=152;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=102;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=51;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=152;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=102;
|
||||
index++;
|
||||
|
||||
// knocks out 4 assignment loops at once :)
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=152;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=230;
|
||||
currentcol->green=134;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(i=1;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=102;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=102;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=175;
|
||||
currentcol->blue=19;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=255;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=203;
|
||||
index++;
|
||||
|
||||
for(j=1;j<5;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=3;i>=0;i--,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
for(i=2;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=0;
|
||||
currentcol->green=51;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
for(i=0;i<5;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=203;
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=227;
|
||||
currentcol->blue=70;
|
||||
index++;
|
||||
|
||||
for(j=2;j<6;j++)
|
||||
{
|
||||
for(i=0;i<6;i++,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=indexvals2[j];
|
||||
currentcol->green=0;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
}
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=51;
|
||||
index++;
|
||||
|
||||
currentcol+=sizeof(rgb_color);
|
||||
currentcol->red=255;
|
||||
currentcol->green=203;
|
||||
currentcol->blue=0;
|
||||
index++;
|
||||
|
||||
for(i=5;i<=0;i--,index++)
|
||||
{
|
||||
currentcol=&(palette[index]);
|
||||
currentcol->red=255;
|
||||
currentcol->green=255;
|
||||
currentcol->blue=indexvals2[i];
|
||||
currentcol->alpha=255;
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#ifndef _SYSTEM_PALETTE_H_
|
||||
#define _SYSTEM_PALETTE_H_
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
void GenerateSystemPalette(rgb_color *palette);
|
||||
extern rgb_color SystemPalette[];
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
@ -1,127 +0,0 @@
|
||||
#ifndef _VIEWDRIVER_H_
|
||||
#define _VIEWDRIVER_H_
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
#include <GraphicsCard.h>
|
||||
#include <GraphicsDefs.h> // for pattern struct
|
||||
#include <Cursor.h>
|
||||
#include <Message.h>
|
||||
#include "DisplayDriver.h"
|
||||
|
||||
class BBitmap;
|
||||
class PortLink;
|
||||
class VDWindow;
|
||||
class ServerCursor;
|
||||
|
||||
class VDView : public BView
|
||||
{
|
||||
public:
|
||||
VDView(BRect bounds);
|
||||
~VDView(void);
|
||||
void AttachedToWindow(void);
|
||||
void Draw(BRect rect);
|
||||
void MouseDown(BPoint pt);
|
||||
void MouseMoved(BPoint pt, uint32 transit, const BMessage *msg);
|
||||
void MouseUp(BPoint pt);
|
||||
void SetMode(int16 width, int16 height, uint8 bpp);
|
||||
|
||||
BBitmap *viewbmp;
|
||||
BView *drawview;
|
||||
PortLink *serverlink;
|
||||
|
||||
protected:
|
||||
friend VDWindow;
|
||||
|
||||
int hide_cursor;
|
||||
BBitmap *cursor;
|
||||
|
||||
BRect cursorframe, oldcursorframe;
|
||||
bool obscure_cursor;
|
||||
};
|
||||
|
||||
class VDWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
VDWindow(void);
|
||||
~VDWindow(void);
|
||||
void MessageReceived(BMessage *msg);
|
||||
bool QuitRequested(void);
|
||||
void WindowActivated(bool active);
|
||||
|
||||
void SafeMode(void);
|
||||
void Reset(void);
|
||||
void SetScreen(uint32 space);
|
||||
void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
|
||||
VDView *view;
|
||||
};
|
||||
|
||||
class ViewDriver : public DisplayDriver
|
||||
{
|
||||
public:
|
||||
ViewDriver(void);
|
||||
virtual ~ViewDriver(void);
|
||||
|
||||
virtual void Initialize(void); // Sets the driver
|
||||
virtual bool IsInitialized(void);
|
||||
virtual void Shutdown(void); // You never know when you'll need this
|
||||
|
||||
virtual void SafeMode(void); // Easy-access functions for common tasks
|
||||
virtual void Reset(void);
|
||||
virtual void Clear(uint8 red,uint8 green,uint8 blue);
|
||||
virtual void Clear(rgb_color col);
|
||||
|
||||
// Settings functions
|
||||
virtual void SetScreen(uint32 space);
|
||||
virtual int32 GetHeight(void);
|
||||
virtual int32 GetWidth(void);
|
||||
virtual int GetDepth(void);
|
||||
|
||||
// Drawing functions
|
||||
virtual void Blit(BPoint dest, ServerBitmap *src, ServerBitmap *dest);
|
||||
virtual void DrawBitmap(ServerBitmap *bitmap);
|
||||
virtual void DrawChar(char c, BPoint point);
|
||||
virtual void DrawString(char *string, int length, BPoint point);
|
||||
|
||||
virtual void FillArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern);
|
||||
virtual void FillBezier(BPoint *points, uint8 *pattern);
|
||||
virtual void FillEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern);
|
||||
virtual void FillPolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void FillRect(BRect rect, uint8 *pattern);
|
||||
virtual void FillRegion(BRegion *region);
|
||||
virtual void FillRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern);
|
||||
virtual void FillShape(BShape *shape);
|
||||
virtual void FillTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern);
|
||||
|
||||
virtual void HideCursor(void);
|
||||
virtual bool IsCursorHidden(void);
|
||||
virtual void MoveCursorTo(float x, float y);
|
||||
virtual void MovePenTo(BPoint pt);
|
||||
virtual void ObscureCursor(void);
|
||||
virtual BPoint PenPosition(void);
|
||||
virtual float PenSize(void);
|
||||
virtual void SetCursor(int32 value);
|
||||
virtual void SetCursor(ServerCursor *cursor);
|
||||
virtual void SetHighColor(uint8 r,uint8 g,uint8 b,uint8 a=255);
|
||||
virtual void SetLowColor(uint8 r,uint8 g,uint8 b,uint8 a=255);
|
||||
virtual void SetPenSize(float size);
|
||||
virtual void SetPixel(int x, int y, uint8 *pattern);
|
||||
virtual void ShowCursor(void);
|
||||
|
||||
virtual void StrokeArc(int centerx, int centery, int xradius, int yradius, float angle, float span, uint8 *pattern);
|
||||
virtual void StrokeBezier(BPoint *points, uint8 *pattern);
|
||||
virtual void StrokeEllipse(float centerx, float centery, float x_radius, float y_radius,uint8 *pattern);
|
||||
virtual void StrokeLine(BPoint point, uint8 *pattern);
|
||||
virtual void StrokePolygon(int *x, int *y, int numpoints, bool is_closed);
|
||||
virtual void StrokeRect(BRect rect,uint8 *pattern);
|
||||
virtual void StrokeRoundRect(BRect rect,float xradius, float yradius, uint8 *pattern);
|
||||
virtual void StrokeShape(BShape *shape);
|
||||
virtual void StrokeTriangle(BPoint first, BPoint second, BPoint third, BRect rect, uint8 *pattern);
|
||||
VDWindow *screenwin;
|
||||
protected:
|
||||
int hide_cursor;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,16 +0,0 @@
|
||||
// main.cpp
|
||||
|
||||
|
||||
const char app_sig[] = "application/x-vnd.myApp";
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if(is_computer_on())
|
||||
{
|
||||
// TODO: start up the application!
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
#include <SupportDefs.h>
|
||||
#include <OS.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
Sends a message to the OpenBeOS app_server's message port
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int32 msgcode;
|
||||
|
||||
if(argc>2)
|
||||
{
|
||||
port_id serverport=atoi(argv[1]);
|
||||
msgcode=atoi(argv[2]);
|
||||
|
||||
write_port(serverport,msgcode,NULL,0);
|
||||
printf("Sent %ld to port %ld\n",msgcode,serverport);
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("obhey port <message code>\n");
|
||||
return 0;
|
||||
}
|
@ -1,639 +0,0 @@
|
||||
/*
|
||||
OBApp.cpp: App faker for OpenBeOS app_server prototype #4
|
||||
|
||||
This one happens to be a graphics tester.
|
||||
|
||||
ReadyToRun is set to spawn a thread to post all the messages. Posting from a
|
||||
separate thread will be necessary once packetized graphics messaging is done.
|
||||
|
||||
Because graphics message packetizing is not done, the code in each function to
|
||||
test the graphics will obviously change even though the data format which the
|
||||
server will ultimately receive will stay the same.
|
||||
*/
|
||||
|
||||
#include <OS.h>
|
||||
#include <GraphicsDefs.h> // for the pattern struct and screen mode defs
|
||||
#include <Rect.h>
|
||||
#include <Region.h>
|
||||
#include <Cursor.h>
|
||||
#include <Font.h>
|
||||
#include <Application.h>
|
||||
#include <Handler.h>
|
||||
#include <Message.h>
|
||||
#include <stdio.h>
|
||||
#include <String.h>
|
||||
#include "ServerProtocol.h"
|
||||
#include "PortLink.h"
|
||||
#include "OBApp.h"
|
||||
|
||||
TestApp::TestApp(void)
|
||||
{
|
||||
initialized=true;
|
||||
|
||||
// Receives messages from server and others
|
||||
messageport=create_port(50,"msgport");
|
||||
if(messageport==B_BAD_VALUE || messageport==B_NO_MORE_PORTS)
|
||||
{ printf("TestApp: Couldn't create message port\n");
|
||||
initialized=false;
|
||||
}
|
||||
|
||||
// Find the port for the app_server
|
||||
serverport=find_port("OBappserver");
|
||||
if(serverport==B_NAME_NOT_FOUND)
|
||||
{ printf("TestApp: Couldn't find server port\n");
|
||||
initialized=false;
|
||||
|
||||
serverlink=new PortLink(create_port(50,"OBAppServer"));
|
||||
}
|
||||
else
|
||||
{
|
||||
serverlink=new PortLink(serverport);
|
||||
}
|
||||
|
||||
// signature=new char[255];
|
||||
signature=new char[strlen("application/x-vnd.wgp-OBTestApp")];
|
||||
sprintf(signature,"application/x-vnd.wgp-OBTestApp");
|
||||
|
||||
}
|
||||
|
||||
TestApp::~TestApp(void)
|
||||
{
|
||||
// printf("%s::~TestApp()\n",signature);
|
||||
delete signature;
|
||||
|
||||
if(initialized==true)
|
||||
delete serverlink;
|
||||
}
|
||||
|
||||
void TestApp::MainLoop(void)
|
||||
{
|
||||
printf("TestApp::MainLoop()\n");
|
||||
|
||||
// Notify server of app's existence
|
||||
serverlink->SetOpCode(CREATE_APP);
|
||||
serverlink->Attach(&messageport,sizeof(port_id));
|
||||
// serverlink.Attach(PID);
|
||||
serverlink->Attach(signature,strlen(signature));
|
||||
serverlink->Flush();
|
||||
|
||||
int32 msgcode;
|
||||
uint8 *msgbuffer=NULL;
|
||||
ssize_t buffersize,bytesread;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
buffersize=port_buffer_size(messageport);
|
||||
|
||||
if(buffersize>0)
|
||||
{
|
||||
// buffers are flattened messages. Allocate necessary buffer and
|
||||
// we'll cast it as a BMessage.
|
||||
msgbuffer=new uint8[buffersize];
|
||||
bytesread=read_port(messageport,&msgcode,msgbuffer,buffersize);
|
||||
}
|
||||
else
|
||||
bytesread=read_port(messageport,&msgcode,NULL,0);
|
||||
|
||||
if (bytesread != B_BAD_PORT_ID && bytesread != B_TIMED_OUT && bytesread != B_WOULD_BLOCK)
|
||||
{
|
||||
switch(msgcode)
|
||||
{
|
||||
case B_QUIT_REQUESTED:
|
||||
{
|
||||
// Attached data:
|
||||
// None
|
||||
printf("%s: Quit requested\n",signature);
|
||||
serverlink->SetOpCode(msgcode);
|
||||
serverlink->Flush();
|
||||
break;
|
||||
}
|
||||
case SET_SERVER_PORT:
|
||||
{
|
||||
// This message is received when the server has created
|
||||
// the ServerApp object to monitor our application. It is
|
||||
// sending us the port to which we send future messages
|
||||
|
||||
// Attached data:
|
||||
// port_id - id of the port of the corresponding ServerApp
|
||||
if(buffersize<1)
|
||||
{
|
||||
printf("%s: Set Server Port has no attached data\n",signature);
|
||||
break;
|
||||
}
|
||||
printf("%s: Set Server Port to %ld\n",signature,*((port_id *)msgbuffer));
|
||||
serverport=*((port_id *)msgbuffer);
|
||||
serverlink->SetPort(serverport);
|
||||
ReadyToRun();
|
||||
break;
|
||||
}
|
||||
case B_MOUSE_MOVED:
|
||||
case B_MOUSE_DOWN:
|
||||
case B_MOUSE_UP:
|
||||
DispatchMessage(msgcode, (int8*)msgbuffer);
|
||||
break;
|
||||
default:
|
||||
printf("OBTestApp received unexpected code %ld\n",msgcode);
|
||||
break;
|
||||
}
|
||||
|
||||
if(msgcode==B_QUIT_REQUESTED)
|
||||
{
|
||||
printf("Quitting %s\n",signature);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(buffersize>0)
|
||||
delete msgbuffer;
|
||||
}
|
||||
}
|
||||
|
||||
void TestApp::DispatchMessage(BMessage *msg, BHandler *handler)
|
||||
{
|
||||
// printf("TestApp::DispatchMessage()\n");
|
||||
}
|
||||
|
||||
// For test application purposes only - will be replaced later
|
||||
void TestApp::DispatchMessage(int32 code, int8 *buffer)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case B_MOUSE_DOWN:
|
||||
case B_MOUSE_UP:
|
||||
case B_MOUSE_MOVED:
|
||||
break;
|
||||
default:
|
||||
printf("TestApp %s received unknown code %ld\n",signature,code);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void TestApp::MessageReceived(BMessage *msg)
|
||||
{
|
||||
// printf("TestApp::MessageReceived()\n");
|
||||
}
|
||||
|
||||
void TestApp::ShowCursor(void)
|
||||
{
|
||||
serverlink->SetOpCode(SHOW_CURSOR);
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::HideCursor(void)
|
||||
{
|
||||
serverlink->SetOpCode(HIDE_CURSOR);
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::ObscureCursor(void)
|
||||
{
|
||||
serverlink->SetOpCode(OBSCURE_CURSOR);
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
bool TestApp::IsCursorHidden(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void TestApp::SetCursor(const void *cursor)
|
||||
{
|
||||
printf("TestApp::SetCursor()\n");
|
||||
// attach & send the 68-byte chunk
|
||||
serverlink->SetOpCode(SET_CURSOR_DATA);
|
||||
serverlink->Attach((void*)cursor, 68);
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::SetCursor(const BCursor *cursor, bool sync=true)
|
||||
{
|
||||
// attach & send the BCursor
|
||||
serverlink->SetOpCode(SET_CURSOR_BCURSOR);
|
||||
serverlink->Attach((BCursor*)cursor, sizeof(BCursor));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::SetCursor(BBitmap *bmp)
|
||||
{
|
||||
// This will be enabled once the BBitmap functionality is better nailed down
|
||||
|
||||
/* // attach & send the TestBitmap's area_id
|
||||
serverlink->SetOpCode(SET_CURSOR_BCURSOR);
|
||||
serverlink->Attach(bmp, sizeof(BCursor));
|
||||
serverlink->Flush();
|
||||
*/
|
||||
}
|
||||
|
||||
void TestApp::ReadyToRun(void)
|
||||
{
|
||||
thread_id tid=spawn_thread(TestGraphics,"testthread",B_NORMAL_PRIORITY,this);
|
||||
if(tid!=B_NO_MEMORY && tid!=B_NO_MORE_THREADS)
|
||||
resume_thread(tid);
|
||||
}
|
||||
|
||||
int32 TestApp::TestGraphics(void *data)
|
||||
{
|
||||
printf("TestGraphics Spawned\n");
|
||||
TestApp *app=(TestApp*)data;
|
||||
|
||||
app->TestScreenStates();
|
||||
app->TestArcs();
|
||||
app->TestBeziers();
|
||||
app->TestEllipses();
|
||||
app->TestLines();
|
||||
// app->TestPolygon();
|
||||
app->TestRects();
|
||||
// app->TestRegions();
|
||||
// app->TestShape();
|
||||
app->TestTriangle();
|
||||
app->TestCursors();
|
||||
app->TestFonts();
|
||||
printf("TestGraphics Exited\n");
|
||||
exit_thread(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TestApp::SetHighColor(uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
// Server always expects an alpha value
|
||||
uint8 a=255;
|
||||
serverlink->SetOpCode(GFX_SET_HIGH_COLOR);
|
||||
serverlink->Attach(&r,sizeof(uint8));
|
||||
serverlink->Attach(&g,sizeof(uint8));
|
||||
serverlink->Attach(&b,sizeof(uint8));
|
||||
serverlink->Attach(&a,sizeof(uint8));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::SetLowColor(uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
// Server always expects an alpha value
|
||||
uint8 a=255;
|
||||
serverlink->SetOpCode(GFX_SET_LOW_COLOR);
|
||||
serverlink->Attach(&r,sizeof(uint8));
|
||||
serverlink->Attach(&g,sizeof(uint8));
|
||||
serverlink->Attach(&b,sizeof(uint8));
|
||||
serverlink->Attach(&a,sizeof(uint8));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::TestScreenStates(void)
|
||||
{
|
||||
// This function is here to test all the graphics state code, such as
|
||||
// resolution, desktop switching, etc.
|
||||
|
||||
// Protocol defined here will be used by the screen-related global functions
|
||||
|
||||
int32 workspace=0;
|
||||
uint32 mode=B_32_BIT_640x480;
|
||||
bool sticky=false;
|
||||
|
||||
// set_screen_space()
|
||||
serverlink->SetOpCode(GFX_SET_SCREEN_MODE);
|
||||
serverlink->Attach(&workspace,sizeof(int32));
|
||||
serverlink->Attach(&mode,sizeof(int32));
|
||||
serverlink->Attach(&sticky,sizeof(bool));
|
||||
serverlink->Flush();
|
||||
|
||||
// This code works, I just don't want to mess with it when I'm
|
||||
// working on the other tests.
|
||||
/*
|
||||
// activate_workspace()
|
||||
workspace=1;
|
||||
serverlink->SetOpCode(GFX_ACTIVATE_WORKSPACE);
|
||||
serverlink->Attach(&workspace,sizeof(int32));
|
||||
serverlink->Flush();
|
||||
*/
|
||||
}
|
||||
|
||||
void TestApp::TestArcs(void)
|
||||
{
|
||||
float centerx=275, centery=95,
|
||||
radx=70, rady=45,
|
||||
angle=40,
|
||||
span=210;
|
||||
|
||||
// Fill Arc
|
||||
SetHighColor(0,0,255);
|
||||
serverlink->SetOpCode(GFX_FILL_ARC);
|
||||
serverlink->Attach(¢erx,sizeof(float));
|
||||
serverlink->Attach(¢ery,sizeof(float));
|
||||
serverlink->Attach(&radx,sizeof(float));
|
||||
serverlink->Attach(&rady,sizeof(float));
|
||||
serverlink->Attach(&angle,sizeof(float));
|
||||
serverlink->Attach(&span,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Stroke Arc
|
||||
for(int i=0; i<45; i+=5)
|
||||
{
|
||||
centerx=280+i;
|
||||
centery=100+i;
|
||||
radx=75+i;
|
||||
rady=50+i;
|
||||
angle=45+i;
|
||||
span=215+i;
|
||||
SetHighColor(128+(i*2),128+(i*2),128+(i*2));
|
||||
serverlink->SetOpCode(GFX_STROKE_ARC);
|
||||
serverlink->Attach(¢erx,sizeof(float));
|
||||
serverlink->Attach(¢ery,sizeof(float));
|
||||
serverlink->Attach(&radx,sizeof(float));
|
||||
serverlink->Attach(&rady,sizeof(float));
|
||||
serverlink->Attach(&angle,sizeof(float));
|
||||
serverlink->Attach(&span,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
void TestApp::TestBeziers(void)
|
||||
{
|
||||
BPoint p1(500,300),
|
||||
p2(350,450),
|
||||
p3(350,300),
|
||||
p4(500,450);
|
||||
|
||||
// Stroke Bezier
|
||||
SetHighColor(0,255,0);
|
||||
serverlink->SetOpCode(GFX_STROKE_BEZIER);
|
||||
serverlink->Attach(&p1,sizeof(BPoint));
|
||||
serverlink->Attach(&p2,sizeof(BPoint));
|
||||
serverlink->Attach(&p3,sizeof(BPoint));
|
||||
serverlink->Attach(&p4,sizeof(BPoint));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Fill Bezier
|
||||
p1.Set(250,250);
|
||||
p2.Set(300,300);
|
||||
p3.Set(300,250);
|
||||
p4.Set(300,250);
|
||||
SetHighColor(255,0,0);
|
||||
serverlink->SetOpCode(GFX_FILL_BEZIER);
|
||||
serverlink->Attach(&p1,sizeof(BPoint));
|
||||
serverlink->Attach(&p2,sizeof(BPoint));
|
||||
serverlink->Attach(&p3,sizeof(BPoint));
|
||||
serverlink->Attach(&p4,sizeof(BPoint));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
}
|
||||
|
||||
void TestApp::TestEllipses(void)
|
||||
{
|
||||
float centerx=200, centery=200,
|
||||
radx=10, rady=5;
|
||||
|
||||
// Fill Ellipse
|
||||
SetHighColor(0,0,0);
|
||||
serverlink->SetOpCode(GFX_FILL_ELLIPSE);
|
||||
serverlink->Attach(¢erx,sizeof(float));
|
||||
serverlink->Attach(¢ery,sizeof(float));
|
||||
serverlink->Attach(&radx,sizeof(float));
|
||||
serverlink->Attach(&rady,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Stroke Ellipse
|
||||
for(int i=5; i<255; i+=10)
|
||||
{
|
||||
SetHighColor(i,i,i);
|
||||
radx=10+i;
|
||||
rady=5+i;
|
||||
serverlink->SetOpCode(GFX_STROKE_ELLIPSE);
|
||||
serverlink->Attach(¢erx,sizeof(float));
|
||||
serverlink->Attach(¢ery,sizeof(float));
|
||||
serverlink->Attach(&radx,sizeof(float));
|
||||
serverlink->Attach(&rady,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
void TestApp::TestFonts(void)
|
||||
{
|
||||
|
||||
// Can't test SetFont() -- we don't have an active BApplication. :(
|
||||
|
||||
// Draw String
|
||||
BString string("OpenBeOS: The Future is Drawing Near...");
|
||||
uint16 length=string.Length();
|
||||
|
||||
// this will be set to a negative value in the case of not being passed
|
||||
// a BPoint
|
||||
BPoint pt(10,175);
|
||||
|
||||
SetHighColor(0,0,0);
|
||||
serverlink->SetOpCode(GFX_DRAW_STRING);
|
||||
|
||||
// String passing protocol for PortLink/AppServer combination:
|
||||
// uint16 length of string precedes each string
|
||||
serverlink->Attach(&length,sizeof(uint16));
|
||||
serverlink->Attach((char *)string.String(),string.Length());
|
||||
serverlink->Attach(&pt,sizeof(BPoint));
|
||||
|
||||
// for now, passing escapements is disabled, so none are attached
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::TestLines(void)
|
||||
{
|
||||
// Protocol for the usual line method (BPoint,BPoint) will simply
|
||||
// result in a MovePenTo call followed by a StrokeLine(BPoint) call
|
||||
|
||||
BPoint pt(100,100);
|
||||
float x=50,y=50,size=1;
|
||||
|
||||
// MovePenTo()
|
||||
serverlink->SetOpCode(GFX_MOVEPENTO);
|
||||
serverlink->Attach(&pt,sizeof(BPoint));
|
||||
serverlink->Flush();
|
||||
|
||||
// StrokeLine(BPoint)
|
||||
pt.Set(10,10);
|
||||
SetHighColor(255,0,255);
|
||||
serverlink->SetOpCode(GFX_STROKE_LINE);
|
||||
serverlink->Attach(&pt,sizeof(BPoint));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// MovePenBy()
|
||||
pt.Set(100,0);
|
||||
serverlink->SetOpCode(GFX_MOVEPENBY);
|
||||
serverlink->Attach(&x,sizeof(float));
|
||||
serverlink->Attach(&y,sizeof(float));
|
||||
serverlink->Flush();
|
||||
|
||||
// Eventually, this will become a LineArray test...
|
||||
for(int i=0;i<256;i++)
|
||||
{
|
||||
// SetPenSize()
|
||||
size=i/10;
|
||||
serverlink->SetOpCode(GFX_SETPENSIZE);
|
||||
serverlink->Attach(&size,sizeof(float));
|
||||
serverlink->Flush();
|
||||
|
||||
// StrokeLine(BPoint)
|
||||
pt.Set(10,10+i);
|
||||
SetHighColor(255,i,255);
|
||||
serverlink->SetOpCode(GFX_STROKE_LINE);
|
||||
serverlink->Attach(&pt,sizeof(BPoint));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
}
|
||||
// SetPenSize()
|
||||
size=1;
|
||||
serverlink->SetOpCode(GFX_SETPENSIZE);
|
||||
serverlink->Attach(&size,sizeof(float));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::TestPolygon(void)
|
||||
{
|
||||
// This one's going to REALLY be a pain. Can't be flattened like a BShape.
|
||||
// Can't access any of its data like BRegion. I guess it'll have to wait until
|
||||
// I've implemented the BView class. I'm starting to get a headache....
|
||||
}
|
||||
|
||||
void TestApp::TestRects(void)
|
||||
{
|
||||
BRect rect(10,270,75,335);
|
||||
float xrad=10,yrad=30;
|
||||
|
||||
SetHighColor(255,0,0);
|
||||
|
||||
// Stroke Rect
|
||||
serverlink->SetOpCode(GFX_STROKE_RECT);
|
||||
serverlink->Attach(&rect,sizeof(BRect));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Fill Rect
|
||||
rect.OffsetBy(100,10);
|
||||
serverlink->SetOpCode(GFX_FILL_RECT);
|
||||
serverlink->Attach(&rect,sizeof(BRect));
|
||||
serverlink->Attach((pattern *)&B_SOLID_LOW, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Stroke Round Rect
|
||||
rect.OffsetBy(100,10);
|
||||
|
||||
SetHighColor(0,255,0);
|
||||
serverlink->SetOpCode(GFX_STROKE_ROUNDRECT);
|
||||
serverlink->Attach(&rect,sizeof(BRect));
|
||||
serverlink->Attach(&xrad,sizeof(float));
|
||||
serverlink->Attach(&yrad,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
// Fill Round Rect
|
||||
rect.OffsetBy(100,10);
|
||||
SetHighColor(0,255,255);
|
||||
serverlink->SetOpCode(GFX_FILL_ROUNDRECT);
|
||||
serverlink->Attach(&rect,sizeof(BRect));
|
||||
serverlink->Attach(&xrad,sizeof(float));
|
||||
serverlink->Attach(&yrad,sizeof(float));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
}
|
||||
|
||||
void TestApp::TestRegions(void)
|
||||
{
|
||||
/*
|
||||
Because of the varying size of BRegions, this will be a bit sticky. Size does
|
||||
not change with added rectangles because the internally, it uses a BList. We
|
||||
also must contend with the fact that they very well may not fit into the
|
||||
port's buffer, which could have very nasty results.
|
||||
|
||||
Possible Solutions:
|
||||
1) Flatten it like a PortLink flattens data and pass the flattened region to
|
||||
the server via an area. We' can simply clone it and pass the second
|
||||
area_id to the server.
|
||||
2) Attach it to a BMessage and fire it off.
|
||||
3) Create an API which operates something like BeginRectArray()
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void TestApp::TestShape(void)
|
||||
{
|
||||
// BShapes are derived from BArchivable, so we'll flatten it, and fire it to
|
||||
// the server via a BMessage. Thus, this will need to be done later...
|
||||
}
|
||||
|
||||
void TestApp::TestTriangle(void)
|
||||
{
|
||||
// In either form of the function, we have to calculate the invaliated
|
||||
// rect which contains the triangle unless the caller gives us one. Thus,
|
||||
// the functions will always send a BRect to the server.
|
||||
|
||||
BRect invalid;
|
||||
|
||||
BPoint pt1(600,100), pt2(500,200), pt3(550,450);
|
||||
|
||||
invalid.Set( MIN( MIN(pt1.x,pt2.x), pt3.x),
|
||||
MIN( MIN(pt1.y,pt2.y), pt3.y),
|
||||
MAX( MAX(pt1.x,pt2.x), pt3.x),
|
||||
MAX( MAX(pt1.y,pt2.y), pt3.y) );
|
||||
|
||||
// Fill Triangle
|
||||
SetHighColor(228,228,50);
|
||||
serverlink->SetOpCode(GFX_FILL_TRIANGLE);
|
||||
serverlink->Attach(&pt1,sizeof(BPoint));
|
||||
serverlink->Attach(&pt2,sizeof(BPoint));
|
||||
serverlink->Attach(&pt3,sizeof(BPoint));
|
||||
serverlink->Attach(&invalid,sizeof(BRect));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
|
||||
|
||||
pt1.Set(50,50);
|
||||
pt2.Set(200,475);
|
||||
pt3.Set(400,400);
|
||||
invalid.Set( MIN( MIN(pt1.x,pt2.x), pt3.x),
|
||||
MIN( MIN(pt1.y,pt2.y), pt3.y),
|
||||
MAX( MAX(pt1.x,pt2.x), pt3.x),
|
||||
MAX( MAX(pt1.y,pt2.y), pt3.y) );
|
||||
// Stroke Triangle
|
||||
SetHighColor(0,128,128);
|
||||
serverlink->SetOpCode(GFX_STROKE_TRIANGLE);
|
||||
serverlink->Attach(&pt1,sizeof(BPoint));
|
||||
serverlink->Attach(&pt2,sizeof(BPoint));
|
||||
serverlink->Attach(&pt3,sizeof(BPoint));
|
||||
serverlink->Attach(&invalid,sizeof(BRect));
|
||||
serverlink->Attach((pattern *)&B_SOLID_HIGH, sizeof(pattern));
|
||||
serverlink->Flush();
|
||||
}
|
||||
|
||||
void TestApp::TestCursors(void)
|
||||
{
|
||||
uint8 cross[] = {16,1,5,5,
|
||||
14,0,4,0,4,0,4,0,128,32,241,224,128,32,4,0,
|
||||
4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0,
|
||||
14,0,4,0,4,0,4,0,128,32,245,224,128,32,4,0,
|
||||
4,0,4,0,14,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
SetCursor(cross);
|
||||
HideCursor();
|
||||
ShowCursor();
|
||||
ObscureCursor();
|
||||
}
|
||||
|
||||
bool TestApp::Run(void)
|
||||
{
|
||||
// printf("TestApp::Run()\n");
|
||||
if(!initialized)
|
||||
return false;
|
||||
|
||||
MainLoop();
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
TestApp app;
|
||||
app.Run();
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
#ifndef _OBOS_APPLICATION_H_
|
||||
#define _OBOS_APPLICATION_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <Bitmap.h>
|
||||
|
||||
class PortLink;
|
||||
|
||||
class TestApp
|
||||
{
|
||||
public:
|
||||
TestApp(void);
|
||||
virtual ~TestApp(void);
|
||||
|
||||
// Replaces BLooper message looping
|
||||
void MainLoop(void);
|
||||
|
||||
// Hmm... What do these do? ;^)
|
||||
void DispatchMessage(int32 code, int8 *buffer);
|
||||
virtual void DispatchMessage(BMessage *msg, BHandler *handler);
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual void ReadyToRun(void);
|
||||
bool Run(void);
|
||||
void ShowCursor(void);
|
||||
void HideCursor(void);
|
||||
void ObscureCursor(void);
|
||||
bool IsCursorHidden(void);
|
||||
void SetCursor(const void *cursor);
|
||||
void SetCursor(const BCursor *cursor, bool sync=true);
|
||||
void SetCursor(BBitmap *bmp);
|
||||
|
||||
port_id messageport, serverport;
|
||||
char *signature;
|
||||
bool initialized;
|
||||
PortLink *serverlink;
|
||||
|
||||
static int32 TestGraphics(void *data);
|
||||
|
||||
// Testing functions:
|
||||
void SetLowColor(uint8 r, uint8 g, uint8 b);
|
||||
void SetHighColor(uint8 r, uint8 g, uint8 b);
|
||||
|
||||
void TestScreenStates(void);
|
||||
void TestArcs(void);
|
||||
void TestBeziers(void);
|
||||
void TestEllipses(void);
|
||||
void TestFonts(void);
|
||||
void TestLines(void);
|
||||
void TestPolygon(void);
|
||||
void TestRects(void);
|
||||
void TestRegions(void);
|
||||
void TestShape(void);
|
||||
void TestTriangle(void);
|
||||
void TestCursors(void);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,438 +0,0 @@
|
||||
/*
|
||||
PortLink.cpp:
|
||||
A helper class for port-based messaging
|
||||
|
||||
------------------------------------------------------------------------
|
||||
How it works:
|
||||
The class utilizes a fixed-size array of PortLinkData object pointers. When
|
||||
data is attached, a new PortLinkData object is allocated and a copy of the
|
||||
passed data is created inside it. When the time comes for the message to be sent,
|
||||
the data is pieced together into a flattened array and written to the port.
|
||||
------------------------------------------------------------------------
|
||||
Data members:
|
||||
|
||||
*attachments[] - fixed-size array of pointers used to hold the attached data
|
||||
opcode - message value which is sent along with any data
|
||||
target - port to which the message is sent when Flush() is called
|
||||
replyport - port used with synchronous messaging - FlushWithReply()
|
||||
bufferlength - total bytes taken up by attachments
|
||||
num_attachments - internal variable which is used to track which "slot"
|
||||
will be the next one to receive an attachment object
|
||||
*/
|
||||
|
||||
#include "PortLink.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
//#define PLDEBUG
|
||||
|
||||
// Internal data storage class for holding attached data whilst it is waiting
|
||||
// to be Flattened() and then Flushed(). There is no need for this to be called outside
|
||||
// the PortLink class.
|
||||
class PortLinkData
|
||||
{
|
||||
public:
|
||||
PortLinkData(void);
|
||||
~PortLinkData(void);
|
||||
bool Set(void *data, size_t size);
|
||||
char *buffer;
|
||||
size_t buffersize;
|
||||
};
|
||||
|
||||
PortLink::PortLink(port_id port)
|
||||
{
|
||||
// For this class to be useful (and to prevent a lot of init problems)
|
||||
// we require a port in the constructor
|
||||
target=port;
|
||||
|
||||
// We start out without any data attached to the port message
|
||||
num_attachments=0;
|
||||
opcode=0;
|
||||
bufferlength=0;
|
||||
replyport=create_port(30,"PortLink reply port");
|
||||
}
|
||||
|
||||
PortLink::~PortLink(void)
|
||||
{
|
||||
// If, for some odd reason, this is deleted with something attached,
|
||||
// free the memory used by the attachments. We do not flush the queue
|
||||
// because the port may no longer be valid in cases such as the app
|
||||
// is in the process of quitting
|
||||
MakeEmpty();
|
||||
}
|
||||
|
||||
void PortLink::SetOpCode(int32 code)
|
||||
{
|
||||
// Sets the message code. This does not change once the message is sent.
|
||||
// Another call to SetOpCode() is required for such things.
|
||||
opcode=code;
|
||||
}
|
||||
|
||||
void PortLink::SetPort(port_id port)
|
||||
{
|
||||
// Sets the target port. While not necessary in most uses, this exists
|
||||
// mostly to prevent flexibility problems
|
||||
target=port;
|
||||
}
|
||||
|
||||
port_id PortLink::GetPort(void)
|
||||
{
|
||||
// Simply returns the port at which the object is pointed.
|
||||
return target;
|
||||
}
|
||||
|
||||
void PortLink::Flush(bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message off to the target, complete with attachments. NOTE:
|
||||
// the recipient must delete all attachments, being the PortLink object assumes
|
||||
// no responsiblity for the attachments once the message is sent.
|
||||
int8 *msgbuffer;
|
||||
int32 size;
|
||||
|
||||
if(num_attachments>0)
|
||||
{
|
||||
FlattenData(&msgbuffer,&size);
|
||||
|
||||
// Dump message to port, reset attachments, and clean up
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,msgbuffer,size,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,msgbuffer,size);
|
||||
MakeEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(timeout!=B_INFINITE_TIMEOUT)
|
||||
write_port_etc(target,opcode,NULL,0,B_TIMEOUT, timeout);
|
||||
else
|
||||
write_port(target,opcode,NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
int8* PortLink::FlushWithReply(int32 *code, status_t *status, ssize_t *buffersize, bigtime_t timeout=B_INFINITE_TIMEOUT)
|
||||
{
|
||||
// Fires a message to the target and then waits for a reply. The target will
|
||||
// receive a message with the first item being the port_id to reply to.
|
||||
// NOTE: like Flush(), any attached data must be deleted.
|
||||
|
||||
// Effectively, an Attach() call inlined for changes
|
||||
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
{
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&replyport,sizeof(port_id)))
|
||||
{
|
||||
bufferlength+=sizeof(port_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
*status=B_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Flatten() inlined to make some necessary changes
|
||||
int8 *buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=buffer;
|
||||
size_t size=0;
|
||||
|
||||
// attach our port_id first
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
|
||||
// attach everything else
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
size+=pld->buffersize;
|
||||
}
|
||||
|
||||
// Flush the thing....FOOSH! :P
|
||||
write_port(target,opcode,buffer,size);
|
||||
MakeEmpty();
|
||||
delete buffer;
|
||||
|
||||
// Now we wait for the reply
|
||||
if(timeout==B_INFINITE_TIMEOUT)
|
||||
{
|
||||
*buffersize=port_buffer_size(replyport);
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buffersize=port_buffer_size_etc(replyport,0,timeout);
|
||||
if(*buffersize==B_TIMED_OUT)
|
||||
{
|
||||
*status=*buffersize;
|
||||
return NULL;
|
||||
}
|
||||
if(*buffersize>0)
|
||||
buffer=(int8*)new int8[*buffersize];
|
||||
read_port(replyport,code, buffer, *buffersize);
|
||||
}
|
||||
|
||||
// We got this far, so we apparently have some data
|
||||
*status=B_OK;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void PortLink::Attach(void *data, size_t size)
|
||||
{
|
||||
// This is the member called to attach data to a message. Attachments are
|
||||
// treated to be in 'Append' mode, tacking on each attached piece of data
|
||||
// to the end of the list.
|
||||
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
if(size==0)
|
||||
return;
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
// These functions were added for a major convenience in passing common types
|
||||
// Eventually, I'd like to templatize these, but for now, this'll do
|
||||
|
||||
void PortLink::Attach(int32 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int32);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int16 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int16);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(int8 data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(int8);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(float data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(float);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(bool data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(bool);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BRect data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BRect);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::Attach(BPoint data)
|
||||
{
|
||||
// Prevent parameter problems
|
||||
if(num_attachments>=_PORTLINK_MAX_ATTACHMENTS)
|
||||
return;
|
||||
|
||||
int32 size=sizeof(BPoint);
|
||||
|
||||
// create a new storage object and stash the data
|
||||
PortLinkData *pld=new PortLinkData;
|
||||
if(pld->Set(&data,size))
|
||||
{
|
||||
num_attachments++;
|
||||
attachments[num_attachments-1]=pld;
|
||||
bufferlength+=size;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pld;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::FlattenData(int8 **buffer,int32 *size)
|
||||
{
|
||||
// This function is where all the magic happens, but it is strictly internal.
|
||||
// It iterates through each PortLinkData object and copies it to the main buffer
|
||||
// which ends up, ultimately, being written to the PortLink's target port.
|
||||
|
||||
// skip if there aree no attachments
|
||||
if(bufferlength<1)
|
||||
return;
|
||||
|
||||
*buffer=new int8[bufferlength];
|
||||
int8 *bufferindex=*buffer;
|
||||
PortLinkData *pld;
|
||||
*size=0;
|
||||
|
||||
for(int i=0;i<num_attachments;i++)
|
||||
{
|
||||
pld=attachments[i];
|
||||
memcpy(bufferindex, pld->buffer, pld->buffersize);
|
||||
bufferindex += pld->buffersize;
|
||||
*size+=pld->buffersize;
|
||||
}
|
||||
}
|
||||
|
||||
void PortLink::MakeEmpty(void)
|
||||
{
|
||||
// Nukes all the attachments currently held by the PortLink class
|
||||
if(num_attachments!=0)
|
||||
{
|
||||
for(int i=0; i<num_attachments; i++)
|
||||
{
|
||||
delete attachments[i];
|
||||
}
|
||||
}
|
||||
num_attachments=0;
|
||||
bufferlength=0;
|
||||
}
|
||||
|
||||
PortLinkData::PortLinkData(void)
|
||||
{
|
||||
// Initialize object to empty
|
||||
buffersize=0;
|
||||
}
|
||||
|
||||
PortLinkData::~PortLinkData(void)
|
||||
{
|
||||
// Frees the buffer if we actually used the class to store data
|
||||
if(buffersize>0)
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
bool PortLinkData::Set(void *data, size_t size)
|
||||
{
|
||||
// Function copies the passed to the internal buffers for storage
|
||||
if(size>0 && buffersize==0 && data!=NULL)
|
||||
{
|
||||
buffer=(char *)malloc(size);
|
||||
if(buffer==NULL)
|
||||
return false;
|
||||
memcpy(buffer, data, size);
|
||||
buffersize=size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user