mirror of
https://github.com/autc04/Retro68.git
synced 2025-02-07 18:31:06 +00:00
LaunchAPPL/Serial: send response
This commit is contained in:
parent
d9ab8bee37
commit
f2542a0ff9
@ -32,11 +32,13 @@ class SerialLauncher : public Launcher
|
||||
{
|
||||
SerialStream stream;
|
||||
ReliableStream rStream;
|
||||
std::vector<char> outputBytes;
|
||||
public:
|
||||
SerialLauncher(po::variables_map& options);
|
||||
virtual ~SerialLauncher();
|
||||
|
||||
virtual bool Go(int timeout = 0);
|
||||
virtual void DumpOutput();
|
||||
|
||||
private:
|
||||
void write(const void *p, size_t n);
|
||||
@ -118,16 +120,17 @@ SerialLauncher::~SerialLauncher()
|
||||
{
|
||||
}
|
||||
|
||||
ssize_t SerialLauncher::read(void *p, size_t n)
|
||||
ssize_t SerialLauncher::read(void *p0, size_t n)
|
||||
{
|
||||
ssize_t available = rStream.read(p, n);
|
||||
while(!available)
|
||||
uint8_t* p = (uint8_t*)p0;
|
||||
ssize_t gotBytes = rStream.read(p, n);
|
||||
while(gotBytes < n)
|
||||
{
|
||||
rStream.flushWrite();
|
||||
stream.wait();
|
||||
available = rStream.read(p, n);
|
||||
gotBytes += rStream.read(p + gotBytes, n - gotBytes);
|
||||
}
|
||||
return available;
|
||||
return gotBytes;
|
||||
}
|
||||
|
||||
void SerialLauncher::write(const void *p, size_t n)
|
||||
@ -167,11 +170,25 @@ bool SerialLauncher::Go(int timeout)
|
||||
stream.wait();
|
||||
|
||||
read(&tmp, 4);
|
||||
tmp = ntohl(tmp);
|
||||
uint32_t result = ntohl(tmp);
|
||||
|
||||
return true;
|
||||
if(result == 0)
|
||||
{
|
||||
read(&tmp, 4);
|
||||
uint32_t size = ntohl(tmp);
|
||||
|
||||
outputBytes.resize(size);
|
||||
if(size > 0)
|
||||
read(outputBytes.data(), size);
|
||||
}
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
void SerialLauncher::DumpOutput()
|
||||
{
|
||||
std::cout.write(outputBytes.data(), outputBytes.size());
|
||||
}
|
||||
|
||||
void Serial::GetOptions(options_description &desc)
|
||||
{
|
||||
|
@ -259,6 +259,9 @@ public:
|
||||
FSDelete("\pRetro68App", 0);
|
||||
Create("\pRetro68App", 0, '????', 'APPL');
|
||||
OpenDF("\pRetro68App", 0, &refNum);
|
||||
FSDelete("\pout", 0);
|
||||
Create("\pout", 0, 'ttxt', 'TEXT');
|
||||
|
||||
state = State::data;
|
||||
remainingSize = dataSize;
|
||||
return 8;
|
||||
@ -308,6 +311,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
short outRefNum;
|
||||
long outSize, outSizeRemaining;
|
||||
|
||||
int main()
|
||||
{
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
@ -433,15 +439,35 @@ int main()
|
||||
if(err)
|
||||
{
|
||||
server.state = LaunchServer::State::respond;
|
||||
SetStatus(AppStatus::uploading, 0, 0);
|
||||
uint32_t zero = 0;
|
||||
rStream.write(&zero, 4);
|
||||
|
||||
OpenDF("\pout", 0, &outRefNum);
|
||||
GetEOF(outRefNum, &outSize);
|
||||
outSizeRemaining = outSize;
|
||||
SetStatus(AppStatus::uploading, 0, outSize);
|
||||
|
||||
rStream.write(&outSize, 4);
|
||||
rStream.flushWrite();
|
||||
}
|
||||
}
|
||||
else if(server.state == LaunchServer::State::respond)
|
||||
{
|
||||
if(rStream.allDataArrived())
|
||||
while(outSizeRemaining && rStream.readyToWrite())
|
||||
{
|
||||
char buf[1024];
|
||||
long count = outSizeRemaining > 1024 ? 1024 : outSizeRemaining;
|
||||
FSRead(outRefNum, &count, buf);
|
||||
rStream.write(buf, count);
|
||||
outSizeRemaining -= count;
|
||||
}
|
||||
SetStatus(AppStatus::uploading, outSize - outSizeRemaining, outSize);
|
||||
|
||||
if(outSizeRemaining == 0)
|
||||
{
|
||||
FSClose(outRefNum);
|
||||
}
|
||||
if(outSizeRemaining == 0 && rStream.allDataArrived())
|
||||
{
|
||||
server.state = LaunchServer::State::size;
|
||||
SetStatus(AppStatus::ready, 0, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user