Stroika Library
3.0d16
Help-Home
Loading...
Searching...
No Matches
LinkMonitor.h
Go to the documentation of this file.
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#ifndef _Stroika_Foundation_IO_Network_LinkMonitor_h_
5
#define _Stroika_Foundation_IO_Network_LinkMonitor_h_ 1
6
7
#include "Stroika/Foundation/StroikaPreComp.h"
8
9
#if qStroika_Foundation_Common_Platform_POSIX
10
#include <arpa/inet.h>
11
#elif qStroika_Foundation_Common_Platform_Windows
12
#include <WinSock2.h>
13
14
#include <in6addr.h>
15
#include <inaddr.h>
16
#endif
17
18
#include "
Stroika/Foundation/Characters/String.h
"
19
#include "Stroika/Foundation/Common/Common.h"
20
#include "
Stroika/Foundation/Execution/Function.h
"
21
#include "
Stroika/Foundation/IO/Network/InternetAddress.h
"
22
23
/**
24
* \file
25
*
26
* \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
27
*
28
* TODO:
29
* @todo Should this API be renamed InterfaceMonitor? Probably yes?
30
*
31
* @todo Optimize of listener is STATIC - and so we only register one (and esp on linux with threads)
32
* only one thread - and fan out to all subscribers. SB pretty easy - just make data static,
33
* but I guess one trick is then you need to be able to remove callbacks (ours - need Function).
34
*
35
* @todo LinkMonitor rnetlink support DELETE
36
*
37
* @todo Support remove callback (once we have new FUNCTION helper - copyable stdfunction) - and usethat
38
* for SignalHandlers as well.
39
*/
40
41
namespace
Stroika::Foundation::IO::Network
{
42
43
using
Characters::String;
44
45
//
46
// @todo Move to Interace API???
47
//
48
//// add options for filtering out disabled ones (not onlnie)
49
/// add optikon for fitlering out localhost
50
//
51
// This isn't always well defined, but is typically. This is the primary ip address used to address this machine.
52
// This CAN return an empty address if none available (like not connected to a network).
53
//. (if no net do we return localhost?))
54
//
55
// @todo THIS WHOLE API SUCKS (IPV4 or IPV6, and what doees this man for multihomed devices?
56
InternetAddress
GetPrimaryInternetAddress
();
57
58
//
59
// @todo Move to Interace API???
60
//
61
// Usefull as a (semi)persisent seed for GUIDs etc
62
// Otherwise, not super-well defined
63
// THINK OUT RELATION BETWEENT HIS AND GetPrimaryInternetAddress???
64
//
65
// think through and document error conditions
66
String GetPrimaryNetworkDeviceMacAddress ();
67
68
/**
69
* Create an instance of this class, and add callbacks to it, and they will be notified
70
* when a network connection comes up or down.
71
*
72
* @todo POSIX code is not really posix but assumes linux==posix =- relaly need separate define to check for netlink
73
* and a windoze impl.
74
*
75
* @todo Decide if this should always auto-call the callback when first loaded? Might be an easier to use
76
* API (with added - for any existing interfaces)? Windoze makes that easy, but not sure about rnetlink?
77
*/
78
struct
LinkMonitor
{
79
LinkMonitor
();
80
LinkMonitor
(
LinkMonitor
&& rhs)
noexcept
=
default
;
81
LinkMonitor
(
const
LinkMonitor
&) =
delete
;
82
83
LinkMonitor
& operator= (
LinkMonitor
&& rhs)
noexcept
=
default
;
84
LinkMonitor
& operator= (
const
LinkMonitor
&) =
delete
;
85
86
enum class
LinkChange {
87
eAdded,
88
eRemoved,
89
};
90
using
Callback
=
Execution::Function
<void (LinkChange,
const
String
& linkName,
const
String
& ipAddr)>;
91
nonvirtual
void
AddCallback (
const
Callback
& callback);
92
nonvirtual
void
RemoveCallback (
const
Callback
& callback);
93
94
private
:
95
struct
Rep_;
96
shared_ptr<Rep_> fRep_;
97
};
98
99
}
100
101
/*
102
********************************************************************************
103
***************************** Implementation Details ***************************
104
********************************************************************************
105
*/
106
#include "LinkMonitor.inl"
107
108
#endif
/*_Stroika_Foundation_IO_Network_LinkMonitor_h_*/
Function.h
InternetAddress.h
String.h
Stroika::Foundation::Characters::String
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition
String.h:201
Stroika::Foundation::Execution::Function
Definition
Function.h:59
Stroika::Foundation::IO::Network
Definition
Cryptography/SSL/SocketStream.inl:5
Stroika::Foundation::IO::Network::GetPrimaryInternetAddress
InternetAddress GetPrimaryInternetAddress()
Definition
LinkMonitor.cpp:135
Stroika::Foundation::IO::Network::LinkMonitor
Definition
LinkMonitor.h:78
Library
Sources
Stroika
Foundation
IO
Network
LinkMonitor.h
Generated by
1.9.8