OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Network2UPnPP Class Reference
Inheritance diagram for C4Network2UPnPP:
[legend]
Collaboration diagram for C4Network2UPnPP:
[legend]

Public Member Functions

 C4Network2UPnPP ()
 
virtual ~C4Network2UPnPP ()
 
void AddMapping (C4Network2IOProtocol protocol, uint16_t intport, uint16_t extport)
 
void ClearMappings ()
 
 C4Network2UPnPP ()=default
 
void AddMapping (C4Network2IOProtocol protocol, uint16_t intport, uint16_t extport)
 
void RemoveMapping (C4Network2IOProtocol protocol, uint16_t extport)
 
void ClearNatMappings ()
 

Public Attributes

bool MustReleaseCOM {false}
 
IStaticPortMappingCollection * mappings {nullptr}
 
std::set< IStaticPortMapping * > added_mappings
 

Private Member Functions

bool AddProc (StdSchedulerProc *pProc)
 
void RemoveProc (StdSchedulerProc *pProc)
 
bool PushEvent (C4InteractiveEventType eEventType, void *pData=nullptr)
 
void ProcessEvents ()
 
bool ThreadLog (const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
 
bool ThreadLogFatal (const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
 
bool ThreadLogS (const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
 
bool ThreadLogDebug (const char *szMessage,...) GNUC_FORMAT_ATTRIBUTE_O
 
template<typename RType = void, typename Functor >
bool ThreadPostAsync (Functor function)
 
void SetCallback (C4InteractiveEventType eEvent, Callback *pnNetworkCallback)
 
void ClearCallback (C4InteractiveEventType eEvent, Callback *pnNetworkCallback)
 

Detailed Description

Definition at line 31 of file C4Network2UPnPLinux.cpp.

Constructor & Destructor Documentation

C4Network2UPnPP::C4Network2UPnPP ( )

Definition at line 64 of file C4Network2UPnPLinux.cpp.

65 {
66  action = std::async(&C4Network2UPnPP::Init, this);
67 }
C4Network2UPnPP::~C4Network2UPnPP ( )
virtual

Definition at line 98 of file C4Network2UPnPLinux.cpp.

References ClearMappings(), and C4InteractiveThread::ProcessEvents().

99 {
100  ClearMappings();
101  action.wait();
102  ProcessEvents(); // necessary for logging
103  if (initialized)
104  {
105  FreeUPNPUrls(&upnp_urls);
106  freeUPNPDevlist(devlist);
107  }
108 }

Here is the call graph for this function:

C4Network2UPnPP::C4Network2UPnPP ( )
default

Member Function Documentation

void C4Network2UPnPP::AddMapping ( C4Network2IOProtocol  protocol,
uint16_t  intport,
uint16_t  extport 
)

Definition at line 110 of file C4Network2UPnPLinux.cpp.

References P_TCP.

111 {
112  PortMapping mapping;
113  mapping.external_port = extport;
114  mapping.internal_port = intport;
115  mapping.protocol = (protocol == P_TCP ? "TCP" : "UDP");
116 
117  added_mappings.push_back(mapping);
118 
119  action = std::async([this, action = std::move(action), mapping]() {
120  action.wait();
121  AddPortMapping(mapping);
122  });
123 }
void C4Network2UPnPP::AddMapping ( C4Network2IOProtocol  protocol,
uint16_t  intport,
uint16_t  extport 
)
void C4Network2UPnPP::ClearMappings ( )

Definition at line 125 of file C4Network2UPnPLinux.cpp.

Referenced by ~C4Network2UPnPP().

126 {
127  action = std::async([this, action = std::move(action)]() {
128  action.wait();
129 
130  for (auto mapping : added_mappings)
131  RemovePortMapping(mapping);
132 
133  added_mappings.clear();
134  });
135 }

Here is the caller graph for this function:

void C4Network2UPnPP::ClearNatMappings ( )

Definition at line 127 of file C4Network2UPnPWin32.cpp.

References LogF(), and mappings.

128 {
129  if (!mappings)
130  return;
131  for(IStaticPortMapping *mapping: added_mappings)
132  {
133  BSTR proto, client;
134  long intport, extport;
135  mapping->get_ExternalPort(&extport);
136  mapping->get_InternalPort(&intport);
137  mapping->get_InternalClient(&client);
138  mapping->get_Protocol(&proto);
139  if (SUCCEEDED(mappings->Remove(extport, proto)))
140  LogF("UPnP: Closed port %d->%s:%d (%s)", (int)extport, StdStrBuf(client).getData(), (int)intport, StdStrBuf(proto).getData());
141  ::SysFreeString(proto);
142  ::SysFreeString(client);
143  SafeRelease(mapping);
144  }
145  SafeRelease(mappings);
146 }
IStaticPortMappingCollection * mappings
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:250

Here is the call graph for this function:

void C4Network2UPnPP::RemoveMapping ( C4Network2IOProtocol  protocol,
uint16_t  extport 
)

Member Data Documentation

std::set<IStaticPortMapping*> C4Network2UPnPP::added_mappings

Definition at line 58 of file C4Network2UPnPWin32.cpp.

IStaticPortMappingCollection* C4Network2UPnPP::mappings {nullptr}

Definition at line 57 of file C4Network2UPnPWin32.cpp.

Referenced by ClearNatMappings().

bool C4Network2UPnPP::MustReleaseCOM {false}

Definition at line 54 of file C4Network2UPnPWin32.cpp.


The documentation for this class was generated from the following files: