start a LaunchAPPL server

This commit is contained in:
Wolfgang Thaller 2018-04-20 19:25:54 +02:00
parent 280b9d0adf
commit bdf4685d82
25 changed files with 196 additions and 38 deletions

View File

@ -52,9 +52,10 @@ add_subdirectory(Samples/SystemExtension)
add_subdirectory(Samples/WDEF)
endif()
add_subdirectory(LaunchAPPL)
enable_testing()
add_subdirectory(AutomatedTests)
else()
set(RETRO68_ROOT ${CMAKE_INSTALL_PREFIX})

View File

@ -1,38 +1,5 @@
find_package(Boost COMPONENTS filesystem program_options)
set(LAUNCHMETHODS
Executor.h Executor.cc
MiniVMac.h MiniVMac.cc
SSH.h SSH.cc
)
if(APPLE)
LIST(APPEND LAUNCHMETHODS
Classic.h Classic.cc
)
LIST(APPEND LAUNCHMETHODS
Carbon.h Carbon.cc)
if(CMAKE_SYSTEM_NAME MATCHES Retro.*)
add_subdirectory(Server)
else()
add_subdirectory(Client)
endif()
add_definitions(-DRETRO68_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_executable(LaunchAPPL
LaunchAPPL.cc
MakeExecutable.cc
LaunchMethod.h LaunchMethod.cc
Launcher.h Launcher.cc
Utilities.h Utilities.cc
${LAUNCHMETHODS})
target_include_directories(LaunchAPPL PRIVATE ${CMAKE_INSTALL_PREFIX}/include ${Boost_INCLUDE_DIR})
target_link_libraries(LaunchAPPL ResourceFiles ${Boost_LIBRARIES})
if(APPLE)
find_library(APPLICATIONSERVICES_FW ApplicationServices)
target_link_libraries(LaunchAPPL ${APPLICATIONSERVICES_FW})
endif()
install(TARGETS LaunchAPPL RUNTIME DESTINATION bin)

View File

@ -0,0 +1,38 @@
find_package(Boost COMPONENTS filesystem program_options)
set(LAUNCHMETHODS
Executor.h Executor.cc
MiniVMac.h MiniVMac.cc
SSH.h SSH.cc
)
if(APPLE)
LIST(APPEND LAUNCHMETHODS
Classic.h Classic.cc
)
LIST(APPEND LAUNCHMETHODS
Carbon.h Carbon.cc)
endif()
add_definitions(-DRETRO68_PREFIX="${CMAKE_INSTALL_PREFIX}")
add_executable(LaunchAPPL
LaunchAPPL.cc
MakeExecutable.cc
LaunchMethod.h LaunchMethod.cc
Launcher.h Launcher.cc
Utilities.h Utilities.cc
${LAUNCHMETHODS})
target_include_directories(LaunchAPPL PRIVATE ${CMAKE_INSTALL_PREFIX}/include ${Boost_INCLUDE_DIR})
target_link_libraries(LaunchAPPL ResourceFiles ${Boost_LIBRARIES})
if(APPLE)
find_library(APPLICATIONSERVICES_FW ApplicationServices)
target_link_libraries(LaunchAPPL ${APPLICATIONSERVICES_FW})
endif()
install(TARGETS LaunchAPPL RUNTIME DESTINATION bin)

View File

@ -0,0 +1 @@
add_application(LaunchAPPLServer CONSOLE main.cc)

View File

@ -0,0 +1,38 @@
#include <stdint.h>
#include <stddef.h>
class Block
{
uint8_t *begin_ = nullptr;
uint8_t *end_ = nullptr;
public:
Block() = default;
Block(uint8_t *p, size_t len) : begin_(p), end_(p+len) {}
Block(uint8_t *b, uint8_t *e) : begin_(b), end_(e) {}
uint8_t * begin() { return begin_; }
const uint8_t * begin() const { return begin_; }
uint8_t * end() { return end_; }
const uint8_t * end() const { return end_; }
size_t size() const { return end_ - begin_; }
};
class StreamListener
{
public:
virtual void onReceive(const Block& b) = 0;
};
class Stream
{
StreamListener *listener_;
public:
void setListener(StreamListener *l) { listener_ = l; }
virtual void send(const Block& b) = 0;
protected:
void onReceive(const Block& b)
{ if(listener_) listener_->onReceive(b); }
};

113
LaunchAPPL/Server/main.cc Normal file
View File

@ -0,0 +1,113 @@
#include <stdio.h>
#include <Serial.h>
#include <Devices.h>
#include <Events.h>
#include <string.h>
#include "Stream.h"
class MacSerialStream : public Stream
{
static const long kInputBufferSize = 4096;
static const long kReadBufferSize = 4096;
char inputBuffer[kInputBufferSize];
char readBuffer[kReadBufferSize];
short outRefNum, inRefNum;
public:
virtual void send(const Block& b) override;
void idle();
MacSerialStream();
~MacSerialStream();
};
MacSerialStream::MacSerialStream()
{
OSErr err;
err = OpenDriver("\p.AOut", &outRefNum);
err = OpenDriver("\p.AIn", &inRefNum);
SerSetBuf(inRefNum, inputBuffer, kInputBufferSize);
SerShk shk;
memset(&shk, 0, sizeof(shk));
shk.fCTS = true;
Control(outRefNum, kSERDHandshake, &shk);
SerReset(outRefNum, baud19200 | data8 | noParity | stop10);
}
MacSerialStream::~MacSerialStream()
{
SerSetBuf(inRefNum, NULL, 0);
CloseDriver(inRefNum);
CloseDriver(outRefNum);
}
void MacSerialStream::send(const Block& b)
{
ParamBlockRec pb;
memset(&pb, 0, sizeof(pb));
pb.ioParam.ioRefNum = outRefNum;
pb.ioParam.ioBuffer = (Ptr)b.begin();
pb.ioParam.ioReqCount = b.size();
OSErr err = PBWriteSync(&pb);
}
void MacSerialStream::idle()
{
long count = 0;
SerGetBuf(inRefNum, &count);
while(count > 0)
{
long count1 = count > kReadBufferSize ? kReadBufferSize : count;
ParamBlockRec pb;
memset(&pb, 0, sizeof(pb));
pb.ioParam.ioRefNum = inRefNum;
pb.ioParam.ioBuffer = (Ptr)&readBuffer;
pb.ioParam.ioReqCount = count1;
OSErr err = PBReadSync(&pb);
if(err)
return;
count -= count1;
onReceive(Block((uint8_t*)readBuffer, count1));
}
}
class DumpToConsole : public StreamListener
{
public:
void onReceive(const Block& b)
{
for(uint8_t c : b)
putchar(c);
}
};
int main()
{
OSErr err;
short outRefNum, inRefNum;
printf("Hello.\n");
{
MacSerialStream stream;
DumpToConsole listener;
stream.setListener(&listener);
while(!Button())
stream.idle();
}
return 0;
}