예제 #1
0
BOOL PEXPORT KppDDEPostAdvise(ATOMID idObjName, ATOMID idSlot)
{
    OBJECTID idLink = FindLink(LinkName(idObjName, idSlot));
    
    if (idLink)
    {
        ATOMID idTopic = Kpp_Get_SlotValue(OBJECT, idLink, Slot(idTopic));
        HSZ hszTopic = AtomToHsz(idTopic);
        WORD wLen = KppGetAtomName(idObjName, return_buffer, RET_BUFFER_LEN);
        BOOL bRes = FALSE;
        HSZ hszItem;
        
        return_buffer[wLen++] = ':';
        KppGetAtomName(idSlot, return_buffer + wLen, RET_BUFFER_LEN - wLen);
        hszItem = DdeCreateStringHandle(dwDDEInst, return_buffer, CP_WINANSI);
        
        if (hszTopic && hszItem)
            bRes = DdePostAdvise(dwDDEInst, hszTopic, hszItem);
        
        DdeFreeStringHandle(dwDDEInst, hszTopic);
        DdeFreeStringHandle(dwDDEInst, hszItem);

        return bRes;
    }
    
    return FALSE;
}
예제 #2
0
//------------------------------------------------------------------------------
// Purpose : Updates network link state if dynamic link state has changed
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CAI_DynamicLink::SetLinkState(void)
{
	if ( !gm_bInitialized )
	{
		// Safe to quietly return. Consistency will be enforced when InitDynamicLinks() is called
		return;
	}

	if (m_nSrcID == NO_NODE || m_nDestID == NO_NODE)
	{
		Vector pos = GetAbsOrigin();
		DevWarning("ERROR: Dynamic link at %f %f %f pointing to invalid node ID!!\n", pos.x, pos.y, pos.z);
		return;
	}

	// ------------------------------------------------------------------
	// Now update the node links...
	//  Nodes share links so we only have to find the node from the src 
	//  For now just using one big AINetwork so find src node on that network
	// ------------------------------------------------------------------
	CAI_Node *pSrcNode = g_pBigAINet->GetNode( m_nSrcID, false );
	if ( !pSrcNode )							 
		return;

	CAI_Link* pLink = FindLink();
	if ( !pLink )
	{
		DevMsg("Dynamic Link Error: (%s) unable to form between nodes %d and %d\n", GetDebugName(), m_nSrcID, m_nDestID );
		return;
	}

	pLink->m_pDynamicLink = this;
	if (m_nLinkState == LINK_OFF)
	{
		pLink->m_LinkInfo |=  bits_LINK_OFF;
	}
	else
	{
		pLink->m_LinkInfo &= ~bits_LINK_OFF;
	}

	if ( m_bPreciseMovement )
	{
		pLink->m_LinkInfo |= bits_LINK_PRECISE_MOVEMENT;
	}
	else
	{
		pLink->m_LinkInfo &= ~bits_LINK_PRECISE_MOVEMENT;
	}

	if ( m_nPriority == 0 )
	{
		pLink->m_LinkInfo &= ~bits_PREFER_AVOID;
	}
	else
	{
		pLink->m_LinkInfo |= bits_PREFER_AVOID;
	}
}
예제 #3
0
void OutgoingLinks(struct Closure *_ptrInput){
	struct internals *_ptrInternals =(struct internals *)_ptrInput->internals;
	struct LinkedListNode *_ptrItemsHead = _ptrInput->Items->Head;
	struct Grammar *_ptrGrammar = (struct Grammar *)_ptrInternals->Grammar;
	struct ItemInClosure *_ptrItemInClosure;
	struct Link *_ptrNewLink;
	struct ItemInClosure *_ptrNewItem;
	int _intToken;
	while (_ptrItemsHead->Next !=NULL){
		_ptrItemInClosure = (struct ItemInClosure *)_ptrItemsHead->Value;
		_intToken = _ptrGrammar->GetItemAfterDot(_ptrGrammar, _ptrItemInClosure->intProduction, _ptrItemInClosure->intDot);
		//dot was not at the end of the production
		if (_intToken!=-1){
			_ptrNewLink =(struct Link *)malloc(sizeof(struct Link *));
			_ptrNewItem = (struct ItemInClosure *)malloc(sizeof(struct ItemInClosure *));
			_ptrNewLink->IsAccept = 0;
			_ptrNewLink->Token = _intToken;
			_ptrNewItem->intDot = _ptrItemInClosure->intDot+1;
			_ptrNewItem->intProduction =_ptrItemInClosure->intProduction;
			_ptrNewLink->NewItem = _ptrNewItem;
			_ptrNewLink->NextClosure = NULL;
			if (FindLink(_ptrInput->Links->Head, _ptrNewLink)==0){
				_ptrInput->Links->Add(_ptrNewLink, _ptrInput->Links);
			}
			
		}
		else if (_intToken ==-1 && _ptrItemInClosure->intProduction==0){
	
			_ptrNewLink =(struct Link *)malloc(sizeof(struct Link *));
			_ptrNewLink->IsAccept = 1;
			_ptrNewLink->Token = -1;
			_ptrNewLink->NewItem = NULL;
			if (FindLink(_ptrInput->Links->Head, _ptrNewLink)==0){
				_ptrInput->Links->Add(_ptrNewLink, _ptrInput->Links);
			}
		}
		_ptrItemsHead= _ptrItemsHead->Next;	


	}
}
예제 #4
0
//------------------------------------------------------------------------------
// Purpose : Updates network link state if dynamic link state has changed
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CAI_DynamicLink::SetLinkState(void)
{
	if (m_nSrcID == NO_NODE || m_nDestID == NO_NODE)
	{
		Vector pos = GetAbsOrigin();
		DevWarning("ERROR: Dynamic link at %f %f %f pointing to invalid node ID!!\n", pos.x, pos.y, pos.z);
		return;
	}

	// ------------------------------------------------------------------
	// Now update the node links...
	//  Nodes share links so we only have to find the node from the src 
	//  For now just using one big AINetwork so find src node on that network
	// ------------------------------------------------------------------
	CAI_Node *	pSrcNode = g_pBigAINet->GetNode(m_nSrcID, false);
	if ( pSrcNode )
	{
		CAI_Link* pLink = FindLink();
		if ( pLink )
		{
			pLink->m_pDynamicLink = this;
			if (m_nLinkState == LINK_OFF)
			{
				pLink->m_LinkInfo |=  bits_LINK_OFF;
			}
			else
			{
				pLink->m_LinkInfo &= ~bits_LINK_OFF;
			}
		}
		else
		{
			DevMsg("Dynamic Link Error: (%s) unable to form between nodes %d and %d\n", GetDebugName(), m_nSrcID, m_nDestID );
		}
	}

}
예제 #5
0
HDDEDATA W_CALLBACK KapDDECallBack(WORD wTran, WORD wFmt, HCONV hConv,
				   HSZ hsz1, HSZ hsz2, HDDEDATA hData,
				   DWORD dwData1, DWORD dwData2)
{
    switch (wTran) {
      case XTYP_ADVSTART:
      case XTYP_ADVSTOP:
      {
          BOOL bRes = FALSE;
    
          if (wFmt == CF_TEXT)
          {
              char *cl;
              
              if (!DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                                  RET_BUFFER_LEN, CP_WINANSI))
                  return (HDDEDATA) FALSE;
              
              cl = strchr(return_buffer, ':');
              if (cl)
              {
                  DDEINFO ddeInfo;
                  ATOMID idName;
                  WORD wType;
                  
                  cl[0] = '\0';
                  idName = KppAddAtom(return_buffer);
                  ddeInfo.idSlot = KppAddAtom(cl + 1);
                  ddeInfo.idObj = KppGetObjectId(idName, &wType);
                  ddeInfo.idApp = ddeInfo.idItem = NULLID;
                  ddeInfo.idTopic = HszToAtom(hsz1);
                  ddeInfo.hConv = hConv;
                  
                  if (ddeInfo.idObj)
                  {
                      UnwindProtect(cleanup1);
                      requests++;
                      switch (wTran) {
                        case XTYP_ADVSTART:
                            if (CreateLink(&ddeInfo))
                                bRes = TRUE;
                            break;
                        case XTYP_ADVSTOP:
                            if (CloseServerLink(&ddeInfo, idName))
                                bRes = TRUE;
                            break;
                      }
                    cleanup1:
                      requests--;
                      EndProtect();
                  }
              }
          }

          return (HDDEDATA) bRes;                  
      }

      case XTYP_EXECUTE:
      {
          DWORD dwLen;
          LPBYTE lpByte = DdeAccessData(hData, &dwLen);
          
          if (lpByte)
          {
              BOOL bFree = FALSE;
              LPBYTE lpCopy;

              if (dwLen < RET_BUFFER_LEN)
              {
                  strcpy(return_buffer, lpByte);
                  lpCopy = return_buffer;
              }
              else
              {
                  lpCopy = strdup(lpByte);
                  bFree = TRUE;
              }
              DdeUnaccessData(hData);
          
              if (lpCopy)
              {
                  UnwindProtect(cleanup2);
                  requests++;
                  if (!KppEvalExpString(lpCopy))
                      KppPostKappaErrorMessageCB();
                cleanup2:
                  requests--;
                  if (bFree)
                      free(lpCopy);
                  EndProtect();
                  
                  return (HDDEDATA) DDE_FACK;
              }
          }
           
          return (HDDEDATA) DDE_FNOTPROCESSED;
      }
          
      case XTYP_CONNECT:
          if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))
          {
              char *dot = strrchr(return_buffer, '.');

              if (dot)
                  dot[0] = '\0';
              
              if (!stricmp(DDETopicName, return_buffer) ||
#ifdef MULTI
                  !stricmp(DDEKappaName, return_buffer) ||
                  S_ILOC == 0 &&
#endif
                  !stricmp("KAPPA", return_buffer))
                  return TRUE;
          }
          
          return (HDDEDATA) FALSE;
          
      case XTYP_DISCONNECT:
          UnwindProtect(cleanup3);
          requests++;
          DeleteDDETasks(hConv);
        cleanup3:
          requests--;
          EndProtect();
          return (HDDEDATA) NULL;
          
      case XTYP_WILDCONNECT:
      {
          HSZPAIR hszPair[3];
              
          hszPair[0].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[0].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDETopicName, CP_WINANSI);
          hszPair[1].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[1].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDEKappaName, CP_WINANSI);
          hszPair[2].hszSvc = hszPair[2].hszTopic = NULL;
          
          return DdeCreateDataHandle(dwDDEInst, (LPVOID) hszPair,
                                     sizeof(HSZPAIR) * 3, 0, 
                                     hszPair[0].hszSvc, CF_TEXT, 0);
      }
          
      case XTYP_POKE:
      {
          UINT flag = DDE_FNOTPROCESSED;
          
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup4);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj && StoreData(lpIDs->idNull, hData, idObj, idSlot))
                  flag = DDE_FACK;
            cleanup4:
              requests--;
              EndProtect();
          }

          return (HDDEDATA) flag;
      }
          
      case XTYP_REQUEST:
      case XTYP_ADVREQ:
          hData = (HDDEDATA) DDE_FNOTPROCESSED;
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup5);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj)
              {
                  BOOL bMulti = FALSE;
                  ITEMID idValue =
                      Kpp_Get_SlotAnyValue(OBJECT_TYPE(idObj),
                                           idObj, idSlot, (LPWORD) &bMulti);
                  GLOBALHANDLE hMem = NULL;
                  LPBYTE lpBytes = NULL;
                  DWORD dwLen = ValueToString(idValue, bMulti, 
                                              &hMem, &lpBytes);
                  
                  if (dwLen)
                  {
                      hData = DdeCreateDataHandle(dwDDEInst, lpBytes, dwLen,
                                                  0, hsz2, CF_TEXT, 0);
                      if (hMem)
                      {
                          GLOBALUNLOCK(hMem);
                          GLOBALFREE(hMem);
                      }
                      if (!hData)
                          hData = (HDDEDATA) DDE_FNOTPROCESSED;
                  }
              }
            cleanup5:
              requests--;
              EndProtect();
          }
          return hData;              
        
      case XTYP_REGISTER:
      {
          ATOMID idApp = HszToAtom(hsz2);
          
          UnwindProtect(cleanup6);
          requests++;
          if (idApp)
          {
              WORD wType;
              OBJECTID idService = KppGetObjectId(idApp, &wType);
              
              if (!idService)
              {
                  idService = KppMakeCO(OBJECT, idApp, idDDEService);
                  wType = OBJECT;
              }
              if (idService)
              {
                  if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                                     RET_BUFFER_LEN, CP_WINANSI))
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        KppAddAtom(return_buffer), EXPATOM);
                  else
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        lpIDs->idNull, EXPATOM);
              }
          }
        cleanup6:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
        
      case XTYP_ADVDATA:
          UnwindProtect(cleanup7);
          requests++;
          if (wFmt == CF_TEXT)
          {
              CONVINFO ci;
              ATOMID idApp, idItem, idName;
              OBJECTID idLink;
              
              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, QID_SYNC, &ci);
              idApp = HszToAtom(ci.hszSvcPartner);
              idItem = HszToAtom(hsz2);
              idName = LinkName(idApp, idItem);
              idLink = FindLink(idName);
              
              if (idLink)
              {
                  WORD wDestType;
                  ATOMID idDest = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDEObject));
                  ATOMID idSlot = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDESlot));
                  OBJECTID idDestObj = KppGetObjectId(idDest, &wDestType);
              
                  StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
              }
          }
        cleanup7:
          requests--;
          EndProtect();
          
          return (HDDEDATA) DDE_FACK;
          
      case XTYP_XACT_COMPLETE:
      {
          char name[20];
          OBJECTID idTask;
          ATOMID idName;
          WORD wType;
          
          UnwindProtect(cleanup8);
          requests++;
          task_name(name, hConv, dwData1);
          idName = KppAddAtom(name);
          idTask = KppGetObjectId(idName, &wType);
          
          if (idTask)
          {
              CONVINFO ci;

              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, dwData1, &ci);
          
              switch (ci.wType) {
                case XTYP_REQUEST:
                    if (wFmt == CF_TEXT)
                    {
                        WORD wDestType;
                        ATOMID idDest = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDEObject));
                        ATOMID idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDESlot));
                        OBJECTID idDestObj = KppGetObjectId(idDest, 
                                                            &wDestType);
              
                        StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
                        DdeDisconnect(hConv);              
                    }
                    break;
                    
                case XTYP_POKE:
                case XTYP_EXECUTE:
                    DdeDisconnect(hConv);              
                    break;
                    
                case (XTYP_ADVSTART | XTYPF_ACKREQ):
                {
                    ATOMID idDest =
                        Kpp_Get_SlotValue(wType, idTask, Slot(idDDEObject));
                    WORD wDestType;
                    DDEINFO ddeInfo;

                    ddeInfo.hConv = hConv;
                    ddeInfo.idApp = Kpp_Get_SlotValue(wType, idTask, 
                                                      Slot(idService));
                    ddeInfo.idTopic = Kpp_Get_SlotValue(wType, idTask, 
                                                        Slot(idTopic));
                    ddeInfo.idItem = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idItem));
                    ddeInfo.idObj = KppGetObjectId(idDest, &wDestType);
                    ddeInfo.idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idDDESlot));
              
                    CreateLink(&ddeInfo);
                    break;
                }
              }

              DeleteDDETask(lpIDs->idNull, wType, idTask, (LPVOID) &hConv);
          }
        cleanup8:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
          
      default:
          return (HDDEDATA) NULL;
    }
}