From cbc2bd49c2e762d96919de555240509106d9acaf Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 2 Nov 2010 17:00:57 -0400 Subject: [PATCH] lib: set ProbeResult's constructor to private Some automated tests from the abi-compliance-checker site use a default ProbeResult to construct Controller, etc. All valid ProbeResult objects come from the Probe class, so this change forces the issue, and prevents usage of invalid probe results by default. --- gui/src/DeviceIface.cc | 7 ++----- gui/src/DeviceIface.h | 3 +-- opensync-plugin-0.4x/src/barry_sync.cc | 2 +- opensync-plugin-0.4x/src/environment.cc | 10 ++++++---- opensync-plugin-0.4x/src/environment.h | 3 ++- opensync-plugin/src/barry_sync.cc | 2 +- opensync-plugin/src/environment.cc | 10 ++++++---- opensync-plugin/src/environment.h | 3 ++- src/probe.h | 9 +++++++++ 9 files changed, 30 insertions(+), 19 deletions(-) diff --git a/gui/src/DeviceIface.cc b/gui/src/DeviceIface.cc index a38ca6c1..66d03212 100644 --- a/gui/src/DeviceIface.cc +++ b/gui/src/DeviceIface.cc @@ -642,11 +642,8 @@ void DeviceInterface::SkipCurrentDB() throw() } } -Device::Device() -{ -} - -Device::Device(Barry::ProbeResult pr) : result(pr) +Device::Device(const Barry::ProbeResult &result) + : result(result) { } diff --git a/gui/src/DeviceIface.h b/gui/src/DeviceIface.h index 11769d25..4cd39cc1 100644 --- a/gui/src/DeviceIface.h +++ b/gui/src/DeviceIface.h @@ -41,8 +41,7 @@ class Device Barry::ProbeResult result; public: - Device(); - Device(Barry::ProbeResult); + Device(const Barry::ProbeResult &result); Barry::Pin GetPIN() const { return Barry::Pin(result.m_pin); }; diff --git a/opensync-plugin-0.4x/src/barry_sync.cc b/opensync-plugin-0.4x/src/barry_sync.cc index 91c593b9..f3d81b3d 100644 --- a/opensync-plugin-0.4x/src/barry_sync.cc +++ b/opensync-plugin-0.4x/src/barry_sync.cc @@ -706,7 +706,7 @@ static void connect(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncContext osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "Unable to find PIN %x", env->m_pin); return; } - env->m_ProbeResult = probe.Get(nIndex); + env->m_ProbeResult.reset( new Barry::ProbeResult(probe.Get(nIndex)) ); trace.log("connecting..."); diff --git a/opensync-plugin-0.4x/src/environment.cc b/opensync-plugin-0.4x/src/environment.cc index 0cde48a5..967eba82 100644 --- a/opensync-plugin-0.4x/src/environment.cc +++ b/opensync-plugin-0.4x/src/environment.cc @@ -103,7 +103,9 @@ void BarryEnvironment::DoConnect() // Then if we get such a timeout, we do the Reconnect again and // hope for the best... this often fixes it. // - m_pCon = new Barry::Controller(m_ProbeResult, 15000); + if( !m_ProbeResult.get() ) + throw std::logic_error("Tried to use empty ProbeResult"); + m_pCon = new Barry::Controller(*m_ProbeResult, 15000); m_pDesktop = new Barry::Mode::Desktop(*m_pCon, m_IConverter); m_pDesktop->Open(m_password.c_str()); @@ -134,7 +136,7 @@ void BarryEnvironment::Connect(const Barry::ProbeResult &result) Disconnect(); // save result in case we need to reconnect later - m_ProbeResult = result; + m_ProbeResult.reset( new Barry::ProbeResult(result) ); DoConnect(); } @@ -160,9 +162,9 @@ void BarryEnvironment::Reconnect() // we add this probe. { Barry::Probe probe; - int i = probe.FindActive(m_ProbeResult.m_pin); + int i = probe.FindActive(m_ProbeResult->m_pin); if( i != -1 ) - m_ProbeResult = probe.Get(i); + m_ProbeResult.reset( new Barry::ProbeResult(probe.Get(i)) ); } DoConnect(); diff --git a/opensync-plugin-0.4x/src/environment.h b/opensync-plugin-0.4x/src/environment.h index 31c96bfa..0c4b540b 100644 --- a/opensync-plugin-0.4x/src/environment.h +++ b/opensync-plugin-0.4x/src/environment.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -66,7 +67,7 @@ public: // device communication Barry::IConverter m_IConverter; - Barry::ProbeResult m_ProbeResult; + std::auto_ptr m_ProbeResult; Barry::Controller *m_pCon; Barry::Mode::Desktop *m_pDesktop; diff --git a/opensync-plugin/src/barry_sync.cc b/opensync-plugin/src/barry_sync.cc index d308edf5..2c2ad687 100644 --- a/opensync-plugin/src/barry_sync.cc +++ b/opensync-plugin/src/barry_sync.cc @@ -316,7 +316,7 @@ static void connect(OSyncContext *ctx) osync_context_report_error(ctx, OSYNC_ERROR_NO_CONNECTION, "Unable to find PIN %lx", env->m_pin); return; } - env->m_ProbeResult = probe.Get(nIndex); + env->m_ProbeResult.reset( new Barry::ProbeResult(probe.Get(nIndex)) ); env->Connect(probe.Get(nIndex)); diff --git a/opensync-plugin/src/environment.cc b/opensync-plugin/src/environment.cc index 13522d70..69bd4d16 100644 --- a/opensync-plugin/src/environment.cc +++ b/opensync-plugin/src/environment.cc @@ -202,7 +202,9 @@ void BarryEnvironment::DoConnect() // Then if we get such a timeout, we do the Reconnect again and // hope for the best... this often fixes it. // - m_pCon = new Barry::Controller(m_ProbeResult, 15000); + if( !m_ProbeResult.get() ) + throw std::logic_error("Tried to use empty ProbeResult"); + m_pCon = new Barry::Controller(*m_ProbeResult, 15000); m_pDesktop = new Barry::Mode::Desktop(*m_pCon, m_IConverter); m_pDesktop->Open(m_password.c_str()); @@ -223,7 +225,7 @@ void BarryEnvironment::Connect(const Barry::ProbeResult &result) Disconnect(); // save result in case we need to reconnect later - m_ProbeResult = result; + m_ProbeResult.reset( new Barry::ProbeResult(result) ); DoConnect(); } @@ -249,9 +251,9 @@ void BarryEnvironment::Reconnect() // we add this probe. { Barry::Probe probe; - int i = probe.FindActive(m_ProbeResult.m_pin); + int i = probe.FindActive(m_ProbeResult->m_pin); if( i != -1 ) - m_ProbeResult = probe.Get(i); + m_ProbeResult.reset( new Barry::ProbeResult(probe.Get(i)) ); } DoConnect(); diff --git a/opensync-plugin/src/environment.h b/opensync-plugin/src/environment.h index 25842c60..4f92e752 100644 --- a/opensync-plugin/src/environment.h +++ b/opensync-plugin/src/environment.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "idmap.h" @@ -86,7 +87,7 @@ public: // device communication Barry::IConverter m_IConverter; - Barry::ProbeResult m_ProbeResult; + std::auto_ptr m_ProbeResult; Barry::Controller *m_pCon; Barry::Mode::Desktop *m_pDesktop; diff --git a/src/probe.h b/src/probe.h index 8f4eeedd..009707ff 100644 --- a/src/probe.h +++ b/src/probe.h @@ -31,8 +31,12 @@ namespace Barry { +class Probe; + struct BXEXPORT ProbeResult { + friend class Probe; + Usb::DeviceIDType m_dev; unsigned char m_interface; Barry::Pin m_pin; @@ -60,11 +64,16 @@ struct BXEXPORT ProbeResult // the probe code if available) std::string m_cfgDeviceName; +private: + // All ProbeResult objects should come from Probe, therefore + // this constructor is private to force the issue. ProbeResult() : m_dev(0), m_interface(0), m_pin(0) , m_needClearHalt(false), m_needSetAltInterface(false) , m_zeroSocketSequence(0) {} + +public: void DumpAll(std::ostream &os) const; bool HasIpModem() const { return m_epModem.IsComplete(); } -- 2.11.4.GIT