//THIS IS TELNET SERVER MODULE FUNCTION bool_t ServiceTelnetInit(ptu32_t para) { bool_t result; u16 evttID; u16 eventID; result = false; pTelnetClientSync = Lock_MutexCreate(NULL); if(NULL == pTelnetClientSync) { goto __TELNET_INIT_EXIT; } evttID = Djy_EvttRegist(EN_CORRELATIVE, gTelnetAcceptPrior, 0, 1, __TelnetAcceptMain,NULL, gTelnetAcceptStack, "TelnetAcceptMain"); eventID = Djy_EventPop(evttID, NULL, 0, 0, 0, 0); if((evttID == CN_EVTT_ID_INVALID)||(eventID == CN_EVENT_ID_INVALID)) { printk("%s:Create the accept main failed:evttID:0x%04x eventID:0x%04x\n\r",\ __FUNCTION__,evttID,eventID); goto __TELNET_INIT_EXIT; } gTelnetClientEvttID = Djy_EvttRegist(EN_CORRELATIVE, gTelnetProcessPrior, 0, 1, TelnetClientMain,NULL, gTelnetProcessStack, "TelnetClientMain"); return __telnetConsoleInstall(); __TELNET_INIT_EXIT: return result; }
// ============================================================================= // FUNCTION:this function is used to initialize the transmit layer // PARA IN: // PARA OUT: // RETURN : // INSTRUCT: // ============================================================================= bool_t TPLInit(ptu32_t para) { bool_t result; pTplProtoTab = (tagTplProtoItem *)malloc(sizeof(tagTplProtoItem)*gTplProtoNum); if(NULL == pTplProtoTab) { goto EXIT_MEMFAIL; } memset((void *)pTplProtoTab,0,sizeof(tagTplProtoItem)*gTplProtoNum); pTplProtoSync = Lock_MutexCreate(NULL); if(NULL == pTplProtoSync) { goto EXIT_SYNCFAILED; } result = true; return result; EXIT_SYNCFAILED: free((void *)pTplProtoTab); pTplProtoTab = NULL; EXIT_MEMFAIL: result = false; return result; }
//----创始桌面窗口-------------------------------------------------------------- //描述: 该函数为内部调用,仅限于创建桌面. //参数:proc: 桌面窗口过程回调函数 // Text: 桌面窗口文字指针 // x,y,w,h: 桌面窗口位置和大小 // pdata: 用户自定义附加数据. //返回:桌面窗口句柄. //------------------------------------------------------------------------------ HWND CreateDesktop( WNDPROC *proc, const char *Text, int x,int y,int w,int h, const void *pdata) { WINDOW *pwin=NULL; struct tagGkWinRsc *pGkWin=NULL; u32 Style; if(NULL!=proc) { pwin =WIN_Alloc(); if(NULL!=pwin) { Style = 0; Style &=~(WS_CHILD); _InitWindow(pwin,proc,Text,Style,x,y,w,h,NULL,0); pGkWin =(struct tagGkWinRsc*)malloc(sizeof(struct tagGkWinRsc)); if(!GK_ApiCreateGkwin(pGkWinDesktop, pGkWin, x,y,x+w,y+h, RGB(0,0,0), CN_WINBUF_BUF, "desktop", CN_SYS_PF_DISPLAY, 0,0,0)) { free(pGkWin); return FALSE; } pwin->pGkWin =pGkWin; pwin->mutex_lock =Lock_MutexCreate(NULL); pwin->pMsgQ =GUI_CreateMsgQ(32); pwin->EventID =Djy_MyEventId(); pwin->Zorder =0; GK_ApiSetPrio(pGkWin,pwin->Zorder,100*mS); HWND_Desktop =pwin; SendMessage(pwin,MSG_CREATE,(u32)pdata,0); } } return pwin; }
// ============================================================================= // 函数功能: Socket_New // 分配套接字内存空间 // 输入参数: 无 // 输出参数: 无 // 返回值 :NULL表示分配不成功(内存不足),否则返回分配的套接字结构 // 说明 :分配时空间已经被初始化完毕 // ============================================================================= tagSocket* Socket_New(void) { tagSocket *result; result = Mb_Malloc(pgSocketPool, CN_TIMEOUT_FOREVER); if(NULL != result) { memset(result,0,sizeof(tagSocket)); result->sync = Lock_MutexCreate(NULL); if(NULL != result->sync) { //init the socket result->valid = true; result->socktype = EN_SOCKET_NOTSURE; sgDebugSocket = result; } else { Mb_Free(pgSocketPool, (void *)result); result = NULL; } } return result; }
// ============================================================================= // 函数功能:TPL_Init // 传输层资源树根节点初始化 // 输入参数:暂时无意义 // 输出参数: // 返回值 :true成功 false失败 // 说明 :注意,该初始化函数应该在所有的传输层协议初始化之前执行,否则添加的协议无效 // ============================================================================= bool_t TPL_Init(ptu32_t para) { bool_t result; static struct tagRscNode treenode; result =false; //创建资源树 pgNetRscNodeTree = Rsc_AddTree(&treenode,sizeof(struct tagRscNode), RSC_RSCNODE,NULL); if (NULL != pgNetRscNodeTree) { //创建资源树互斥锁 pgNetRscNodeSync = Lock_MutexCreate(NULL); if (NULL == pgNetRscNodeSync) { Rsc_DelNode(pgNetRscNodeTree); pgNetRscNodeTree = NULL; } else { result = true; } } return result; }
//----创建窗口------------------------------------------------------------------ //描述: 该函数可以创建主窗口和子窗口(控件) //参数:proc: 窗口过程回调函数 // Text: 窗口文字指针 // Style: 窗口风格(具体参考窗口风格组合说明) // x,y,w,h: 桌面窗口位置和大小 // hParent: 父窗口句柄.如果是NULL,则默认桌面为父窗口. // WinId: 窗口Id.如果是主窗口,该参数被忽略. // pdata: 用户自定义附加数据. //返回:窗口句柄. //------------------------------------------------------------------------------ HWND CreateWindow(WNDPROC *pfWinProc, const char *Text,u32 Style, s32 x,s32 y,s32 w,s32 h, HWND hParent,u32 WinId,const void *pdata) { WINDOW *pwin=NULL; struct tagGkWinRsc *pGkWin=NULL; if(NULL==hParent) { hParent =GetDesktopWindow(); } if(HWND_Lock(hParent)) { pwin =WIN_Alloc(); if(NULL!=pwin) { //初始化窗口数据 _InitWindow(pwin,pfWinProc,Text,Style,x,y,w,h,hParent,WinId); x =pwin->WinRect.left; y =pwin->WinRect.top; w =RectW(&pwin->WinRect); h =RectH(&pwin->WinRect); pGkWin =(struct tagGkWinRsc*)malloc(sizeof(struct tagGkWinRsc)); if(Style&WS_CHILD) { if(!GK_ApiCreateGkwin(pGkWinDesktop, pGkWin,x,y,x+w,y+h, RGB(0,0,0), CN_WINBUF_BUF, pwin->Name, CN_SYS_PF_DISPLAY, 0,0,0)) { free(pGkWin); return NULL; } pwin->mutex_lock =hParent->mutex_lock; //子窗口使用父窗口锁 pwin->pMsgQ =hParent->pMsgQ; //子窗口使用父窗口消息队列 pwin->EventID =hParent->EventID; pwin->Zorder =hParent->Zorder-1; GK_ApiSetPrio(pGkWin,pwin->Zorder,100*mS); } else { if(!GK_ApiCreateGkwin(pGkWinDesktop, pGkWin,x,y,x+w,y+h, RGB(0,0,0), CN_WINBUF_BUF, pwin->Name, CN_SYS_PF_DISPLAY, 0,0,0)) { free(pGkWin); return NULL; } pwin->mutex_lock =Lock_MutexCreate(NULL); pwin->pMsgQ =GUI_CreateMsgQ(32); pwin->EventID =Djy_MyEventId(); pwin->Zorder =hParent->Zorder-1; GK_ApiSetPrio(pGkWin,pwin->Zorder,100*mS); } pwin->pGkWin = pGkWin; //将新窗口添加到父窗口 _AddChild(hParent,pwin); } HWND_Unlock(hParent); if(NULL!=pwin) { SendMessage(pwin,MSG_CREATE,(u32)pdata,0); InvalidateWindow(pwin); } } return pwin; }