vcglib/apps/nexus/nxsdispatcher.h

92 lines
1.7 KiB
C
Raw Normal View History

2004-11-28 05:16:19 +01:00
#ifndef NXS_DISPATCHER_H
#define NXS_DISPATCHER_H
2004-11-18 19:30:15 +01:00
#include <ptypes/pinet.h>
#include <ptypes/pasync.h>
#include <vector>
#include <map>
#include <string>
2004-11-28 08:58:49 +01:00
#include "decimate.h"
2004-11-18 19:30:15 +01:00
namespace nxs {
#define MSG_SEND MSG_USER + 1
#define MSG_RECEIVE MSG_USER + 2
#define MSG_FAIL MSG_USER + 3
class Fragment;
class Nexus;
2004-12-02 21:16:13 +01:00
class VChain;
2004-11-18 19:30:15 +01:00
class Server;
class FragIO;
class Dispatcher;
class Opener: public pt::thread {
public:
Opener(Server *s): thread(false), server(s) {}
~Opener() { waitfor(); }
void execute();
void cleanup() {}
Server *server;
};
class Server: public pt::ipstream {
public:
2004-11-28 02:23:26 +01:00
Server(pt::string host, int port): ipstream(host, port), queue(0),
2004-11-18 19:30:15 +01:00
connected(false), opener(this) {}
int queue;
pt::mutex reading;
pt::mutex writing;
bool connected;
Opener opener;
};
class Dispatcher: public pt::msgqueue {
public:
2004-12-02 21:16:13 +01:00
Dispatcher(Nexus *nx, VChain *ch):
2004-11-28 02:23:26 +01:00
count(0), maxqueue(3), nexus(nx), chain(ch) {}
2004-11-18 19:30:15 +01:00
~Dispatcher();
bool Init(const std::string &file);
void SendFragment(Fragment *frag);
void ReceiveFragment(Fragment *in, Fragment *out);
Server *BestServer();
void msghandler(pt::message &msg);
int count;
2004-11-28 02:23:26 +01:00
int maxqueue;
2004-11-18 19:30:15 +01:00
Nexus *nexus;
2004-12-02 21:16:13 +01:00
VChain *chain;
2004-11-28 08:58:49 +01:00
Decimation mode;
float scaling;
2004-11-18 19:30:15 +01:00
std::vector<Server *> servers;
std::map<int, FragIO *> frags;
};
class FragIO: public pt::thread {
public:
FragIO(Server *se, Dispatcher *di, Fragment *frag):
thread(false), server(se), dispatcher(di), fragin(frag) {}
~FragIO() { waitfor(); }
void execute();
void cleanup() {}
Server *server;
Dispatcher *dispatcher;
Fragment *fragin;
};
}
2004-11-28 05:16:19 +01:00
2004-12-02 21:16:13 +01:00
#endif