2 * $Id: channel_manager.c 44 2011-02-15 12:32:29Z kaori $
4 * Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
5 * Copyright (c) 2002-2011, Professor Benoit Macq
6 * Copyright (c) 2010-2011, Kaori Hagihara
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
34 #include "channel_manager.h"
37 #include "fcgi_stdio.h"
38 #define logstream FCGI_stdout
40 #define FCGI_stdout stdout
41 #define FCGI_stderr stderr
42 #define logstream stderr
45 channellist_param_t * gene_channellist()
47 channellist_param_t *channellist;
49 channellist = (channellist_param_t *)malloc( sizeof(channellist_param_t));
51 channellist->first = NULL;
52 channellist->last = NULL;
57 channel_param_t * gene_channel( query_param_t query_param, cachemodel_param_t *cachemodel, channellist_param_t *channellist)
59 channel_param_t *channel;
62 fprintf( FCGI_stdout, "Status: 404\r\n");
63 fprintf( FCGI_stdout, "Reason: cnew cancelled\r\n");
67 channel = (channel_param_t *)malloc( sizeof(channel_param_t));
68 channel->cachemodel = cachemodel;
70 // set channel ID and get present time
71 snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
75 set_channel_variable_param( query_param, channel);
77 if( channellist->first != NULL)
78 channellist->last->next = channel;
80 channellist->first = channel;
81 channellist->last = channel;
83 fprintf( FCGI_stdout, "JPIP-cnew: cid=%s", channel->cid);
84 // only http implemented for now
85 fprintf( FCGI_stdout, ",transport=http\r\n");
91 void set_channel_variable_param( query_param_t query_param, channel_param_t *channel)
93 // set roi information
97 void delete_channel( channel_param_t **channel, channellist_param_t *channellist)
101 if( *channel == channellist->first)
102 channellist->first = (*channel)->next;
104 ptr = channellist->first;
105 while( ptr->next != *channel){
109 ptr->next = (*channel)->next;
111 if( *channel == channellist->last)
112 channellist->last = ptr;
115 fprintf( logstream, "local log: channel: %s deleted\n", (*channel)->cid);
120 void delete_channellist( channellist_param_t **channellist)
122 channel_param_t *channelPtr, *channelNext;
124 channelPtr = (*channellist)->first;
125 while( channelPtr != NULL){
126 channelNext=channelPtr->next;
128 fprintf( logstream, "local log: channel %s deleted!\n", channelPtr->cid);
131 channelPtr=channelNext;
136 void print_allchannel( channellist_param_t *channellist)
138 channel_param_t *ptr;
140 ptr = channellist->first;
142 fprintf( logstream,"channel-ID=%s \t target=%s\n", ptr->cid, ptr->cachemodel->target->filename);
147 channel_param_t * search_channel( char cid[], channellist_param_t *channellist)
149 channel_param_t *foundchannel;
151 foundchannel = channellist->first;
153 while( foundchannel != NULL){
155 if( strcmp( cid, foundchannel->cid) == 0)
158 foundchannel = foundchannel->next;
160 fprintf( FCGI_stdout, "Status: 503\r\n");
161 fprintf( FCGI_stdout, "Reason: Channel %s not found in this session\r\n", cid);