Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

qtipcserver.cpp 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright (c) 2009-2012 The Bitcoin developers
  2. // Distributed under the MIT/X11 software license, see the accompanying
  3. // file license.txt or http://www.opensource.org/licenses/mit-license.php.
  4. #include <boost/algorithm/string.hpp>
  5. #include <boost/interprocess/ipc/message_queue.hpp>
  6. #include <boost/tokenizer.hpp>
  7. #include <boost/date_time/posix_time/posix_time.hpp>
  8. #include <boost/version.hpp>
  9. #if defined(WIN32) && (!defined(BOOST_INTERPROCESS_HAS_WINDOWS_KERNEL_BOOTTIME) || !defined(BOOST_INTERPROCESS_HAS_KERNEL_BOOTTIME) || BOOST_VERSION < 104900)
  10. #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
  11. #endif
  12. #include "ui_interface.h"
  13. #include "qtipcserver.h"
  14. using namespace boost::interprocess;
  15. using namespace boost::posix_time;
  16. using namespace boost;
  17. using namespace std;
  18. void ipcShutdown()
  19. {
  20. message_queue::remove(BITCOINURI_QUEUE_NAME);
  21. }
  22. void ipcThread(void* parg)
  23. {
  24. message_queue* mq = (message_queue*)parg;
  25. char strBuf[257];
  26. size_t nSize;
  27. unsigned int nPriority;
  28. loop
  29. {
  30. ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(100);
  31. if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
  32. {
  33. uiInterface.ThreadSafeHandleURI(std::string(strBuf, nSize));
  34. Sleep(1000);
  35. }
  36. if (fShutdown)
  37. {
  38. ipcShutdown();
  39. break;
  40. }
  41. }
  42. ipcShutdown();
  43. }
  44. void ipcInit()
  45. {
  46. #ifdef MAC_OSX
  47. // TODO: implement bitcoin: URI handling the Mac Way
  48. return;
  49. #endif
  50. message_queue* mq;
  51. char strBuf[257];
  52. size_t nSize;
  53. unsigned int nPriority;
  54. try {
  55. mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256);
  56. // Make sure we don't lose any bitcoin: URIs
  57. for (int i = 0; i < 2; i++)
  58. {
  59. ptime d = boost::posix_time::microsec_clock::universal_time() + millisec(1);
  60. if(mq->timed_receive(&strBuf, sizeof(strBuf), nSize, nPriority, d))
  61. {
  62. uiInterface.ThreadSafeHandleURI(std::string(strBuf, nSize));
  63. }
  64. else
  65. break;
  66. }
  67. // Make sure only one bitcoin instance is listening
  68. message_queue::remove(BITCOINURI_QUEUE_NAME);
  69. mq = new message_queue(open_or_create, BITCOINURI_QUEUE_NAME, 2, 256);
  70. }
  71. catch (interprocess_exception &ex) {
  72. return;
  73. }
  74. if (!CreateThread(ipcThread, mq))
  75. {
  76. delete mq;
  77. }
  78. }