예제 #1
0
void
BuildLayer::deleteModule()
{
  if(NULL == mStation || mStation->getModuleCount() == 1) return;

  // Find the potential next module to select
  Module* nextSelection = NULL;
  ConnectionList connections = mSelectedModule->getConnections();
  for(unsigned int iConnection = 0; iConnection < connections.size(); ++iConnection) {
    if(NULL != connections[iConnection]) {
      nextSelection = connections[iConnection];
      break;
    }
  }
     
  mStation->getMission()->useActionPoint();
// // Profile: Update number of modules removed
// ConfigManager::getPlayer()->mModulesDeleted++;

  mStation->removeModule(mSelectedModule);

  if(nextSelection == NULL) {
    setReadyState();
  }
  else {
    setSelectedState(nextSelection);
  }
    
  //SoundManager::playSoundEffect("orbit/undocking");
}
ConnectionList CAndroidNetworkManager::GetConnections()
{
  ConnectionList connections;

  if (!m_ethernetConnection.get())
    GetEthernetConnection();
  if (!m_currentWifi.get())
    GetCurrentWifiConnection();
  if (m_wifiAccessPoints.empty())
    GetWifiAccessPoints();


  if(m_ethernetConnection.get())
    connections.push_back(m_ethernetConnection);

  if(m_currentWifi.get() && !m_currentWifi->GetName().empty() && m_currentWifi->GetState() != NETWORK_CONNECTION_STATE_DISCONNECTED)
    connections.push_back(m_currentWifi);

  for(CAndroidConnectionList::iterator i = m_wifiAccessPoints.begin(); i < m_wifiAccessPoints.end(); i++)
  {
    CAndroidConnectionPtr connection(*i);
    if (!connection.get())
      continue;
    if(!connection->GetName().empty() && (!m_currentWifi || (connection->GetName() != m_currentWifi->GetName()) || m_currentWifi->GetState() == NETWORK_CONNECTION_STATE_DISCONNECTED))
      connections.push_back(connection);
  }
  return connections;
}
예제 #3
0
void CGUIDialogAccessPoints::UpdateConnectionList()
{
  m_connectionsFileList->Clear();

  CGUIMessage msgReset(GUI_MSG_LABEL_RESET, GetID(), ACCESS_POINT_LIST);
  OnMessage(msgReset);

  int connectedItem = 0;
  ConnectionList connections = g_application.getNetworkManager().GetConnections();

  std::string connection_name;
  for (size_t i = 0; i < connections.size(); i++)
  {
    connection_name = connections[i]->GetName();
    CFileItemPtr item(new CFileItem(connection_name));

    if (m_use_ipconfig)
    {
      if (connection_name.find(m_ipname) != std::string::npos)
        connectedItem = i;
    }
    else
    {
      if (connections[i]->GetState() == NETWORK_CONNECTION_STATE_CONNECTED)
        connectedItem = i;
    }
    if (connections[i]->GetType() == NETWORK_CONNECTION_TYPE_WIFI)
    {
      int signal, strength = connections[i]->GetStrength();
      if (strength == 0 || strength < 20)
        signal = 1;
      else if (strength == 20 || strength < 40)
        signal = 2;
      else if (strength == 40 || strength < 60)
        signal = 3;
      else if (strength == 60 || strength < 80)
        signal = 4;
      else
        signal = 5;

        if (strength <= 20) item->SetArt("thumb", "ap-signal1.png");                                                                                                                      
        else if (strength <= 40) item->SetArt("thumb", "ap-signal2.png");                                                                                                                 
        else if (strength <= 60) item->SetArt("thumb", "ap-signal3.png");                                                                                                                 
        else if (strength <= 80) item->SetArt("thumb", "ap-signal4.png");                                                                                                                 
        else if (strength <= 100) item->SetArt("thumb", "ap-signal5.png");

      item->SetProperty("signal",     signal);
      item->SetProperty("encryption", EncryptionToString(connections[i]->GetEncryption()));
    }

    item->SetProperty("type",  ConnectionTypeToString(connections[i]->GetType()));
    item->SetProperty("state", ConnectionStateToString(connections[i]->GetState()));
 
    m_connectionsFileList->Add(item);
  }

  CGUIMessage msg(GUI_MSG_LABEL_BIND, GetID(), ACCESS_POINT_LIST, connectedItem, 0, m_connectionsFileList);
  OnMessage(msg);
}
예제 #4
0
void RhsListener::RemoveAllListeners(Connection* pConnection)
{
	// We need to walk the list of all rhs functions, removing this connection
	for (RhsMapIter mapIter = m_RhsMap.begin() ; mapIter != m_RhsMap.end() ; mapIter++)
	{
		std::string function  = mapIter->first ;
		ConnectionList* pList = mapIter->second ;

		pList->remove(pConnection) ;
	}
}
예제 #5
0
// Start listening for a specific RHS user function.  When it fires we'll call to the client
// (over the connection) to implement it.
void RhsListener::RemoveRhsListener(char const* pFunctionName, Connection* pConnection)
{
	ConnectionList* pList = GetRhsListeners(pFunctionName) ;

	// We have no record of anyone listening for this event
	// That's not an error -- it's OK to call this for all events in turn
	// to make sure a connection is removed completely.
	if (pList == NULL || pList->size() == 0)
		return ;

	pList->remove(pConnection) ;
}
예제 #6
0
	void ConnectionPool::Execute()
	{
		while(!m_stopDesired)
		{
			time_t nowTime = time(NULL);
			if(!m_conf_lua_file.empty() && nowTime >= m_nextLoadTime)
			{
				time_t lastModify = JG_F::KFileUtil::GetLastModified(m_conf_lua_file.c_str());
				if(lastModify != m_lastModifiedTime)
				{
					PoolSettings::ConnectionSettingArray cpy(m_settings.m_settings);
					if(!m_settings.reload(m_conf_lua_file.c_str()))
					{
						Log(LOG_WARN, "warn: fail reload pool setting file '%s', recover", m_conf_lua_file.c_str());
						m_settings.m_settings = cpy;
					}
					m_lastModifiedTime = lastModify;
				}
				m_nextLoadTime = nowTime + 10;
			}
			if(nowTime > m_nextCheckIdleTime)
			{
				JG_S::KAutoThreadMutex mx(m_mx);
				ConnectionMap::iterator it = m_cnnMap.begin(), ite = m_cnnMap.end();
				for(; it != ite; it++)
				{
					ConnectionList tmp;
					ConnectionList& lst = it->second;
					PooledConnection* cnn;
					while(cnn = lst.pop_front())
					{
						if(cnn->isExpire(nowTime))
						{
							Log(LOG_DEBUG, "debug: %s expire, abandon", cnn->toString().c_str());
							cnn->destroy();
						}
						else
						{
							tmp.push_back(cnn);
						}
					}
					while(cnn = tmp.pop_front())
					{
						lst.push_back(cnn);
					}
				}
				m_nextCheckIdleTime = nowTime + 30;
			}
			msleep(100);
		}
	}
예제 #7
0
void ConnectionPool::_cleanUpStaleHosts_inlock(Date_t now) {
    if (now > _lastCleanUpTime + kCleanUpInterval) {
        for (HostLastUsedMap::iterator itr = _lastUsedHosts.begin(); itr != _lastUsedHosts.end();
             itr++) {
            if (itr->second <= _lastCleanUpTime) {
                ConnectionList connList = _connections.find(itr->first)->second;
                _cleanUpOlderThan_inlock(now, &connList);
                invariant(connList.empty());
                itr->second = kNeverTooStale;
            }
        }

        _lastCleanUpTime = now;
    }
}
예제 #8
0
파일: PongGame.hpp 프로젝트: Mourtz/pomdog
    void Reset(Keys keyUpIn, Keys keyDownIn, std::shared_ptr<Keyboard> const& keyboard)
    {
        keyUp = keyUpIn;
        keyDown = keyDownIn;

        connections.Disconnect();
        auto & connect = connections;

        connect(keyboard->KeyUp, [this](Keys key) {
            POMDOG_ASSERT(keyUp != keyDown);
            if (key == keyUp) {
                up = ButtonState::Released;
            }
            else if (key == keyDown) {
                down = ButtonState::Released;
            }
        });

        connect(keyboard->KeyDown, [this](Keys key) {
            POMDOG_ASSERT(keyUp != keyDown);
            if (key == keyUp) {
                up = ButtonState::Pressed;
            }
            else if (key == keyDown) {
                down = ButtonState::Pressed;
            }
        });
    }
예제 #9
0
// Start listening for a specific RHS user function.  When it fires we'll call to the client
// (over the connection) to implement it.
void RhsListener::AddRhsListener(char const* pFunctionName, Connection* pConnection)
{
	RhsMapIter mapIter = m_RhsMap.find(pFunctionName) ;

	ConnectionList* pList = NULL ;

	// Either create a new list or retrieve the existing list of listeners
	if (mapIter == m_RhsMap.end())
	{
		pList = new ConnectionList() ;
		m_RhsMap[pFunctionName] = pList ;
	}
	else
	{
		pList = mapIter->second ;
	}

	pList->push_back(pConnection) ;
}
예제 #10
0
TEST(ConnectionList, Disconnect)
{
    Signal<void(std::string)> nameChanged;
    ConnectionList connections;
    std::string name;

    connections += nameChanged.Connect([&](std::string const& n) {
        name = n;
    });

    nameChanged("alice");
    EXPECT_EQ("alice", name);
    nameChanged("bob");
    EXPECT_EQ("bob", name);
    nameChanged("chuck");
    EXPECT_EQ("chuck", name);

    connections.Disconnect();

    nameChanged("norris");
    EXPECT_EQ("chuck", name);
}
예제 #11
0
/*************************************************************
* @brief	Returns true if at least one filter is registered.
*************************************************************/
bool KernelSML::HasFilterRegistered()
{
	ConnectionList* pListeners = m_RhsListener.GetRhsListeners(sml_Names::kFilterName) ;

	return (pListeners && pListeners->size() > 0) ;
}
예제 #12
0
Bool ConnectObjects(
    String prefix, const maxon::BaseArray<BaseObject*>& objects,
    ConnectOptions& options)
{

  // Check if the object can successfully be allocatd for the
  // specified plugin id.
  BaseObject* test = BaseObject::Alloc(options.forcePluginId);
  if (!test)
  {
    GeDebugOut("Can not allocate plugin object " + String::IntToString(options.forcePluginId));
    return false;
  }

  // Get the name of the object so we can use it later.
  options.forceName = test->GetName();
  BaseObject::Free(test);
  if (!prefix.Content())
    prefix = options.forceName + ": ";

  // Final result of the function.
  Bool success = true;

  // Create the ConnectionList for the objects.
  ConnectionList list;
  switch (options.connectMode)
  {
    case CMB_MODE_ALL:
    {
      const auto end = objects.End();
      for (auto it=objects.Begin(); it != end; ++it)
      {
        for (auto jt=objects.Begin(); jt != end; ++jt)
        {
          if (*it == *jt) continue;
          if (list.HasConnection(*it, *jt)) continue;
          list.Append(Connection(*it, *jt));
        }
      }
      break;
    }
    case CMB_MODE_NEIGHBOR:
    {
      const auto end = objects.End();
      for (auto it=objects.Begin(); it != end; ++it)
      {

        // Find the nearest object.
        BaseObject* nearest = nullptr;
        Float delta;
        for (auto jt=objects.Begin(); jt != end; ++jt)
        {
          if (*it == *jt) continue;
          if (list.HasConnection(*it, *jt)) continue;

          Connection conn(*it, *jt);
          if (!nearest || conn.delta < delta)
          {
            nearest = *jt;
            delta = conn.delta;
          }
        }

        if (nearest)
          list.Append(Connection(*it, nearest));
      }
      break;
    }
    case CMB_MODE_CHAIN:
    {
      options.radius = 0;
      options.maxConnections = 0;
      const auto first = objects.Begin();
      for (auto it=objects.Begin(); it != objects.End(); ++it)
      {
        Bool isLast = (it + 1) == objects.End();
        if (isLast && (options.closedChain && *it != *first))
        {
          Connection conn(*it, *first);
          list.Append(conn);
        }
        else if (!isLast)
        {
          Connection conn(*it, *(it + 1));
          list.Append(conn);
        }
      }
      break;
    }
    default:
      GeDebugOut(String(__FUNCTION__) + ": Invalid connectMode");
      return false;
  }

  // Sort the list by distance.
  list.SortByDelta();

  // This map contains the number of connections each
  // object already has to make sure no object exceeds the
  // maximum number if connections.
  maxon::Bool created = false;
  maxon::HashMap<C4DAtom*, Int32> map;

  // Iterate over all connections and establish them.
  const auto end = list.End();
  for (auto it=list.Begin(); it != end; ++it)
  {
    if (options.radius > 0.000001 && it->delta > options.radius)
      continue;

    // Find and eventually initialize the entries in the map.
    auto entry1 = map.FindOrCreateEntry(it->obj1, created);
    if (created) entry1->GetValue() = 0;
    auto entry2 = map.FindOrCreateEntry(it->obj2, created);
    if (created) entry2->GetValue() = 0;

    // Determine if the maximum number of connections is reached.
    const Int32 nConn1 = entry1->GetValue();
    const Int32 nConn2 = entry2->GetValue();
    if (options.maxConnections > 0 &&
        (nConn1 >= options.maxConnections || nConn2 >= options.maxConnections))
      continue;

    // Create the force object.
    BaseObject* force = BaseObject::Alloc(options.forcePluginId);
    if (!force)
    {
      success = false;
      break;
    }

    // Update the parameters.
    force->SetParameter(FORCE_TYPE, options.forceType, DESCFLAGS_SET_0);
    force->SetParameter(FORCE_OBJECT_A, it->obj1, DESCFLAGS_SET_0);
    force->SetParameter(FORCE_OBJECT_B, it->obj2, DESCFLAGS_SET_0);
    force->SetBit(BIT_ACTIVE);
    force->SetName(prefix + it->obj1->GetName() + " - " + it->obj2->GetName());
    ++entry1->GetValue();
    ++entry2->GetValue();

    options.output.Append(force);

    // Position the force object in between the two objects.
    Matrix mg;
    mg.off = (it->obj1->GetMg().off + it->obj2->GetMg().off) * 0.5;
    force->SetMl(mg);
  }

  return true;
}
예제 #13
0
bool RhsListener::ExecuteRhsCommand(AgentSML* pAgentSML, smlRhsEventId eventID, std::string const& functionName, std::string const& arguments, std::string* pResultStr)
{
	bool result = false ;

	// Get the list of connections (clients) who have registered to implement this right hand side (RHS) function.
	ConnectionList* pList = GetRhsListeners(functionName.c_str()) ;

	// If nobody is listening we're done (not a bug as we register for all rhs functions and only forward specific ones that the client has registered)
	if (!pList || pList->size() == 0)
		return result ;

	ConnectionListIter connectionIter = pList->begin() ;

	// We need the first connection for when we're building the message.  Perhaps this is a sign that
	// we shouldn't have rolled these methods into Connection.
	Connection* pConnection = *connectionIter ;

	// Convert eventID to a string
	char const* event = m_pKernelSML->ConvertEventToString(eventID) ;

	// Build the SML message we're doing to send.
	// Pass the agent in the "name" parameter not the "agent" parameter as this is a kernel
	// level event, not an agent level one (because you need to register with the kernel to get "agent created").
	soarxml::ElementXML* pMsg = pConnection->CreateSMLCommand(sml_Names::kCommand_Event) ;
	if (pAgentSML) pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamName, pAgentSML->GetName()) ;
	pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamEventID, event) ;
	pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamFunction, functionName.c_str()) ;
	pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamValue, arguments.c_str()) ;

#ifdef _DEBUG
	// Generate a text form of the XML so we can look at it in the debugger.
	char* pStr = pMsg->GenerateXMLString(true) ;
#endif

	AnalyzeXML response ;

	// We want to call embedded connections first, so that we get the best performance
	// for these functions.  I don't want to sort the list or otherwise change it so
	// instead we'll just use a rather clumsy outer loop to do this.
	for (int phase = 0 ; phase < 2 && !result ; phase++)
	{
		// Only call to embedded connections
		bool embeddedPhase = (phase == 0) ;

		// Reset the iterator to the beginning of the list
		connectionIter = pList->begin();

		// Keep looping until we get a result
		while (connectionIter != pList->end() && !result)
		{
			pConnection = *connectionIter ;

			// We call all embedded connections (same process) first before
			// trying any remote methods.  This ensures that if multiple folks register
			// for the same function we execute the fastest one (w/o going over a socket for the result).
			if (pConnection->IsRemoteConnection() && embeddedPhase)
			{
				connectionIter++ ;
				continue ;
			}

			// It would be faster to just send a message here without waiting for a response
			// but that could produce incorrect behavior if the client expects to act *during*
			// the event that we're notifying them about (e.g. notification that we're in the input phase).
			bool ok = pConnection->SendMessageGetResponse(&response, pMsg) ;

			if (ok)
			{
				char const* pResult = response.GetResultString() ;

				if (pResult != NULL)
				{
					(*pResultStr) = pResult ;
					result = true ;
				}
			}

			connectionIter++ ;
		}
	}

#ifdef _DEBUG
	// Release the string form we generated for the debugger
	pMsg->DeleteString(pStr) ;
#endif

	// Clean up
	delete pMsg ;

	return result ;
}
예제 #14
0
bool RhsListener::HandleFilterEvent(smlRhsEventId eventID, AgentSML* pAgent, char const* pArgument,
						    std::string &pReturnValue)
{
	// Currently only supporting one event here, but that could change in time.
	assert(eventID == smlEVENT_FILTER) ;

	// Filters are handled as a RHS function call internally, using a special reserved name.
	char const* pFunctionName = sml_Names::kFilterName ;

	// Get the list of connections (clients) who have registered to implement this right hand side (RHS) function.
	ConnectionList* pList = GetRhsListeners(pFunctionName) ;

	bool result = false ;

	// If nobody is listening we're done (not a bug as we register for all rhs functions and only forward specific ones that the client has registered)
	if (!pList || pList->size() == 0)
		return result ;

	ConnectionListIter connectionIter = pList->begin() ;

	// We need the first connection for when we're building the message.  Perhaps this is a sign that
	// we shouldn't have rolled these methods into Connection.
	Connection* pConnection = *connectionIter ;

	// Convert eventID to a string
	char const* event = m_pKernelSML->ConvertEventToString(eventID) ;

	// Copy the initial command line into the return buffer and send that over.
	// This will be sequentially replaced by each filter in turn and whatever
	// is left in here at the end is the result of the filtering.
	// This allows multiple filters to act on the data, each modifying it as it goes.
	// A side effect of this is that the order the filters work on the data is significant.
	// Anyone in the chain can set the string to be the empty string, which brings the
	// whole process to a halt (they have eaten the command line at that point).
    pReturnValue.reserve(strlen(pArgument) + 1); //adding 1 because strlen does not count the terminating null character
	pReturnValue.assign(pArgument);	

	bool stop = false ;

	while (connectionIter != pList->end() && !stop)
	{
		// Build the SML message we're doing to send.
		// Pass the agent in the "name" parameter not the "agent" parameter as this is a kernel
		// level event, not an agent level one (because you need to register with the kernel to get "agent created").
		soarxml::ElementXML* pMsg = pConnection->CreateSMLCommand(sml_Names::kCommand_Event) ;
		pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamName, pAgent ? pAgent->GetName() : "") ;
		pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamEventID, event) ;
		pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamFunction, sml_Names::kFilterName) ;
		pConnection->AddParameterToSMLCommand(pMsg, sml_Names::kParamValue, pReturnValue.c_str()) ;	// We send the current command line over

#ifdef _DEBUG
		// Generate a text form of the XML so we can look at it in the debugger.
		char* pStr = pMsg->GenerateXMLString(true) ;
#endif

		AnalyzeXML response ;

		pConnection = *connectionIter ;

		bool ok = pConnection->SendMessageGetResponse(&response, pMsg) ;

		if (ok)
		{
			char const* pResult = response.GetResultString() ;

			if (pResult != NULL)
			{
				// If the listener returns a result then take that
				// value and return it in "pReturnValue" to the caller.
				// If the client returns a longer string than the caller, pReturnValue is resized to fit it.
                pReturnValue.reserve(strlen(pResult) + 1); //adding 1 because strlen does not count the terminating null character
                pReturnValue.assign(pResult);	
				result = true ;
			}
			else
			{
				// If one of the filters returns an empty string, stop the process at that point
				// because the command has been "eaten".  Make the result the empty string.
				pReturnValue[0] = 0 ;
				result = true ;
				stop = true ;
			}
		}

		connectionIter++ ;

	#ifdef _DEBUG
		// Release the string form we generated for the debugger
		pMsg->DeleteString(pStr) ;
	#endif

		// Clean up
		delete pMsg ;
	}

	return result ;
}
예제 #15
0
ConnectionList CNullNetworkManager::GetConnections()
{
  ConnectionList list;
  list.push_back(CConnectionPtr(new CNullConnection()));
  return list;
}