summaryrefslogtreecommitdiff
path: root/client/networksender.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/networksender.cc')
-rw-r--r--client/networksender.cc54
1 files changed, 32 insertions, 22 deletions
diff --git a/client/networksender.cc b/client/networksender.cc
index b43dcc8..e51fbe3 100644
--- a/client/networksender.cc
+++ b/client/networksender.cc
@@ -25,18 +25,26 @@
* 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 <util.h>
NetworkSender::NetworkSender(QString cpr)
{
- ip = "127.0.0.1";
- port = 6666;
+ if(MIaV::config->get("server_addr", &ip))
+ MIaV::info->error("Could not read the symbol [server_addr] from the donf file!");
+
+ if(MIaV::config->get("server_port", &port))
+ MIaV::info->error("Could not read the symbol [server_port] from the donf file!");
// Connect
- // sleep(1);
+ socket = new Socket(port);
+ socket->sconnect((char*)ip.c_str());
+ network = new Network(socket);
+
server_diskspace = 0xffffffff;
server_diskspace_max = 0xffffffff;
server_load = 0xffffffff;
@@ -51,12 +59,12 @@ NetworkSender::NetworkSender(QString cpr)
NetworkSender::~NetworkSender()
{
+ sleep(1); // FIXME: This is needed to prevent a crash!
+
// Disconnect
- sleep_1_frame();
- sleep_1_frame();
- sleep_1_frame();
- sleep_1_frame();
-
+ delete network;
+ delete socket;
+
fprintf(stderr, "Disconnect [%p]\n", this);
}
@@ -88,6 +96,8 @@ unsigned int NetworkSender::queueSize()
void NetworkSender::run()
{
+ setPriority(QThread::IdlePriority);
+
fprintf(stderr, " Run %p\n", this);
while(running) {
@@ -99,26 +109,26 @@ void NetworkSender::run()
mutex.unlock();
if(frame) {
- // TODO: Send it over the network
- sleep_1_frame();
- sleep_1_frame();
- sleep_1_frame();
- sleep_1_frame();
+ // Send the frame over the network
+ network->sendFrame(frame);
if(frame->vframe) delete frame->vframe;
if(frame->aframe) delete frame->aframe;
delete frame;
- // TODO: Read status from network
+ // Status status;
+ // network->recvStatus(&status);
+
// Set status
statusmutex.lock();
- server_diskspace_max = 1000000;
- if(server_diskspace == 0xffffffff) server_diskspace = server_diskspace_max;
- server_diskspace -= (int)(((double)rand() / (double)RAND_MAX) * 10.0);
-
- server_load = 90 + (int)(((double)rand() / (double)RAND_MAX) * 10.0);
- server_load_max = 100;
- server_ping_ms = (int)(((double)rand() / (double)RAND_MAX) * 100);
- server_fps = 25.0;
+ 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;
+
statusmutex.unlock();
}
}