[svn-commits] tzafrir: branch tzafrir/monitor-rtp r224438 - in /team/tzafrir/monitor-rtp: i...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Oct 18 13:24:31 CDT 2009


Author: tzafrir
Date: Sun Oct 18 13:24:24 2009
New Revision: 224438

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=224438
Log:
Cleaner write-by-FD interface

file.h now has:

struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type);

void* ast_filestream_get_fd_state(struct ast_filestream *fs);

ast_writefd() is similar to ast_writefile() - initiates writing to a
file. However it gets a file descriptor and a pointer to a state
information struct.

ast_filestream_get_fd_state() returns that state information struct.

In order to avoid breaking ABI, the filename field is still (ab)used to
save the state information pointer.

(ast_writefd() was previously a local function called indirectly through
ast_writefile() and ast_filestream_get_fd_state() had a temporary name)

Modified:
    team/tzafrir/monitor-rtp/include/asterisk/file.h
    team/tzafrir/monitor-rtp/main/file.c
    team/tzafrir/monitor-rtp/res/res_monitor.c

Modified: team/tzafrir/monitor-rtp/include/asterisk/file.h
URL: http://svnview.digium.com/svn/asterisk/team/tzafrir/monitor-rtp/include/asterisk/file.h?view=diff&rev=224438&r1=224437&r2=224438
==============================================================================
--- team/tzafrir/monitor-rtp/include/asterisk/file.h (original)
+++ team/tzafrir/monitor-rtp/include/asterisk/file.h Sun Oct 18 13:24:24 2009
@@ -181,6 +181,17 @@
  */
 struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode);
 
+/*!
+ * \brief Starts writing a filestream, as passed through a file-descriptor
+ * \param stateinfo
+ * \param fd number of filedescriptor
+ * \param type format of file you wish to write out to
+ * Please note, this is a blocking function.  Program execution will not return until ast_waitstream completes it's execution.
+ * \retval a struct ast_filestream on success.
+ * \retval NULL on failure.
+*/
+struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type);
+
 /*! 
  * \brief Starts writing a file 
  * \param filename the name of the file to write to
@@ -208,13 +219,14 @@
  */
 int ast_writestream(struct ast_filestream *fs, struct ast_frame *f);
 
-/*! \brief Returns the raw name of a filestream
- *
- * \fixme This function needlessly exposes an internal structure.
- * We should probably provide a better interface for using file
- * descriptors / sockets rather than exposing it.
- */
-char* ast_filestream_xxx_get_filename(struct ast_filestream *stream);
+/*! 
+ * \brief Returns the raw name of a filestream
+ * \param fs file. Should be one created by ast_writefd().
+ *
+ * \retval Private state as set by ast_writefd(). Result is undefined
+ *         otherwise.
+ */
+void* ast_filestream_get_fd_state(struct ast_filestream *fs);
 
 /*! 
  * \brief Closes a stream 

Modified: team/tzafrir/monitor-rtp/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/tzafrir/monitor-rtp/main/file.c?view=diff&rev=224438&r1=224437&r2=224438
==============================================================================
--- team/tzafrir/monitor-rtp/main/file.c (original)
+++ team/tzafrir/monitor-rtp/main/file.c Sun Oct 18 13:24:24 2009
@@ -336,15 +336,9 @@
 	ast_module_unref(f->fmt->module);
 }
 
-/*! \brief Returns the raw name of a filestream
- *
- * \fixme This function needlessly exposes an internal structure.
- * We should probably provide a better interface for using file
- * descriptors / sockets rather than exposing it.
- */
-char* ast_filestream_xxx_get_filename(struct ast_filestream *fs)
-{
-	return fs->filename;
+void* ast_filestream_get_fd_state(struct ast_filestream *fs)
+{
+	return (void*)fs->filename;
 }
 
 static struct ast_filestream *get_filestream(struct ast_format *fmt, FILE *bfile)
@@ -1037,7 +1031,7 @@
 	return fs;
 }
 
-static struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type)
+struct ast_filestream *ast_writefd(void *stateinfo, int fd, const char *type)
 {
 	struct ast_filestream *fs = NULL;
 	FILE *bfile = NULL;
@@ -1089,12 +1083,6 @@
 	size_t size = 0;
 	int format_found = 0;
 
-	/*
-	 * Use 'check' for an open file descriptor
-	 */
-	if (check > 0) {
-		return ast_writefd((void *)filename, check, type);
-	}
 	AST_RWLIST_RDLOCK(&formats);
 
 	/* set the O_TRUNC flag if and only if there is no O_APPEND specified */

Modified: team/tzafrir/monitor-rtp/res/res_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/tzafrir/monitor-rtp/res/res_monitor.c?view=diff&rev=224438&r1=224437&r2=224438
==============================================================================
--- team/tzafrir/monitor-rtp/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp/res/res_monitor.c Sun Oct 18 13:24:24 2009
@@ -410,7 +410,7 @@
 	rtp_state->ts_start = ast_tvnow();
 	rtp_state->dest = saddr;
 	ast_log(LOG_NOTICE, "%s: sockfd=%d\n", __FUNCTION__, sock);
-	fs = ast_writefile((const char *) rtp_state, PCM_FORMAT, "UDP", 0, sock, 0);
+	fs = ast_writefd(rtp_state, sock, PCM_FORMAT);
 	if (!fs) {
 		ast_log(LOG_WARNING, "No such format '%s'\n", PCM_FORMAT);
 		ast_free(rtp_state);
@@ -558,10 +558,10 @@
 		struct monitor_rtp_state *rtp_state_rx;
 		struct monitor_rtp_state *rtp_state_tx;
 
-		rtp_state_rx = (struct monitor_rtp_state *)
-			ast_filestream_xxx_get_filename(chan->monitor->read_stream);
-		rtp_state_tx = (struct monitor_rtp_state *)
-			ast_filestream_xxx_get_filename(chan->monitor->write_stream);
+		rtp_state_rx = ast_filestream_get_fd_state(
+						chan->monitor->read_stream);
+		rtp_state_tx = ast_filestream_get_fd_state(
+						chan->monitor->write_stream);
 
 		if (chan->monitor->read_stream) {
 			ast_log(LOG_NOTICE, "%s: close read_stream\n", __FUNCTION__);
@@ -647,10 +647,8 @@
 		ast_closestream(monitor->read_stream);
 		goto out;
 	}
-	rtp_state_rx = (struct monitor_rtp_state *)
-		ast_filestream_xxx_get_filename(monitor->read_stream);
-	rtp_state_tx = (struct monitor_rtp_state *)
-		ast_filestream_xxx_get_filename(monitor->write_stream);
+	rtp_state_rx = ast_filestream_get_fd_state(monitor->read_stream);
+	rtp_state_tx = ast_filestream_get_fd_state(monitor->write_stream);
 	send_cdr(chan, 1, 1, rtp_state_rx);
 	send_cdr(chan, 1, 0, rtp_state_tx);
 	monitor->stop = monitor2rtp_stop;




More information about the svn-commits mailing list