[core] Added stream related generic list operations;

v0.5.xx
Alexander Vdolainen 9 years ago
parent 059e2bcc9d
commit 6534dda8a0

@ -201,6 +201,10 @@ struct sxstream_opened {
uint16_t pin_channelid;
};
#define sxstream_opened_setpriv(n, p) (n)->priv = (p)
#define sxstream_opened_getpriv(n) (n)->priv
#define sxstream_opened_getelist(n) (n)->ent_buf
struct sxstream_ops {
int (*s_open)(sxlink_t *, struct sxstream_opened *, const char *);
int (*s_close)(struct sxstream_opened *);
@ -414,6 +418,11 @@ int sxmp_rpclist_add_function(usrtc_t *tree, int type, const char *fu_name,
int sxmp_rpclist_filter(usrtc_t *source, usrtc_t **dest, int flag, int *filter);
/* generic sxstream list functions */
list_head_t *sxstream_generic_slist_alloc(void);
void sxstream_generic_slist_free(list_head_t *list);
int sxstream_generic_slist_additem(list_head_t *list, const char *value);
#ifdef __cplusplus
}
#endif

@ -15,7 +15,7 @@ lib_LTLIBRARIES = libsxmp.la
libsxmp_la_SOURCES = \
sxmplv2.c hub.c channel.c message.c rpc.c \
uuid.c stream.c error.c
uuid.c stream_generic_listops.c stream.c error.c
libsxmp_la_LDFLAGS =

@ -0,0 +1,89 @@
/*
* Secure X Message Passing Library v2 implementation.
* (sxmplv2) it superseed all versions before due to the:
* - memory consumption
* - new features such as pulse emitting
* - performance optimization
*
* (c) Askele Group 2013-2015 <http://askele.com>
* (c) Alexander Vdolainen 2013-2015,2016 <avdolainen@zoho.com>
*
* libsxmp is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* libsxmp is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <tdata/usrtc.h>
#include <tdata/list.h>
#include <sexpr/sexp.h>
#include <sxmp/sxmp.h>
list_head_t *sxstream_generic_slist_alloc(void)
{
list_head_t *list = malloc(sizeof(list_head_t));
if(list) list_init_head(list);
return list;
}
void sxstream_generic_slist_free(list_head_t *list)
{
struct _nn_stream_entry_node *entry;
list_node_t *iter, *siter;
list_for_each_safe(list, iter, siter) {
entry = list_entry(iter, struct _nn_stream_entry_node, node);
list_del(iter);
free(entry->value);
free(entry);
}
free(list);
return;
}
int sxstream_generic_slist_additem(list_head_t *list, const char *value)
{
struct _nn_stream_entry_node *entry = malloc(sizeof(struct _nn_stream_entry_node));
size_t value_len = 0;
if(!entry) return -1;
if(!value) {
__enomem:
free(entry);
return -1;
} else value_len = strlen(value) + 3*sizeof(char); /* additional nil and two underscopes */
if(!(entry->value = malloc(value_len)))
goto __enomem;
else snprintf(entry->value, value_len, "\"%s\"", value);
list_init_node(&entry->node);
list_add2tail(list, &entry->node);
return 0;
}
Loading…
Cancel
Save