diff --git a/include/sxmp/sxmp.h b/include/sxmp/sxmp.h index d1025ea..49aced3 100644 --- a/include/sxmp/sxmp.h +++ b/include/sxmp/sxmp.h @@ -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 diff --git a/lib/Makefile.am b/lib/Makefile.am index 5424fdd..f3fe7ea 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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 = diff --git a/lib/stream_generic_listops.c b/lib/stream_generic_listops.c new file mode 100644 index 0000000..19a0529 --- /dev/null +++ b/lib/stream_generic_listops.c @@ -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 + * (c) Alexander Vdolainen 2013-2015,2016 + * + * 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 ."; + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +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; +} +