src/Network/Node.hh
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 03:02:02 +0200
changeset 441 f769fab21a6c
parent 431 c6d7272a164b
permissions -rw-r--r--
fix bug with NetworkBufferOutput where push_write doesn't update offset
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
#ifndef NETWORK_NODE_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     2
#define NETWORK_NODE_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     3
400
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     4
/**
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     5
 * @file
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     6
 *
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     7
 * Remote NetworkSessions
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     8
 */
d64bf28c4340 more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents: 286
diff changeset
     9
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    10
// forward-declare
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    11
class NetworkNode;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    13
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    14
 * Used to differentiate between different kinds of nodes in NetworkSession::build_node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    15
 *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    16
 * @see NetworkSession::build_node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    17
 */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
enum NetworkNodeType {
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    19
    NETWORK_NODE_SERVER_CLIENT,     //<<< A server's client
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    20
    NETWORK_NODE_CLIENT_SERVER      //<<< A client's server
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    21
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    23
#include "TCP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    24
#include "UDP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    25
#include "Session.hh"
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    26
#include "Target.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    27
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    28
/**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    29
 * A NetworkNode represents a remote NetworkSession connected to our NetworkSession.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    30
 *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    31
 * A NetworkNode has a tcp connection, plus an udp socket to us (either NetworkSession's udp_srv or udp_client)
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    32
 *
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    33
 * NetworkNode implements the NetworkTarget interface, so you can use send()
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    34
 */
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    35
class NetworkNode : public NetworkTarget {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    36
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    37
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    38
         * Our local NetworkSession
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    39
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    40
        NetworkSession &session;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    41
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    42
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    43
         * The TCP connection
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    44
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    45
        NetworkTCPTransport *tcp;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    46
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    47
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    48
         * Our NetworkSession's UDP socket that we should use to send UDP packets to this node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    49
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    50
        NetworkUDP *udp;
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    51
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    52
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    53
         * This address that the node connected from using TCP, used to associate received UDP packets with this node
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    54
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    55
        const NetworkAddress address;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    56
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    57
        CL_SlotContainer slots;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    58
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    59
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    60
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    61
         * Construct a new NetworkNode from the given tcp/udp sockets and address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    62
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    63
         * @param session our NetworkSession
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    64
         * @param tcp this node's TCP socket
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    65
         * @param udp the UDP socket to use for outgoing packets
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    66
         * @param address the remote address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    67
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    68
        NetworkNode (NetworkSession &session, NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &address);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    69
        
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    70
    private:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    71
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    72
         * Node should not be copied
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    73
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    74
        NetworkNode (const NetworkNode &copy);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    75
        ~NetworkNode (void);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    76
        NetworkNode& operator= (const NetworkNode &copy);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    77
        
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    78
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    79
         * Our TCP socket indicates disconnect, tell NetworkSession and trigger sig_disconnect
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    80
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    81
        void on_disconnect (void);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    82
         
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    83
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    84
         * Our disconnect signal
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    85
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    86
        CL_Signal_v0 _sig_disconnected;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    87
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    88
    protected:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    89
        /**
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    90
         * Send the given packet to this node, used by NetworkTarget
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    91
         */
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    92
        virtual void send_pkt (const NetworkPacketBuffer &pkt, bool reliable = true);
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    93
        
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 400
diff changeset
    94
    public:
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    95
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    96
         * Get this node's remote address (both TCP and UDP).
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    97
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    98
         * @return NetworkAddress the remote address
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
    99
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   100
        const NetworkAddress& getRemoteAddress (void);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   101
        
286
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   102
        /**
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   103
         * This node's TCP connection was lost, and the node has been removed from the NetworkSession's nodes list.
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   104
         *
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   105
         * Once this completes, the node will be destructed
2a8f20a53ff2 more network documentation
terom
parents: 202
diff changeset
   106
         */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   107
        CL_Signal_v0& sig_disconnected (void) { return _sig_disconnected; }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   108
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   109
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   110
#endif /* NETWORK_NODE_HH */