DSMCC  17.9.0
 All Data Structures Files Functions Typedefs
loadRqst.c
1 /*******************************************************************************
2  * Copyright © 2015 The DTVKit Open Software Foundation Ltd (www.dtvkit.org)
3  *
4  * This file is part of a DTVKit Software Component
5  * You are permitted to copy, modify or distribute this file subject to the terms
6  * of the DTVKit 1.0 Licence which can be found in licence.txt or at www.dtvkit.org
7  *
8  * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
9  * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES
10  * OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * If you or your organisation is not a member of DTVKit then you have access
13  * to this source code outside of the terms of the licence agreement
14  * and you are expected to delete this and any associated files immediately.
15  * Further information on DTVKit, membership and terms can be found at www.dtvkit.org
16  *******************************************************************************/
25 /*---includes for this file--------------------------------------------------*/
26 #include <string.h>
27 #include "loadRqst.h"
28 #include "cacheMgr.h"
29 
30 /*------------------------------- Local Macros -------------------------------*/
31 
32 
33 /*------------------------------ Exported Data -----------------------------*/
34 
35 
36 
37 /*--------------------------------Local Types --------------------------------*/
38 
39 
40 /*------------------------------- Local Statics ------------------------------*/
41 
42 /*------------------- local prototypes/forward declarations ------------------*/
43 
44 
45 /*------------------------------ Local Functions -----------------------------*/
46 
47 
48 /*---------------------------- Exported Functions ----------------------------*/
49 
50 E_DscError DSC_LoadRsqtCreate( P_DsmCoreInst idp, U32BIT size,
51  E_TargetType targetKind, H_Object target, F_LoadFinalise finalise,
52  P_RootLoadRqst *ppLoadRqst )
53 {
54  P_RootLoadRqst pLoadRqst;
55  E_DscError err;
56 
57  dsmAssert((idp != NULL));
58  dsmAssert((size >= sizeof(S_RootLoadRqst)));
59 
60  pLoadRqst = (P_RootLoadRqst)DSC_CmMemGet( idp, size );
61  if (!pLoadRqst)
62  {
63  err = CLDSM_ERR_MEM_HEAP_FULL;
64  }
65  else
66  {
67  llLinkInit( pLoadRqst->llData, NUM_LISTS_LOAD_REQUEST );
68  if (!LLInsertHead( idp->llcCurrLoadRequests, pLoadRqst ))
69  {
70  /* should never get here */
71  ASSERT(0)
72  ERRPRINT("insert list fail - already in list?");
73  err = CLDSM_ERR_INTERNAL;
74  DSC_CmMemRelease( idp, pLoadRqst );
75  pLoadRqst = NULL;
76  }
77  else
78  {
79  err = CLDSM_OK;
80  pLoadRqst->magic = LOAD_REQUEST_MAGIC;
81  pLoadRqst->status = LRS_INITIAL;
82  pLoadRqst->targetKind = targetKind;
83  pLoadRqst->target = target;
84  pLoadRqst->finalise = finalise;
85  pLoadRqst->remaining = 0;
86  pLoadRqst->cachingRules = CACHE_RULES_DEFAULT;
87  pLoadRqst->usrRef = 0;
88  if (size > sizeof(S_RootLoadRqst))
89  {
90  memset(pLoadRqst + 1, 0, size - sizeof(S_RootLoadRqst));
91  }
92  }
93  }
94  *ppLoadRqst = pLoadRqst;
95  return err;
96 }
97 
98 void DSC_LoadRsqtDestroy( P_DsmCoreInst idp, P_RootLoadRqst pLoadRqst )
99 {
100  dsmAssert((idp != NULL));
101  dsmAssert((pLoadRqst != NULL));
102 
103  dsmAssert((pLoadRqst->magic == LOAD_REQUEST_MAGIC));
104 
105  /* -- Should not be in any lists */
106  dsmAssert((LLCheckInListId( MODULE_LOAD_REQUEST_LIST, pLoadRqst ) == FALSE));
107 
108  /* -- NULL carousel contents. */
109  pLoadRqst->magic = 0;
110 
111  LLRemove( pLoadRqst, CURR_LOAD_REQUEST_LIST );
112 
113  DSC_CmMemRelease( idp, pLoadRqst );
114 }
115 
116 void DSC_LoadRsqtFinalise( P_DsmCoreInst idp, P_RootLoadRqst pLoadRqst )
117 {
118  if (pLoadRqst->finalise != NULL)
119  {
120  pLoadRqst->finalise( idp, pLoadRqst );
121  }
122  DSC_LoadRsqtDestroy( idp, pLoadRqst );
123 }
124 
125 void DSC_LoadRsqtNotify( P_DsmCoreInst idp, P_RootLoadRqst pLoadRqst, E_LRStatus status )
126 {
127  pLoadRqst->status = status;
128  if (pLoadRqst->finalise != NULL)
129  {
130  pLoadRqst->finalise( idp, pLoadRqst );
131  }
132 }
133 
134 void DSC_LoadRsqtFinalNotify( P_DsmCoreInst idp, P_RootLoadRqst pLoadRqst, E_LRStatus status )
135 {
136  pLoadRqst->status = status;
137  if (pLoadRqst->finalise != NULL)
138  {
139  pLoadRqst->finalise( idp, pLoadRqst );
140  }
141  LLRemove( pLoadRqst, MODULE_LOAD_REQUEST_LIST );
142  DSC_LoadRsqtDestroy( idp, pLoadRqst );
143 }
144 
145 E_SFPriority DSC_LoadRsqtPriority( P_RootLoadRqst pLoadRqst )
146 {
147  dsmAssert((pLoadRqst != NULL));
148  dsmAssert((pLoadRqst->magic == LOAD_REQUEST_MAGIC));
149  return (pLoadRqst->cachingRules == CACHE_RULES_FROM_STREAM)? SF_PRIORITY_DIRECT :
150  (pLoadRqst->finalise != NULL)? SF_PRIORITY_HIGH : SF_PRIORITY_LOW;
151 }
152 
158 {
159  dsmAssert((idp != NULL));
160  dsmAssert((pLoadRqst != NULL));
161 
162  switch (pLoadRqst->status)
163  {
164  default:
165  pLoadRqst->status = LRS_ABORTED_LOAD_ERROR;
166  /*follow thro*/
167  case LRS_ABORTED_BY_REQUESTER:
168  case LRS_ABORTED_TIMEOUT:
169  DSC_LoadRsqtFinalise( idp, pLoadRqst );
170  break;
171  case LRS_ABORT_PENDING_RELOAD:
172  /* Ignore abort */
173  break;
174  }
175 }
176 
177 
void DSC_LoadRsqtAbort(P_DsmCoreInst idp, P_RootLoadRqst pLoadRqst)
Force abort (on error) any type of load request Finalise the load request (notify client) and destroy...
Definition: loadRqst.c:157
Header defining.
Header to the cacheMgr module.