LaunchAPPLServer: Carbon version (no backend yet)

This commit is contained in:
Wolfgang Thaller 2018-05-14 23:58:11 +02:00
parent dbfa7e8645
commit bf9cba16b8
7 changed files with 141 additions and 51 deletions

View File

@ -1,10 +1,7 @@
add_subdirectory(Common) add_subdirectory(Common)
if(CMAKE_SYSTEM_NAME MATCHES Retro.*) if(CMAKE_SYSTEM_NAME MATCHES Retro.*)
if(CMAKE_SYSTEM_NAME MATCHES RetroCarbon)
else()
add_subdirectory(Server) add_subdirectory(Server)
endif()
else() else()
add_subdirectory(Client) add_subdirectory(Client)
endif() endif()

View File

@ -1,33 +1,44 @@
add_application(LaunchAPPLServer set(CONNECTION_SOURCES)
TYPE "APPL"
CREATOR "R68L"
if(CMAKE_SYSTEM_NAME MATCHES RetroCarbon)
LaunchAPPLServer.r else()
LauncherIcon.r list(APPEND CONNECTION_SOURCES
LaunchAPPLServer.cc
MacSerialStream.h
MacSerialStream.cc
AppLauncher.h
AppLauncher.cc
ToolLauncher.cc
StatusDisplay.h
StatusDisplay.cc
ConnectionProvider.h
SerialConnectionProvider.h SerialConnectionProvider.h
SerialConnectionProvider.cc SerialConnectionProvider.cc
MacSerialStream.h
MacSerialStream.cc
MacTCPStream.h MacTCPStream.h
MacTCPStream.cc MacTCPStream.cc
TCPConnectionProvider.h TCPConnectionProvider.h
TCPConnectionProvider.cc TCPConnectionProvider.cc
) )
endif()
add_application(LaunchAPPLServer
TYPE "APPL"
CREATOR "R68L"
LaunchAPPLServer.r
LauncherIcon.r
LaunchAPPLServer.cc
AppLauncher.h
AppLauncher.cc
ToolLauncher.cc
StatusDisplay.h
StatusDisplay.cc
ConnectionProvider.h
CarbonFileCompat.h
${CONNECTION_SOURCES}
)
target_link_libraries(LaunchAPPLServer LaunchAPPLCommon) target_link_libraries(LaunchAPPLServer LaunchAPPLCommon)
set_target_properties(LaunchAPPLServer PROPERTIES set_target_properties(LaunchAPPLServer PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17
) )
target_compile_options(LaunchAPPLServer PRIVATE -ffunction-sections -fno-exceptions -Os) target_compile_options(LaunchAPPLServer PRIVATE -ffunction-sections -Os) # -fno-exceptions
if(CMAKE_SYSTEM_NAME MATCHES Retro68) if(CMAKE_SYSTEM_NAME MATCHES Retro68)
set_target_properties(LaunchAPPLServer PROPERTIES set_target_properties(LaunchAPPLServer PROPERTIES
LINK_FLAGS "-Wl,-gc-sections -Wl,--mac-segments -Wl,${CMAKE_CURRENT_SOURCE_DIR}/LaunchAPPLServer.segmap" LINK_FLAGS "-Wl,-gc-sections -Wl,--mac-segments -Wl,${CMAKE_CURRENT_SOURCE_DIR}/LaunchAPPLServer.segmap"

View File

@ -0,0 +1,30 @@
#pragma once
#include <Files.h>
#if TARGET_API_MAC_CARBON
inline OSErr Create(ConstStr255Param fileName, short vRefNum, OSType creator, OSType fileType)
{
return HCreate(vRefNum, 0, fileName, creator, fileType);
}
inline OSErr OpenDF(ConstStr255Param fileName, short vRefNum, short *refNum)
{
return HOpenDF(vRefNum, 0, fileName, fsCurPerm, refNum);
}
inline OSErr OpenRF(ConstStr255Param fileName, short vRefNum, short *refNum)
{
return HOpenRF(vRefNum, 0, fileName, fsCurPerm, refNum);
}
inline OSErr FSDelete(ConstStr255Param fileName, short vRefNum)
{
return HDelete(vRefNum, 0, fileName);
}
inline OSErr Rename(ConstStr255Param oldName, short vRefNum, ConstStr255Param newName)
{
return HRename(vRefNum, 0, oldName, newName);
}
#endif

View File

@ -40,8 +40,13 @@
#include <memory> #include <memory>
#include "ConnectionProvider.h" #include "ConnectionProvider.h"
#if !TARGET_API_MAC_CARBON
#include "SerialConnectionProvider.h" #include "SerialConnectionProvider.h"
#include "TCPConnectionProvider.h" #include "TCPConnectionProvider.h"
#endif
#include "CarbonFileCompat.h"
#include <Stream.h> #include <Stream.h>
enum enum
@ -65,7 +70,12 @@ enum class Port : int
printerPort, printerPort,
macTCP macTCP
}; };
#if TARGET_API_MAC_CARBON
bool portsAvailable[] = { false, false, false };
#else
bool portsAvailable[] = { true, true, false }; bool portsAvailable[] = { true, true, false };
#endif
struct Prefs struct Prefs
{ {
@ -111,12 +121,19 @@ void ConnectionChanged();
void ShowAboutBox() void ShowAboutBox()
{ {
WindowRef w = GetNewWindow(128, NULL, (WindowPtr) -1); WindowRef w = GetNewWindow(128, NULL, (WindowPtr) -1);
#if !TARGET_API_MAC_CARBON #if TARGET_API_MAC_CARBON
MacMoveWindow(w, Rect screenBounds = (*GetMainDevice())->gdRect;
qd.screenBits.bounds.right/2 - w->portRect.right/2, Rect portBounds;
qd.screenBits.bounds.bottom/2 - w->portRect.bottom/2, GetWindowPortBounds(w,&portBounds);
false); #else
const Rect& screenBounds = qd.screenBits.bounds;
const Rect& portBounds = w->portRect;
#endif #endif
MacMoveWindow(w,
screenBounds.right/2 - portBounds.right/2,
screenBounds.bottom/2 - portBounds.bottom/2,
false);
ShowWindow(w); ShowWindow(w);
#if TARGET_API_MAC_CARBON #if TARGET_API_MAC_CARBON
SetPortWindowPort(w); SetPortWindowPort(w);
@ -126,12 +143,8 @@ void ShowAboutBox()
Handle h = GetResource('TEXT', 128); Handle h = GetResource('TEXT', 128);
HLock(h); HLock(h);
#if TARGET_API_MAC_CARBON Rect r = portBounds;
Rect r;
GetWindowPortBounds(w,&r);
#else
Rect r = w->portRect;
#endif
InsetRect(&r, 10,10); InsetRect(&r, 10,10);
TETextBox(*h, GetHandleSize(h), &r, teJustLeft); TETextBox(*h, GetHandleSize(h), &r, teJustLeft);
@ -161,7 +174,7 @@ void SetItemEnabled(MenuHandle m, short item, bool enabled)
void UpdateMenus() void UpdateMenus()
{ {
MenuRef m = GetMenu(kMenuFile); MenuRef m = GetMenuHandle(kMenuFile);
WindowRef w = FrontWindow(); WindowRef w = FrontWindow();
#if TARGET_API_MAC_CARBON #if TARGET_API_MAC_CARBON
@ -169,7 +182,7 @@ void UpdateMenus()
#define DisableItem DisableMenuItem #define DisableItem DisableMenuItem
#endif #endif
m = GetMenu(kMenuEdit); m = GetMenuHandle(kMenuEdit);
bool enableEditMenu = (w && GetWindowKind(w) < 0); bool enableEditMenu = (w && GetWindowKind(w) < 0);
// Desk accessory in front: Enable edit menu items // Desk accessory in front: Enable edit menu items
@ -178,7 +191,7 @@ void UpdateMenus()
for(short i : {1,3,4,5,6}) for(short i : {1,3,4,5,6})
SetItemEnabled(m,i,enableEditMenu); SetItemEnabled(m,i,enableEditMenu);
m = GetMenu(kMenuConnection); m = GetMenuHandle(kMenuConnection);
SetItemEnabled(m, 1, portsAvailable[(int)Port::macTCP]); SetItemEnabled(m, 1, portsAvailable[(int)Port::macTCP]);
CheckMenuItem(m, 1, gPrefs.port == Port::macTCP); CheckMenuItem(m, 1, gPrefs.port == Port::macTCP);
SetItemEnabled(m, 2, portsAvailable[(int)Port::modemPort]); SetItemEnabled(m, 2, portsAvailable[(int)Port::modemPort]);
@ -245,7 +258,7 @@ void DoMenuCommand(long menuCommand)
gPrefs.port = Port::printerPort; gPrefs.port = Port::printerPort;
break; break;
default: default:
GetMenuItemText(GetMenu(menuID), menuItem, str); GetMenuItemText(GetMenuHandle(menuID), menuItem, str);
StringToNum(str, &gPrefs.baud); StringToNum(str, &gPrefs.baud);
} }
ConnectionChanged(); ConnectionChanged();
@ -374,6 +387,7 @@ public:
void idle() void idle()
{ {
++nullEventCounter; ++nullEventCounter;
if(connection)
connection->idle(); connection->idle();
if(state == State::launch) if(state == State::launch)
@ -486,6 +500,7 @@ void ConnectionChanged()
{ {
switch(gPrefs.port) switch(gPrefs.port)
{ {
#if !TARGET_API_MAC_CARBON
case Port::macTCP: case Port::macTCP:
connection = std::make_unique<TCPConnectionProvider>(statusDisplay.get());; connection = std::make_unique<TCPConnectionProvider>(statusDisplay.get());;
break; break;
@ -495,11 +510,15 @@ void ConnectionChanged()
case Port::printerPort: case Port::printerPort:
connection = std::make_unique<SerialConnectionProvider>(0, gPrefs.baud, statusDisplay.get()); connection = std::make_unique<SerialConnectionProvider>(0, gPrefs.baud, statusDisplay.get());
break; break;
#endif
} }
if(connection)
{
connection->setListener(&server); connection->setListener(&server);
server.onReset(); server.onReset();
} }
}
pascal OSErr aeRun (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) pascal OSErr aeRun (const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon)
{ {
@ -521,12 +540,13 @@ pascal OSErr aeQuit (const AppleEvent *theAppleEvent, AppleEvent *reply, long ha
int main() int main()
{ {
#if !TARGET_API_MAC_CARBON
// default stack size is 8KB on B&W macs // default stack size is 8KB on B&W macs
// and 24 KB on Color macs. // and 24 KB on Color macs.
// 8KB is too little as soon as we allocate a buffer on the stack. // 8KB is too little as soon as we allocate a buffer on the stack.
// To allow that, increae stack size: SetApplLimit(GetApplLimit() - 8192); // To allow that, increae stack size: SetApplLimit(GetApplLimit() - 8192);
MaxApplZone(); MaxApplZone();
#if !TARGET_API_MAC_CARBON
InitGraf(&qd.thePort); InitGraf(&qd.thePort);
InitFonts(); InitFonts();
InitWindows(); InitWindows();
@ -566,6 +586,8 @@ int main()
const Boolean hasGestalt = true; const Boolean hasGestalt = true;
const Boolean hasAppleEvents = true; const Boolean hasAppleEvents = true;
#endif #endif
#if !TARGET_API_MAC_CARBON
if(hasGestalt) if(hasGestalt)
{ {
long resp; long resp;
@ -579,7 +601,7 @@ int main()
(resp & ((1 << gestaltHidePortB) | (1<< gestaltPortBDisabled))) == 0; (resp & ((1 << gestaltHidePortB) | (1<< gestaltPortBDisabled))) == 0;
} }
} }
#endif
SetMenuBar(GetNewMBar(128)); SetMenuBar(GetNewMBar(128));
AppendResMenu(GetMenu(128), 'DRVR'); AppendResMenu(GetMenu(128), 'DRVR');
@ -643,7 +665,11 @@ int main()
DisposeWindow(win); DisposeWindow(win);
break; break;
case inDrag: case inDrag:
#if !TARGET_API_MAC_CARBON
DragWindow(win, e.where, &qd.screenBits.bounds); DragWindow(win, e.where, &qd.screenBits.bounds);
#else
DragWindow(win, e.where, nullptr);
#endif
break; break;
case inMenuBar: case inMenuBar:
UpdateMenus(); UpdateMenus();

View File

@ -140,7 +140,7 @@ resource 'SIZE' (-1) {
notDisplayManagerAware, notDisplayManagerAware,
reserved, reserved,
reserved, reserved,
150 * 1024, 350 * 1024,
136 * 1024 136 * 1024
}; };

View File

@ -22,7 +22,12 @@ StatusDisplay::StatusDisplay()
{ {
statusWindow = GetNewWindow(129, NULL, (WindowPtr) -1); statusWindow = GetNewWindow(129, NULL, (WindowPtr) -1);
#if TARGET_API_MAC_CARBON
Rect bounds;
GetWindowPortBounds(statusWindow, &bounds);
#else
Rect bounds = statusWindow->portRect; Rect bounds = statusWindow->portRect;
#endif
SetRect(&statusRect, 10, 0, bounds.right-10, 30); SetRect(&statusRect, 10, 0, bounds.right-10, 30);
SetRect(&progressRect, 10, 30, bounds.right-10, 46); SetRect(&progressRect, 10, 30, bounds.right-10, 46);
@ -30,7 +35,11 @@ StatusDisplay::StatusDisplay()
memset(columnWidths, 0, sizeof(columnWidths)); memset(columnWidths, 0, sizeof(columnWidths));
columnWidths[1] = columnWidths[4] = 50; columnWidths[1] = columnWidths[4] = 50;
#if TARGET_API_MAC_CARBON
SetPortWindowPort(statusWindow);
#else
SetPort(statusWindow); SetPort(statusWindow);
#endif
TextSize(9); TextSize(9);
TextFace(bold); TextFace(bold);
for(int i = 0; i < 2 * nValues; i++) for(int i = 0; i < 2 * nValues; i++)
@ -77,6 +86,16 @@ StatusDisplay::~StatusDisplay()
DisposeRgn(background); DisposeRgn(background);
} }
void StatusDisplay::Inval(const Rect& r)
{
#if TARGET_API_MAC_CARBON
InvalWindowRect(statusWindow, &r);
#else
SetPort(statusWindow);
InvalRect(&r);
#endif
}
void StatusDisplay::DrawValue(Stat stat, ConstStr255Param str) void StatusDisplay::DrawValue(Stat stat, ConstStr255Param str)
{ {
Rect& r = valueRects[(short)stat]; Rect& r = valueRects[(short)stat];
@ -120,10 +139,20 @@ void StatusDisplay::Update()
SetRect(&r, progressRect.left+1, progressRect.top+1, SetRect(&r, progressRect.left+1, progressRect.top+1,
progressRect.left+1 + (progressRect.right-progressRect.left-2) * progressDone / progressTotal, progressRect.left+1 + (progressRect.right-progressRect.left-2) * progressDone / progressTotal,
progressRect.bottom-1); progressRect.bottom-1);
FillRect(&r, &qd.dkGray);
#if TARGET_API_MAC_CARBON
Pattern fg, bg;
GetQDGlobalsDarkGray(&fg);
GetQDGlobalsLightGray(&bg);
#else
const Pattern& fg = qd.dkGray;
const Pattern& bg = qd.ltGray;
#endif
FillRect(&r, &fg);
r.left = r.right; r.left = r.right;
r.right = progressRect.right - 1; r.right = progressRect.right - 1;
FillRect(&r, &qd.ltGray); FillRect(&r, &bg);
} }
else else
EraseRect(&progressRect); EraseRect(&progressRect);
@ -144,7 +173,9 @@ void StatusDisplay::Update()
} }
TextFace(normal); TextFace(normal);
#if !TARGET_API_MAC_CARBON
DrawValue(Stat::heapSize, (ApplicationZone()->bkLim - (Ptr)ApplicationZone()) / 1024); DrawValue(Stat::heapSize, (ApplicationZone()->bkLim - (Ptr)ApplicationZone()) / 1024);
#endif
DrawValue(Stat::freeMem, freeMem); DrawValue(Stat::freeMem, freeMem);
if(progressTotal) if(progressTotal)
{ {
@ -169,8 +200,7 @@ void StatusDisplay::Idle()
if(newFreeMem != freeMem) if(newFreeMem != freeMem)
{ {
freeMem = newFreeMem; freeMem = newFreeMem;
SetPort(statusWindow); Inval(valueRects[(short)Stat::freeMem]);
InvalRect(&valueRects[(short)Stat::freeMem]);
} }
long newTimeRemaining = -1; long newTimeRemaining = -1;
@ -185,8 +215,7 @@ void StatusDisplay::Idle()
if(newSpeed != speed) if(newSpeed != speed)
{ {
speed = newSpeed; speed = newSpeed;
SetPort(statusWindow); Inval(valueRects[(short)Stat::speed]);
InvalRect(&valueRects[(short)Stat::speed]);
} }
} }
} }
@ -194,8 +223,7 @@ void StatusDisplay::Idle()
if(newTimeRemaining != timeRemaining) if(newTimeRemaining != timeRemaining)
{ {
timeRemaining = newTimeRemaining; timeRemaining = newTimeRemaining;
SetPort(statusWindow); Inval(valueRects[(short)Stat::timeRemaining]);
InvalRect(&valueRects[(short)Stat::timeRemaining]);
} }
} }
@ -207,8 +235,7 @@ void StatusDisplay::SetStatus(AppStatus stat)
if(status == AppStatus::downloading || status == AppStatus::upgrading) if(status == AppStatus::downloading || status == AppStatus::upgrading)
startTime = TickCount(); startTime = TickCount();
GetIndString(statusString,128,(short)stat); GetIndString(statusString,128,(short)stat);
SetPort(statusWindow); Inval(statusRect);
InvalRect(&statusRect);
} }
} }
@ -216,11 +243,10 @@ void StatusDisplay::SetProgress(int done, int total)
{ {
if(done != progressDone || total != progressTotal) if(done != progressDone || total != progressTotal)
{ {
SetPort(statusWindow); Inval(progressRect);
InvalRect(&progressRect);
if(total != progressTotal) if(total != progressTotal)
InvalRect(&valueRects[(short)Stat::fileSize]); Inval(valueRects[(short)Stat::fileSize]);
InvalRect(&valueRects[(short)Stat::transferred]); Inval(valueRects[(short)Stat::transferred]);
progressTotal = total; progressTotal = total;
progressDone = done; progressDone = done;
} }
@ -237,7 +263,6 @@ void StatusDisplay::SetErrorCount(int newErrorCount)
if(newErrorCount != errorCount) if(newErrorCount != errorCount)
{ {
errorCount = newErrorCount; errorCount = newErrorCount;
SetPort(statusWindow); Inval(valueRects[(short)Stat::transmissionErrors]);
InvalRect(&valueRects[(short)Stat::transmissionErrors]);
} }
} }

View File

@ -37,6 +37,7 @@ class StatusDisplay
void DrawValue(Stat stat, ConstStr255Param str); void DrawValue(Stat stat, ConstStr255Param str);
void DrawValue(Stat stat, long val); void DrawValue(Stat stat, long val);
void Inval(const Rect& r);
public: public:
StatusDisplay(); StatusDisplay();