brmlife/connection.h
Petr Baudis 93882f79b9 Track agent energy
Base energy, move energy
2011-11-27 02:32:59 +01:00

46 lines
651 B
C++

#ifndef BRMLIFE__CONNECTION_H
#define BRMLIFE__CONNECTION_H
#include <string>
#include <pthread.h>
#include <unistd.h>
#include "map.h"
class agent;
class connection {
public:
int fd;
bool error;
connection(int fd_)
: fd(fd_), error(false)
{
spawn_thread();
}
~connection()
{
close(fd);
}
void senses(int tick_id, int energy, char around[4]);
void actions(class agent *);
void cancel(void);
private:
std::string out_buf, in_buf;
pthread_mutex_t buf_lock;
pthread_cond_t cancel_cond;
pthread_mutex_t cancel_lock;
void spawn_thread(void);
friend void *conn_thread_worker(void *ctx);
void thread_loop(void);
};
#endif