kb_machblue_client_task.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:6k
- //*****************************************************************************
- //FileName:kb_machblue_task.c
- //
- //Description:Machblue client task.
- //
- //Author:steven
- //
- //Date: 2007.03.17
- //
- //Version: v1.0
- //*****************************************************************************
- #include "osp.h"
- #include "nvod.h"
- #include "kb_dc.h"
- #include "kb_dc_task.h"
- #include "kb_porting.h"
- #include "stcommon.h"
- #include "machblue_customer.h"
- #include "machblue_defines.h"
- #include "machblue_porting_core.h"
- #include "kb_machblue_client.h"
- #include "kb_machblue_client_task.h"
- #include "kb_machblue_client_lc.h"
- #include "kb_machblue_client_data.h"
- #define KB_MB_MSG_COUNT 20
- static unsigned long _kb_mb_msgIndex=0;
- static kb_movie_msg_t _kb_mb_msg[KB_MB_MSG_COUNT];
- static mb_semaphore_t _kb_mQueueSem;
- static message_queue_t *pQueue=NULL;
- /**
- * machblue client task post
- * send message to client task
- *
- * key < key value from remote >
- *
- * @return MB_SUCCESS, MB_FAILURE otherwise.
- */
- mb_error_t kb_machblue_task_post(KB_OSPMsgNode *msg)
- {
- #if 1
- KB_OSPRet ret;
-
- ret=KB_OSPMsgSend((unsigned long)pQueue,msg);
- if(ret!=RET_OK)
- mb_printf("nkb_machblue_task_post error.");
- #else
- unsigned char index;
- BOOL eLoop=FALSE;
- KB_OSPMsgNode * pMessage;
- clock_t timeout;
- while(1)
- {
- for(index=0;index<KB_MB_MSG_COUNT;index++)
- {
- if(_kb_mb_msg[index].used==FALSE)
- {
- eLoop=TRUE;
- break;
- }
- }
- if(eLoop)
- break;
- }
-
- mb_semaphore_wait(_kb_mQueueSem);
- timeout=time_plus(time_now(),3*ST_GetClocksPerSecondLow());
- pMessage = (KB_OSPMsgNode *)message_claim_timeout((message_queue_t*)pQueue,&timeout);
- if(pMessage == NULL)
- {
- mb_printf("n[Machblue]:kb_machblue_task_post error.");
- mb_semaphore_signal(_kb_mQueueSem);
- return MB_FAILURE;
- }
- _kb_mb_msg[index].msg.Word1=pMessage->Word1=msg->Word1;
- _kb_mb_msg[index].msg.Word2=pMessage->Word2=msg->Word2;
- _kb_mb_msg[index].msg.Word3=pMessage->Word3=msg->Word3;
- _kb_mb_msg[index].msg.Word4=pMessage->Word4=_kb_mb_msgIndex++;
- _kb_mb_msg[index].used=TRUE;
- message_send((message_queue_t*)pQueue, (void*)pMessage);
- mb_semaphore_signal(_kb_mQueueSem);
- return MB_SUCCESS;
- #endif
- }
- /**
- * machblue client task wait
- * wait message whic sent to client task
- *
- * pMsg < buffer which storage client msg information >
- *
- * @return MB_SUCCESS, MB_FAILURE otherwise.
- */
- mb_error_t kb_machblue_task_wait(KB_OSPMsgNode *pMsg)
- {
- void* pMessage;
-
- if(pMsg == NULL)
- {
- mb_printf("n[Machblue]:Msg get no wait NULL.");
- return MB_FAILURE;
- }
- mb_semaphore_wait(_kb_mQueueSem);
-
- pMessage = message_receive_timeout((message_queue_t*)pQueue,(clock_t*)TIMEOUT_IMMEDIATE);
- if(pMessage != NULL)
- {
- pMsg->Word1=((KB_OSPMsgNode *)pMessage)->Word1;
- pMsg->Word2=((KB_OSPMsgNode *)pMessage)->Word2;
- pMsg->Word3=((KB_OSPMsgNode *)pMessage)->Word3;
- pMsg->Word4=((KB_OSPMsgNode *)pMessage)->Word4;
-
- message_release((message_queue_t*)pQueue, pMessage);
- mb_semaphore_signal(_kb_mQueueSem);
-
- return MB_SUCCESS;
- }
- else
- {
- mb_semaphore_signal(_kb_mQueueSem);
-
- return MB_FAILURE;
- }
- }
- /**
- * machblue client task release msg buf
- *
- * pMsg < buffer which storage client msg information >
- *
- * @return None.
- */
- void kb_machblue_task_releaseMsg(KB_OSPMsgNode *pMsg)
- {
- unsigned char index;
-
- for(index=0;index<KB_MB_MSG_COUNT;index++)
- {
- if(_kb_mb_msg[index].msg.Word4==pMsg->Word4)
- {
- _kb_mb_msg[index].used=FALSE;
- break;
- }
- }
- }
- /**
- * machblue client task
- * @return None.
- */
- void kb_machblue_task(void)
- {
- KB_OSPMsgNode msg,msg2;
- unsigned short tsID,serviceID;
- while(1)
- {
- KB_OSPTaskDelay(10);
-
- //
- //if(kb_machblue_task_wait(&msg)==MB_FAILURE)
- if(KB_OSPMsgGet((unsigned long)pQueue,KB_Wait,(unsigned long)TIMEOUT_INFINITY,&msg)!=Ret_OK)
- continue;
- switch(msg.Word1)
- {
- //key event
- case KB_MOVIE_KEY_REQUEST:
- kb_machblue_key(msg.Word2);
- break;
- case KB_MOVIE_LC_TO_CCODE:
- kb_machblue_localConnection((kb_lc_attributes_t*)msg.Word2);
- break;
- case KB_MOVIE_LC_TO_MOVIE:
- KB_Machblue_LC_To_Movie(msg.Word2);
- break;
- case KB_MOVIE_SCHEDULE_CREATE:
- kb_machblue_create_schedule(msg.Word2);
- break;
-
- case KB_MOVIE_PROMPT_TO_MOVIE:
- kb_machblue_lc_2_prompt((char*)msg.Word2);
- break;
- case KB_MOVIE_NVOD_TO_MOVIE:
- {
- mb_error_t ret;
- UINT32 word;
- UINT8 pNum;
- KB_NVOD_Info *Address[KB_NVOD_MAX_TS_NUM];
- if (KB_DBGetNvodNum()>0)
- {
- mb_printf("n[machblue]enter nvod taskn");
- KB_NVOD_GetValidFreInfo(&pNum,Address);
- mb_printf("n[machblue]after KB_NVOD_GetValidFreInfo pNum = %dn",pNum);
-
- ret = kb_machblue_service_list_NVOD_init(pNum,Address);
- if (ret != MB_SUCCESS)
- word = 0;
- else
- word = 1;
- }
- else
- word = 0;
- mb_printf("n[machblue]enter nvod task word = %dn",word);
- KB_MB_lc_2_movie_word_Post_Task(word);
- }
- break;
- case KB_CLIENT_FRE_SWITCH:
- KB_OSPTaskDelay(500);
- //search xml info
- msg2.Word1=kb_dc_version_check;
- KB_DcMsgSend(&msg2);
- KB_DTVGetCurPrgInfo(&tsID,&serviceID);
- KB_EPG_SetCurrentTsNum(tsID);
- //KB_EPG_ResetSchInfoByTsid(tsID);
- KB_SIStopEitSCH(KB_SI_STOP_ALL);
- //kb_mb_event_schedule_reset();
- kb_machblue_search_schedule();
- //KB_OTA_NewChannel();
- break;
-
- default:
- break;
- }
- kb_machblue_task_releaseMsg(&msg);
- }
- }
- /**
- * init machblue client task
- * @return MB_SUCCESS, MB_FAILURE otherwise.
- */
- mb_error_t kb_machblue_task_init(void)
- {
- KB_OSPRet ret;
- unsigned char index;
- unsigned long taskID;
- mb_semaphore_create(&_kb_mQueueSem,1);
- //create queue
- pQueue=message_create_queue_timeout(sizeof(KB_OSPMsgNode),2000);
-
- ret=KB_OSPTaskInit("mb_client",16*1024,(void (*)(void*))kb_machblue_task,5*16,NULL,&taskID);
- if(ret!=Ret_OK)
- {
- mb_printf("n[Machblue]:kb_machblue_task_init error.");
- return MB_FAILURE;
- }
- for(index=0;index<KB_MB_MSG_COUNT;index++)
- {
- _kb_mb_msg[index].used=FALSE;
- }
- return MB_SUCCESS;
- }