From f0eb337e569ad0785e34d5af95e104dc8a6181c0 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Fri, 16 May 2008 16:50:55 -0400 Subject: [PATCH] Added -z and -Z command line options to btool Added -z and -Z command line options to btool to control the non-threaded/threaded behaviour, respectively; and updated the man page. --- ChangeLog | 3 +++ man/btool.1 | 15 +++++++++++++-- tools/btool.cc | 43 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index cf23550a..20833b8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,9 @@ Release: version 0.13 - 2008/05/?? - added verbose log message to Controller constructors, so it is possible to determine whether a program is using threaded or non-threaded sockets + - added -z and -Z command line options to btool to control + the non-threaded/threaded behaviour, respectively; + and updated the man page 2008/05/15 - mention CVS and git on main documentation "how to" list - moved PPP filter logic into its own class diff --git a/man/btool.1 b/man/btool.1 index acfb9a9c..ec543077 100644 --- a/man/btool.1 +++ b/man/btool.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) -.TH BTOOL 1 "November 30, 2007" +.TH BTOOL 1 "May 16, 2008" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: @@ -20,7 +20,7 @@ \- Barry Project's program to interface with BlackBerry handheld .SH SYNOPSIS .B btool -[-B busname][-N devname][-c dn][-C dnattr][-d db [-f file][-r#][-R#]-D#]][-h][-l][-L][-m cmd][-M][-p pin][-s db -f file][-S][-t][-v][-X] +[-B busname][-N devname][-c dn][-C dnattr][-d db [-f file][-r#][-R#]-D#]][-h][-l][-L][-m cmd][-M][-p pin][-s db -f file][-S][-t][-v][-X][-z][-Z] .SH DESCRIPTION .PP .B btool @@ -133,6 +133,17 @@ Dump verbose protocol data during operation. .B \-X Reset device. .TP +.B \-z +Use non-threaded sockets when communicating with the device. This is +the behaviour seen in versions 0.12 and earlier, since threads were +not yet supported. This option, along with -Z, are for debugging +and testing. +.TP +.B \-Z +Use a threaded socket router when communicating with the device. +This is the default for btool. This option, along with -Z, are for +debugging and testing. +.TP .B \-h, \-\-help Show summary of options. diff --git a/tools/btool.cc b/tools/btool.cc index 23d1ac8c..63b4583e 100644 --- a/tools/btool.cc +++ b/tools/btool.cc @@ -82,6 +82,8 @@ void Usage() << " -T db Show record state table for given database\n" << " -v Dump protocol data during operation\n" << " -X Reset device\n" + << " -z Use non-threaded sockets\n" + << " -Z Use threaded socket router (default)\n" << "\n" << " -d Command modifiers: (can be used multiple times for more than 1 record)\n" << "\n" @@ -420,6 +422,7 @@ int main(int argc, char *argv[]) list_contact_fields = false, list_ldif_map = false, epp_override = false, + threaded_sockets = true, record_state = false; string ldifBaseDN, ldifDnAttr; string filename; @@ -432,7 +435,7 @@ int main(int argc, char *argv[]) // process command line options for(;;) { - int cmd = getopt(argc, argv, "B:c:C:d:D:e:f:hlLm:MN:p:P:r:R:Ss:tT:vX"); + int cmd = getopt(argc, argv, "B:c:C:d:D:e:f:hlLm:MN:p:P:r:R:Ss:tT:vXzZ"); if( cmd == -1 ) break; @@ -540,6 +543,14 @@ int main(int argc, char *argv[]) reset_device = true; break; + case 'z': // non-threaded sockets + threaded_sockets = false; + break; + + case 'Z': // threaded socket router + threaded_sockets = true; + break; + case 'h': // help default: Usage(); @@ -625,11 +636,7 @@ int main(int argc, char *argv[]) return 0; } - // Create our socket router and thread - SocketRoutingQueue router; - router.SpinoffSimpleReadThread(); - - // Create our controller object + // Override device endpoints if user asks Barry::ProbeResult device = probe.Get(activeDevice); if( epp_override ) { device.m_ep.read = epOverride.read; @@ -640,7 +647,29 @@ int main(int argc, char *argv[]) << (unsigned int) device.m_ep.read << "," << (unsigned int) device.m_ep.write << endl; } - Barry::Controller con(device, router); + + // + // Create our controller object + // + // Order is important in the following auto_ptr<> objects, + // since Controller must get destroyed before router. + // Normally you'd pick one method, and not bother + // with auto_ptr<> and so the normal C++ constructor + // rules would guarantee this safety for you, but + // here we want the user to pick. + // + auto_ptr router; + auto_ptr pcon; + if( threaded_sockets ) { + router.reset( new SocketRoutingQueue ); + router->SpinoffSimpleReadThread(); + pcon.reset( new Barry::Controller(device, *router) ); + } + else { + pcon.reset( new Barry::Controller(device) ); + } + + Barry::Controller &con = *pcon; Barry::Mode::Desktop desktop(con); // -- 2.11.4.GIT