00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00026
00027
00028
00029
00030
00031
00032 #include <stdio.h>
00033 #include <string.h>
00034 #include <glib.h>
00035
00036 #include <libermanifest/ermanifest.h>
00037
00038 #include "contentListerLog.h"
00039 #include "stack.h"
00040
00041
00042 static GArray *g_stacks[TOTAL_STACK_COUNT];
00043
00044 void stackInitAll(void)
00045 {
00046 int index;
00047
00048 CL_STACKPRINTF("entry");
00049
00050 for (index = 0; index < TOTAL_STACK_COUNT; index++)
00051 {
00052 g_stacks[index] = g_array_sized_new(FALSE, TRUE, sizeof(stItem_t), INITIAL_STACK_ARRAY_SIZE);
00053 }
00054 }
00055
00056 void stackDestroyAll(void)
00057 {
00058 int index;
00059
00060 CL_STACKPRINTF("entry");
00061
00062 for (index = 0; index < TOTAL_STACK_COUNT; index++)
00063 {
00064 if (g_stacks[index])
00065 {
00066 stackClear(index);
00067 g_array_free(g_stacks[index], TRUE);
00068 g_stacks[index] = NULL;
00069 }
00070 }
00071 }
00072
00073 void stackPush(st_ContentType_e contentType, stItem_t * stackItem)
00074 {
00075 if (stackItem)
00076 {
00077 CL_STACKPRINTF("%d-0x%x", contentType, (unsigned int) stackItem);
00078 g_array_append_val(g_stacks[contentType], *stackItem);
00079 }
00080 }
00081
00082 void stackPop(st_ContentType_e contentType)
00083 {
00084 stItem_t *theItem = NULL;
00085
00086 if (g_stacks[contentType]->len > 0)
00087 {
00088 CL_STACKPRINTF("%d-0x%x", contentType,
00089 (unsigned int) &g_array_index(g_stacks[contentType], stItem_t,
00090 (g_stacks[contentType]->len - 1)));
00091
00092 theItem = &g_array_index(g_stacks[contentType], stItem_t, (g_stacks[contentType]->len - 1));
00093
00094
00095 if (theItem)
00096 {
00097 if (theItem->dirArray)
00098 {
00099 CL_STACKPRINTF("dirArray - 0x%x", (unsigned int) theItem->dirArray);
00100 g_array_free(theItem->dirArray, TRUE);
00101 theItem->dirArray = NULL;
00102 }
00103 }
00104
00105 g_array_remove_index(g_stacks[contentType], (g_stacks[contentType]->len - 1));
00106 }
00107 return;
00108 }
00109
00110 stItem_t *stackPeek(st_ContentType_e contentType)
00111 {
00112 stItem_t *theItem = NULL;
00113
00114 if (g_stacks[contentType]->len > 0)
00115 {
00116 CL_STACKPRINTF("%d-0x%x", contentType,
00117 (unsigned int) &g_array_index(g_stacks[contentType], stItem_t,
00118 (g_stacks[contentType]->len - 1)));
00119
00120 theItem = &g_array_index(g_stacks[contentType], stItem_t, (g_stacks[contentType]->len - 1));
00121 }
00122
00123 return theItem;
00124 }
00125
00126 int stackHeight(st_ContentType_e contentType)
00127 {
00128 CL_STACKPRINTF("%d-%d", contentType, g_stacks[contentType]->len);
00129
00130 return g_stacks[contentType]->len;
00131 }
00132
00133 void stackClear(st_ContentType_e contentType)
00134 {
00135 int index;
00136 stItem_t *theItem = NULL;
00137
00138 CL_STACKPRINTF("type %d - length %d", contentType, g_stacks[contentType]->len);
00139
00140
00141 if (g_stacks[contentType]->len > 0)
00142 {
00143 for (index = 0; index < g_stacks[contentType]->len; index++)
00144 {
00145 theItem = &g_array_index(g_stacks[contentType], stItem_t, index);
00146
00147 if (theItem->dirArray)
00148 {
00149 CL_STACKPRINTF("dirArray - 0x%x", (unsigned int) theItem->dirArray);
00150 g_array_free(theItem->dirArray, TRUE);
00151 theItem->dirArray = NULL;
00152 }
00153 }
00154
00155
00156 g_array_remove_range(g_stacks[contentType], 0, g_stacks[contentType]->len);
00157 }
00158 }
00159
00160 void stackItemDestroy(stItem_t * stackItem)
00161 {
00162 CL_STACKPRINTF("0x%x", (unsigned int) stackItem);
00163
00164 if (stackItem)
00165 {
00166 if (stackItem->dirArray)
00167 {
00168 CL_STACKPRINTF("dirArray - 0x%x", (unsigned int) stackItem->dirArray);
00169 g_array_free(stackItem->dirArray, TRUE);
00170 }
00171
00172 g_free(stackItem);
00173 stackItem = NULL;
00174 }
00175 else
00176 {
00177 CL_STACKPRINTF("stackItem == NULL");
00178 }
00179 }
00180
00181 void stackItemDisplay(stItem_t * stackItem)
00182 {
00183 int index;
00184 mdsDirectory_t *directory;
00185
00186 CL_STACKPRINTF("0x%x", (unsigned int) stackItem);
00187
00188 if (stackItem)
00189 {
00190 if (stackItem->dirArray)
00191 {
00192 CL_STACKPRINTF("dirArray - 0x%x", (unsigned int) stackItem->dirArray);
00193
00194 for (index = 0; index < stackItem->dirArray->len; index++)
00195 {
00196 directory = &g_array_index(stackItem->dirArray, mdsDirectory_t, index);
00197 CL_STACKPRINTF("dir : %s", directory->szFilename);
00198 }
00199 }
00200
00201 CL_STACKPRINTF("sort fieldType %d", stackItem->sort.ft);
00202 CL_STACKPRINTF("sort ascending %d", stackItem->sort.ascending);
00203 CL_STACKPRINTF("index %d", stackItem->index);
00204 }
00205 }
00206
00207 void stackDisplay(st_ContentType_e contentType)
00208 {
00209 int index;
00210 stItem_t *theItem = NULL;
00211
00212
00213 if (g_stacks[contentType]->len > 0)
00214 {
00215 for (index = 0; index < g_stacks[contentType]->len; index++)
00216 {
00217 theItem = &g_array_index(g_stacks[contentType], stItem_t, (g_stacks[contentType]->len - 1));
00218 CL_STACKPRINTF("\n*****************[%d]**********************", index);
00219 stackItemDisplay(theItem);
00220 CL_STACKPRINTF("\n*******************************************\n");
00221 }
00222 }
00223 }
00224
00225
00226 gboolean stackIsStorage(st_ContentType_e contentType)
00227 {
00228 if ( (contentType >= st_StorageTypeCF)
00229 || (contentType <= st_StorageTypeSD)
00230 || (contentType <= st_StorageTypeUSB)
00231 || (contentType <= st_StorageTypeMain) )
00232 {
00233 return TRUE;
00234 }
00235 else
00236 {
00237 return FALSE;
00238 }
00239 }
00240
00241 gboolean stackIsArchive(st_ContentType_e contentType)
00242 {
00243 if ( (contentType == st_ContentTypeBooks)
00244 || (contentType == st_ContentTypeNews)
00245 || (contentType == st_ContentTypeDocs)
00246 || (contentType == st_ContentTypeNotes) )
00247 {
00248 return TRUE;
00249 }
00250 else
00251 {
00252 return FALSE;
00253 }
00254 }