DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
siq_main.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright © 2014 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  * Copyright © 2004 Ocean Blue Software Ltd
4  *
5  * This file is part of a DTVKit Software Component
6  * You are permitted to copy, modify or distribute this file subject to the terms
7  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
8  *
9  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
10  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
11  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * If you or your organisation is not a member of DTVKit then you have access
14  * to this source code outside of the terms of the licence agreement
15  * and you are expected to delete this and any associated files immediately.
16  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
17  *******************************************************************************/
24 /*---includes for this file--------------------------------------------------*/
25 #include <string.h>
26 
27 /* third party header files */
28 #include "cldsmcc.h"
29 
30 /* SIQ header files */
31 #include "siq_cache.h"
32 #include "siq_debug.h"
33 #include "siq_main.h"
34 #include "siq_pmt.h"
35 
36 /*---constant definitions for this file--------------------------------------*/
37 
38 #define NEWLOG(x, ...) if (pSetup->errPrintf) \
39  pSetup->errPrintf( x "\n", ##__VA_ARGS__);
40 
41 /*---local typedef structs for this file-------------------------------------*/
42 
43 typedef struct s_SiqRequests
44 {
45  struct s_SiqRequests *next;
46  S_SIQueryRequest query;
47  H_SIQueryRef dsmQueryRef;
48  void *dsmUserData;
49 } S_SiqRequests;
50 
51 
52 /*---local (static) variable declarations for this file----------------------*/
53 /* (internal variables declared static to make them local) */
54 
55 /*------------Local function definitions for this file-----------------------*/
56 /* (internal functions declared static to make them local) */
57 
58 
59 /*------------GLOBAL function definitions for this file----------------------*/
60 
61 
68 {
69  S_SiqInstance *siq = NULL;
70  S_SiqSetup *iptr;
71 
72  FUNCTION_START(SIQ_CreateInstance)
73  if (pSetup != NULL)
74  {
75  if (pSetup->memAlloc == NULL)
76  {
77  NEWLOG("memAlloc NULL")
78  }
79  else if (pSetup->memFree == NULL)
80  {
81  NEWLOG("memFree NULL")
82  }
83  else if (pSetup->dvpRequestTable == NULL)
84  {
85  NEWLOG("dvpRequestTable NULL")
86  }
87  else if (pSetup->dvpCancelTable == NULL)
88  {
89  NEWLOG("dvpCancelTable NULL")
90  }
91  else if (pSetup->parseDataBroadcastId == NULL &&
92  pSetup->parseSsuSelectorBytes == NULL)
93  {
94  NEWLOG("parseDataBroadcastId or parseSsuSelectorBytes is NULL")
95  }
96  else
97  {
98  siq = pSetup->memAlloc( sizeof(S_SiqInstance));
99  if (siq != NULL)
100  {
101  iptr = &siq->setup;
102  memcpy( iptr, pSetup, sizeof(S_SiqSetup));
103  iptr++;
104  memset(iptr, 0, sizeof(S_SiqInstance) - sizeof(S_SiqSetup));
105 
106  if (!SIQ_CacheInit( siq ))
107  {
108  pSetup->memFree( siq );
109  siq = NULL;
110  }
111  }
112  }
113  }
114  FUNCTION_FINISH(SIQ_CreateInstance)
115  return siq;
116 }
117 
126 void SIQ_SetDebugConfig( H_SiqInstance siq, F_Printf errPrintf,
127  F_Printf dbgPrintf, U32BIT dbgState )
128 {
129  ASSERT(siq != NULL)
130  siq->setup.errPrintf = errPrintf;
131  siq->setup.dbgPrintf = dbgPrintf;
132  siq->setup.dbgState = dbgState;
133 }
134 
141 void SIQ_SetDebugState( H_SiqInstance siq, U32BIT dbgState )
142 {
143  ASSERT(siq != NULL)
144  siq->setup.dbgState = dbgState;
145 }
146 
153 {
154  S_SiqRequests *pRequest, *pr;
155 
156  pRequest = siq->queryHead;
157  while (pRequest != NULL)
158  {
159  ERRLOG("Leaked Query kind=%d srv_id=%d", pRequest->query.kind, pRequest->query.serviceId)
160  pr = pRequest;
161  pRequest = pRequest->next;
162  siq->setup.memFree( pr );
163  }
164 
165  SIQ_CacheExit( siq );
166 
167  siq->setup.memFree( siq );
168 }
169 
177 {
178  FUNCTION_START(SIQ_SetDsmInstance)
179  siq->dsmInstance = dsmInstance;
180  FUNCTION_FINISH(SIQ_SetDsmInstance)
181 }
182 
190  H_SIQueryRef dsmQueryRef, void *dsmUserData,
191  P_SIQueryResult pResult )
192 {
193  S_SiqRequests *pRequest;
194  H_SiqPmtTable hpmt;
195  E_DscError err;
196  U32BIT gettingPmt;
197  /* no need to check for duplicates requests - dsmcc lib does that */
198  hpmt = SIQ_CacheRetrievePmt( siq, pQuery->serviceId, &gettingPmt );
199  if (hpmt != NULL)
200  {
201  SIQ_PmtProcessQuery( siq, pQuery, hpmt, pResult );
202  if (pResult->kind == SIRESULT_FAILURE)
203  {
204  DBGLOG(DS_QUERY, "SIQ_PmtProcessQuery(kind=%d) failed", pQuery->kind)
205  err = CLDSM_ERR_SI_QUERY_FAILED;
206  }
207  else
208  {
209  err = CLDSM_OK;
210  }
211  }
212  else if (!gettingPmt)
213  {
214  ERRLOG("Eek! SIQ_CacheRetrievePmt(serv_id=%d) failed, and not getting PMT either! Q-kind=%d", pQuery->serviceId, pQuery->kind)
215  err = CLDSM_ERR_INVALID_SIQUERY_STATUS;
216  }
217  else
218  {
219  pRequest = siq->setup.memAlloc( sizeof(S_SiqRequests));
220  if (pRequest == NULL)
221  {
222  err = CLDSM_ERR_ALLOC_FAILED;
223  }
224  else
225  {
226  DBGLOG(DS_QUERY, "Pending Query request serviceId=%d kind=%d", pQuery->serviceId, pQuery->kind)
227  pRequest->query = *pQuery;
228  pRequest->dsmQueryRef = dsmQueryRef;
229  pRequest->dsmUserData = dsmUserData;
230 
231  pRequest->next = siq->queryHead;
232  siq->queryHead = pRequest;
233 
234  pResult->kind = SIRESULT_PENDING;
235  pResult->data.queryHandle = pRequest;
236  err = CLDSM_PENDING;
237  }
238  }
239  return err;
240 }
241 
249  void *queryHandle, H_SIQueryRef dsmQueryRef )
250 {
251  S_SiqRequests **ppRequest, *pRequest;
252 
253  ppRequest = &(siq->queryHead);
254  while (*ppRequest != NULL)
255  {
256  if (*ppRequest == queryHandle)
257  {
258  pRequest = *ppRequest;
259  ASSERT( pRequest->dsmQueryRef == dsmQueryRef );
260  *ppRequest = pRequest->next;
261  siq->setup.memFree( pRequest );
262  break;
263  }
264  ppRequest = &((*ppRequest)->next);
265  }
266 }
267 
268 void SIQ_DeleteQueriesOnService(S_SiqInstance *siq, U16BIT serviceId)
269 {
270  S_SiqRequests **ppRequest, *pRequest;
271 
272  ppRequest = &(siq->queryHead);
273  while (*ppRequest != NULL)
274  {
275  pRequest = *ppRequest;
276  if (pRequest->query.serviceId == serviceId)
277  {
278  *ppRequest = pRequest->next;
279  siq->setup.memFree( pRequest );
280  }
281  else
282  {
283  ppRequest = &((*ppRequest)->next);
284  }
285  }
286 }
287 
293 void SIQ_QueryPmtReceive(S_SiqInstance *siq, U16BIT serviceId, H_SiqPmtTable hpmt)
294 {
295  S_SiqRequests **ppRequest, *pRequest;
296  S_SIQueryResult result;
297 
298  //DBGLOG(DS_QUERY,"serviceId=%d",serviceId)
299  pRequest = siq->queryHead;
300  ppRequest = &(siq->queryHead);
301  while (pRequest != NULL)
302  {
303  DBGLOG(DS_QUERY, "pRequest=%p ppRequest=%p", pRequest, ppRequest)
304  if (pRequest->query.serviceId == serviceId)
305  {
306  *ppRequest = pRequest->next;
307  SIQ_PmtProcessQuery( siq, &pRequest->query, hpmt, &result );
308  if (CDSM_SysProcessSIQueryEvent( siq->dsmInstance,
309  pRequest->dsmQueryRef, pRequest->dsmUserData, &result ) != CLDSM_OK)
310  {
311  ERRLOG("clDsmSysProcessSIQueryEvent: failed")
312  }
313  siq->setup.memFree( pRequest );
314  }
315  else
316  {
317  ppRequest = &(pRequest->next);
318  DBGLOG(DS_QUERY, "ppRequest=%p", ppRequest)
319  }
320  pRequest = *ppRequest;
321  }
322 }
323 
E_DscError SIQ_RequestQueryStart(S_SiqInstance *siq, P_SIQueryRequest pQuery, H_SIQueryRef dsmQueryRef, void *dsmUserData, P_SIQueryResult pResult)
Start query request. Called by DSM-CC component.
Definition: siq_main.c:189
H_SiqInstance SIQ_CreateInstance(S_SiqSetup *pSetup)
Create SIQ instance.
Definition: siq_main.c:67
void SIQ_SetDebugConfig(H_SiqInstance siq, F_Printf errPrintf, F_Printf dbgPrintf, U32BIT dbgState)
Set Debug config for SIQ.
Definition: siq_main.c:126
void SIQ_DestroyInstance(H_SiqInstance siq)
Destroy instance created by SIQ_CreateInstance.
Definition: siq_main.c:152
E_DscError CDSM_SysProcessSIQueryEvent(H_DsmCoreInst instance, H_SIQueryRef clDsmSIQueryRef, void *clDsmSIUserData, P_SIQueryResult pResult)
Notifies the result of the specified SI query (ie. a callback to startSIQueryFunc that returned SIQUE...
Definition: clDsmMain.c:1034
Main API to DSM-CC core layer (provided functions and required callbacks).
void SIQ_QueryPmtReceive(S_SiqInstance *siq, U16BIT serviceId, H_SiqPmtTable hpmt)
Definition: siq_main.c:293
Service Information Query: debug definitions.
void SIQ_SetDebugState(H_SiqInstance siq, U32BIT dbgState)
Set Debug state for SIQ.
Definition: siq_main.c:141
Service Information Query: cache functionality.
Service Information Query: PMT parsing functions.
void SIQ_PmtProcessQuery(S_SiqInstance *siq, P_SIQueryRequest pQuery, H_SiqPmtTable hpmt, P_SIQueryResult pResult)
Retrieve Information required by Query request from SIQ's PMT table.
Definition: siq_pmt.c:921
Service Information Query: main definitions.
void SIQ_SetDsmInstance(H_SiqInstance siq, H_DsmCoreInst dsmInstance)
Set instance handle for DSM-CC that SIQ is supporting.
Definition: siq_main.c:176
void SIQ_RequestQueryStop(S_SiqInstance *siq, void *queryHandle, H_SIQueryRef dsmQueryRef)
Stop query request. Called by DSM-CC component.
Definition: siq_main.c:248