1 /* 2 * Copyright 2017, Adrien Destugues, pulkomandy@pulkomandy.tk 3 * Distributed under terms of the MIT license. 4 */ 5 6 7 #include "FileSender.h" 8 9 #include "SerialApp.h" 10 11 #include <DataIO.h> 12 #include <Message.h> 13 #include <SerialPort.h> 14 15 16 FileSender::~FileSender() 17 { 18 } 19 20 21 RawSender::RawSender(BDataIO* source, BSerialPort* sink, BHandler* listener) 22 { 23 // FIXME doing this all here in the constructor is not good. We need to 24 // do things asynchronously instead so as not to lock the application 25 // thread. 26 off_t sourceSize; 27 off_t position; 28 29 BPositionIO* pos = dynamic_cast<BPositionIO*>(source); 30 if (pos) 31 pos->GetSize(&sourceSize); 32 else 33 sourceSize = 0; 34 position = 0; 35 36 BMessenger messenger(listener); 37 38 uint8_t buffer[256]; 39 for (;;) { 40 ssize_t s = source->Read(&buffer, sizeof(buffer)); 41 if (s <= 0) 42 return; 43 44 sink->Write(buffer, s); 45 position += s; 46 47 BMessage msg(kMsgProgress); 48 msg.AddInt32("pos", position); 49 msg.AddInt32("size", sourceSize); 50 msg.AddString("info", "Sending" B_UTF8_ELLIPSIS); 51 messenger.SendMessage(&msg); 52 53 //usleep(20000); 54 } 55 } 56 57 58 RawSender::~RawSender() 59 { 60 } 61 62 63 bool 64 RawSender::BytesReceived(const uint8_t* data, size_t length) 65 { 66 // Nothing to do with received bytes, this protocol has no kind of 67 // acknowledgement from remote side. 68 return true; 69 } 70