PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/cpvt.h

http://datacard.googlecode.com/
C++ Header | 117 lines | 79 code | 26 blank | 12 comment | 7 complexity | 4a2b3deb3fbc89b312300b66a3ccf8cb MD5 | raw file
  1/*
  2   Copyright (C) 2010 bg <bg_one@mail.ru>
  3*/
  4#ifndef CHAN_DATACARD_CPVT_H_INCLUDED
  5#define CHAN_DATACARD_CPVT_H_INCLUDED
  6
  7#include <asterisk.h>
  8#include <asterisk/linkedlists.h>		/* AST_LIST_ENTRY() */
  9#include <asterisk/frame.h>			/* AST_FRIENDLY_OFFSET */
 10
 11#include "export.h"				/* EXPORT_DECL EXPORT_DEF */
 12#include "mixbuffer.h"				/* struct mixstream */
 13#include "mutils.h"				/* enum2str() ITEMS_OF() */
 14
 15#define FRAME_SIZE		320
 16
 17typedef enum {
 18	CALL_STATE_MIN		= 0,
 19
 20/* values from CLCC */
 21	CALL_STATE_ACTIVE	= CALL_STATE_MIN,		/*!< comes from CLCC */
 22	CALL_STATE_ONHOLD,					/*!< comes from CLCC */
 23	CALL_STATE_DIALING,					/*!< comes from CLCC */
 24	CALL_STATE_ALERTING,					/*!< comes from CLCC */
 25	CALL_STATE_INCOMING,					/*!< comes from CLCC */
 26	CALL_STATE_WAITING,					/*!< comes from CLCC */
 27
 28	CALL_STATE_RELEASED,					/*!< on CEND or channel_hangup() called */
 29	CALL_STATE_INIT,					/*!< channel_call() called */
 30	CALL_STATE_MAX		= CALL_STATE_INIT
 31} call_state_t;
 32#define CALL_STATES_NUMBER	(CALL_STATE_MAX - CALL_STATE_MIN + 1)
 33
 34typedef enum {
 35	CALL_FLAG_NONE		= 0,
 36	CALL_FLAG_HOLD_OTHER	= 1,				/*!< external, from channel_call() hold other calls and dial this number */
 37	CALL_FLAG_NEED_HANGUP	= 2,				/*!< internal, require issue AT+CHUP or AT+CHLD=1x for call */
 38	CALL_FLAG_ACTIVATED	= 4,				/*!< internal, fd attached to channel fds list */
 39	CALL_FLAG_ALIVE		= 8,				/*!< internal, temporary, still listed in CLCC */
 40	CALL_FLAG_CONFERENCE	= 16,				/*!< external, from dial() begin conference after activate this call */
 41	CALL_FLAG_MASTER	= 32,				/*!< internal, channel fd[0] is pvt->audio_fd and  fd[1] is timer fd */
 42	CALL_FLAG_BRIDGE_LOOP	= 64,				/*!< internal, found channel bridged to channel on same device */
 43	CALL_FLAG_BRIDGE_CHECK	= 128,				/*!< internal, we already do check for bridge loop */
 44	CALL_FLAG_MULTIPARTY	= 256,				/*!< internal, CLCC mpty is 1 */
 45} call_flag_t;
 46
 47
 48/* */
 49typedef struct cpvt {
 50	AST_LIST_ENTRY (cpvt)	entry;				/*!< linked list pointers */
 51
 52	struct ast_channel*	channel;			/*!< Channel pointer */
 53	struct pvt		*pvt;				/*!< pointer to device structure */
 54
 55	short			call_idx;			/*!< device call ID */
 56#define MIN_CALL_IDX		0
 57#define MAX_CALL_IDX		31
 58
 59	call_state_t		state;				/*!< see also call_state_t */
 60	int			flags;				/*!< see also call_flag_t */
 61
 62/* TODO: join with flags */
 63	unsigned int		dir:1;				/*!< call direction */
 64#define CALL_DIR_OUTGOING	0
 65#define CALL_DIR_INCOMING	1
 66
 67	int			rd_pipe[2];			/*!< pipe for split readed from device */
 68#define PIPE_READ		0
 69#define PIPE_WRITE		1
 70
 71	struct mixstream	mixstream;			/*!< mix stream */
 72	char			a_read_buf[FRAME_SIZE + AST_FRIENDLY_OFFSET];/*!< audio read buffer */
 73	struct ast_frame	a_read_frame;			/*!< readed frame buffer */
 74
 75//	size_t			write;				/*!< write position in pvt->a_write_buf */
 76//	size_t			used;				/*!< bytes used in pvt->a_write_buf */
 77//	char			a_write_buf[FRAME_SIZE * 5];	/*!< audio write buffer */
 78//	struct ringbuffer	a_write_rb;			/*!< audio ring buffer */
 79
 80} cpvt_t;
 81
 82#define CPVT_SET_FLAGS(cpvt, flag)	do { (cpvt)->flags |= (flag); } while(0)
 83#define CPVT_RESET_FLAGS(cpvt, flag)	do { (cpvt)->flags &= ~((int)flag); } while(0)
 84#define CPVT_TEST_FLAG(cpvt, flag)	((cpvt)->flags & (flag))
 85#define CPVT_TEST_FLAGS(cpvt, flag)	(((cpvt)->flags & (flag)) == (flag))
 86
 87#define CPVT_IS_MASTER(cpvt)		CPVT_TEST_FLAG(cpvt, CALL_FLAG_MASTER)
 88#define CPVT_IS_ACTIVE(cpvt)		((cpvt)->state == CALL_STATE_ACTIVE)
 89#define CPVT_IS_SOUND_SOURCE(cpvt)	((cpvt)->state == CALL_STATE_ACTIVE || (cpvt)->state == CALL_STATE_DIALING || (cpvt)->state == CALL_STATE_ALERTING)
 90
 91
 92EXPORT_DECL struct cpvt * cpvt_alloc(struct pvt * pvt, int call_idx, unsigned dir, call_state_t statem);
 93EXPORT_DECL void cpvt_free(struct cpvt* cpvt);
 94
 95EXPORT_DECL struct cpvt * pvt_find_cpvt(struct pvt * pvt, int call_idx);
 96
 97#/* */
 98INLINE_DECL const char * call_state2str(call_state_t state)
 99{
100	static const char * const states[] = {
101	/* real device states */
102		"active",
103		"held",
104		"dialing",
105		"alerting",
106		"incoming",
107		"waiting",
108
109	/* pseudo states */
110		"released",
111		"initialize"
112	};
113
114	return enum2str(state, states, ITEMS_OF(states));
115}
116
117#endif /* CHAN_DATACARD_CPVT_H_INCLUDED */