From 6aa1dbb1e89d0aca573ac9a938e6a266606ee543 Mon Sep 17 00:00:00 2001 From: Toby Gray Date: Mon, 23 Aug 2010 11:48:20 +0100 Subject: [PATCH] Updating text, names and comments to be consistent and generally make a bit more sense. --- man/brawchannel.1 | 2 +- po/POTFILES.in | 4 ++-- src/controller.cc | 4 ++-- src/m_mode_base.cc | 2 +- src/m_raw_channel.h | 6 ------ tools/brawchannel.cc | 50 +++++++++++++++++++++++++++++--------------------- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/man/brawchannel.1 b/man/brawchannel.1 index d8ae779a..0bd02ebe 100644 --- a/man/brawchannel.1 +++ b/man/brawchannel.1 @@ -17,7 +17,7 @@ .\" for manpage-specific macros, see man(7) .SH NAME .B brawchannel -\- Barry Project's program to create channel to BlackBerry applications +\- Barry Project's program to create a channel to a BlackBerry application .SH SYNOPSIS .B brawchannel [-h][-p pin][-P pass][-v] .SH DESCRIPTION diff --git a/po/POTFILES.in b/po/POTFILES.in index fe873af0..1500db22 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -19,7 +19,7 @@ src/threadwrap.cc src/r_servicebook.cc src/iconv.cc src/m_desktop.cc -src/m_vnc_server.cc +src/m_raw_channel.cc src/record.cc src/dp_codinfo.cc src/time.cc @@ -88,5 +88,5 @@ tools/btool.cc tools/bfuse.cc tools/upldif.cc tools/bjavaloader.cc -tools/bvncrelay.cc +tools/brawchannel.cc diff --git a/src/controller.cc b/src/controller.cc index f2cb57bf..d15dd1aa 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -154,7 +154,7 @@ Controller::~Controller() // Tells device which mode is desired, and returns the suggested // socket ID to use for that mode. // - uint16_t Controller::SelectMode(ModeType mode) +uint16_t Controller::SelectMode(ModeType mode) { return SelectMode(mode, NULL); } @@ -168,7 +168,7 @@ Controller::~Controller() // // The RawChannel mode requires an explicitModeName to be specified. // - uint16_t Controller::SelectMode(ModeType mode, const char *explicitModeName) +uint16_t Controller::SelectMode(ModeType mode, const char *explicitModeName) { // select mode Protocol::Packet packet; diff --git a/src/m_mode_base.cc b/src/m_mode_base.cc index 8e804762..1b6f3dd1 100644 --- a/src/m_mode_base.cc +++ b/src/m_mode_base.cc @@ -90,7 +90,7 @@ void Mode::Open(const char *password) /// is responsible for safely handling the raw password data. /// /// It uses the provided name as the name for the socket used in this mode. -/// Usually this shouldn't be needed unless using the raw socket mode. +/// Usually this shouldn't be needed unless using the raw channel mode. /// /// You can retry the password by catching Barry::BadPassword and /// calling RetryPassword() with the new password. diff --git a/src/m_raw_channel.h b/src/m_raw_channel.h index a1ff51bd..fde4ea2e 100644 --- a/src/m_raw_channel.h +++ b/src/m_raw_channel.h @@ -88,12 +88,6 @@ public: void HandleReceivedData(Data& data); // Not intended for use by users of this class. - // Instead acknowledgement of data send will come - // in via the RawChannelDataCallback::DataSendAck(); - // callback. - void HandleSequencePacket(Data& data); - - // Not intended for use by users of this class. // This method is called by the internals of // Barry when setting up a connection. void OnOpen(); diff --git a/tools/brawchannel.cc b/tools/brawchannel.cc index 8b95292e..abe73df1 100644 --- a/tools/brawchannel.cc +++ b/tools/brawchannel.cc @@ -214,10 +214,10 @@ void Semaphore::Signal() lock.Unlock(); } -class StdoutWriter : public Barry::Mode::RawChannelDataCallback +class CallbackHandler : public Barry::Mode::RawChannelDataCallback { public: - StdoutWriter(volatile bool& keepGoing, bool verbose, Semaphore& semaphore) + CallbackHandler(volatile bool& keepGoing, bool verbose, Semaphore& semaphore) : m_continuePtr(&keepGoing), m_verbose(verbose), m_semaphore(semaphore) @@ -238,7 +238,7 @@ private: }; -void StdoutWriter::DataReceived(Data& data) +void CallbackHandler::DataReceived(Data& data) { if (m_verbose) { cerr << "From BB: "; @@ -267,28 +267,29 @@ void StdoutWriter::DataReceived(Data& data) } } -void StdoutWriter::DataSendAck() +void CallbackHandler::DataSendAck() { m_semaphore.Signal(); } -void StdoutWriter::ChannelError(string msg) +void CallbackHandler::ChannelError(string msg) { - cerr << "StdoutWriter: Received error: " << msg << endl; + cerr << "CallbackHandler: Received error: " << msg << endl; ChannelClose(); } -void StdoutWriter::ChannelClose() +void CallbackHandler::ChannelClose() { *m_continuePtr = false; m_semaphore.Signal(); } -// Class which adds error detection and setting of a continue boolean -// to false when an error is detected to SocketRoutingQueue. -// This code is heavily based on the thread creation code of -// SocketRoutingQueue, which sadly has too many private variables -// to just sub-class. +// Class which extends the functionality of SocketRoutingQueue to add +// error detection and setting of a continue boolean to false when an +// error is detected. +// This code is heavily based on the thread +// creation code of SocketRoutingQueue, which sadly has too many +// private variables to just sub-class. class ErrorHandlingSocketRoutingQueue { public: @@ -405,6 +406,9 @@ int main(int argc, char *argv[]) cerr.sync_with_stdio(true); // since libusb uses // stdio for debug messages + + // Buffer to hold data read in from STDIN before sending it + // to the BlackBerry. unsigned char* buf = NULL; try { uint32_t pin = 0; @@ -480,7 +484,7 @@ int main(int argc, char *argv[]) // anything else. Barry::Init(data_dump, &cerr); - // Probe the USB bus for Blackberry devices and display. + // Probe the USB bus for Blackberry devices. // If user has specified a PIN, search for it in the // available device list here as well Barry::Probe probe; @@ -490,8 +494,7 @@ int main(int argc, char *argv[]) return 1; } - // Now start to read from stdin and get ready to write - // to the BlackBerry. + // Now get setup to open the channel. if (data_dump) cerr << "Connected to device, starting read/write\n"; @@ -500,9 +503,9 @@ int main(int argc, char *argv[]) Semaphore sem; // Create the thing which will write onto stdout - StdoutWriter stdoutWriter(running, data_dump, sem); + // and perform other callback duties. + CallbackHandler callbackHandler(running, data_dump, sem); - // Set up the BlackBerry gubbins // Start a thread to handle any data arriving from // the BlackBerry. auto_ptr router; @@ -512,11 +515,9 @@ int main(int argc, char *argv[]) // Create our controller object Barry::Controller con(probe.Get(activeDevice), *router->GetSocketRoutingQueue()); - Barry::Mode::RawChannel rawChannel(con, stdoutWriter); + Barry::Mode::RawChannel rawChannel(con, callbackHandler); - // - // execute each mode that was turned on - // + // Try to open the requested channel now everything is setup rawChannel.Open(password.c_str(), channelName.c_str()); // We now have a thread running to read from the @@ -528,6 +529,11 @@ int main(int argc, char *argv[]) struct timeval tv; FD_ZERO(&rfds); + // Set up the signal restorers to restore signal + // handling (in their destructors) before the socket + // starts to be closed. This allows, for example, + // double control-c presses to stop graceful close + // down. SignalRestorer srh(SIGHUP, oldSigHup); SignalRestorer srt(SIGTERM, oldSigTerm); SignalRestorer sri(SIGINT, oldSigInt); @@ -559,6 +565,8 @@ int main(int argc, char *argv[]) cerr.setf(ios::dec, ios::basefield); cerr << "Sent " << ios::dec << haveRead << " bytes stdin->USB\n"; } + // Wait for the write to be completed before reading + // the next data to send. sem.WaitForSignal(); } else if (haveRead < 0) { -- 2.11.4.GIT