summaryrefslogtreecommitdiff
path: root/client/networksender.cc
diff options
context:
space:
mode:
authordeva <deva>2006-08-25 21:20:07 +0000
committerdeva <deva>2006-08-25 21:20:07 +0000
commit8196872e3b240ef93fc17dd3c05a7d97a8015d88 (patch)
treee531edeb1c7178a8e58170c84645ce8eb706624e /client/networksender.cc
parent347b1d8ed3a4f780f3a5c0d57a04eab05ca517a2 (diff)
Rearranged the network and socket code.origin
Added status messages sent over the network using udp packets.
Diffstat (limited to 'client/networksender.cc')
-rw-r--r--client/networksender.cc76
1 files changed, 46 insertions, 30 deletions
diff --git a/client/networksender.cc b/client/networksender.cc
index e51fbe3..0aa1036 100644
--- a/client/networksender.cc
+++ b/client/networksender.cc
@@ -25,35 +25,41 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "networksender.h"
-#include "status.h"
#include "configuration.h"
#include "info.h"
+#include <sys/time.h>
+
#include <util.h>
NetworkSender::NetworkSender(QString cpr)
{
if(MIaV::config->get("server_addr", &ip))
- MIaV::info->error("Could not read the symbol [server_addr] from the donf file!");
+ MIaV::info->error("Could not read the symbol [server_addr] from the conf file!");
if(MIaV::config->get("server_port", &port))
- MIaV::info->error("Could not read the symbol [server_port] from the donf file!");
+ MIaV::info->error("Could not read the symbol [server_port] from the conf file!");
// Connect
- socket = new Socket(port);
- socket->sconnect((char*)ip.c_str());
+ socket = new TCPSocket(port, ip);
+ if(socket->connect()) {
+ MIaV::info->error("Could not connect to %s on port %d because: %s",
+ ip.c_str(), port, socket->error().c_str());
+ }
network = new Network(socket);
- server_diskspace = 0xffffffff;
- server_diskspace_max = 0xffffffff;
- server_load = 0xffffffff;
- server_load_max = 0xffffffff;
- server_ping_ms = 0xffffffff;
- server_fps = -1.0;
+ fps = 0.0;
running = true;
+ gettimeofday(&oldtime, NULL);
+ for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
+ frametime[cnt] = 41660;
+ }
+ gettimeofday(&time, NULL);
+ interval = 0;
+
fprintf(stderr, "Connect [%p]\n", this);
}
@@ -115,20 +121,9 @@ void NetworkSender::run()
if(frame->aframe) delete frame->aframe;
delete frame;
- // Status status;
- // network->recvStatus(&status);
-
// Set status
statusmutex.lock();
- server_diskspace_max = 0;//status.diskspace_max;
- server_diskspace = 0;//status.server_diskspace;
- server_load = 0;//status.load;
- server_load_max = 0;//status.load_max;
-
- // TODO: Calculate these values.
- server_ping_ms = 0;
- server_fps = 0;
-
+ checkPoint();
statusmutex.unlock();
}
}
@@ -144,14 +139,35 @@ void NetworkSender::stop()
terminatesemaphore.acquire(); // Wait for the thread to stop
}
-void NetworkSender::getServerStatus(Status *status)
+double NetworkSender::getfps()
{
+ double f;
+
statusmutex.lock();
- status->server_diskspace = server_diskspace;
- status->server_diskspace_max = server_diskspace_max;
- status->server_load = server_load;
- status->server_load_max = server_load_max;
- status->server_ping_ms = server_ping_ms;
- status->server_fps = server_fps;
+ f = fps;
statusmutex.unlock();
+
+ return f;
}
+
+void NetworkSender::checkPoint()
+{
+ for(int cnt = BUFFERSIZE - 1; cnt > 0; cnt--) {
+ frametime[cnt] = frametime[cnt-1];
+ }
+
+ frametime[0] = (1000000 * time.tv_sec + time.tv_usec) - (1000000 * oldtime.tv_sec + oldtime.tv_usec);
+
+ oldtime.tv_sec = time.tv_sec;
+ oldtime.tv_usec = time.tv_usec;
+
+ gettimeofday(&time, NULL);
+
+ double total = 0.0;
+ for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
+ total += (double)frametime[cnt];
+ }
+ fps = 1000000.0 / (total / (double)BUFFERSIZE);
+
+}
+