2012-02-07 16:28:30 +00:00
// Copyright (c) 2009-2012 The Bitcoin developers
2011-12-24 04:27:12 +00:00
// Distributed under the MIT/X11 software license, see the accompanying
// file license.txt or http://www.opensource.org/licenses/mit-license.php.
# include <boost/algorithm/string.hpp>
# include <boost/interprocess/ipc/message_queue.hpp>
# include <boost/tokenizer.hpp>
# include <boost/date_time/posix_time/posix_time.hpp>
2012-03-25 20:17:39 +00:00
# include <boost/version.hpp>
# if defined(WIN32) && (!defined(BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME) || !defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) || BOOST_VERSION < 104900)
# warning Compiling without BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME and BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME uncommented in boost / interprocess / detail / tmp_dir_helpers.hpp or using a boost version before 1.49 may have unintended results see svn.boost.org / trac / boost / ticket / 5392
# endif
2011-12-24 04:27:12 +00:00
2012-04-16 12:56:45 +00:00
# include "ui_interface.h"
2012-03-25 21:25:10 +00:00
# include "qtipcserver.h"
2012-07-08 21:22:08 +00:00
# include "util.h"
2011-12-24 04:27:12 +00:00
using namespace boost : : interprocess ;
using namespace boost : : posix_time ;
using namespace boost ;
using namespace std ;
Fix Qt build on OSX
Compiling boost::interprocess::message_queue against
boost 1.50 macports with -arch i386 (how releases are built,
for minimum download size and maximum compatibility) is failing:
src/qt/qtipcserver.cpp:37: error: no matching function for call to ‘boost::interprocess::message_queue_t<boost::interprocess::offset_ptr<void, int, long unsigned int, 0u> >::timed_receive(char (*)[257], long unsigned int, size_t&, unsigned int&, boost::posix_time::ptime&)’
This is probably a boost or macports bug, but since interprocess::message_queue
is only used for URI support, which isn't implemented on OSX anyway, I fixed
the build by #ifdef'ing out that code.
2012-07-09 15:03:38 +00:00
# ifdef MAC_OSX
// URI handling not implemented on OSX yet
void ipcInit ( ) { }
void ipcShutdown ( ) { }
# else
2011-12-24 04:27:12 +00:00
void ipcShutdown ( )
{
2012-03-25 21:25:10 +00:00
message_queue : : remove ( BITCOINURI_QUEUE_NAME ) ;
2011-12-24 04:27:12 +00:00
}
void ipcThread ( void * parg )
{
2012-07-08 21:22:08 +00:00
// Make this thread recognisable as the GUI-IPC thread
RenameThread ( " bitcoin-gui-ipc " ) ;
2011-12-24 04:27:12 +00:00
message_queue * mq = ( message_queue * ) parg ;
char strBuf [ 257 ] ;
size_t nSize ;
unsigned int nPriority ;
loop
{
ptime d = boost : : posix_time : : microsec_clock : : universal_time ( ) + millisec ( 100 ) ;
if ( mq - > timed_receive ( & strBuf , sizeof ( strBuf ) , nSize , nPriority , d ) )
{
2012-05-06 17:40:58 +00:00
uiInterface . ThreadSafeHandleURI ( std : : string ( strBuf , nSize ) ) ;
2011-12-24 04:27:12 +00:00
Sleep ( 1000 ) ;
}
if ( fShutdown )
{
ipcShutdown ( ) ;
break ;
}
}
ipcShutdown ( ) ;
}
void ipcInit ( )
{
message_queue * mq ;
char strBuf [ 257 ] ;
size_t nSize ;
unsigned int nPriority ;
try {
2012-03-25 21:25:10 +00:00
mq = new message_queue ( open_or_create , BITCOINURI_QUEUE_NAME , 2 , 256 ) ;
2011-12-24 04:27:12 +00:00
// Make sure we don't lose any bitcoin: URIs
for ( int i = 0 ; i < 2 ; i + + )
{
ptime d = boost : : posix_time : : microsec_clock : : universal_time ( ) + millisec ( 1 ) ;
if ( mq - > timed_receive ( & strBuf , sizeof ( strBuf ) , nSize , nPriority , d ) )
{
2012-05-06 17:40:58 +00:00
uiInterface . ThreadSafeHandleURI ( std : : string ( strBuf , nSize ) ) ;
2011-12-24 04:27:12 +00:00
}
else
break ;
}
// Make sure only one bitcoin instance is listening
2012-03-25 21:25:10 +00:00
message_queue : : remove ( BITCOINURI_QUEUE_NAME ) ;
mq = new message_queue ( open_or_create , BITCOINURI_QUEUE_NAME , 2 , 256 ) ;
2011-12-24 04:27:12 +00:00
}
catch ( interprocess_exception & ex ) {
return ;
}
if ( ! CreateThread ( ipcThread , mq ) )
{
delete mq ;
}
}
Fix Qt build on OSX
Compiling boost::interprocess::message_queue against
boost 1.50 macports with -arch i386 (how releases are built,
for minimum download size and maximum compatibility) is failing:
src/qt/qtipcserver.cpp:37: error: no matching function for call to ‘boost::interprocess::message_queue_t<boost::interprocess::offset_ptr<void, int, long unsigned int, 0u> >::timed_receive(char (*)[257], long unsigned int, size_t&, unsigned int&, boost::posix_time::ptime&)’
This is probably a boost or macports bug, but since interprocess::message_queue
is only used for URI support, which isn't implemented on OSX anyway, I fixed
the build by #ifdef'ing out that code.
2012-07-09 15:03:38 +00:00
# endif