Demand.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:36k
- //
- // (C)版权2006 深圳市键桥通讯技术有限公司
- //
- // 文件名称: Demand.c
- //
- // 创建日期: 2007.03.25
- //
- // 创建人 :wangxiaorong
- //
- // 修改人 : ***
- //
- //修改日期: 2007.3.29
- //
- // 描 述: 预约实现源文件
- //
- // 版 本:1.0.0
- //--------------------------------------------------------------------
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include "osd.h"
- #include "db.h"
- #include "rckeymap.h"
- #include "epg.h"
- #include "timeclk.h"
- #include "Nvod.h"
- #include "Demand.h"
- #include "sr_time.h"
- static EPGDDataLink *EDDataLink=NULL;
- #if 0
- /*=============================================================
- 函数名称 : EDHF_AddDataLink
- 功 能 : 添加预约信息数据链
- 入 口 : int prgno --------节目号
- int eid -------- 事件号
- USHORT mjd ------ 播放日期
- int secs --------播放起始时间
- int dur --------播放时长
- int edt --------事件类型
- 出 口 : 无
- 返 回 : TRUE---成功,FALSE---失败
- =============================================================*/
- BOOL KB_AddDataLink(int prgno,int eid,USHORT mjd,int secs,int dur,int edt)
- {
- EPGDDataLink **ppEDL=&EDDataLink;
- //搜索到最后
- while(*ppEDL != NULL)
- {
- ppEDL=&((*ppEDL)->nextnode);
- }
- //追加
- *ppEDL=(EPGDDataLink*)KB_OSPMalloc(sizeof(EPGDDataLink));
- if(*ppEDL == NULL)
- {
- printf("n预约信息存储空间分配失败!");
- return FALSE;
- }
- (*ppEDL)->prgno=prgno;
- (*ppEDL)->eid=eid;
- (*ppEDL)->mjd=mjd;
- (*ppEDL)->seconds=secs;
- (*ppEDL)->duration=dur;
- (*ppEDL)->edt=edt;
- (*ppEDL)->nextnode=NULL;
- return TRUE;
- }
- #else
- /*=============================================================
- 函数名称 : KB_AddDataLink
- 功 能 : 添加预约信息数据链
- 入 口 : EPGDDataLink *Demanddata
- 出 口 : 无
- 返 回 : TRUE---成功,FALSE---失败
- =============================================================*/
- BOOL KB_AddDataLink(EPGDDataLink *Demanddata)
- {
- EPGDDataLink **ppEDL=&EDDataLink;
- //搜索到最后
- while(*ppEDL != NULL)
- {
- ppEDL=&((*ppEDL)->nextnode);
- }
- //追加
- *ppEDL=(EPGDDataLink*)KB_OSPMalloc(sizeof(EPGDDataLink));
- if(*ppEDL == NULL)
- {
- printf("n预约信息存储空间分配失败!");
- return FALSE;
- }
- (*ppEDL)->prgno=Demanddata->prgno;
- (*ppEDL)->eid=Demanddata->eid;
- (*ppEDL)->mjd=Demanddata->mjd;
- (*ppEDL)->seconds=Demanddata->seconds;
- (*ppEDL)->duration=Demanddata->duration;
- (*ppEDL)->edt=Demanddata->edt;
- strcpy((*ppEDL)->chlname, Demanddata->chlname);
- strcpy((*ppEDL)->prgname, Demanddata->prgname);
- strcpy((*ppEDL)->date,Demanddata->date);
- strcpy((*ppEDL)->time,Demanddata->time);
- (*ppEDL)->nextnode=NULL;
- return TRUE;
- }
- #endif
- /*=============================================================
- 函数名称 : KD_DelDataLink
- 功 能 : 删除指定的预约信息
- 入 口 : USHORT mjd --- 指定的预约日期
- int sec -----指定的播出时间
- 出 口 : 无
- 返 回 : TRUE---成功,FALSE---失败
- =============================================================*/
- BOOL KB_DelDataLink(USHORT mjd,int sec)
- {
- EPGDDataLink *pEDL=EDDataLink,*qEDL=NULL;
- //删除指定的节点
- while(pEDL != NULL)
- {
- if(pEDL->mjd== mjd && pEDL->seconds==sec)
- break;
- qEDL=pEDL;
- pEDL=pEDL->nextnode;
- }
- //如果没找到,返回
- if(pEDL == NULL)
- return FALSE;
- //找到删除
- if(qEDL== NULL)
- {
- EDDataLink=EDDataLink->nextnode;
- }
- else
- {
- qEDL->nextnode=pEDL->nextnode;
- }
- KB_OSPFree(pEDL);
- return TRUE;
- }
- /*=============================================================
- 函数名称 : KB_GetDataLink
- 功 能 : 获取指定索引的预约信息
- 入 口 : int nItemIdx --- 指定的预约索引
- 出 口 : struct _EDHFDataLink* pdl --获取节点
- 返 回 : TRUE---成功,FALSE---失败
- =============================================================*/
- BOOL KB_GetDataLink(int nItemIdx,EPGDDataLink* pdl)
- {
- EPGDDataLink *pEDL=EDDataLink;
- int i=0;
- if(pdl == NULL)
- {
- printf("n传入节点地址不存在!");
- return FALSE;
- }
- //获取指定的节点
- while(pEDL != NULL)
- {
- if(i == nItemIdx)
- {
- memcpy(pdl,pEDL,sizeof(EPGDDataLink));
- return TRUE;
- }
- pEDL=pEDL->nextnode;
- i++;
- }
- return FALSE;
- }
- /*=============================================================
- 函数名称 : KB_GetDataLinkNum
- 功 能 : 获取预约信息的总数
- 入 口 : 无
- 出 口 :UINT *num--预约信息的总数
- 返 回 : TRUE---成功,FALSE---失败
- =============================================================*/
- BOOL KB_GetDataLinkNum(UINT *num)
- {
- EPGDDataLink *pEDL=EDDataLink;
- int i=0;
-
- while(pEDL != NULL)
- {
- pEDL=pEDL->nextnode;
- i++;
- }
- *num=i;
-
- return TRUE;
- }
- /*=============================================================
- 函数名称 : KB_ClearDataLink
- 功 能 : 清除所有预约信息
- 入 口 : 无
- 出 口 : 无
- 返 回 : 无
- =============================================================*/
- void KB_ClearDataLink()
- {
- EPGDDataLink *pEDL=EDDataLink,*qEDL;
- //删除所有的节点
- while(pEDL != NULL)
- {
- qEDL=pEDL->nextnode;
- KB_OSPFree(pEDL);
- pEDL=qEDL;
- }
- EDDataLink=NULL;
- }
- /*=============================================================
- 函数名称 : KB_DelOnTimeDmdEnt
- 功 能 : 清除预约到时节目
- 入 口 : 无
- 出 口 : 无
- 返 回 : 无
- =============================================================*/
- void KB_DelOnTimeDmdEnt()
- {
- time_t cur_seconds;
- EPGDChlLink *pp=EDTLink,*pq=NULL;
- EPGDEntLink *sp,*sq;
- int CurWeekDay=0,nYear, nMonth, nDay;
-
- //先获取当前时间
- if(KB_TimeGetCurTime(&cur_seconds)==0)
- return;
- //检验前把所有今天之前预约的节目清除
- CurWeekDay=ConvertTimeStampToDate((U32)cur_seconds, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- while(pp != NULL)
- {
- sp=pp->DmdEnt;
- sq=NULL;
- while(sp!=NULL)
- {
- if((CurWeekDay)==sp->mjd)///////////////////////////////////////注意问题
- {
- //清除播放的预约节目
- if((cur_seconds >= sp->seconds-30)&&(cur_seconds<=sp->seconds + sp->duration))
- {
- KB_DelDataLink(sp->mjd,(int)sp->seconds);
- //printf("n---------del-------- yijingbofangjiemu");
- if(sq == NULL)
- {
- pp->DmdEnt=pp->DmdEnt->next;
- KB_OSPFree(sp);
- sp=pp->DmdEnt;
- }
- else
- {
- sq->next=sp->next;
- KB_OSPFree(sp);
- sp=sq->next;
- }
- }
- else
- {
- sq=sp;
- sp=sp->next;
- }
- }
- else
- {
- sq=sp;
- sp=sp->next;
- }
- }
- //如果当前频道没有任何预约节目,清除该频道
- if(pp->DmdEnt == NULL)
- {
- if(pq == NULL)
- {
- EDTLink=EDTLink->next;
- KB_OSPFree(pp);
- pp=EDTLink;
- }
- else
- {
- pq->next=pp->next;
- KB_OSPFree(pp);
- pp=pq->next;
- }
- }
- else
- {
- pq =pp;
- pp=pp->next;
- }
- }
- }
- /*=============================================================
- 函数名称 : KB_CheckOnlyOne
- 功 能 : 预约节目是否同时播出校验
- 入 口 : USHORT mjg-----------节目播出日期
- int secs ------------节目播出起始秒
- 出 口 : int * nManiIdx------ 频道索引
- int* nSubIdx ------- 节目索引
- 返 回 : TRUE---成功(有同时播出的节目,但不替换),FALSE---失败(没有相同或者已经替换掉)
- =============================================================*/
- BOOL KB_CheckOnlyOne(USHORT mjg,int secs,int * nManiIdx,int* nSubIdx)
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- EPGDEntLink *p1,*p2;
- register int nm=0,ns;
- //char *pszInfo;
- int nLangType;
- nLangType=KB_DBGetLanguageFlag();
- //搜索同日期同时播出的节目
- while(pp != NULL)
- {
- sp=pp->DmdEnt;
- ns=0;
- p1=sp;
- while(sp != NULL)
- {
-
- if((sp->mjd == mjg )&&(sp->seconds == secs))
- {
- *nManiIdx=nm;
- *nSubIdx=ns;
- //pszInfo=KB_GetLanguageInfoStr(nLangType,STR_BEIJING);//提示只能同时播一个节目
- //if(pszInfo != NULL)
- //nRet=D_OSD_MSGBox("冲突替换原有的吗?", MB_YESNO|MB_ICONINFORMATION, 0,IDNO);
- //if(nRet == IDNO) //不替换
- //return TRUE;
- //替换
- if(sp==pp->DmdEnt)
- {
- pp->DmdEnt=sp->next;
- }
- else
- {
- p2->next=p1->next;
- }
- KB_OSPFree(sp);
- return FALSE;//替换
- }
- ns++;
- sp = sp->next;
- if(p1->next!=NULL)
- {
- p2=p1;
- p1=p1->next;
- }
- }
- nm++;
- pp = pp->next;
- }
- //没有找到
- *nManiIdx=-1;
- *nSubIdx=-1;
-
- return FALSE;//无冲突
- }
- /*=============================================================
- 函数名称 : KB_GetDmdEntCount
- 功 能 : 获取预约节目总数目
- 入 口 : 无
- 出 口 : 无
- 返 回 : 预约节目总数
- =============================================================*/
- int KB_GetDmdEntCount()
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- register int i=0;
- while(pp!=NULL)
- {
- sp=pp->DmdEnt;
- while(sp!=NULL)
- {
- i++;
- sp=sp->next;
- }
- pp=pp->next;
- }
- return i;
- }
- /*=============================================================
- 函数名称 : KB_CheckOntimeDemand
- 功 能 : 检验出到时间的预约节目,然后提示用户
- 入 口 : 无
- 出 口 : 无
- 返 回 : TRUE---有,FALSE---没有
- =============================================================*/
- BOOL KB_CheckOntimeDemand(int *chno,int*type,int*entid)
- {
- EPGDChlLink *pp=EDTLink,*pq=NULL;
- EPGDEntLink *sp,*sq;
- time_t cur_seconds;
- int nYear, nMonth, nDay;
- int sCurWeekDay=0;
- //先获取当前时间
- KB_TimeGetCurTime(&cur_seconds);
- sCurWeekDay=ConvertTimeStampToDate((U32)cur_seconds, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- //检验前把所有今天之前预约的节目清除
- while(pp != NULL)
- {
- sp=pp->DmdEnt;
- sq=NULL;
- while(sp!=NULL)
- {
- //凡是预约日期小于当天日期的,全部清除
- if(sp->mjd<sCurWeekDay)
- {
- if(sq == NULL)
- {
- pp->DmdEnt=pp->DmdEnt->next;
- KB_OSPFree(sp);
- sp=pp->DmdEnt;
- }
- else
- {
- sq->next=sp->next;
- KB_OSPFree(sp);
- sp=sq->next;
- }
- }
- else if(sCurWeekDay==sp->mjd)
- {
- //当天如果已经被播放过,清除它
- if (cur_seconds >= sp->seconds+24)
- {
- if(sq == NULL)
- {
- pp->DmdEnt=pp->DmdEnt->next;
- KB_OSPFree(sp);
- sp=pp->DmdEnt;
- }
- else
- {
- sq->next=sp->next;
- KB_OSPFree(sp);
- sp=sq->next;
- }
- }
- else
- {
- sq=sp;
- sp=sp->next;
- }
- }
- else
- {
- sq=sp;
- sp=sp->next;
- }
- }
- //如果当前频道没有任何预约节目,清除该频道
- if(pp->DmdEnt == NULL)
- {
- if(pq == NULL)
- {
- EDTLink=EDTLink->next;
- KB_OSPFree(pp);
- pp=EDTLink;
- }
- else
- {
- pq->next=pp->next;
- KB_OSPFree(pp);
- pp=pq->next;
- }
- }
- else
- {
- pq =pp;
- pp=pp->next;
- }
- }
- //开始校验
- pq=EDTLink;
- while(pq != NULL)
- {
- sq=pq->DmdEnt;
- while(sq != NULL)
- {
- //持续秒
- //printf("n----left time------%d",cur_seconds - sq->seconds);
- if ((cur_seconds >= (sq->seconds-30))&& (cur_seconds < sq->seconds) )
- {
- if(chno != NULL&&type!= NULL&&entid!= NULL)
- {
- *chno=pq->ProgIndex;
- *type=pq->edt;
- *entid=sq->eventid;
- }
- return TRUE;
- }
-
- sq=sq->next;
- }
- pq=pq->next;
- }
- return FALSE;
- }
- /*=============================================================
- 函数名称 : KB_SaveDmdEnt
- 功 能 : 存储预约信息到NVM,前4个字节是操作标记,紧接着4个字节
- 放数据信息的大小,其次接着4个字节是频道数,每个频道的
- 数据信息前面4个字节存放当前频道预约节目个数,
- ---------------------------------------------------------------------------------
- | 标记 | 总数 | 频道 | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | 据大 | 总数 | | id | 总数 | | | | |
- | 4b | 小4b | 4b | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- ---------------------------------------------------------------------------------
- --------------------------------------------------------
- | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | id | 总数 | | | | |
- | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- --------------------------------------------------------
- --------------------------------------------------------
- | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | id | 总数 | | | | |
- | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- --------------------------------------------------------
- 入 口 : 无
- 出 口 : 无
- 返 回 : OSD_RETURN_FAIL:失败,OSD_RETURN_OK:成功
- =============================================================*/
- int KB_SaveDmdEnt()
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- char *debuf;
- UINT nSize=12;
- int ret;
- int nchlsum=0,npgmsum,*pnde,*ppnde;
- //先计算数据信息的大小
- while(pp!= NULL)
- {
- nchlsum+=1;
- nSize+=8;
- sp=pp->DmdEnt;
- while(sp != NULL)
- {
- nSize+=16;
- sp=sp->next;
- }
- pp=pp->next;
- }
- //总字节数
- nSize+=nchlsum*4;
- debuf=(char*)KB_OSPMalloc(nSize);
- if(NULL==debuf)
- return OSD_RETURN_FAIL;
- memset(debuf,0x00,nSize);
- strcpy(debuf,EDHF_OPER_FLAG);
- //存储预约信息
- pnde=(int*)(debuf+4);
- pp=EDTLink;
- *(pnde++)=nSize;
- *(pnde++)=nchlsum;
- while(pp!= NULL)
- {
- *(pnde++)=pp->edt;
- *(pnde++)=pp->ProgIndex;
- sp=pp->DmdEnt;
- ppnde=pnde++;
- npgmsum=0;
- while(sp != NULL)
- {
- npgmsum+=1;
- *(pnde++)=(int)(sp->mjd&0x0000FFFF);
- *(pnde++)=(int)sp->seconds;
- *(pnde++)=(int)sp->duration;
- *(pnde++)=(int)(sp->eventid&0x0000FFFF);
- sp=sp->next;
- }
- *ppnde=npgmsum;
- pp=pp->next;
- }
-
- //写入NVM
- // ret=BQ_Storage_DmdEntSave((ULONG)nSize,debuf);
- KB_DBSaveDemandInfo(nSize, (UINT8 *)debuf );//存储到e2p
- KB_OSPFree(debuf);
- return ret;
- }
- /*=============================================================
- 函数名称 : KB_LoadDmdEnt
- 功 能 : 加载预约信息到预约结构
- ---------------------------------------------------------------------------------
- | 标记 | 总数 | 频道 | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | 据大 | 总数 | | id | 总数 | | | | |
- | 4b | 小4b | 4b | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- ---------------------------------------------------------------------------------
- --------------------------------------------------------
- | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | id | 总数 | | | | |
- | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- --------------------------------------------------------
- --------------------------------------------------------
- | 类型 | 节目 | 事件 | mjd | sec | dur | eid |
- | | id | 总数 | | | | |
- | 4b | 4b | 4b | 4b | 4b | 4b | 4b |
- --------------------------------------------------------
- 入 口 : 无
- 出 口 : 无
- 返 回 : OSD_RETURN_FAIL:失败,OSD_RETURN_OK:成功
- =============================================================*/
- int KB_LoadDmdEnt()
- {
- char *debuf,head[9];
- UINT nSize;
- int *pnde;
- register int chlsum,i,j,npgmsum;
- int pi,sec,dur;
- USHORT mjd;
- short eventid;
- KB_DBRET ret;
- enumDemandType edt;
- EPGDChlLink **pp;
- EPGDEntLink **sp;
- BOOL bFind;
- //先读取信息的总长度
- memset(head,0x00,9);
- ret=KB_DBGetDemandInfo(8,(UINT8 *)head);
- if(ret==RET_FAIL)
- return OSD_RETURN_FAIL;
- if(strncmp(head,EDHF_OPER_FLAG,4)!=0)
- return OSD_RETURN_FAIL;
-
- pnde=(int*)head;
- nSize=*(pnde+1);
- //分配信息内存
- debuf=(char*)KB_OSPMalloc(nSize);
- if(NULL == debuf)
- return OSD_RETURN_FAIL;
- memset(debuf,0x00,nSize);
- //读取信息
- ret=KB_DBGetDemandInfo(nSize,(UINT8 *)debuf);
- if(ret==RET_FAIL)
- {
- KB_OSPFree(debuf);
- return OSD_RETURN_FAIL;
- }
- pnde=(int*)(debuf+8);
- chlsum=*(pnde++);
- for(i=0;i<chlsum;i++)
- {
- edt=*(pnde++);
- pi=*(pnde++);
- pp=&EDTLink;
- bFind=FALSE;
- //添加预约项
- //搜索到到指定的频道,如果没有添加指定频道
- while(*pp != NULL)
- {
- if((*pp)->ProgIndex == pi)
- {
- bFind = TRUE;
- break;
- }
- pp = &((*pp)->next);
- }
- //没有找到
- if(!bFind)
- {
- //先添加频道
- *pp=(EPGDChlLink*)KB_OSPMalloc(sizeof(EPGDChlLink));
- if(*pp == NULL)
- {
- printf("nEPG节目预约内存分配失败!");
- KB_OSPFree(debuf);
- return OSD_RETURN_FAIL;
- }
- memset(*pp,0x00,sizeof(EPGDChlLink));
- (*pp)->edt=edt;
- (*pp)->ProgIndex = pi;
- }
- npgmsum=*(pnde++);
- for(j=0;j<npgmsum;j++)
- {
- mjd=(USHORT)(*(pnde++)&0xFFFF);
- sec=*(pnde++);
- dur=*(pnde++);
- eventid=(short)(*(pnde++)&0xFFFF);
- //搜索到预约节目
- bFind=FALSE;
- sp=&((*pp)->DmdEnt);
- while(*sp != NULL)
- {
- if((*sp)->mjd == mjd &&(*sp)->seconds == sec&&(*sp)->eventid==eventid)
- {
- bFind = TRUE;
- break;
- }
- sp = &((*sp)->next);
- }
- //如果找到,说明已经被添加
- if(bFind)
- {
- continue;
- }
- //添加预约节目
- *sp=(EPGDEntLink*)KB_OSPMalloc(sizeof(EPGDEntLink));
- if(*sp == NULL)
- {
- printf("nEPG节目预约内存分配失败!");
- KB_OSPFree(debuf);
- return OSD_RETURN_FAIL;
- }
- memset(*sp,0x00,sizeof(EPGDEntLink));
- (*sp)->seconds=sec;
- (*sp)->mjd=mjd;
- (*sp)->duration=dur;
- (*sp)->eventid=eventid;
- (*sp)->next=NULL;
- }
- }
- KB_OSPFree(debuf);
- return OSD_RETURN_OK;
- }
- /*=============================================================
- 函数名称 : KB_AddDmdEnt
- 功 能 : 预约节目
- 入 口 : int nChlNo----------频道索引号
- int nent------------事件索引号
- int nWeekCurTab----预约日期
- 出 口 : 无
- 返 回 : OSD_RETURN_OK---成功,OSD_RETURN_FAIL---失败
- =============================================================*/
- int KB_AddDmdEnt(int nChlNo,int nent,int nWeekCurTab,int Evntid,int type)
- {
- EPGDChlLink **pp=&EDTLink;
- EPGDEntLink **sp;
- //EPGDEntLink **p1,**p2;
- BOOL bFind=FALSE;
- time_t cur_seconds,start_time,duration_time;
- KB_SIEitSchEvent po;
- //U32 year, month, day;
- //USHORT po_MJD;
- int sum;
- //UINT nRet=IDYES;
- int nLangType;
- //char *pszInfo;
- //BOOL displace_order;
- KB_EPGDayInfo *dateinfo;
- int ncurday=0;
- //int nYear, nMonth, nDay;
- KB_NVODStruct *curNvodNodeHead;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
- nLangType=KB_DBGetLanguageFlag();
- KB_TimeGetCurTime(&cur_seconds);
- if(type==DT_EPG)
- {
- KB_DBGetChnlInfoByPrgNO(DTVPRG, nChlNo+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- dateinfo= KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, nChlNo),nWeekCurTab);
- po =dateinfo->ptEvent[nent];
- start_time=po.start_time;
- duration_time=po.duration;
- ncurday=nWeekCurTab;
- Evntid=nent;
- }
- if(type==DT_NVOD)
- {
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(nChlNo);
- start_time=curNvodNodeHead->TimeNode[nent].startTime;
- duration_time=curNvodNodeHead->durTime;
- Evntid=-1;
- }
- if(type==DT_MANAGE)
- {
- start_time=nent;
- ncurday=nWeekCurTab;
- }
- //printf("nshengyushijian----%d",cur_seconds - start_time);
- //当天当时以后的节目都可以预约
-
- //printf("n[KB_AddDmdEnt]: cur_seconds=%ld,start_time=%ld,nent=%ld",cur_seconds,start_time,nent);
- //cur_seconds-=100000;
- if (cur_seconds >= Time_2_Local_Tiem(start_time))
- {
- #if 0 //在老版本的代码中打开这段代码
- pszInfo=KB_GetLanguageInfoStr(nLangType,STR_SYSSETTING);
- if(pszInfo != NULL)
- D_OSD_MSGBox("已经过时", MB_OK|MB_ICONINFORMATION, 0,IDOK);
- #endif
- return OSD_RETURN_FAIL;
- }
- //在老版本的代码中打开这段代码,用于检测是否有冲突预定节目并判断是否替换
- #if 0
- //同时播出校验
- displace_order=KB_CheckOnlyOne((USHORT)nWeekCurTab,start_time,&nm,&ns);
- if (displace_order==TRUE)
- {
- printf("n有相同,但不替换");
- return OSD_RETURN_FAIL;
- }
- #endif
-
- sum=KB_GetDmdEntCount();
- if(sum>=10)
- {
- #if 0//在老版本代码中打开
- pszInfo=KB_GetLanguageInfoStr(nLangType,STR_SYSSETTING);
- if(pszInfo != NULL)
- D_OSD_MSGBox("已经满10个", MB_OK, 0,IDOK);
- #endif
- return OSD_RETURN_FAIL;
- }
- //添加
- while(*pp != NULL)
- {
- if(type==DT_MANAGE)
- type=(*pp)->edt;
- if((*pp)->ProgIndex == nChlNo&&(*pp)->edt==type)
- {
- bFind = TRUE;
- //printf("n-----------find the same chl");
- break;
- }
- pp = &((*pp)->next);
- }
- //没有找到相同的频道
- if(!bFind)
- {
- //先添加频道
- *pp=(EPGDChlLink*)KB_OSPMalloc(sizeof(EPGDChlLink));
- if(*pp == NULL)
- {
- printf("nEPG节目预约内存分配失败!");
- return OSD_RETURN_FAIL;
- }
- memset(*pp,0x00,sizeof(EPGDChlLink));
- (*pp)->edt=type;
- (*pp)->ProgIndex = nChlNo;
- //printf("n--------no--find ");
- }
- sp=&((*pp)->DmdEnt);
- //搜索到预约节目的末尾
- bFind=FALSE;
- while(*sp != NULL)
- {
- if((*sp)->seconds == start_time)
- {
- bFind = TRUE;
- printf("n---------find event");
- break;
- }
- sp = &((*sp)->next);
- }
- //如果找到,说明已经被预约
- if(bFind)
- {
- //pszInfo=KB_GetLanguageInfoStr(nLangType,STR_SYSSETTING);
- #if 0//在老版本代码中打开
- if(pszInfo != NULL)
- D_OSD_MSGBox("已经被预约", MB_OK|MB_ICONINFORMATION, 0,IDOK);
- #endif
- return OSD_RETURN_FAIL;
- }
- //添加预约节目
- *sp=(EPGDEntLink*)KB_OSPMalloc(sizeof(EPGDEntLink));
- if(*sp == NULL)
- {
- printf("nEPG节目预约内存分配失败!");
- return OSD_RETURN_FAIL;
- }
- memset(*sp,0x00,sizeof(EPGDEntLink));
- (*sp)->seconds=start_time;
- (*sp)->duration=duration_time;
- (*sp)->mjd=(USHORT)ncurday;
- (*sp)->eventid=Evntid;
- (*sp)->next=NULL;
- return OSD_RETURN_OK;
- }
- /*=============================================================
- 函数名称 : KB_DelDmdEnt
- 功 能 : 取消预约
- 入 口 : int nChlNo----------频道索引号
- int nent-----------事件索引号
- int nWeekCurTab----预约日期
-
- 出 口 : 无
- 返 回 : OSD_RETURN_OK---成功,OSD_RETURN_FAIL---失败
- =============================================================*/
- int KB_DelDmdEnt(int nChlNo,int nent,int nWeekCurTab ,int type)
- {
- EPGDChlLink *pp=EDTLink,*pq=NULL;
- EPGDEntLink *sp,*sq;
- BOOL bFind=FALSE;
- //int seconds,dtv_type;
- KB_EPGDayInfo *dateinfo;
- KB_SIEitSchEvent po;
- KB_NVODStruct *curNvodNodeHead;
- time_t cur_seconds,start_time;
- int ncurday,nYear, nMonth, nDay;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
-
- //printf("n-----------------del");
- if(type==DT_EPG)
- {
- KB_DBGetChnlInfoByPrgNO(DTVPRG, nChlNo+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- dateinfo= KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, nChlNo),nWeekCurTab);
- po =dateinfo->ptEvent[nent];
- ncurday=nWeekCurTab;
- start_time=po.start_time;
- }
- if(type==DT_NVOD)
- {
- KB_TimeGetCurTime(&cur_seconds);
- ncurday=ConvertTimeStampToDate((U32)cur_seconds, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(nChlNo);
- start_time=curNvodNodeHead->TimeNode[nent].startTime;
- }
- if(type==DT_MANAGE)
- {
- ncurday=nWeekCurTab;
- start_time=nent;
- }
- //搜查指定频道,如果指定频道没有预定节目,清除此频道
- while(pp != NULL)
- {
- if(type==DT_MANAGE)
- type=pp->edt;
- if(pp->ProgIndex ==nChlNo&&pp->edt==type)
- {
- bFind=TRUE;
- break;
- }
- pq=pp;
- pp =pp->next;
- }
- //没有找到,并且是第一个节点,而且还是没有节目
- //删除它
- if(!bFind)
- {
- if(pq == NULL && pp->DmdEnt==NULL)
- {
- EDTLink=EDTLink->next;
- KB_OSPFree(pp);
- }
- return OSD_RETURN_OK;
- }
- sp=pp->DmdEnt;
- sq =NULL;
- bFind=FALSE;
- //搜索指定的预约节目
- while(sp != NULL)
- {
- if(sp->mjd== ncurday && sp->seconds==start_time)
- {
- bFind=TRUE;
- break;
- }
- sq =sp;
- sp=sp->next;
- }
- //找到,释放,如果频道没有预约节目,释放频道
- if(bFind)
- {
- if(sq == NULL)
- pp->DmdEnt=pp->DmdEnt->next;
- else
- sq->next=sp->next;
- KB_OSPFree(sp);
- if(pp->DmdEnt == NULL)
- {
- if(pq==NULL)
- EDTLink=EDTLink->next;
- else
- pq->next=pp->next;
- KB_OSPFree(pp);
- }
- }
- return OSD_RETURN_OK;
- }
- /*=============================================================
- 函数名称 : KB_CheckDmdEnt
- 功 能 : 预约校验,检查该事件是否预约
- 入 口 : int nChlNo----------频道索引号
- int nent-----------事件索引号
- int nWeekCurTab----预约日期//NVOD时无效
- int type---------------类别
- 出 口 : 无
- 返 回 : TRUE---预约,FALSE---没有预约
- =============================================================*/
- BOOL KB_CheckDmdEnt(int nChlNo,int nent,int nWeekCurTab,int type)
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- BOOL bFind=FALSE;
- int seconds;
- KB_EPGDayInfo *dateinfo;
- KB_SIEitSchEvent po;
- KB_NVODStruct *curNvodNodeHead;
- time_t cur_seconds;
- int ncurday,nYear, nMonth, nDay;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
-
- if(type==DT_EPG)
- {
- KB_DBGetChnlInfoByPrgNO(DTVPRG, nChlNo+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- dateinfo= KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, nChlNo),nWeekCurTab);
- po =dateinfo->ptEvent[nent];
- ncurday=nWeekCurTab;
- seconds=(int)po.start_time;
- }
- if(type==DT_NVOD)
- {
- KB_TimeGetCurTime(&cur_seconds);
- ncurday=ConvertTimeStampToDate((U32)cur_seconds, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(nChlNo);
- seconds = (int)curNvodNodeHead->TimeNode[nent].startTime;
- }
- if(type==DT_MANAGE)
- {
- seconds=nent;
- ncurday=nWeekCurTab;
- }
- //搜查指定频道,如果指定频道没有预定节目,清除此频道
- while(pp != NULL)
- {
- if(type==DT_MANAGE)
- type=pp->edt;
-
- if(pp->ProgIndex == nChlNo&&pp->edt==type)
- {
- bFind=TRUE;
- break;
- }
- pp =pp->next;
- }
- //没有找到,返回
- if(!bFind)
- return FALSE;
- //搜索指定的预约节目
- sp=pp->DmdEnt;
- while(sp != NULL)
- {
- if(sp->mjd==ncurday && sp->seconds == seconds)
- {
- return TRUE;
- }
- sp=sp->next;
- }
- return FALSE;
- }
- //added by whale 07/06/08 start
- /*=============================================================
- 函数名称 : KB_CreatDmdDataLink
- 功 能 : 预约管理列表内容初始化
- 入 口 : BOOL bOnTime------显示标志(TRUE:所有预约到时节目,FALSE:所有预约节目)
- BOOL bNoList------没有列表显示
- 出 口 : 无
- 返 回 : OSD_RETURN_OK---成功,OSD_RETURN_FAIL---失败
- =============================================================*/
- int KB_CreatDmdDataLink(void)
- {
- time_t cur_seconds;
- int nYear, nMonth, nDay,nHour,nMinute,nSec;
- EPGDChlLink *pq=EDTLink;
- EPGDEntLink *sq;
- //int nRet,si=0;
- char strname[50],*pszName;
- U32 nLocalTime;
- KB_EPGDayInfo * pEPGInfo;
- KB_SIEitSchEvent po;
- KB_NVODStruct *curNvodNodeHead;
- int nLangType;
- int i=0,sCurWeekDay=0;
- //added by yyj 2007.6.11
- EPGDDataLink demanddata;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
-
- nLangType=KB_DBGetLanguageFlag();
- //先获取当前时间
- KB_TimeGetCurTime(&cur_seconds);
- //printf("n[KB_CreatDmdDataLink]:cur_seconds=%ld",cur_seconds);
- sCurWeekDay=ConvertTimeStampToDate((U32)cur_seconds, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- // printf("n[KB_CreatDmdDataLink]:sCurWeekDay=%d",sCurWeekDay);
- KB_ClearDataLink();
- while(pq != NULL)
- {
- sq=pq->DmdEnt;
- if(pq->edt == DT_EPG)
- {
- //pEPGInfo =KB_EPGGetSchInfo(KB_DBGetSvcIDByNO(DTVPRG, pq->ProgIndex), pq->DmdEnt->mjd);
- KB_DBGetChnlInfoByPrgNO(DTVPRG, pq->ProgIndex+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- pEPGInfo=KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, pq->ProgIndex),pq->DmdEnt->mjd);
-
- }
- else
- {
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(pq->ProgIndex);
- }
-
- while(sq != NULL)
- {
- if(pq->edt == DT_EPG)
- {
- po=pEPGInfo->ptEvent[sq->eventid];
- }
-
- {
- //设置0单元频道名称
- if(pq->edt == DT_EPG)
- {
- if(pq->ProgIndex<0)
- ;
- else
- {
- pszName=(char *)KB_DBGetPrgName(DTVPRG,pq->ProgIndex+1);
- memset(strname,0x00,50);
- sprintf(strname,"%02d%s",++i,pszName);
- if(strname!=NULL)
- printf("-=频道名称:%s=-n", strname);
- strcpy(demanddata.chlname, strname);
- /*
- if(strname!=NULL)
- nRet= AddListViewItem(&hEDHFlv,demanddata.chlname);
- if(-1 == nRet)
- {
- printf("n添加预约节目列表项0失败!");
- return OSD_RETURN_FAIL;
- }
- */
-
- }
- }
- else
- {
- memset(strname,0x00,50);
- sprintf(strname,"%02d%s",++i,"NVOD");
- printf("-=频道名称:%s=-n", strname);
- strcpy(demanddata.chlname, strname);
- /*
- nRet= AddListViewItem(&hEDHFlv,strname);
- if(-1 == nRet)
- {
- printf("n添加预约节目列表项0失败!");
- return OSD_RETURN_FAIL;
- }
- */
- }
- nLocalTime = (U32)Time_2_Local_Tiem(sq->seconds);
- //printf("n[KB_CreatDmdDataLink]:nLocalTime=%ld,sq->seconds=%ld",nLocalTime,sq->seconds);
- //节目播放日期
- ConvertTimeStampToDate(nLocalTime, (U32 *)&nYear, (U32 *)&nMonth, (U32 *)&nDay);
- memset(demanddata.date,0x00,20);
- sprintf(demanddata.date,"%04d-%02d-%02d",nYear, nMonth, nDay);
- printf("n[KB_CreatDmdDataLink]:date=%sn",demanddata.date);
- //节目播放时间
- ConvertTimeStampToTime(nLocalTime,( U32 * )&nHour, (U32 *)&nMinute, (U32 *)&nSec);
- memset(demanddata.time,0x00,20);
- sprintf(demanddata.time,"%02d:%02d",nHour, nMinute);
- printf("n[KB_CreatDmdDataLink]:time=%sn",demanddata.time);
- //memset(str,0x00,50);
- //sprintf(str,"%04ld-%02ld-%02ld %02d:%02d",nYear,nMonth,nDay,nHour,nMinute);
- /*
- //设置1单元节目播放时间
- sprintf(str,"%s %s",demanddata.date,demanddata.time);
- printf("n[KB_CreatDmdDataLink]:str=%s",str);
- if(strlen(str)<=0)
- nRet = SetLVItemText(&hEDHFlv,nRet,1,"---");
- else
- nRet = SetLVItemText(&hEDHFlv,nRet,1,str);
- if(-1 == nRet)
- {
- printf("n添加预约节目列表项1失败!");
- return OSD_RETURN_FAIL;
- }
- */
-
- //设置2单元频道名称
- if(pq->edt == DT_EPG)
- {
- memset(strname,0x00,50);
- sprintf(strname,"%s",(char*)po.chinese.event_name);
- if(strlen((char*)po.chinese.event_name)>0)
- printf("-=epg节目名称:%s=-n", strname);
- strcpy(demanddata.prgname, strname);
- /*
- if(strlen((char*)po.chinese.event_name)>0)
- nRet= SetLVItemText(&hEDHFlv,nRet,2,demanddata.prgname);
- else
- nRet= SetLVItemText(&hEDHFlv,nRet,2,"- - -");
- if(-1 == nRet)
- {
- printf("n添加预约节目列表项2失败!");
- return OSD_RETURN_FAIL;
- }
- */
- }
- else
- {
- memset(strname,0x00,50);
- sprintf(strname,"%s",(char*)curNvodNodeHead->PrgName);
- if(strlen((char*)curNvodNodeHead->PrgName)>0)
- printf("-=nvod节目名称:%s=-n", strname);
- strcpy(demanddata.prgname, strname);
- /*
- if(strlen((char*)curNvodNodeHead.PrgName)>0)
- nRet= SetLVItemText(&hEDHFlv,nRet,2,demanddata.prgname);
- else
- nRet= SetLVItemText(&hEDHFlv,nRet,2,"- - -");
- if(-1 == nRet)
- {
- printf("n添加预约节目列表项2失败!");
- return OSD_RETURN_FAIL;
- }
- */
- }
-
- #if 0
- if(!KB_AddDataLink(pq->ProgIndex,sq->eventid, sq->mjd,sq->seconds,sq->duration,pq->edt))
- continue;
- #else
- if(!KB_AddDataLink(&demanddata))
- continue;
- #endif
- }
- sq=sq->next;
- }
- pq=pq->next;
- }
- return OSD_RETURN_OK;
- }
- //added by whale 07/06/08 end
- //added by yyj 2007.7.3 start
- /*=============================================================
- 函数名称 : KB_ClearAllDmdEnt
- 功 能 : 清除预约链表中的所有节目
- 入 口 : 无
- 出 口 : 无
- 返 回 : 无
- =============================================================*/
- void KB_ClearAllDmdEnt(void)
- {
- EPGDChlLink *pp=EDTLink,*pq=NULL;
- while(pp != NULL)
- {
- pq = pp->next;
- while(pp->DmdEnt!=NULL)
- {
- pq->DmdEnt = pp->DmdEnt->next;
- KB_OSPFree(pp->DmdEnt);
- pp->DmdEnt = pq->DmdEnt;
- }
- KB_OSPFree(pp);
- pp = pq;
- }
- EDTLink = NULL;
- }
- //added by yyj 2007.7.3 end
- //added by yyj 2007.7.4 start
- /*=============================================================
- 函数名称 : KB_CheckConfilictDmdEnt
- 功 能 : 检测预约节目是否同时播出
- 入 口 : USHORT mjg-----------节目播出日期
- int nChlNo----------节目频道号
- int nent-------------事件索引号
- int type------------节目类型
- 出 口 : int * nManiIdx------ 频道索引
- int* nSubIdx ------- 节目索引
- 返 回 : DEMAND_PGM_OVERTIME----预约节目过时
- DEMAND_PGM_CONFLICT----有冲突的预定节目
- DEMAND_PGM_NO_CONFLICT----没有冲突的预定节目
- =============================================================*/
- BOOL KB_CheckConfilictDmdEnt(USHORT mjg,int nChlNo,int nent,int * nManiIdx,int* nSubIdx,int type)
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- register int nm=0,ns;
- //char *pszInfo;
- int nLangType;
- time_t cur_seconds,start_time,duration_time;
- KB_EPGDayInfo *dateinfo;
- KB_SIEitSchEvent po;
- int ncurday=0;
- KB_NVODStruct *curNvodNodeHead;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
- //UINT8 sum;
- nLangType=KB_DBGetLanguageFlag();
- KB_TimeGetCurTime(&cur_seconds);
- if(type==DT_EPG)
- {
- KB_DBGetChnlInfoByPrgNO(DTVPRG, nChlNo+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- dateinfo= KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, nChlNo),mjg);
- po =dateinfo->ptEvent[nent];
- start_time=po.start_time;
- duration_time=po.duration;
- ncurday=mjg;
- //Evntid=nent;
- }
- if(type==DT_NVOD)
- {
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(nChlNo);
- start_time=curNvodNodeHead->TimeNode[nent].startTime;
- duration_time=curNvodNodeHead->durTime;
- //Evntid=-1;
- }
- if(type==DT_MANAGE)
- {
- start_time=nent;
- ncurday=mjg;
- }
-
- if (cur_seconds >= Time_2_Local_Tiem(start_time))
- {
- printf("n预定节目过时!");
- return DEMAND_PGM_OVERTIME;
- }
-
- //搜索同日期同时播出的节目
- while(pp != NULL)
- {
- sp=pp->DmdEnt;
- ns=0;
- while(sp != NULL)
- {
- if((sp->mjd == mjg )&&(sp->seconds == start_time))
- {
- *nManiIdx=nm;
- *nSubIdx=ns;
-
- return DEMAND_PGM_CONFLICT;//有冲突的预定节目
- }
- ns++;
- sp = sp->next;
- }
- nm++;
- pp = pp->next;
- }
- //没有找到
- *nManiIdx=-1;
- *nSubIdx=-1;
- return DEMAND_PGM_NO_CONFLICT;//没有冲突的预定节目
- }
- /*=============================================================
- 函数名称 : KB_DelConfilictDmdEnt
- 功 能 : 删除同时播出的预约节目
- 入 口 : USHORT mjg-----------节目播出日期
- int nChlNo----------节目频道号
- int nent-------------事件索引号
- int type------------节目类型
- 出 口 : int * nManiIdx------ 频道索引
- int* nSubIdx ------- 节目索引
- 返 回 : TRUE---成功(删除冲突的预约节目),FALSE---失败(没有冲突节目)
- =============================================================*/
- BOOL KB_DelConfilictDmdEnt(USHORT mjg,int nChlNo,int nent,int * nManiIdx,int* nSubIdx,int type)
- {
- EPGDChlLink *pp=EDTLink;
- EPGDEntLink *sp;
- EPGDEntLink *p1,*p2;
- register int nm=0,ns;
- //char *pszInfo;
- int nLangType;
- time_t cur_seconds,start_time,duration_time;
- KB_EPGDayInfo *dateinfo;
- KB_SIEitSchEvent po;
- int ncurday=0;
- KB_NVODStruct *curNvodNodeHead;
- unsigned long fre, sym;
- unsigned char qam;
- UINT16 tsid;
- nLangType=KB_DBGetLanguageFlag();
- KB_TimeGetCurTime(&cur_seconds);
- if(type==DT_EPG)
- {
- KB_DBGetChnlInfoByPrgNO(DTVPRG, nChlNo+1, &fre, &sym, &qam);
- KB_DBGetTsIDByFre(&tsid, fre/100000);
- dateinfo= KB_EPGGetSchInfo(tsid, KB_DBGetSvcIDByNO(DTVPRG, nChlNo),mjg);
- po =dateinfo->ptEvent[nent];
- start_time=po.start_time;
- duration_time=po.duration;
- ncurday=mjg;
- //Evntid=nent;
- }
- if(type==DT_NVOD)
- {
- curNvodNodeHead=KB_NVOD_GetTsIndexFromCur(nChlNo);
- start_time=curNvodNodeHead->TimeNode[nent].startTime;
- duration_time=curNvodNodeHead->durTime;
- //Evntid=-1;
- }
- if(type==DT_MANAGE)
- {
- start_time=nent;
- ncurday=mjg;
- }
- while(pp != NULL)
- {
- sp=pp->DmdEnt;
- ns=0;
- p1=sp;
- while(sp != NULL)
- {
- if((sp->mjd == mjg )&&(sp->seconds == start_time))
- {
- *nManiIdx=nm;
- *nSubIdx=ns;
- //删除冲突节目
- if(sp==pp->DmdEnt)
- {
- pp->DmdEnt=sp->next;
- }
- else
- {
- p2->next=p1->next;
- }
- KB_OSPFree(sp);
- return TRUE;//删除冲突节目
- }
- ns++;
- sp = sp->next;
- if(p1->next!=NULL)
- {
- p2=p1;
- p1=p1->next;
- }
- }
- nm++;
- pp = pp->next;
- }
- //没有找到
- *nManiIdx=-1;
- *nSubIdx=-1;
- return FALSE;//无相同
- }
- //added by yyj 2007.7.4 end