stream_pool.h 2.51 KB
#ifndef SCOT_STREAM_POOL_H
#define SCOT_STREAM_POOL_H

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include <scot/event_listener.h>
#include <scot/stream.h>
#include <scot/thread.h>
#include <scot/stream_pool_fraction.h>

#define GEN_LOCAL
# include <scot/list.h>
#undef  GEN_LOCAL

/*
 * folgende masken dienen dazu zu bestimmen in welches fd_set
 * (read, write, exception) ein filehandle eingetragen werden soll.
 * D.h. für welche operation der select diesen handle überwachen soll.
 */
#define SCOT_STREAM_POOL_FD_ADD_RMASK        0x1
#define SCOT_STREAM_POOL_FD_ADD_WMASK        0x2
#define SCOT_STREAM_POOL_FD_ADD_EMASK        0x4

#define SCOT_STREAM_POOL_CLEANUP             0x00
#define SCOT_STREAM_POOL_RESTART_FRACTION    0x01
#define SCOT_STREAM_POOL_START_FRACTION      0x02
#define SCOT_STREAM_POOL_STOP_FRACTION       0x03
#define SCOT_STREAM_POOL_RESTART_ALL_FRAC    0x04
#define SCOT_STREAM_POOL_START_ALL_FRAC      0x05
#define SCOT_STREAM_POOL_STOP_ALL_FRAC       0x06

#define SCOT_STREAM_POOL_KEEP_STREAMS        0x0
#define SCOT_STREAM_POOL_FREE_STREAMS        0x1


typedef struct scot_sp_fraction scot_sp_fraction;
GEN_LIST_TYPE_PROTO (scot_sp_fraction);

struct scot_stream_pool
{
	struct scot_event_listener el;

	uint16_t cmd;
	void *   cmd_arg;
	THREAD_COND_T    cmd_cond;
	THREAD_COND_CS_T cmd_cs;

	list_scot_sp_fraction_node_t * pool;
	THREAD_MUTEX_T mutex;
};


struct scot_stream_pool * scot_stream_pool_new     (struct scot_stream_pool *);
void                      scot_stream_pool_free    (struct scot_stream_pool *);
void                      scot_stream_pool_free_s  (struct scot_stream_pool *,
                                                    int);
void                      scot_stream_pool_add     (struct scot_stream_pool *, 
                                                    struct scot_stream *,
                                                    int);
void                      scot_stream_pool_remove  (struct scot_stream_pool *,
                                                    struct scot_stream *,
                                                    int);
int                       scot_stream_pool_get_rwe (struct scot_stream_pool *, 
                                                    struct scot_stream *);
void                      scot_stream_pool_cmd     (struct scot_stream_pool *,
                                                    uint16_t,
																	 void *);
struct scot_stream *      scot_sp_get_all_streams  (struct scot_stream_pool *);

#endif /* SCOT_STREAM_POOL_H */