HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_ConnectionHandler.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: NET_ConnectionHandler.h
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __NET_CONNECTIONHANDLER_H__
13 #define __NET_CONNECTIONHANDLER_H__
14 
15 #include "NET_API.h"
16 
17 #include "NET_Error.h"
18 #include "NET_InfoCallback.h"
19 
20 #include <UT/UT_Debug.h>
21 #include <UT/UT_BoostAsio.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <UT/UT_NonCopyable.h>
24 #include <UT/UT_Set.h>
25 #include <UT/UT_Lock.h>
26 #include <UT/UT_SharedPtr.h>
27 
28 #include <SYS/SYS_AtomicInt.h>
29 
31 
33 {
34 public:
37 
39  {
40  myInfoCallback = std::move(info_clb);
41  }
42 protected:
44  myConnectionManager(conn_mgr)
45  {
46  }
47 
48  friend class NET_ConnectionManager;
49 
50  virtual void start() = 0;
51  virtual void stop(bool force) = 0;
52 
54 
56 };
57 
59 
61 {
62 public:
63  void start(const NET_ConnectionHandlerSPtr& handler)
64  {
65  UT_ASSERT(handler != nullptr);
66  {
67  UT_AutoLock lock(myLock);
68  myConnections.insert(handler);
69  }
70  handler->start();
71  }
72  void stop(const NET_ConnectionHandlerSPtr& handler)
73  {
74  UT_ASSERT(handler != nullptr);
75  {
76  UT_AutoLock lock(myLock);
77  myConnections.erase(handler);
78  }
79  handler->stop(true /*force*/);
80  }
81  void remove(const NET_ConnectionHandlerSPtr& handler)
82  {
83  UT_ASSERT(handler != nullptr);
84  UT_AutoLock lock(myLock);
85  myConnections.erase(handler);
86  }
87  void stopAll(bool force)
88  {
90  {
91  UT_AutoLock lock(myLock);
92  myConnections.swap(connections);
93  myConnections.clear();
94  }
95  // It is possible that the stop calls back into this objects stop which
96  // will invalidate the iterator. Use a temp object to hold the
97  // connections we need to stop to ensure calling stop from within
98  // the users stop doesnt cause undefined behaviour.
99  for (auto&& handler : connections)
100  {
101  UT_ASSERT(handler != nullptr);
102  handler->stop(force);
103  }
104  }
105 
106 private:
107  UT_Lock myLock;
108  UT_Set<NET_ConnectionHandlerSPtr> myConnections;
109 };
110 
111 #endif // __NET_CONNECTIONHANDLER_H__
112 
void stop(const NET_ConnectionHandlerSPtr &handler)
UT_UniquePtr< NET_InfoCallback > myInfoCallback
GLuint start
Definition: glcorearb.h:475
NET_ConnectionHandler(NET_ConnectionManager &conn_mgr)
void start(const NET_ConnectionHandlerSPtr &handler)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define NET_API
Definition: NET_API.h:9
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
UT_SharedPtr< NET_ConnectionHandler > NET_ConnectionHandlerSPtr
SIM_API const UT_StringHolder force
NET_ConnectionManager & myConnectionManager
void setInfoCallback(UT_UniquePtr< NET_InfoCallback > info_clb)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156