Changeset 49842 in vbox for trunk/src/VBox/NetworkServices/NetLib
- Timestamp:
- Dec 9, 2013 1:49:46 PM (11 years ago)
- Location:
- trunk/src/VBox/NetworkServices/NetLib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.cpp
r49831 r49842 29 29 #include <VBox/com/ErrorInfo.h> 30 30 #include <VBox/com/errorprint.h> 31 #include <VBox/com/EventQueue.h>32 31 #include <VBox/com/VirtualBox.h> 32 #include <VBox/com/NativeEventQueue.h> 33 33 34 34 #include <iprt/alloca.h> … … 44 44 #include <iprt/string.h> 45 45 #include <iprt/time.h> 46 #include <iprt/thread.h> 46 47 #include <iprt/mem.h> 47 48 #include <iprt/message.h> … … 83 84 m_pIfBuf(NULL), 84 85 m_cVerbosity(0), 85 m_fNeedMain(false) 86 m_fNeedMain(false), 87 m_EventQ(NULL), 88 m_hThrRecv(NIL_RTTHREAD), 89 fShutdown(false) 86 90 { 87 91 int rc = RTCritSectInit(&m_csThis); … … 113 117 /* Controls whether service will connect SVC for runtime needs */ 114 118 bool m_fNeedMain; 119 /* Event Queue */ 120 com::NativeEventQueue *m_EventQ; 121 122 /** receiving thread, used only if main is used */ 123 RTTHREAD m_hThrRecv; 124 125 bool fShutdown; 126 static int recvLoop(RTTHREAD, void *); 115 127 }; 116 128 … … 133 145 134 146 147 int VBoxNetBaseService::Data::recvLoop(RTTHREAD, void *pvUser) 148 { 149 VBoxNetBaseService *pThis = static_cast<VBoxNetBaseService *>(pvUser); 150 151 HRESULT hrc = com::Initialize(); 152 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR); 153 154 pThis->doReceiveLoop(); 155 156 return VINF_SUCCESS; 157 } 158 159 135 160 VBoxNetBaseService::VBoxNetBaseService(const std::string& aName, const std::string& aNetworkName):m(NULL) 136 161 { … … 149 174 if (m != NULL) 150 175 { 176 shutdown(); 151 177 if (m->m_hIf != INTNET_HANDLE_INVALID) 152 178 { … … 193 219 { 194 220 return m->m_fNeedMain; 221 } 222 223 224 int VBoxNetBaseService::run() 225 { 226 /** 227 * If child class need Main we start receving thread which calls doReceiveLoop and enter to event polling loop 228 * and for the rest clients we do receiving on the current (main) thread. 229 */ 230 if (isMainNeeded()) 231 return startReceiveThreadAndEnterEventLoop(); 232 else 233 { 234 doReceiveLoop(); 235 return VINF_SUCCESS; 236 } 195 237 } 196 238 … … 414 456 void VBoxNetBaseService::shutdown(void) 415 457 { 458 syncEnter(); 459 m->fShutdown = true; 460 syncLeave(); 416 461 } 417 462 … … 678 723 679 724 725 int VBoxNetBaseService::startReceiveThreadAndEnterEventLoop() 726 { 727 AssertMsgReturn(isMainNeeded(), ("It's expected that we need Main"), VERR_INTERNAL_ERROR); 728 729 /* start receiving thread */ 730 int rc = RTThreadCreate(&m->m_hThrRecv, /* thread handle*/ 731 &VBoxNetBaseService::Data::recvLoop, /* routine */ 732 this, /* user data */ 733 128 * _1K, /* stack size */ 734 RTTHREADTYPE_IO, /* type */ 735 0, /* flags, @todo: waitable ?*/ 736 "RECV"); 737 AssertRCReturn(rc,rc); 738 739 m->m_EventQ = com::NativeEventQueue::getMainEventQueue(); 740 AssertPtrReturn(m->m_EventQ, VERR_INTERNAL_ERROR); 741 742 while(true) 743 { 744 m->m_EventQ->processEventQueue(0); 745 746 if (m->fShutdown) 747 break; 748 749 m->m_EventQ->processEventQueue(500); 750 } 751 752 return VINF_SUCCESS; 753 } 754 755 680 756 void VBoxNetBaseService::debugPrint(int32_t iMinLevel, bool fMsg, const char *pszFmt, ...) const 681 757 { -
trunk/src/VBox/NetworkServices/NetLib/VBoxNetBaseService.h
r49832 r49842 30 30 31 31 32 class VBoxNetLockee 33 { 34 public: 35 virtual int syncEnter() = 0; 36 virtual int syncLeave() = 0; 37 }; 38 39 40 class VBoxNetALock 41 { 42 public: 43 VBoxNetALock(VBoxNetLockee *a_lck):m_lck(a_lck) 44 { 45 if (m_lck) 46 m_lck->syncEnter(); 47 } 48 49 ~VBoxNetALock() 50 { 51 if (m_lck) 52 m_lck->syncLeave(); 53 } 54 55 private: 56 VBoxNetLockee *m_lck; 57 }; 58 32 59 # ifndef BASE_SERVICES_ONLY 33 class VBoxNetBaseService: public VBoxNetHlpUDPService 60 class VBoxNetBaseService: public VBoxNetHlpUDPService, public VBoxNetLockee 34 61 { 35 62 public: … … 48 75 void const *pvData, size_t cbData) const; 49 76 virtual void usage(void) = 0; 50 virtual int run(void) = 0;51 77 virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal) = 0; 52 78 virtual int processFrame(void *, size_t) = 0; … … 56 82 57 83 virtual int init(void); 84 virtual int run(void); 58 85 virtual bool isMainNeeded() const; 59 86 … … 96 123 virtual void debugPrintV(int32_t iMinLevel, bool fMsg, const char *pszFmt, va_list va) const; 97 124 125 private: 98 126 void doReceiveLoop(); 99 127 100 protected: 128 /** starts receiving thread and enter event polling loop. */ 129 int startReceiveThreadAndEnterEventLoop(); 130 131 protected: 101 132 /* VirtualBox instance */ 102 133 ComPtr<IVirtualBox> virtualbox; 103 134 104 private:135 private: 105 136 struct Data; 106 137 Data *m; 107 138 108 private:139 private: 109 140 PRTGETOPTDEF getOptionsPtr(); 110 141 };
Note:
See TracChangeset
for help on using the changeset viewer.