mirror of
https://github.com/autc04/Retro68.git
synced 2025-04-11 14:37:50 +00:00
LaunchAPPLServer: OpenTransport backend (TCP for Carbon)
This commit is contained in:
parent
d1a3939015
commit
5ab830d8c3
@ -15,6 +15,16 @@ else()
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES Retro68)
|
||||
else()
|
||||
list(APPEND CONNECTION_SOURCES
|
||||
OpenTptStream.h
|
||||
OpenTptStream.cc
|
||||
OpenTptConnectionProvider.h
|
||||
OpenTptConnectionProvider.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
add_application(LaunchAPPLServer
|
||||
TYPE "APPL"
|
||||
@ -48,3 +58,23 @@ else()
|
||||
LINK_FLAGS "-Wl,-gc-sections"
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES RetroPPC)
|
||||
target_link_libraries(LaunchAPPLServer -lOpenTransportAppPPC -lOpenTransportLib -lOpenTptInternetLib )
|
||||
endif()
|
||||
|
||||
if(FALSE)
|
||||
add_application(tcptest
|
||||
CONSOLE
|
||||
|
||||
|
||||
tcptest.cc
|
||||
)
|
||||
|
||||
target_link_libraries(tcptest LaunchAPPLCommon)
|
||||
set_target_properties(tcptest PROPERTIES
|
||||
CXX_STANDARD 17
|
||||
LINK_FLAGS "-Wl,-gc-sections"
|
||||
)
|
||||
|
||||
endif()
|
||||
|
@ -44,6 +44,10 @@
|
||||
#include "SerialConnectionProvider.h"
|
||||
#include "TCPConnectionProvider.h"
|
||||
#endif
|
||||
#if !TARGET_CPU_68K
|
||||
#include "OpenTptConnectionProvider.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include "CarbonFileCompat.h"
|
||||
|
||||
@ -68,13 +72,14 @@ enum class Port : int
|
||||
{
|
||||
modemPort = 0,
|
||||
printerPort,
|
||||
macTCP
|
||||
macTCP,
|
||||
openTptTCP
|
||||
};
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
bool portsAvailable[] = { false, false, false };
|
||||
bool portsAvailable[] = { false, false, false, false };
|
||||
#else
|
||||
bool portsAvailable[] = { true, true, false };
|
||||
bool portsAvailable[] = { true, true, false, true/*###*/ };
|
||||
#endif
|
||||
|
||||
struct Prefs
|
||||
@ -194,11 +199,13 @@ void UpdateMenus()
|
||||
m = GetMenuHandle(kMenuConnection);
|
||||
SetItemEnabled(m, 1, portsAvailable[(int)Port::macTCP]);
|
||||
CheckMenuItem(m, 1, gPrefs.port == Port::macTCP);
|
||||
SetItemEnabled(m, 2, portsAvailable[(int)Port::modemPort]);
|
||||
CheckMenuItem(m, 2, gPrefs.port == Port::modemPort);
|
||||
SetItemEnabled(m, 3, portsAvailable[(int)Port::printerPort]);
|
||||
CheckMenuItem(m, 3, gPrefs.port == Port::printerPort);
|
||||
for(int i = 4; i <= CountMenuItems(m); i++)
|
||||
SetItemEnabled(m, 2, portsAvailable[(int)Port::openTptTCP]);
|
||||
CheckMenuItem(m, 2, gPrefs.port == Port::openTptTCP);
|
||||
SetItemEnabled(m, 3, portsAvailable[(int)Port::modemPort]);
|
||||
CheckMenuItem(m, 3, gPrefs.port == Port::modemPort);
|
||||
SetItemEnabled(m, 4, portsAvailable[(int)Port::printerPort]);
|
||||
CheckMenuItem(m, 4, gPrefs.port == Port::printerPort);
|
||||
for(int i = 5; i <= CountMenuItems(m); i++)
|
||||
{
|
||||
Str255 str;
|
||||
long baud;
|
||||
@ -252,9 +259,12 @@ void DoMenuCommand(long menuCommand)
|
||||
gPrefs.port = Port::macTCP;
|
||||
break;
|
||||
case 2:
|
||||
gPrefs.port = Port::modemPort;
|
||||
gPrefs.port = Port::openTptTCP;
|
||||
break;
|
||||
case 3:
|
||||
gPrefs.port = Port::modemPort;
|
||||
break;
|
||||
case 4:
|
||||
gPrefs.port = Port::printerPort;
|
||||
break;
|
||||
default:
|
||||
@ -498,6 +508,7 @@ LaunchServer server;
|
||||
|
||||
void ConnectionChanged()
|
||||
{
|
||||
connection.reset(); // deallocate before we create the new provider
|
||||
switch(gPrefs.port)
|
||||
{
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
@ -510,6 +521,11 @@ void ConnectionChanged()
|
||||
case Port::printerPort:
|
||||
connection = std::make_unique<SerialConnectionProvider>(0, gPrefs.baud, statusDisplay.get());
|
||||
break;
|
||||
#endif
|
||||
#if !TARGET_CPU_68K
|
||||
case Port::openTptTCP:
|
||||
connection = std::make_unique<OpenTptConnectionProvider>(statusDisplay.get());;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ resource 'MENU' (131) {
|
||||
"Connection";
|
||||
{
|
||||
"MacTCP", noIcon, noKey, noMark, plain;
|
||||
"OpenTransport TCP", noIcon, noKey, noMark, plain;
|
||||
"Modem Port", noIcon, noKey, noMark, plain;
|
||||
"Printer Port", noIcon, noKey, noMark, plain;
|
||||
"-", noIcon, noKey, noMark, plain;
|
||||
|
39
LaunchAPPL/Server/OpenTptConnectionProvider.cc
Normal file
39
LaunchAPPL/Server/OpenTptConnectionProvider.cc
Normal file
@ -0,0 +1,39 @@
|
||||
#include "OpenTptConnectionProvider.h"
|
||||
#include "OpenTptStream.h"
|
||||
#include <ReliableStream.h>
|
||||
#include "StatusDisplay.h"
|
||||
|
||||
|
||||
OpenTptConnectionProvider::OpenTptConnectionProvider(StatusDisplay *statusDisplay)
|
||||
: statusDisplay(statusDisplay)
|
||||
{
|
||||
stream = std::make_unique<OpenTptStream>();
|
||||
}
|
||||
|
||||
OpenTptConnectionProvider::~OpenTptConnectionProvider()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Stream* OpenTptConnectionProvider::getStream()
|
||||
{
|
||||
return stream.get();
|
||||
}
|
||||
|
||||
void OpenTptConnectionProvider::idle()
|
||||
{
|
||||
if(stream)
|
||||
{
|
||||
stream->setListener(listener);
|
||||
stream->idle();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenTptConnectionProvider::unloadSegDummy()
|
||||
{
|
||||
}
|
||||
|
||||
void *OpenTptConnectionProvider::segmentToUnload()
|
||||
{
|
||||
return nullptr;//(void*) &unloadSegDummy;
|
||||
}
|
24
LaunchAPPL/Server/OpenTptConnectionProvider.h
Normal file
24
LaunchAPPL/Server/OpenTptConnectionProvider.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "ConnectionProvider.h"
|
||||
#include <memory>
|
||||
|
||||
class StatusDisplay;
|
||||
class OpenTptStream;
|
||||
|
||||
class OpenTptConnectionProvider : public ConnectionProvider
|
||||
{
|
||||
StatusDisplay *statusDisplay;
|
||||
|
||||
std::unique_ptr<OpenTptStream> stream;
|
||||
|
||||
static void unloadSegDummy();
|
||||
public:
|
||||
OpenTptConnectionProvider(StatusDisplay *statusDisplay);
|
||||
virtual ~OpenTptConnectionProvider();
|
||||
|
||||
virtual Stream* getStream();
|
||||
|
||||
virtual void idle();
|
||||
|
||||
virtual void* segmentToUnload();
|
||||
};
|
126
LaunchAPPL/Server/OpenTptStream.cc
Normal file
126
LaunchAPPL/Server/OpenTptStream.cc
Normal file
@ -0,0 +1,126 @@
|
||||
#include <ConditionalMacros.h>
|
||||
#if TARGET_API_MAC_CARBON
|
||||
#define OTCARBONAPPLICATION 1
|
||||
#endif
|
||||
|
||||
#include "OpenTptStream.h"
|
||||
|
||||
#include <OpenTransport.h>
|
||||
#include <OpenTransportProviders.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <TextUtils.h>
|
||||
|
||||
OpenTptStream::OpenTptStream()
|
||||
{
|
||||
InitOpenTransport();
|
||||
OSStatus err;
|
||||
|
||||
|
||||
//endpoint = OTOpenEndpoint(OTCreateConfiguration(kTCPName), 0, nullptr, &err);
|
||||
endpoint = OTOpenEndpoint(OTCreateConfiguration(kTCPName), 0, nullptr, &err);
|
||||
|
||||
InetAddress addr, retAddr;
|
||||
OTInitInetAddress(&addr, 1984, 0);
|
||||
|
||||
TBind req, ret;
|
||||
|
||||
req.addr.len = sizeof(addr);
|
||||
req.addr.buf = (UInt8*) &addr;
|
||||
req.qlen = 1;
|
||||
ret.addr.maxlen = sizeof(retAddr);
|
||||
ret.addr.buf = (UInt8*) &retAddr;
|
||||
|
||||
|
||||
endpoint->Bind(&req, &ret);
|
||||
|
||||
endpoint->SetSynchronous();
|
||||
endpoint->SetNonBlocking();
|
||||
tryListening();
|
||||
}
|
||||
|
||||
void OpenTptStream::tryListening()
|
||||
{
|
||||
if(connected)
|
||||
DebugStr("\pDouble connect");
|
||||
|
||||
InetAddress clientAddr;
|
||||
memset(&call, 0, sizeof(call));
|
||||
call.addr.maxlen = sizeof(clientAddr);
|
||||
call.addr.len = sizeof(clientAddr);
|
||||
call.addr.buf = (UInt8*) &clientAddr;
|
||||
|
||||
OSStatus err;
|
||||
|
||||
err = endpoint->Listen(&call);
|
||||
if(err < 0)
|
||||
return; // hopefully, kOTNoData
|
||||
|
||||
endpoint->SetBlocking();
|
||||
|
||||
err = endpoint->Accept(endpoint, &call);
|
||||
endpoint->SetNonBlocking();
|
||||
|
||||
connected = true;
|
||||
tryReading();
|
||||
}
|
||||
|
||||
OpenTptStream::~OpenTptStream()
|
||||
{
|
||||
endpoint->SetSynchronous();
|
||||
endpoint->SetNonBlocking();
|
||||
if(connected)
|
||||
endpoint->SndDisconnect(&call);
|
||||
endpoint->Unbind();
|
||||
OTCloseProvider(endpoint);
|
||||
CloseOpenTransport();
|
||||
}
|
||||
|
||||
void OpenTptStream::write(const void* p, size_t n)
|
||||
{
|
||||
endpoint->SetBlocking();
|
||||
endpoint->Snd((void*)p, n, 0);
|
||||
endpoint->SetNonBlocking();
|
||||
}
|
||||
|
||||
void OpenTptStream::tryReading()
|
||||
{
|
||||
OSStatus err;
|
||||
OTResult result;
|
||||
OTFlags flags;
|
||||
do
|
||||
{
|
||||
result = endpoint->Rcv(readBuffer, kReadBufferSize, &flags);
|
||||
if(result > 0)
|
||||
{
|
||||
notifyReceive(readBuffer, result);
|
||||
}
|
||||
} while(result > 0);
|
||||
}
|
||||
|
||||
void OpenTptStream::idle()
|
||||
{
|
||||
OSStatus err;
|
||||
switch(endpoint->Look())
|
||||
{
|
||||
case T_DISCONNECT:
|
||||
endpoint->RcvDisconnect(nullptr);
|
||||
connected = false;
|
||||
tryListening();
|
||||
break;
|
||||
case T_ORDREL:
|
||||
err = endpoint->RcvOrderlyDisconnect();
|
||||
if(err == noErr)
|
||||
endpoint->SndOrderlyDisconnect();
|
||||
connected = false;
|
||||
tryListening();
|
||||
break;
|
||||
case T_LISTEN:
|
||||
tryListening();
|
||||
break;
|
||||
case T_DATA:
|
||||
tryReading();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
28
LaunchAPPL/Server/OpenTptStream.h
Normal file
28
LaunchAPPL/Server/OpenTptStream.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <Stream.h>
|
||||
#include <OpenTransport.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class OpenTptStream : public Stream
|
||||
{
|
||||
static const long kReadBufferSize = 4096;
|
||||
uint8_t readBuffer[kReadBufferSize];
|
||||
|
||||
bool connected = false;
|
||||
|
||||
TEndpoint *endpoint;
|
||||
TCall call;
|
||||
|
||||
void tryListening();
|
||||
void tryReading();
|
||||
public:
|
||||
virtual void write(const void* p, size_t n) override;
|
||||
|
||||
void idle();
|
||||
|
||||
OpenTptStream();
|
||||
~OpenTptStream();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user