• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ProgressiveSoapCall.h

Go to the documentation of this file.
00001 /* Copyright (C) 2008 AbiSource Corporation B.V.
00002  *
00003  * This program is free software; you can redistribute it and/or
00004  * modify it under the terms of the GNU General Public License
00005  * as published by the Free Software Foundation; either version 2
00006  * of the License, or (at your option) any later version.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00016  * 02110-1301 USA.
00017  */
00018 
00019 #ifndef __PROGRESSIVE_SOAP_CALL__
00020 #define __PROGRESSIVE_SOAP_CALL__
00021 
00022 #ifdef _MSC_VER
00023 #include "msc_stdint.h"
00024 #else
00025 #include <stdint.h>
00026 #endif
00027 #include <boost/bind.hpp>
00028 #include "InterruptableAsyncWorker.h"
00029 #include "soa_soup.h"
00030 
00031 class ProgressiveSoapCall : public boost::enable_shared_from_this<ProgressiveSoapCall>
00032 {
00033 public:
00034     ProgressiveSoapCall(const std::string& uri, soa::function_call& fc, const std::string& ssl_ca_file)
00035         : m_uri(uri),
00036         m_mi(soa::method_invocation("urn:AbiCollabSOAP", fc)),
00037         m_ssl_ca_file(ssl_ca_file),
00038         m_worker_ptr()
00039     {}
00040 
00041     soa::GenericPtr run()
00042     {
00043         UT_DEBUGMSG(("ProgressiveSoapCall::run()\n"));
00044 
00045         m_worker_ptr.reset(new InterruptableAsyncWorker<bool>(
00046                     boost::bind(&ProgressiveSoapCall::invoke, shared_from_this())
00047                 ));
00048 
00049         // start the asynchronous process and display the dialog
00050         try
00051         {
00052             bool res = m_worker_ptr->run();
00053             if (!res)
00054                 return soa::GenericPtr();
00055             return soa::parse_response(m_result, m_mi.function().response());
00056         }
00057         catch (InterruptedException e)
00058         {
00059             UT_DEBUGMSG(("Soap call interrupted!\n"));
00060             return soa::GenericPtr();
00061         }
00062     }
00063 
00064 private:
00065     bool invoke()
00066     {
00067         UT_DEBUGMSG(("ProgressiveSoapCall::invoke()\n"));
00068         return soup_soa::invoke(
00069                         m_uri, m_mi, m_ssl_ca_file,
00070                         boost::bind(&ProgressiveSoapCall::_progress_cb, this, _1, _2, _3),
00071                         m_result
00072                     );
00073     }
00074 
00075     void _progress_cb(SoupSession* session, SoupMessage* msg, uint32_t progress)
00076     {
00077         UT_DEBUGMSG(("ProgressiveSoapCall::_progress_cb()\n"));
00078         UT_return_if_fail(session && msg);
00079         UT_return_if_fail(m_worker_ptr);
00080 
00081         if (m_worker_ptr->cancelled())
00082         {
00083 #ifdef SOUP24
00084             soup_session_cancel_message(session, msg, SOUP_STATUS_CANCELLED);
00085 #else
00086             soup_message_set_status(msg, SOUP_STATUS_CANCELLED);
00087             soup_session_cancel_message(session, msg);
00088 #endif
00089             return;
00090         }
00091 
00092         m_worker_ptr->progress(progress);
00093     }
00094 
00095     std::string                         m_uri;
00096     soa::method_invocation              m_mi;
00097     std::string                         m_ssl_ca_file;
00098 
00099     boost::shared_ptr< InterruptableAsyncWorker<bool> >
00100                                         m_worker_ptr;
00101 
00102     std::string                         m_result;
00103 };
00104 
00105 #endif /* __PROGRESSIVE_SOAP_CALL__ */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1