From ab959d7b4194715870128e616b8e29d4a101e488 Mon Sep 17 00:00:00 2001 From: etobi Date: Tue, 3 Sep 2013 09:48:41 +0200 Subject: Imported Upstream version 1.1.1+rev1207 --- test/libdvben50221/test-session.c | 171 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 test/libdvben50221/test-session.c (limited to 'test/libdvben50221/test-session.c') diff --git a/test/libdvben50221/test-session.c b/test/libdvben50221/test-session.c new file mode 100644 index 0000000..14dc13e --- /dev/null +++ b/test/libdvben50221/test-session.c @@ -0,0 +1,171 @@ +/* + en50221 encoder An implementation for libdvb + an implementation for the en50221 transport layer + + Copyright (C) 2004, 2005 Manu Abraham (manu@kromtek.com) + Copyright (C) 2005 Julian Scheel (julian at jusst dot de) + Copyright (C) 2006 Andrew de Quincey (adq_dvb@lidskialf.net) + + This library 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 2.1 of + the License, or (at your option) any later version. + + This program 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 library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include +#include +#include +#include +#include +#include + +void *stackthread_func(void* arg); +int test_lookup_callback(void *arg, uint8_t slot_id, uint32_t requested_resource_id, + en50221_sl_resource_callback *callback_out, void **arg_out, uint32_t *connected_resource_id); +int test_session_callback(void *arg, int reason, uint8_t slot_id, uint16_t session_number, uint32_t resource_id); + + +int shutdown_stackthread = 0; + +#define DEFAULT_SLOT 0 + +int main(int argc, char * argv[]) +{ + (void)argc; + (void)argv; + + int i; + pthread_t stackthread; + + // create transport layer + struct en50221_transport_layer *tl = en50221_tl_create(5, 32); + if (tl == NULL) { + fprintf(stderr, "Failed to create transport layer\n"); + exit(1); + } + + // find CAMs + int slot_count = 0; + int cafd= -1; + for(i=0; i<20; i++) { + if ((cafd = dvbca_open(i, 0)) > 0) { + if (dvbca_get_cam_state(cafd, DEFAULT_SLOT) == DVBCA_CAMSTATE_MISSING) { + close(cafd); + continue; + } + + // reset it and wait + dvbca_reset(cafd, DEFAULT_SLOT); + printf("Found a CAM on adapter%i... waiting...\n", i); + while(dvbca_get_cam_state(cafd, DEFAULT_SLOT) != DVBCA_CAMSTATE_READY) { + usleep(1000); + } + + // register it with the CA stack + int slot_id = 0; + if ((slot_id = en50221_tl_register_slot(tl, cafd, DEFAULT_SLOT, 1000, 100)) < 0) { + fprintf(stderr, "Slot registration failed\n"); + exit(1); + } + printf("slotid: %i\n", slot_id); + slot_count++; + } + } + + // create session layer + struct en50221_session_layer *sl = en50221_sl_create(tl, 256); + if (sl == NULL) { + fprintf(stderr, "Failed to create session layer\n"); + exit(1); + } + + // start another thread running the stack + pthread_create(&stackthread, NULL, stackthread_func, tl); + + // register callbacks + en50221_sl_register_lookup_callback(sl, test_lookup_callback, sl); + en50221_sl_register_session_callback(sl, test_session_callback, sl); + + // create a new connection + for(i=0; i