Buffer simplifications, preparations and additions.

This commit is contained in:
Thulinma 2013-12-03 10:06:45 +01:00
parent 045fe1cd70
commit 4ad866cc61
6 changed files with 104 additions and 127 deletions

View file

@ -7,9 +7,41 @@
#include <mist/json.h>
#include <mist/socket.h>
#include "tinythread.h"
#include "buffer_user.h"
namespace Buffer {
/// Converts a stats line to up, down, host, connector and conntime values.
class Stats{
public:
unsigned int up;///<The amount of bytes sent upstream.
unsigned int down;///<The amount of bytes received downstream.
std::string host;///<The connected host.
std::string connector;///<The connector the user is connected with.
unsigned int conntime;///<The amount of time the user is connected.
Stats(std::string s);
Stats();
};
///\brief Keeps track of connected users.
///
///Keeps track of which buffer the user currently uses,
///and its connection status.
class user{
public:
DTSC::Ring * myRing; ///< Ring of the buffer for this user.
unsigned int playUntil; ///< Time until where is being played or zero if undefined.
Stats lastStats; ///< Holds last known stats for this connection.
Stats tmpStats; ///< Holds temporary stats for this connection.
std::string sID; ///< Holds the connection ID.
unsigned int curr_up; ///< Holds the current estimated transfer speed up.
unsigned int curr_down; ///< Holds the current estimated transfer speed down.
Socket::Connection S; ///< Connection to user
/// Creates a new user from a newly connected socket.
user(Socket::Connection fd, long long int ID);
/// Disconnects the current user. Doesn't do anything if already disconnected.
void Disconnect(std::string reason);
};
/// Keeps track of a single streams inputs and outputs, taking care of thread safety and all other related issues.
class Stream : public DTSC::Stream{
public:
@ -43,12 +75,10 @@ namespace Buffer {
~Stream();
/// TODO: WRITEME
bool parsePacket(std::string & buffer);
bool parsePacket(Socket::Buffer & buffer);
bool parsePacket(Socket::Connection & c);
DTSC::livePos getNext(DTSC::livePos & pos, std::set<int> & allowedTracks);
private:
void deletionCallback(DTSC::livePos deleting);
volatile int readers; ///< Current count of active readers;
volatile int writers; ///< Current count of waiting/active writers.
tthread::mutex rw_mutex; ///< Mutex for read/write locking.
tthread::condition_variable rw_change; ///< Triggered when reader/writer count changes.
static Stream * ref;