
Events property
Reference to event handlers.
Type
VPNEventsStruct structure.Syntax
- C++
VPNEventsStruct Events;
The Events() syntax has these parts:
The Events() syntax has these parts:
Return value | Returns pointer to internal events structure. |
Remarks
To use specific event with devVPN, you must implement your own function that has same declaration as the event, and give a reference to VPNEventsStruct for the function. VPNEventStruct members correspond to events, and default to NULL. Below in code samples is shown how to do it for some events.This is the declaration of VPNEventsStruct
typedef struct VPNEventsStruct
{
void (*StateChange)(CVPN *vpn, States state);
bool (*PeerConnecting)(CVPN *vpn, CP2P *p2p, char *peerName, char *peerAddrs);
void (*PeerConnected)(CVPN *vpn, CP2P *p2p, char *address, int port);
void (*PeerDisconnected)(CVPN *vpn, CP2P *p2p, Errors error);
} VPNEventsStruct;
Code sample
- C++
void vpn_StateChange(devP2Plib::CVPN *vpn, devP2Plib::States state)
{
printf("State changed to %s\r\n", vpn->StateText(state));
}
bool vpn_PeerConnecting(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, char *peerName, char *peerAddrs)
{
printf("PeerConnecting %s\r\n", peerName);
return true;
}
void vpn_PeerConnected(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, char *address, int port)
{
struct in_addr ina;
ina.s_addr = p2p->PeerAdapterIP;
printf("PeerConnected %s, IP %s\r\n", p2p->PeerName, inet_ntoa(ina));
}
void vpn_PeerDisconnected(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, devP2Plib::Errors error)
{
struct in_addr ina;
ina.s_addr = p2p->PeerAdapterIP;
printf("PeerDisconnected %s, IP %s (%s)\r\n", p2p->PeerName, inet_ntoa(ina), vpn->ErrorText(error));
}
/* ...... */
int main(int argc, char **argv)
{
devP2Plib::CVPN *vpnhost;
vpnhost = devP2Plib::CVPN::Create();
vpnhost->Events.PeerConnected = vpn_PeerConnected;
vpnhost->Events.PeerConnecting = vpn_PeerConnecting;
vpnhost->Events.PeerDisconnected = vpn_PeerDisconnected;
vpnhost->Events.StateChange = vpn_StateChange;
/* ..... */
}
{
printf("State changed to %s\r\n", vpn->StateText(state));
}
bool vpn_PeerConnecting(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, char *peerName, char *peerAddrs)
{
printf("PeerConnecting %s\r\n", peerName);
return true;
}
void vpn_PeerConnected(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, char *address, int port)
{
struct in_addr ina;
ina.s_addr = p2p->PeerAdapterIP;
printf("PeerConnected %s, IP %s\r\n", p2p->PeerName, inet_ntoa(ina));
}
void vpn_PeerDisconnected(devP2Plib::CVPN *vpn, devP2Plib::CP2P *p2p, devP2Plib::Errors error)
{
struct in_addr ina;
ina.s_addr = p2p->PeerAdapterIP;
printf("PeerDisconnected %s, IP %s (%s)\r\n", p2p->PeerName, inet_ntoa(ina), vpn->ErrorText(error));
}
/* ...... */
int main(int argc, char **argv)
{
devP2Plib::CVPN *vpnhost;
vpnhost = devP2Plib::CVPN::Create();
vpnhost->Events.PeerConnected = vpn_PeerConnected;
vpnhost->Events.PeerConnecting = vpn_PeerConnecting;
vpnhost->Events.PeerDisconnected = vpn_PeerDisconnected;
vpnhost->Events.StateChange = vpn_StateChange;
/* ..... */
}
Platforms
WindowsMac OSX
Linux
BSD
iPhone IOS