Ejemplo n.º 1
0
CPLErr GNMGenericNetwork::DisconnectFeatures(GNMGFID nSrcGFID, GNMGFID nTgtGFID,
                                             GNMGFID nConGFID)
{
    if(!m_bIsGraphLoaded && LoadGraph() != CE_None)
    {
        return CE_Failure;
    }

    OGRFeature *poFeature = FindConnection(nSrcGFID, nTgtGFID, nConGFID);
    if (poFeature == NULL)
    {
        CPLError( CE_Failure, CPLE_AppDefined, "The connection not exist" );
        return CE_Failure;
    }

    if (m_poGraphLayer->DeleteFeature(poFeature->GetFID()) != OGRERR_NONE)
    {
        OGRFeature::DestroyFeature(poFeature);
        return CE_Failure;
    }

    OGRFeature::DestroyFeature(poFeature);

    // update graph

    m_oGraph.DeleteEdge(nConGFID);

    return CE_None;
}
Ejemplo n.º 2
0
CPLErr GNMGenericNetwork::ReconnectFeatures(GNMGFID nSrcGFID, GNMGFID nTgtGFID,
                                            GNMGFID nConGFID, double dfCost,
                                            double dfInvCost, GNMDirection eDir)
{
    if(!m_bIsGraphLoaded && LoadGraph() != CE_None)
    {
        return CE_Failure;
    }

    OGRFeature *poFeature = FindConnection(nSrcGFID, nTgtGFID, nConGFID);
    if (poFeature == NULL)
    {
        CPLError( CE_Failure, CPLE_AppDefined, "The connection not exist" );
        return CE_Failure;
    }

    poFeature->SetField( GNM_SYSFIELD_COST, dfCost );
    poFeature->SetField( GNM_SYSFIELD_INVCOST, dfInvCost );
    poFeature->SetField( GNM_SYSFIELD_DIRECTION, eDir );

    if( m_poGraphLayer->SetFeature( poFeature ) != OGRERR_NONE )
    {
        OGRFeature::DestroyFeature( poFeature );
        CPLError( CE_Failure, CPLE_AppDefined, "Failed to update feature." );
        return CE_Failure;
    }

    OGRFeature::DestroyFeature( poFeature );

    // update graph

    m_oGraph.ChangeEdge(nConGFID, dfCost, dfInvCost);

    return CE_None;
}
Ejemplo n.º 3
0
int DoMessage(int id) {
  int status=0;
  static Message *(*processMessage)(Connection *,Message *) = 0;
  Connection *c=FindConnection(id,0);
  if (processMessage == 0) {
    DESCRIPTOR(MdsIpSrvShr,"MdsIpSrvShr");
    DESCRIPTOR(procmsg,"ProcessMessage");
    status = LibFindImageSymbol(&MdsIpSrvShr,&procmsg,&processMessage);
  }
  if (c && processMessage) {
    Message *msgptr = GetMdsMsg(id,&status);
    Message *ans=0;
    if (status & 1) {
      ans = (*processMessage)(c, msgptr);
      if (ans) {
	status = SendMdsMsg(id, ans, 0);
	free(ans);
      }
    }
    else
      CloseConnection(id);
    if (msgptr)
      free(msgptr);
  }
  return status;
}
Ejemplo n.º 4
0
void Resistor::HandleMouseDown (HWND hWnd, int _x, int _y)
{
  int value;
  int resistance;
  Connection * inConnection = FindConnection (input);
  Connection * outConnection = FindConnection (output);
  
  if (input->isActive) // we are over the ground spot     
    input->Select(!input->isSelected);
  else if (output->isActive)
    output->Select(!output->isSelected);  
  else
  {
    HighLevelMenu::Instance()->BestValue(input,output,value,resistance);	
    HighLevelMenu::Instance()->WriteValue (input,value,resistance,false);  	
  }  
}
Ejemplo n.º 5
0
void Server::Login(Connection* connection, QString user_name)
{
    if(FindConnection(user_name) == NULL)
    {
        connection->SetName(user_name);
        SendConfirm(connection, LOGIN_ACC, 1);
    }
    else
    {
        SendConfirm(connection, LOGIN_ACC, 0);
    }
}
Ejemplo n.º 6
0
int CloseConnection(int id) {
  int status=0;
  static int (*removeConnection)(int) = 0;
  Connection *c=FindConnection(id,0);
  if (c) {
    if (removeConnection == 0) {
      DESCRIPTOR(MdsIpSrvShr,"MdsIpSrvShr");
      DESCRIPTOR(rmcon,"RemoveConnection");
      status = LibFindImageSymbol(&MdsIpSrvShr,&rmcon,&removeConnection);
    } else
      status=1;
    if (status & 1) {
      status = (*removeConnection)(id);
    }
  }
  return status;
}
//3rd argument optional.
BOOL CWorldConnList::AddConnection(IVWCommConnection *pCommConnection, IWorld *pWorld, IVWComm *vwcomm, BSTR bstrWorldName)
{
	if (FindConnection(pCommConnection) != NULL)
		return FALSE;

	ConnectionInfo cinfo;

	cinfo.pWorld = pWorld;
	cinfo.pVWComm = vwcomm;
	cinfo.bstrWorldName = bstrWorldName;
	SAFEADDREF(vwcomm);
	SAFEADDREF(pWorld);

	SetAt(pCommConnection, cinfo);

	SAFEADDREF(pCommConnection);

	return TRUE;
}
Ejemplo n.º 8
0
CPLErr GNMGenericNetwork::ConnectFeatures(GNMGFID nSrcGFID, GNMGFID nTgtGFID,
                                          GNMGFID nConGFID, double dfCost,
                                          double dfInvCost, GNMDirection eDir)
{
    if(!m_bIsGraphLoaded && LoadGraph() != CE_None)
    {
        return CE_Failure;
    }

    OGRFeature *poFeature = FindConnection(nSrcGFID, nTgtGFID, nConGFID);
    if(poFeature != NULL)
    {
        OGRFeature::DestroyFeature( poFeature );
        CPLError( CE_Failure, CPLE_AppDefined, "The connection already created" );
        return CE_Failure;
    }

    if(m_asRules.empty())
    {
        CPLError( CE_Failure, CPLE_AppDefined, "The connection forbidden" );
        return CE_Failure;
    }
    else
    {
        CPLString soSrcLayerName = m_moFeatureFIDMap[nSrcGFID];
        CPLString soTgtLayerName = m_moFeatureFIDMap[nTgtGFID];
        CPLString soConnLayerName = m_moFeatureFIDMap[nConGFID];
        for(size_t i = 0; i < m_asRules.size(); ++i)
        {
            if(!m_asRules[i].CanConnect(soSrcLayerName, soTgtLayerName,
                                        soConnLayerName))
            {
                CPLError( CE_Failure, CPLE_AppDefined, "The connection forbidden" );
                return CE_Failure;
            }
        }
    }

    // we support both vertices and edge to be virtual
    if(nConGFID == -1)
       nConGFID = GetNewVirtualFID();
    if(nSrcGFID == -1)
       nSrcGFID = GetNewVirtualFID();
    if(nTgtGFID == -1)
       nTgtGFID = GetNewVirtualFID();

    poFeature = OGRFeature::CreateFeature( m_poGraphLayer->GetLayerDefn() );
    poFeature->SetField( GNM_SYSFIELD_SOURCE, nSrcGFID );
    poFeature->SetField( GNM_SYSFIELD_TARGET, nTgtGFID );
    poFeature->SetField( GNM_SYSFIELD_CONNECTOR, nConGFID );
    poFeature->SetField( GNM_SYSFIELD_COST, dfCost );
    poFeature->SetField( GNM_SYSFIELD_INVCOST, dfInvCost );
    poFeature->SetField( GNM_SYSFIELD_DIRECTION, eDir );
    poFeature->SetField( GNM_SYSFIELD_BLOCKED, GNM_BLOCK_NONE );

    if( m_poGraphLayer->CreateFeature( poFeature ) != OGRERR_NONE )
    {
        OGRFeature::DestroyFeature( poFeature );
        CPLError( CE_Failure, CPLE_AppDefined, "Failed to create feature." );
        return CE_Failure;
    }

    OGRFeature::DestroyFeature( poFeature );

    // update graph

    m_oGraph.AddEdge(nConGFID, nSrcGFID, nTgtGFID, eDir == GNM_EDGE_DIR_BOTH,
                     dfCost, dfInvCost);

    return CE_None;
}
Ejemplo n.º 9
0
int BuildConnection(PLC *plc)
{	int path_size=0;
	char ip[16],path[40];
	
	Log(LOG_DEBUG,"Building connection for %s (%d connections)\n",plc->PlcName,CONNECTIONs.Count);
	
	if ((plc==NULL)||(plc->Connection!=NULL)) return(0);
	
	Eip_Session *session=plc->Session;
	Eip_Connection *connection=plc->Connection;
	
	path_size=ParsePath(plc->PlcPath,ip,path);
	if (path_size>0)
	{ // Creating Sessions
		if (plc->Connection==NULL)
		{
			// Creating Connections
			connection=FindConnection(plc->PlcPath,&PLCs);
			if (connection==NULL) // not found
			{
				if (plc->NetWork)
					connection=_ConnectPLCOverDHP(session,
					plc->PlcType,
					_Priority,_TimeOut_Ticks,
					(int)session, //TO_ConnID,
					GetSerial(), //ConnSerialNumber
					_OriginatorVendorID,_OriginatorSerialNumber,_TimeOutMultiplier,
					MAX_SAMPLE,
					_Transport,
					plc->NetWork,
					path,
					path_size);
				else
					connection=_ConnectPLCOverCNET(session,
					plc->PlcType,
					_Priority,_TimeOut_Ticks,
					(int)session, //TO_ConnID,
					GetSerial(), //ConnSerialNumber
					_OriginatorVendorID,_OriginatorSerialNumber,_TimeOutMultiplier,
					MAX_SAMPLE,
					_Transport,
					path,
					path_size);
				
				if (connection!=NULL)
				{
					plc->Connection=connection;
					AddChListe(&CONNECTIONs,connection);
					Log(LOG_DEBUG,"Connection (%p) created for PLC : %s (%s) (%d connections)\n",connection,plc->PlcName,cip_err_msg,CONNECTIONs.Count);
					connection->References=1;
					return(1);
					//CONNECTIONs[Connection_count++]=connection;
				} else 
				{
					Log(LOG_CRIT,"Unable to create connection for Plc: %s (%s)\n",plc->PlcName,cip_err_msg);
					return(0);
				}
			}	else 
			{
				plc->Connection=connection;
				connection->References++;
				Log(LOG_DEBUG,"%s Sharing Connection (%p) with another PLC (%d references)\n",plc->PlcName,connection,connection->References);
				return(1);
			}
		} else return(0);
	} else 
	{
		Log(LOG_CRIT,"Error while parsing IP/Path for Plc : %s\n",plc->PlcName);
		return(0);
	}
}
Ejemplo n.º 10
0
void set_connection(char *sp, char *dh, char *dp, enum event_types type)
{

  int cx;

  /* A connection is identified by the host/port 3-tuple (the source IP
     address is not needed because only one client is handled at a time).
     The connection's status depends on the type of the event that caused
     the update.  The following event type are defined with their effect
     on the connection's status:
           SYN, ACT-REQ, - The connection has begun (is an "active"
           ACT-RSP         connection.  Add it to the table as idle
                           (activity == 0) if a SYN or with request/
                           response activity (activity == 1) for ACT-REQ
                           or ACT-RSP.
           REQ           - Find the connection in the table and mark it with
                           an outstanding request (activity == 1).
           RSP           - Find the connection in the table and mark it with
                           a completed request (activity == 0).
           END           - The connection has ended (is no longer an "active"
                           connection).  Remove it from the table.
  */

  switch (type)
     {   
      case SYN:
      case ACT_REQ:
      case ACT_RSP:
	 {
          cx = AddConnection(sp, dh, dp);
          if (cx < 0)  /* already there */
	     {
              error_state("Add for existing connection");
              return;
             }            
          if (cx > MAX_CONNECTIONS)  /* table overflow */
	     {
              error_state("Active connections exceeds maximum");
              exit (-1);
             } 
          connections[cx].state = type;
          if (type == SYN)
             connections[cx].activity = 0;
          else
             connections[cx].activity = 1;
          break;
	 }    

      case REQ:
	 {
          cx = FindConnection(sp, dh, dp);
          if (cx < 0)  /* not there */
	     {
              error_state("REQ for non-existent connection");
              return;
             }
          if ((connections[cx].state == RSP) ||
              (connections[cx].state == ACT_REQ) ||
              (connections[cx].state == SYN))
	     {
              connections[cx].activity = 1; 
              connections[cx].state = REQ;
             }       
          else
              error_state("REQ in invalid connection state");

          break;
         }

      case RSP:
	 {
          cx = FindConnection(sp, dh, dp);
          if (cx < 0)  /* not there */
	     {
              error_state("RSP for non-existent connection");
              return;
             }
          if ((connections[cx].state == REQ) ||
              (connections[cx].state == ACT_RSP) ||
              (connections[cx].state == SYN))
	     {
              connections[cx].activity = 0; 
              connections[cx].state = RSP;
             }      
          else
              error_state("RSP in invalid connection state");

          break;
         }

      case END:
	 {
          cx = FindConnection(sp, dh, dp);
          if (cx < 0)  /* not there */
	     {
              error_state("End for non-existent connection");
              return;
             }
          connections[cx].activity = 0; 
          connections[cx].state = END;
          cx = RemoveConnection(sp, dh, dp);
          break;
	 }
      default:
      break;

     }
}
Ejemplo n.º 11
0
TBool CHCEmulator::Decode(const TDesC8& aOpcodeBuf, const TDesC8& aRemainderBuf)
	{
	TUint16 opcode = static_cast<TUint16>((aOpcodeBuf[1] << 8) + aOpcodeBuf[0]);

	TBuf<60> command;
	
	// Separate if to catch all Vendor Specific opcodes.
	if ((opcode & KOGFMask) == KVendorDebugOGF)
		{
		command = _L("VendorSpecificDebug");
		const TUint16 KOCFMask = KMaxTUint16 & ~KOGFMask;
		if((opcode &  KOCFMask) != 0) //OCF = 0 is used by tproxy to indicate that we do not want a reply
			{
			VendorSpecificDebugCompleteEvent(opcode, aRemainderBuf);
			}
		else
			{
			DefaultCommandCompleteEvent(KNopOpcode, KHCIOK);
			}
		}
	else
		{
		switch (opcode)
			{
			case KResetOpcode:
				command = _L("Reset");
	
				ResetEmulator();
	
				DefaultCommandCompleteEvent(KResetOpcode, KHCIOK);
				CommandStatusEvent(KNoOpcode, KHCIOK);	// for CSR
				break;
			case KSetHostControllerToHostFlowOpcode:
				command = _L("SetHostControllerToHostFlow");
				DefaultCommandCompleteEvent(KSetHostControllerToHostFlowOpcode, KHCIOK);
				break;
			case KWritePageTimeoutOpcode:
				command = _L("WritePageTimeout");
				DefaultCommandCompleteEvent(KWritePageTimeoutOpcode, KHCIOK);
				break;
			case KHostBufferSizeOpcode:
				command = _L("HostBufferSize");
				DefaultCommandCompleteEvent(KHostBufferSizeOpcode, KHCIOK);
				break;
			case KWriteScanEnableOpcode:
				command = _L("WriteScanEnable");
				DefaultCommandCompleteEvent(KWriteScanEnableOpcode, KHCIOK);
				break;
			case KWriteConnectionAcceptTimeoutOpcode:
				command = _L("WriteConnectionAcceptTimeout");
				DefaultCommandCompleteEvent(KWriteConnectionAcceptTimeoutOpcode, KHCIOK);
				break;
			case KChangeLocalNameOpcode:
				command = _L("ChangeLocalName");
				iLocalName.SetLength(248);
				iLocalName.Replace(0, aRemainderBuf.Length(), aRemainderBuf);
				DefaultCommandCompleteEvent(KChangeLocalNameOpcode, KHCIOK);
				break;
			case KReadBdaddrOpcode:
				command = _L("ReadBDAddr");
				ReadBDAddrCompleteEvent(KHCIOK);
				break;
			case KReadLocalNameOpcode:
				command = _L("ReadLocalName");
				ReadLocalNameCompleteEvent(KHCIOK);
				break;
			case KReadBufferSizeOpcode:
				command = _L("ReadBufferSize");
				ReadBufferSizeCompleteEvent(KHCIOK);
				break;
			case KCreateACLConnectionOpcode:
				{
				// decode this and store in emulated connections
				command = _L("CreateConnection");
				CommandStatusEvent(KCreateACLConnectionOpcode, KHCIOK);
	
				TBTDevAddr remoteaddr;
				GetBigEndianDevAddr(remoteaddr, aRemainderBuf.Ptr());
	#ifdef _CONNECT_TYPE_1
				ConnectionRequestEvent(remoteaddr, KEmulatedInquiryClassOfDevice, EACLLink);
	#else
				TBTConnect newConnection;
				
				//GetBigEndianDevAddr(newConnection.iBdaddr, aRemainderBuf.Ptr());
	
				newConnection.iBdaddr=remoteaddr;
				newConnection.iLinkType=EACLLink;
				newConnection.iEncryptMode=KEmulatedEncryptMode;
				newConnection.iConnH = static_cast<TUint16>(KEmulatedBaseConnectionHandle + iConnections.Count());
	
				//update connection model - stick in separate class that wraps RArray/Console
				iConnections.Append(newConnection);
				TBuf<30> readableaddr;
				newConnection.iBdaddr.GetReadable(readableaddr);
				iConnectionsConsole->Printf(_L("Connection added: Handle 0x%04x, Remote address %S, Type ACL\n"), newConnection.iConnH, &readableaddr);
	
				ConnectionCompleteEvent(KHCIOK, EACLLink);
	#endif
				// CommandStatusEvent(KCreateACLConnectionOpcode, KHCICommandDisallowed); 
				}
				break;
	
			case KAcceptConnectionRequestOpcode:
				{
				TBTConnect newConnection;
				
				//GetBigEndianDevAddr(newConnection.iBdaddr, aRemainderBuf.Ptr());
	
				newConnection.iLinkType=EACLLink;
				newConnection.iEncryptMode=KEmulatedEncryptMode;
				newConnection.iConnH = static_cast<TUint16>(KEmulatedBaseConnectionHandle + iConnections.Count());
	
				//update connection model - stick in separate class that wraps RArray/Console
				iConnections.Append(newConnection);
				TBuf<30> readableaddr;
				newConnection.iBdaddr.GetReadable(readableaddr);
				iConnectionsConsole->Printf(_L("Connection added: Handle 0x%04x, Remote address %S, Type ACL\n"), newConnection.iConnH, &readableaddr);
	
	#ifdef DISCONNECT_ON_ACCEPT
				//This was first used for reproducing DEF074193 
				//we need to send a disconnect to a SCO socket
				//that is in state TSCOLinkStateAccepting.
				DisconnectionCompleteEvent(KHCIOK, 1, KHCINoConnection);
	#else
				ConnectionCompleteEvent(KHCIOK, EACLLink);
	#endif
				}
				break;
	
			case KDisconnectOpcode:
				{
				command = _L("Disconnect");
				CommandStatusEvent(KDisconnectOpcode, KHCIOK);
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
				
				TUint8 reason;
				GetByte(reason, aRemainderBuf.Ptr()+2); //+2 or else first byte of connection handle will be read
	
				TInt index = FindConnection(connh);
				if (index!=KErrNotFound)
					{
					iConnections.Remove(index);				// delete from emulator's connections
					iConnectionsConsole->Printf(_L("Connection removed: Handle 0x%04x\n"), connh);
					DisconnectionCompleteEvent(KHCIOK, connh, reason);
					}
				else
					DisconnectionCompleteEvent(KHCIOK, connh, KHCINoConnection);
	
	
				}
				break;
	
			case KInquiryOpcode:
				command = _L("Inquiry");
				CommandStatusEvent(KInquiryOpcode, KHCIOK);
				InquiryStartEvent(KHCIOK);
				break;
	
			case KInquiryCancelOpcode:
				command = _L("InquiryCancel");
				InquiryCancelCompleteEvent(KHCIOK);
				break;
				
			case KRemoteNameRequestOpcode:
				{
				command = _L("RemoteNameRequest");
				CommandStatusEvent(KRemoteNameRequestOpcode, KHCIOK);
				
				TBTDevAddr remoteAddr;
				GetBigEndianDevAddr(remoteAddr, aRemainderBuf.Ptr());
				
				TPtrC8 namePtr;
				TInt err = GetRemoteName(remoteAddr, namePtr);
				
				ReadRemoteNameCompleteEvent(err, remoteAddr, namePtr);
				break;
				}
	
			case KReadLocalSupportedFeaturesOpcode:
				{
				command = _L("ReadLocalSupportedFeatures");			
				ReadLocalSupportedFeaturesCompleteEvent(KHCIOK);
				break;
				}
				
			case KReadLocalVersionInfoOpcode:
				{
				command = _L("ReadLocalVersionInformation");
				ReadLocalVersionInfoCompleteEvent(KHCIOK);
				break;		
				}
				
			case KWriteVoiceSettingOpcode:
				{
				command = _L("WriteVoiceSetting");	
				WriteVoiceSettingCompleteEvent(KHCIOK);
				break;
				}
			
			case KWriteCurrentIACLAPOpcode:
				{
				command = _L("WriteCurrentIACLAP");	
				WriteCurrentIACLAPCompleteEvent(KHCIOK);
				break;	
				}
				
			case KReadClassOfDeviceOpcode:
				{
				command = _L("ReadClassOfDevice");	
				ReadClassOfDeviceCompleteEvent(KHCIOK);
				break;	
				}
		
			case KWriteLinkPolicySettingsOpcode:
				{
				command = _L("WriteLinkPolicySettings");
				CommandStatusEvent(KWriteLinkPolicySettingsOpcode, KHCIOK);
				
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
	
				WriteLinkPolicySettingsCompleteEvent(KHCIOK, connh);
				}
				break;
				
			case KReadClockOffsetOpcode:
				{
				command = _L("ReadClockOffset");
				CommandStatusEvent(KReadClockOffsetOpcode, KHCIOK);
						
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
	
				ReadClockOffsetCompleteEvent(KHCIOK, connh);		
				}
				break;
			
			case KReadRemoteSupportedFeaturesOpcode:
				{
				command = _L("ReadRemoteSupportedFeatures");
				CommandStatusEvent(KReadRemoteSupportedFeaturesOpcode, KHCIOK);
						
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
	
				ReadRemoteSupportedFeaturesCompleteEvent(KHCIOK, connh);	
				}
				break;
			
			case KReadRemoteVersionInfoOpcode:
				{
				command = _L("ReadRemoteVersionInfo");
				CommandStatusEvent(KReadRemoteVersionInfoOpcode, KHCIOK);
						
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
	
				ReadRemoteVersionInfoCompleteEvent(KHCIOK, connh);				
				}
				break;
			
			case KChangeConnectionPacketTypeOpcode:
				{
				command = _L("ChangeConnectPacketType");
				CommandStatusEvent(KChangeConnectionPacketTypeOpcode, KHCIOK);
						
				THCIConnHandle connh;
				GetConnHandle(connh, aRemainderBuf.Ptr());
	
				ConnectionPacketTypeChangedEvent(KHCIOK, connh);		
				}
				break;
			case KNopOpcode:
				{
				command = _L("NoOperationOpcode");
				DefaultCommandCompleteEvent(KNopOpcode, KHCIOK);
				}
				break;
			case KSetEventMaskOpcode:
				{
				command = _L("SetEventMaskOpcode");
				DefaultCommandCompleteEvent(KSetEventMaskOpcode, KHCIOK);
				}
				break;
			default:
				command = _L("Unknown");
				break;
			} // switch
		} // opcode OGF is not Vendor Debug
	iConsole.Printf(_L("%S command received - opcode 0x%x\n"), &command, opcode); //FIXME

	return ETrue;
	}