00001 // Filename: netDatagram.cxx 00002 // Created by: jns (07Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "netDatagram.h" 00016 00017 TypeHandle NetDatagram::_type_handle; 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: NetDatagram::Constructor 00021 // Access: Public 00022 // Description: Constructs an empty datagram. 00023 //////////////////////////////////////////////////////////////////// 00024 NetDatagram:: 00025 NetDatagram() { 00026 } 00027 00028 //////////////////////////////////////////////////////////////////// 00029 // Function: NetDatagram::Constructor 00030 // Access: Public 00031 // Description: Constructs a datagram from an existing block of data. 00032 //////////////////////////////////////////////////////////////////// 00033 NetDatagram:: 00034 NetDatagram(const void *data, size_t size) : 00035 Datagram(data, size) { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: NetDatagram::Copy Constructor 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 NetDatagram:: 00044 NetDatagram(const Datagram ©) : 00045 Datagram(copy) 00046 { 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: NetDatagram::Copy Constructor 00051 // Access: Public 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 NetDatagram:: 00055 NetDatagram(const NetDatagram ©) : 00056 Datagram(copy), 00057 _connection(copy._connection), 00058 _address(copy._address) 00059 { 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: NetDatagram::Copy Assignment Operator 00064 // Access: Public 00065 // Description: 00066 //////////////////////////////////////////////////////////////////// 00067 void NetDatagram:: 00068 operator = (const Datagram ©) { 00069 Datagram::operator = (copy); 00070 _connection.clear(); 00071 _address.clear(); 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: NetDatagram::Copy Assignment Operator 00076 // Access: Public 00077 // Description: 00078 //////////////////////////////////////////////////////////////////// 00079 void NetDatagram:: 00080 operator = (const NetDatagram ©) { 00081 Datagram::operator = (copy); 00082 _connection = copy._connection; 00083 _address = copy._address; 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: NetDatagram::clear 00088 // Access: Public, Virtual 00089 // Description: Resets the datagram to empty, in preparation for 00090 // building up a new datagram. 00091 //////////////////////////////////////////////////////////////////// 00092 void NetDatagram:: 00093 clear() { 00094 Datagram::clear(); 00095 _connection.clear(); 00096 _address.clear(); 00097 } 00098 00099 //////////////////////////////////////////////////////////////////// 00100 // Function: NetDatagram::set_connection 00101 // Access: Public 00102 // Description: Specifies the socket to which the datagram should be 00103 // written. 00104 //////////////////////////////////////////////////////////////////// 00105 void NetDatagram:: 00106 set_connection(const PT(Connection) &connection) { 00107 _connection = connection; 00108 } 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: NetDatagram::set_connection 00112 // Access: Public 00113 // Description: Retrieves the socket from which the datagram was 00114 // read, or to which it is scheduled to be written. 00115 //////////////////////////////////////////////////////////////////// 00116 PT(Connection) NetDatagram:: 00117 get_connection() const { 00118 return _connection; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: NetDatagram::set_address 00123 // Access: Public 00124 // Description: Specifies the host to which the datagram should be 00125 // sent. 00126 //////////////////////////////////////////////////////////////////// 00127 void NetDatagram:: 00128 set_address(const NetAddress &address) { 00129 _address = address; 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: NetDatagram::set_address 00134 // Access: Public 00135 // Description: Retrieves the host from which the datagram was 00136 // read, or to which it is scheduled to be sent. 00137 //////////////////////////////////////////////////////////////////// 00138 const NetAddress &NetDatagram:: 00139 get_address() const { 00140 return _address; 00141 }