void
PacketProbe::ConnectByPath (std::string path)
{
  NS_LOG_FUNCTION (this << path);
  NS_LOG_DEBUG ("Name of probe to search for in config database: " << path);
  Config::ConnectWithoutContext (path, MakeCallback (&ns3::PacketProbe::TraceSink, this));
}
Example #2
0
/*
========================
idProfileMgr::SaveSettingsAsync
========================
*/
void idProfileMgr::SaveSettingsAsync()
{
	if( !saveGame_enable.GetBool() )
	{
		idLib::Warning( "Skipping profile save because saveGame_enable = 0" );
	}
	
	if( GetProfile() != NULL )
	{
		// Issue the async save...
		if( profileSaveProcessor->InitSaveProfile( profile, "" ) )
		{
		
		
			profileSaveProcessor->AddCompletedCallback( MakeCallback( this, &idProfileMgr::OnSaveSettingsCompleted, &profileSaveProcessor->GetParmsNonConst() ) );
			handle = session->GetSaveGameManager().ExecuteProcessor( profileSaveProcessor.get() );
			profile->SetState( idPlayerProfile::SAVING );
			
		}
	}
	else
	{
		idLib::Warning( "Not saving profile, profile is NULL." );
	}
}
    void CachingControllerApplication::HandleConfigurationAccept(Ptr<Socket> socket, const Address &from) {
        NS_LOG_FUNCTION (this);
        m_gatewaysConn.push_back(socket);
        socket->SetRecvCallback(MakeCallback(&CachingControllerApplication::HandleClientConfigurationInput, this));


    }
void
SSLinkManager::StartScanning (
  SubscriberStationNetDevice::EventType type, bool deleteParameters)
{
  // temp parameter "type" just to check on expiry of which event the function was called

  if (deleteParameters)
    {
      DeleteUplinkParameters ();
    }

  NS_ASSERT_MSG (!m_ss->IsRegistered (),
                 "Subscriber Station: Error while scanning: Already registered with a BS");

  if (m_ss->GetState () != SubscriberStationNetDevice::SS_STATE_IDLE)
    {
      m_dlChnlNr++;
    }

  // using max number of channel according to according to Section 8.5.1 of IEEE 802.16-2004 standard.
  if (m_dlChnlNr >= 200)
    {
      m_dlChnlNr = 0;
    }

  uint64_t dlChannel = m_ss->GetChannel (m_dlChnlNr);

  m_ss->SetState (SubscriberStationNetDevice::SS_STATE_SCANNING);
  m_ss->GetPhy ()->StartScanning (dlChannel, m_ss->GetIntervalT20 (),
                                  MakeCallback (&SSLinkManager::EndScanning, this));
}
/*
========================
idSessionLocal::DeleteSaveGameSync
========================
*/
saveGameHandle_t idSessionLocal::DeleteSaveGameSync( const char * name ) {
	saveGameHandle_t handle = 0;

	// Done this way so we know it will be shutdown properly on early exit or exception
	struct local_t {
		local_t() { 
			// Prepare background renderer or loadscreen with what you want to show
			{
				// with mode: SAVE_GAME_MODE_DELETE
			}
		}
		~local_t() { 
			// Shutdown background renderer or loadscreen
			{
			}
		}
	} local;

	if ( processorDelete->InitDelete( name ) ) {
		processorDelete->AddCompletedCallback( MakeCallback( this, &idSessionLocal::OnDeleteCompleted, &processorDelete->GetParmsNonConst() ) );
		handle = GetSaveGameManager().ExecuteProcessorAndWait( processorDelete );
	}

	// Errors within the process of saving are handled in OnDeleteCompleted()
	// so that asynchronous save errors are handled the same was as synchronous.
	if ( handle == 0 ) {
		idSaveLoadParms & parms = processorDelete->GetParmsNonConst();
		parms.errorCode = SAVEGAME_E_UNKNOWN;

		// Uniform error handling
		OnDeleteCompleted( &parms );
	}

	return handle;
}
/*
========================
idSessionLocal::SaveGameSync
========================
*/
saveGameHandle_t idSessionLocal::SaveGameSync( const char * name, const saveFileEntryList_t & files, const idSaveGameDetails & description ) {
	saveGameHandle_t handle = 0;

	// serialize the description file behind their back...
	saveFileEntryList_t filesWithDetails( files );
	idFile_SaveGame * gameDetailsFile = new (TAG_SAVEGAMES) idFile_SaveGame( SAVEGAME_DETAILS_FILENAME, SAVEGAMEFILE_TEXT | SAVEGAMEFILE_AUTO_DELETE );
	gameDetailsFile->MakeWritable();
	description.descriptors.WriteToIniFile( gameDetailsFile );
	filesWithDetails.Append( gameDetailsFile );

	if ( processorSaveFiles->InitSave( name, filesWithDetails, description ) ) {
		processorSaveFiles->AddCompletedCallback( MakeCallback( this, &idSessionLocal::OnSaveCompleted, &processorSaveFiles->GetParmsNonConst() ) );
		handle = GetSaveGameManager().ExecuteProcessorAndWait( processorSaveFiles );
	}

	// Errors within the process of saving are handled in OnSaveCompleted()
	// so that asynchronous save errors are handled the same was as synchronous.
	if ( handle == 0 ) {
		idSaveLoadParms & parms = processorSaveFiles->GetParmsNonConst();
		parms.errorCode = SAVEGAME_E_UNKNOWN;

		// Uniform error handling
		OnSaveCompleted( &parms );
	}

	return handle;
}
Example #7
0
/*
========================
idProfileMgr::LoadSettingsAsync
========================
*/
void idProfileMgr::LoadSettingsAsync()
{
	if( profile != NULL && saveGame_enable.GetBool() )
	{
		if( profileLoadProcessor->InitLoadProfile( profile, "" ) )
		{
			// Skip the not found error because this might be the first time to play the game!
			profileLoadProcessor->SetSkipSystemErrorDialogMask( SAVEGAME_E_FOLDER_NOT_FOUND | SAVEGAME_E_FILE_NOT_FOUND );
			
			profileLoadProcessor->AddCompletedCallback( MakeCallback( this, &idProfileMgr::OnLoadSettingsCompleted, &profileLoadProcessor->GetParmsNonConst() ) );
			handle = session->GetSaveGameManager().ExecuteProcessor( profileLoadProcessor.get() );
			profile->SetState( idPlayerProfile::LOADING );
			
			
		}
	}
	else
	{
		// If not able to save the profile, just change the state and leave
		if( profile == NULL )
		{
			idLib::Warning( "Not loading profile, profile is NULL." );
		}
		if( !saveGame_enable.GetBool() )
		{
			idLib::Warning( "Skipping profile load because saveGame_enable = 0" );
		}
	}
}
bool
PacketProbe::ConnectByObject (std::string traceSource, Ptr<Object> obj)
{
  NS_LOG_FUNCTION (this << traceSource << obj);
  NS_LOG_DEBUG ("Name of probe (if any) in names database: " << Names::FindPath (obj));
  bool connected = obj->TraceConnectWithoutContext (traceSource, MakeCallback (&ns3::PacketProbe::TraceSink, this));
  return connected;
}
void Adaptor::RequestProcessEventsOnIdle()
{
  // Only request a notification if the Adaptor is actually running
  // and we haven't installed the idle notification
  if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState ) )
  {
    mNotificationOnIdleInstalled = AddIdle( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ) );
  }
}
Example #10
0
void OnRead(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
  TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(handle->data);
  IOTJS_ASSERT(tcp_wrap != NULL);

  // tcp handle
  JObject jtcp = tcp_wrap->jobject();
  IOTJS_ASSERT(jtcp.IsObject());

  // socket object
  JObject jsocket = jtcp.GetProperty("owner");
  IOTJS_ASSERT(jsocket.IsObject());

  // onread callback
  JObject jonread = jtcp.GetProperty("onread");
  IOTJS_ASSERT(jonread.IsFunction());

  JArgList jargs(4);
  jargs.Add(jsocket);
  jargs.Add(JVal::Number((int)nread));
  jargs.Add(JVal::Bool(false));

  if (nread <= 0) {
    if (buf->base != NULL) {
      ReleaseBuffer(buf->base);
    }
    if (nread < 0) {
      if (nread == UV__EOF) {
        jargs.Set(2, JVal::Bool(true));
      }
      MakeCallback(jonread, JObject::Null(), jargs);
    }
    return;
  }

  JObject jbuffer(CreateBuffer(static_cast<size_t>(nread)));
  BufferWrap* buffer_wrap = BufferWrap::FromJBuffer(jbuffer);

  buffer_wrap->Copy(buf->base, nread);

  jargs.Add(jbuffer);
  MakeCallback(jonread, JObject::Null(), jargs);

  ReleaseBuffer(buf->base);
}
int
main(int argc, char* argv[])
{
  // setting default parameters for PointToPoint links and channels
  Config::SetDefault("ns3::PointToPointNetDevice::DataRate", StringValue("1Mbps"));
  Config::SetDefault("ns3::PointToPointChannel::Delay", StringValue("10ms"));
  Config::SetDefault("ns3::QueueBase::MaxPackets", UintegerValue(20));

  // Read optional command-line parameters (e.g., enable visualizer with ./waf --run=<> --visualize
  CommandLine cmd;
  cmd.Parse(argc, argv);

  // Creating nodes
  NodeContainer nodes;
  nodes.Create(3);

  // Connecting nodes using two links
  PointToPointHelper p2p;
  p2p.Install(nodes.Get(0), nodes.Get(1));
  p2p.Install(nodes.Get(1), nodes.Get(2));

  // Install NDN stack on all nodes
  ndn::StackHelper ndnHelper;
  ndnHelper.SetDefaultRoutes(true);
  ndnHelper.InstallAll();

  // Installing applications

  // Consumer
  ndn::AppHelper consumerHelper("ns3::ndn::ConsumerCbr");
  // Consumer will request /prefix/0, /prefix/1, ...
  consumerHelper.SetPrefix("/prefix");
  consumerHelper.SetAttribute("Frequency", StringValue("10")); // 10 interests a second
  consumerHelper.Install(nodes.Get(0));                        // first node

  // Producer
  ndn::AppHelper producerHelper("ns3::ndn::Producer");
  // Producer will reply to all requests starting with /prefix
  producerHelper.SetPrefix("/prefix");
  producerHelper.SetAttribute("PayloadSize", StringValue("1024"));
  producerHelper.SetAttribute("Signature", UintegerValue(100));
  producerHelper.SetAttribute("KeyLocator", StringValue("/unique/key/locator"));
  producerHelper.Install(nodes.Get(2)); // last node

  PcapWriter trace("ndn-simple-trace.pcap");
  Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::PointToPointNetDevice/MacTx",
                                MakeCallback(&PcapWriter::TracePacket, &trace));

  Simulator::Stop(Seconds(20.0));

  Simulator::Run();
  Simulator::Destroy();

  return 0;
}
Example #12
0
void
L2Tracer::Connect()
{
  for (uint32_t devId = 0; devId < m_nodePtr->GetNDevices(); devId++) {
    Ptr<PointToPointNetDevice> p2pnd =
      DynamicCast<PointToPointNetDevice>(m_nodePtr->GetDevice(devId));
    if (p2pnd) {
      p2pnd->GetQueue()->TraceConnectWithoutContext("Drop", MakeCallback(&L2Tracer::Drop, this));
    }
  }
}
Example #13
0
void FceApplication::StartApplication(void) {

	NS_LOG_FUNCTION ("");

	// initialize vehicle
	string vehicleId = Names::FindName(GetNode());
	vehicle.initialize(vehicleId);
	vehicle.setScenario(scenario);
	TIS::getInstance().initializeStaticTravelTimes(scenario.getAlternativeRoutes());

	// ns3
	mobilityModel = GetNode()->GetObject<ConstantVelocityMobilityModel>();
	// Connect the callback for the neighbor discovery service
	std::ostringstream oss;
	oss << "/NodeList/" << GetNode()->GetId() << "/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::BeaconingAdhocWifiMac/NeighborLost";
	Config::Connect(oss.str(), MakeCallback(&FceApplication::NeighborLost, this));
	std::ostringstream oss2;
	oss2 << "/NodeList/" << GetNode()->GetId() << "/DeviceList/*/$ns3::WifiNetDevice/Mac/$ns3::BeaconingAdhocWifiMac/NewNeighbor";
	Config::Connect(oss2.str(), MakeCallback(&FceApplication::NewNeighborFound, this));
	// set socket
	Ptr<SocketFactory> socketFactory = GetNode()->GetObject<UdpSocketFactory> ();
	m_socket = socketFactory->CreateSocket();
	m_socket->Connect (InetSocketAddress (Ipv4Address::GetBroadcast(), m_port));
	m_socket->SetAllowBroadcast(true);
	m_socket->SetRecvCallback(MakeCallback(&FceApplication::ReceivePacket, this));
	m_socket->Bind(InetSocketAddress(Ipv4Address::GetAny(), m_port));

	// start simualtion
	running = true;

	Log::getInstance().getStream("strategy") << strategy << endl;

	double r = (double)(rand()%RAND_MAX)/(double)RAND_MAX * SIMULATION_STEP_INTERVAL;
//	double r = rando.GetValue(0, SIMULATION_STEP_INTERVAL);
	double r2 = (double)(rand()%RAND_MAX)/(double)RAND_MAX * TRAFFIC_INFORMATION_SENDING_INTERVAL;
//	double r2 = rando.GetValue(0, TRAFFIC_INFORMATION_SENDING_INTERVAL);

	m_simulationEvent = Simulator::Schedule(Seconds(r), &FceApplication::SimulationRun, this);
	m_trafficInformationEvent = Simulator::Schedule(Seconds(1+r2), &FceApplication::SendTrafficInformation, this);

}
    void CachingControllerApplication::StartApplication(void) {
        NS_LOG_FUNCTION (this);

        m_socketConfiguration = Socket::CreateSocket(GetNode(), TcpSocketFactory::GetTypeId());
        Ptr<TcpNewReno> newReno = DynamicCast<TcpNewReno>(m_socketConfiguration);
        /*Config::SetDefault ("ns3::DropTailQueue::MaxPackets", StringValue ("80"));
        newReno->SetAttribute("SndBufSize",ns3::UintegerValue(1000000));
        newReno->SetAttribute("SegmentSize",ns3::UintegerValue(1460));*/


        m_socketConfiguration->Bind(m_configuration);
        m_socketConfiguration->Listen();
        m_socketConfiguration->SetAcceptCallback(
                MakeCallback(&CachingControllerApplication::HandleConnectionRequest, this),
                MakeCallback(&CachingControllerApplication::HandleConfigurationAccept, this));


        NS_LOG_FUNCTION (this << "callbacks registered");


    }
Example #15
0
// Socket close result handler.
static void AfterClose(uv_handle_t* handle) {
  HandleWrap* tcp_wrap = HandleWrap::FromHandle(handle);
  IOTJS_ASSERT(tcp_wrap != NULL);

  // tcp object.
  JObject jtcp = tcp_wrap->jobject();
  IOTJS_ASSERT(jtcp.IsObject());

  // callback function.
  JObject jcallback = jtcp.GetProperty("onclose");
  if (jcallback.IsFunction()) {
    MakeCallback(jcallback, JObject::Null(), JArgList::Empty());
  }
}
StackHelper::StackHelper()
  : m_needSetDefaultRoutes(false)
  , m_maxCsSize(100)
{
  setCustomNdnCxxClocks();

  m_ndnFactory.SetTypeId("ns3::ndn::L3Protocol");
  m_contentStoreFactory.SetTypeId("ns3::ndn::cs::Lru");

  m_netDeviceCallbacks.push_back(
    std::make_pair(PointToPointNetDevice::GetTypeId(),
                   MakeCallback(&StackHelper::PointToPointNetDeviceCallback, this)));
  // default callback will be fired if non of others callbacks fit or did the job
}
Example #17
0
NetDeviceFace::NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
  : Face(FaceUri("netDeviceFace://"), FaceUri("netDeviceFace://"),getLevelFromNode(node),false)
  , m_node(node)
  , m_netDevice(netDevice)
{
  NS_LOG_FUNCTION(this << netDevice);

  setMetric(1); // default metric

  NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");

  m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this),
                                  L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
                                  true /*promiscuous mode*/);
}
Example #18
0
void Application::OnInit()
{
  mFramework->AddAbortCallback( MakeCallback( this, &Application::QuitFromMainLoop ) );

  CreateWindow();
  CreateAdaptor();

  // Run the adaptor
  mAdaptor->Start();

  // Check if user requires no vsyncing and set on X11 Adaptor
  if (mCommandLineOptions->noVSyncOnRender)
  {
    mAdaptor->SetUseHardwareVSync(false);
  }

  Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetStereoBase( mCommandLineOptions->stereoBase );
  if( mCommandLineOptions->viewMode != 0 )
  {
    ViewMode viewMode = MONO;
    if( mCommandLineOptions->viewMode <= STEREO_INTERLACED )
    {
      viewMode = static_cast<ViewMode>( mCommandLineOptions->viewMode );
    }
    Internal::Adaptor::Adaptor::GetImplementation( *mAdaptor ).SetViewMode( viewMode );
  }

  if( ! mStylesheet.empty() )
  {
    Dali::StyleMonitor::Get().SetTheme( mStylesheet );
  }

  // Wire up the LifecycleController
  Dali::LifecycleController lifecycleController = Dali::LifecycleController::Get();

  InitSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnInit );
  TerminateSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnTerminate );
  PauseSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnPause );
  ResumeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResume );
  ResetSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnReset );
  ResizeSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnResize );
  LanguageChangedSignal().Connect( &GetImplementation( lifecycleController ), &LifecycleController::OnLanguageChanged );

  Dali::Application application(this);
  mInitSignal.Emit( application );

  mAdaptor->NotifySceneCreated();
}
Example #19
0
static void AfterShutdown(uv_shutdown_t* req, int status) {
  ShutdownReqWrap* req_wrap = reinterpret_cast<ShutdownReqWrap*>(req->data);
  TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(req->handle->data);
  IOTJS_ASSERT(req_wrap != NULL);
  IOTJS_ASSERT(tcp_wrap != NULL);

  // function onShutdown(status)
  JObject jonshutdown(req_wrap->jcallback());
  IOTJS_ASSERT(jonshutdown.IsFunction());

  JArgList args(1);
  args.Add(JVal::Number(status));

  MakeCallback(jonshutdown, JObject::Null(), args);

  delete req_wrap;
}
Example #20
0
        // Any new return statements added here should call MakeWeak() on bufferHandle_,
        // if it is not empty.
        void CallbackOverride(SQLRETURN ret) {
            EOS_DEBUG_METHOD();

            if (!SQL_SUCCEEDED(ret) && ret != SQL_NO_DATA) {
                if (!bufferHandle_.IsEmpty())
                    NanDisposePersistent(bufferHandle_);
                return CallbackErrorOverride(ret);
            }

            EOS_DEBUG(L"Final Result: %hi\n", ret);

            Handle<Value> argv[4];

            argv[0] = NanUndefined();
            if (totalLength_ != SQL_NO_TOTAL)
                argv[2] = NanNew<Number>(totalLength_);
            else
                argv[2] = NanUndefined();
            argv[3] = NanNew<Boolean>(totalLength_ > bufferLength_ || (totalLength_ == SQL_NO_TOTAL && ret == SQL_SUCCESS_WITH_INFO));

            if (ret == SQL_NO_DATA)
                argv[1] = NanUndefined();
            else if (totalLength_ == SQL_NULL_DATA)
                argv[1] = NanNull();
            else if (raw_) {
                assert(!bufferHandle_.IsEmpty());
                argv[1] = NanNew(bufferHandle_);
            } else if (cType_ == SQL_C_BINARY) {
                if (totalLength_ >= bufferLength_) 
                    argv[1] = NanNew(bufferHandle_);
                else
                    argv[1] = JSBuffer::Slice(NanNew(bufferHandle_), 0, totalLength_);
            } else {
                argv[1] = Eos::ConvertToJS(buffer_, totalLength_, bufferLength_, cType_);
                if (argv[1]->IsUndefined())
                    argv[0] = OdbcError("Unable to interpret contents of result buffer");
            }

            // Can we Dispose() things that JS-land is referencing? We'll soon find out!
            if (!bufferHandle_.IsEmpty())
                NanDisposePersistent(bufferHandle_);
            
            MakeCallback(argv);
        }
Example #21
0
static void After(uv_fs_t* req) {
  FsReqWrap* req_wrap = static_cast<FsReqWrap*>(req->data);
  IOTJS_ASSERT(req_wrap != NULL);
  IOTJS_ASSERT(req_wrap->data() == req);

  JObject cb = req_wrap->jcallback();
  IOTJS_ASSERT(cb.IsFunction());

  JArgList jarg(2);
  if (req->result < 0) {
    JObject jerror(CreateUVException(req->result, "open"));
    jarg.Add(jerror);
  } else {
    jarg.Add(JObject::Null());
    switch (req->fs_type) {
      case UV_FS_CLOSE:
      {
        break;
      }
      case UV_FS_OPEN:
      case UV_FS_READ:
      case UV_FS_WRITE:
      {
        JObject arg1(static_cast<int>(req->result));
        jarg.Add(arg1);
        break;
      }
      case UV_FS_STAT: {
        uv_stat_t s = (req->statbuf);
        JObject ret(MakeStatObject(&s));
        jarg.Add(ret);
        break;
      }
      default:
        jarg.Add(JObject::Null());
    }
  }

  JObject res = MakeCallback(cb, JObject::Null(), jarg);

  uv_fs_req_cleanup(req);

  delete req_wrap;
}
Example #22
0
	void session::init(ns3::Ptr<Node> node, ns3::Ipv4Address ip, std::pair<int, int> listen_range, char const* listen_interface
		, fingerprint const& id, int flags, boost::uint32_t alert_mask TORRENT_LOGPATH_ARG)
	{
        NS_LOG_FUNCTION(this);
        ns3::Callback<void> initCallback = MakeCallback(&session::initCallback, this);
		m_impl.reset(new session_impl(initCallback, node, ip, listen_range, id, listen_interface, alert_mask TORRENT_LOGPATH));

#ifdef TORRENT_MEMDEBUG
		start_malloc_debug();
#endif

		m_impl->start_session();

		if (flags & start_default_features)
		{
		//	start_upnp();
		//	start_natpmp();
		}
	}
Example #23
0
void Ping6::StartApplication ()
{
  NS_LOG_FUNCTION_NOARGS ();

  if (!m_socket)
    {
      TypeId tid = TypeId::LookupByName ("ns3::Ipv6RawSocketFactory");
      m_socket = Socket::CreateSocket (GetNode (), tid);

      NS_ASSERT (m_socket);

      m_socket->Bind (Inet6SocketAddress (m_localAddress, 0));
      m_socket->Connect (Inet6SocketAddress (m_peerAddress, 0));
      m_socket->SetAttribute ("Protocol", UintegerValue (Ipv6Header::IPV6_ICMPV6));
      m_socket->SetRecvCallback (MakeCallback (&Ping6::HandleRead, this));
    }

  ScheduleTransmit (Seconds (0.));
}
Example #24
0
void AfterWrite(uv_write_t* req, int status) {
  WriteReqWrap* req_wrap = reinterpret_cast<WriteReqWrap*>(req->data);
  TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(req->handle->data);
  IOTJS_ASSERT(req_wrap != NULL);
  IOTJS_ASSERT(tcp_wrap != NULL);

  // Take callback function object.
  JObject jcallback = req_wrap->jcallback();

  // Only parameter is status code.
  JArgList args(1);
  args.Add(JVal::Number(status));

  // Make callback.
  MakeCallback(jcallback, JObject::Null(), args);

  // Release request wrapper.
  delete req_wrap;
}
Example #25
0
// A client socket wants to connect to this server.
// Parameters:
//   * uv_stream_t* handle - server handle
//   * int status - status code
static void OnConnection(uv_stream_t* handle, int status) {
  // Server tcp wrapper.
  TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(handle->data);
  IOTJS_ASSERT(tcp_wrap->tcp_handle() == reinterpret_cast<uv_tcp_t*>(handle));

  // Tcp object
  JObject jtcp = tcp_wrap->jobject();
  IOTJS_ASSERT(jtcp.IsObject());

  // `onconnection` callback.
  JObject jonconnection = jtcp.GetProperty("onconnection");
  IOTJS_ASSERT(jonconnection.IsFunction());

  // The callback takes two parameter
  // [0] status
  // [1] client tcp object
  JArgList args(2);
  args.Add(JVal::Number(status));

  if (status == 0) {
    // Create client socket handle wrapper.
    JObject jcreate_tcp = jtcp.GetProperty("createTCP");
    IOTJS_ASSERT(jcreate_tcp.IsFunction());

    JObject jclient_tcp = jcreate_tcp.CallOk(JObject::Null(),
                                             JArgList::Empty());
    IOTJS_ASSERT(jclient_tcp.IsObject());

    TcpWrap* tcp_wrap = reinterpret_cast<TcpWrap*>(jclient_tcp.GetNative());

    uv_stream_t* client_handle =
        reinterpret_cast<uv_stream_t*>(tcp_wrap->tcp_handle());

    int err = uv_accept(handle, client_handle);
    if (err) {
      return;
    }

    args.Add(jclient_tcp);
  }

  MakeCallback(jonconnection, jtcp, args);
}
/*
========================
idMenuScreen_Shell_GameBrowser::UpdateServerList
========================
*/
void idMenuScreen_Shell_GameBrowser::UpdateServerList() {
	idMenuHandler_Shell * const mgr = dynamic_cast< idMenuHandler_Shell * >( menuData );

	if ( mgr == NULL ) {
		return;
	}

	for ( int i = 0; i < listWidget->GetChildren().Num(); ++i ) {
		idMenuWidget & child = listWidget->GetChildByIndex( i );
		child.SetState( WIDGET_STATE_HIDDEN );
	}

	// need to show the pacifier before actually making the ListServers call, because it can fail
	// immediately and send back an error result to SWF. Things get confused if the showLoadingPacifier
	// then gets called after that.
	mgr->ShowPacifier( "#str_online_mpstatus_searching" );

	session->ListServers( MakeCallback( this, &idMenuScreen_Shell_GameBrowser::OnServerListReady ) );
}
/*
========================
idSessionLocal::DeleteSaveGameAsync
========================
*/
saveGameHandle_t idSessionLocal::DeleteSaveGameAsync( const char * name ) {
	saveGameHandle_t handle = 0;
	if ( processorDelete->InitDelete( name ) ) {
		processorDelete->AddCompletedCallback( MakeCallback( this, &idSessionLocal::OnDeleteCompleted, &processorDelete->GetParmsNonConst() ) );
		common->Dialog().ShowSaveIndicator( true );
		handle = GetSaveGameManager().ExecuteProcessor( processorDelete );
	}

	// Errors within the process of saving are handled in OnDeleteCompleted()
	// so that asynchronous save errors are handled the same was as synchronous.
	if ( handle == 0 ) {
		idSaveLoadParms & parms = processorDelete->GetParmsNonConst();
		parms.errorCode = SAVEGAME_E_UNKNOWN;

		// Uniform error handling
		OnDeleteCompleted( &parms );
	}

	return handle;
}
Example #28
0
void StartFlow(ns3::Ptr<ns3::Socket> sock, const char* to, uint16_t port_number)
{
  SgFlow* flow = getFlowFromSocket(sock);
  ns3::InetSocketAddress serverAddr(to, port_number);

  sock->Connect(serverAddr);
  // tell the tcp implementation to call send_cb again
  // if we blocked and new tx buffer space becomes available
  sock->SetSendCallback(MakeCallback(&send_cb));
  // Notice when the send is over
  sock->SetRecvCallback(MakeCallback(&receive_callback));
  // Notice when we actually sent some data (mostly for the TRACING module)
  sock->SetDataSentCallback(MakeCallback(&datasent_cb));

  XBT_DEBUG("startFlow of F[%p, %p, %u] dest=%s port=%d", flow, flow->action_, flow->totalBytes_, to, port_number);

  sock->SetConnectCallback(MakeCallback(&succeededConnect_callback), MakeCallback(&failedConnect_callback));
  sock->SetCloseCallbacks(MakeCallback(&normalClose_callback), MakeCallback(&errorClose_callback));
}
/*
========================
idSessionLocal::SaveGameAsync
========================
*/
saveGameHandle_t idSessionLocal::SaveGameAsync( const char * name, const saveFileEntryList_t & files, const idSaveGameDetails & description ) {
	saveGameHandle_t handle = 0;

	// Done this way so we know it will be shutdown properly on early exit or exception
	struct local_t {
		local_t( idSaveLoadParms * localparms ) : parms( localparms ) { 
			// Prepare background renderer
		}
		~local_t() { 
			// Shutdown background renderer
		}
		idSaveLoadParms * parms;
	} local( &processorSaveFiles->GetParmsNonConst() );

	// serialize the description file behind their back...
	saveFileEntryList_t filesWithDetails( files );
	idFile_SaveGame * gameDetailsFile = new (TAG_SAVEGAMES) idFile_SaveGame( SAVEGAME_DETAILS_FILENAME, SAVEGAMEFILE_TEXT | SAVEGAMEFILE_AUTO_DELETE );
	gameDetailsFile->MakeWritable();
	description.descriptors.WriteToIniFile( gameDetailsFile );
	filesWithDetails.Append( gameDetailsFile );

	if ( processorSaveFiles->InitSave( name, filesWithDetails, description ) ) {
		processorSaveFiles->AddCompletedCallback( MakeCallback( this, &idSessionLocal::OnSaveCompleted, &processorSaveFiles->GetParmsNonConst() ) );
		handle = GetSaveGameManager().ExecuteProcessor( processorSaveFiles );
	}

	// Errors within the process of saving are handled in OnSaveCompleted()
	// so that asynchronous save errors are handled the same was as synchronous.
	if ( handle == 0 ) {
		idSaveLoadParms & parms = processorSaveFiles->GetParmsNonConst();
		parms.errorCode = SAVEGAME_E_UNKNOWN;

		common->Dialog().ShowSaveIndicator( false );
		// Uniform error handling
		OnSaveCompleted( &parms );
	}


	return handle;
}
NetDeviceFace::NetDeviceFace(Ptr<Node> node, const Ptr<NetDevice>& netDevice)
  : Face(FaceUri("netDeviceFace://"),
         FaceUri("netDeviceFace://"),
         false,
         // this is the mod mentioned above
         ( netDevice->GetObject<Object>
             ( TypeId::LookupByName( "ndntac::IsEdgeFlag" ) )
             ? true : false ),
         false )
  , m_node(node)
  , m_netDevice(netDevice)
{
  NS_LOG_FUNCTION(this << netDevice);

  setMetric(1); // default metric

  NS_ASSERT_MSG(m_netDevice != 0, "NetDeviceFace needs to be assigned a valid NetDevice");

  m_node->RegisterProtocolHandler(MakeCallback(&NetDeviceFace::receiveFromNetDevice, this),
                                  L3Protocol::ETHERNET_FRAME_TYPE, m_netDevice,
                                  true /*promiscuous mode*/);
}