Msgman.cpp
资源名称:(vc).rar [点击查看]
上传用户:wpp2016
上传日期:2010-02-01
资源大小:1250k
文件大小:8k
源码类别:
Telnet服务器
开发平台:
Visual C++
- // Msgman.cpp : implementation file
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "Msgman.h"
- #include "visualfx.h"
- #include "frameprop.h"
- //test code
- #include "mainfrm.h" //没用
- #include "anywheredoc.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMsgman
- CMsgman::CMsgman(CAnywhereDoc *pDoc)
- {
- msglist_pos=NULL;
- m_pDoc=pDoc;
- }
- CMsgman::~CMsgman()
- {
- Msglist_type *pmsg;
- while (!Msglist.IsEmpty()) {
- pmsg=(Msglist_type *)Msglist.RemoveHead();
- delete pmsg;
- }
- }
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CMsgman, CAsyncSocket)
- //{{AFX_MSG_MAP(CMsgman)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
- /////////////////////////////////////////////////////////////////////////////
- // CMsgman member functions
- void CMsgman::init(HWND hFrame)
- {
- //msglist_pos=NULL;
- m_hFrame=hFrame;
- }
- void CMsgman::SendMsg(CString order)
- {
- //CString order;
- CString text;
- DWORD ThreadId;
- //if (msglist_pos) {
- /*
- Msglist_type *pmsg=(Msglist_type *)Msglist.GetTail();
- order=pmsg->message;
- */
- //}
- if (order=="CONNECT")
- {
- AfxBeginThread(Connect,&linkrc);
- }
- if (order=="GETINFO*")
- {
- //linkrc.pmsgman=this;
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- //AfxBeginThread(Send,&linkrc);
- }
- if (order=="VIEWSCR*")
- {
- //linkrc.pmsgman=this;
- CreateThread(NULL,0,ViewScr,&linkrc,0,&ThreadId);
- //AfxBeginThread(ViewScr,&linkrc);
- }
- if (order=="LISTFILE")
- {
- hSend=CreateThread(NULL,0,SendThread,&linkrc,0,&ThreadId);
- }
- //InsertItem(num,pfile->filename,pfile->icon);
- }
- BOOL CMsgman::AddMsg(CString message, CString msg_tip,enum status_type status, BOOL bEnable, CSockAddr target, int priority)
- {
- /* if (!CheckConnect())
- if (IDYES==MessageBox(m_hMainWnd,"现在需要连接远程主机吗? ","提示:",MB_YESNO))
- {
- Msglist_type * pMsg=new Msglist_type;
- pMsg->message="CONNECT";
- pMsg-msg_tip="与远程机器连接";
- pMsg->status=first;
- pMsg->target=linkrc.sAddr;
- pMsg->bEnable=TRUE;
- msglist_pos=Msglist.InsertAfter(msglist_pos,(CObject*)pMsg);
- SendMsg();//立即发送连接消息
- //优先级并无用处
- return TRUE;
- }
- else return FALSE;
- */
- //msglist_pos=Msglist.GetTailPosition();
- int order=CheckMsg(message);
- if (order==0) {//表示是新的命令
- Msglist_type * pMsg=new Msglist_type;
- pMsg->message=message;
- pMsg->msg_tip=msg_tip;
- pMsg->status=status;
- pMsg->target=target;
- pMsg->bEnable=bEnable;
- Msglist.AddTail(pMsg);
- //msglist_pos=Msglist.InsertAfter(msglist_pos,(CObject*)pMsg);
- //SendMsg();//立即发送
- return TRUE;
- }
- /*
- else if (order==1) { //队列已存在该命令
- if (IDYES==MessageBox(m_hFrame,"系统先前已接受了该条消息,但还没有完成,你希望将命令加入队列,等待发送吗?",
- "提示:",MB_YESNO))
- {
- Msglist_type * pMsg=new Msglist_type;
- pMsg->message=message;
- pMsg->msg_tip=msg_tip;
- pMsg->status=wait;//标记为等待
- pMsg->target=target;
- pMsg->bEnable=bEnable;
- msglist_pos=Msglist.InsertAfter(msglist_pos,(CObject*)pMsg);
- return TRUE;
- }
- }
- */
- return FALSE;//失败的命令
- }
- int CMsgman::CheckMsg(CString message)
- {
- if (!Msglist.IsEmpty()) {
- msglist_pos=Msglist.GetHeadPosition();
- }
- POSITION pos;
- while ((pos=msglist_pos)!=NULL)
- {
- Msglist.GetNext(pos);
- if (pos) {
- Msglist_type *pmsg=(Msglist_type*)Msglist.GetAt(pos);
- if (pmsg->message==message)
- {
- //msglist_pos=Msglist.GetTailPosition();
- //if (pmsg->status==wait)
- return 1;//(找到标记为等待的)
- //else return 2;
- }
- msglist_pos=pos;
- }
- else {
- //msglist_pos=Msglist.GetTailPosition();
- return 0;//没找到立即执行
- }
- }
- //msglist_pos=Msglist.GetTailPosition();
- return 0;//没找到立即执行
- //return TRUE;
- }
- int CMsgman::Respones(CString text)
- {
- //test---
- CString order=text.Left(8);
- int length=text.GetLength();
- text=text.Right(length-8);//text已更改为主要内容
- length=text.GetLength();
- POSITION list_pos=NULL;
- // int pos;
- int num=0;
- if (!CheckMsg(order))
- {
- if (order=="GETINFO*")
- {
- Dispense(text);
- /*BOOL bFinished=FALSE;
- char *pdrv;
- while (!bFinished) {
- if ((pos=m_pDoc->m_sys[8].Find("\"))!=-1)
- {
- pdrv=new char[4];
- strcpy(pdrv,m_pDoc->m_sys[8].Left(pos));
- pdrv[3]=0;
- list_pos=m_pDoc->drvlist.InsertAfter(list_pos,pdrv);
- m_pDoc->m_sys[8]=m_pDoc->m_sys[8].Right(m_pDoc->m_sys[8].GetLength()-pos-1);
- num++;
- }
- else bFinished=TRUE;
- }*/
- return 1;//为sysinfo 的id
- }
- if (order=="VIEWSCR*")
- return 4;
- if (order=="LISTFILE")
- {
- return 2;}
- }
- return 0;//返回值是窗口的id
- }
- void CMsgman::Dispense(CString text)//处理得到的系统信息
- {
- BOOL bFinished=FALSE;
- int num=0;
- int pos;
- while (!bFinished) {
- if ((pos=text.Find("*"))!=-1)
- {
- m_pDoc->m_sys[num]=text.Left(pos);
- text=text.Right(text.GetLength()-pos-1);
- num++;
- }
- else bFinished=TRUE;
- /*else {
- m_pDoc->m_sys[num]=text;
- bFinished=TRUE;
- }*/
- }
- //SendMessage(m_hFrame,WM_SETACTIVE,1,0);
- //m_pDoc->UpdateAllViews(NULL);
- //m_pFrame->SetActive(2);
- //CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
- //m_pDoc->UpdateAllViews();
- //CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
- //if (pFrame) {
- // CDocument *pDoc2=pFrame->GetActiveDocument();
- //CAnywhereDoc *pDoc=(CAnywhereDoc *)(pFrame->GetActiveDocument());
- //}
- }
- int CMsgman::Okmsg(CString text,BOOL success)
- {
- /* if (!Msglist.IsEmpty()) {
- msglist_pos=Msglist.GetHeadPosition();
- }
- */
- // POSITION pos;
- //CString order=text.Left(8);
- if (success)return (Respones(text));
- else return 0; //返回无效id0意味失败;
- /*
- while ((pos=msglist_pos)!=NULL)
- {
- Msglist.GetNext(pos);
- if (pos) {
- Msglist_type *pmsg=(Msglist_type*)Msglist.GetAt(pos);
- if (pmsg->message==order)
- {
- //pmsg->status=done;//标记为完成
- Msglist_type *pmsg=Msglist.GetAt(pos);
- Msglist.RemoveAt(pos);//删除该条命令
- delete pmsg;
- if (success)return (Respones(text));
- else return 0; //返回无效id0意味失败;
- //msglist_pos=Msglist.GetTailPosition();
- //return FALSE;//找到了
- }
- msglist_pos=pos;
- }
- else {
- //msglist_pos=Msglist.GetTailPosition();
- return 0;//没找到
- }
- }
- return 0;
- */
- }
- void CMsgman::SetActive(int id)
- {
- //int nIndex;
- //TVisualFramework *m_Fx;
- //CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
- //m_Fx=&(m_pDoc->m_pFrame)->m_Framework;
- //m_Fx=&((CMainFrame *)AfxGetMainWnd())->m_Framework;
- // (m_pFrame->m_Framework).SetActivePane(m_pFrame->pObject);
- //TVisualFramework m_Fx;
- //&m_Fx=&((CMainFrame*)AfxGetMainWnd())->m_Framework;
- /*TVisualFrameworkIterator it((m_pDoc->m_pFrame)->m_Framework);
- while (!it.End()) {
- TVisualObject *pObject = it.Get();
- if ((pObject->CanFocus()) & (pObject->GetID()==id)) {
- ((m_pDoc->m_pFrame)->m_Framework).SetActivePane(pObject);
- //nIndex = m_List.AddString(pObject->GetDescription());
- //m_List.SetItemData(nIndex, (DWORD)pObject);
- }
- it ++;
- }
- */
- //CFrameworkProperties dialog(
- //dialog.DoModal();
- }
- BOOL CMsgman::CheckConnect()
- {
- if (linkrc.bConnected==1) return
- TRUE;
- else return FALSE;
- }