void Publication::addSubscriberLink(const SubscriberLinkPtr& sub_link)
{
  {
    boost::mutex::scoped_lock lock(subscriber_links_mutex_);

    if (dropped_)
    {
      return;
    }

    subscriber_links_.push_back(sub_link);

    if (sub_link->isIntraprocess())
    {
      ++intraprocess_subscriber_count_;
    }
  }

  if (latch_ && last_message_.buf)
  {
    sub_link->enqueueMessage(last_message_, true, true);
  }

  // This call invokes the subscribe callback if there is one.
  // This must happen *after* the push_back above, in case the
  // callback uses publish().
  peerConnect(sub_link);
}
int main(){
  bootUp();
  initialize();
  peerConnect();
  listenIn();

  exit(EXIT_SUCCESS);
}
Beispiel #3
0
    void connectPeerEndpoints (std::vector <IPAddress> const& list)
    {
        typedef std::vector <IPAddress> List;

        for (List::const_iterator iter (list.begin());
            iter != list.end(); ++iter)
            peerConnect (iter->withPort (0), iter->port());
    }
Beispiel #4
0
int test_main(int argc, char **argv)
{
	PEER peer;  // peer object (initialized with peerInitialize

	/* peerInitialize */   
	PEERCallbacks callbacks;  // we will need to add all of the supported callbacks

	/* peerSetTitle parameters */
	gsi_char  secret_key[9];      // your title's assigned secret key
	int maxUpdates = 10;  // max server queries the SDK will send out at a time
	PEERBool natNeg = PEERFalse;  // nat negotiation will not be supported
	PEERBool pingRooms[NumRooms];  
	PEERBool crossPingRooms[NumRooms];

	/* peerConnect parameters */
	int profileID = 0;  // we will not be using gp accounts, so this will be ignored
	void * userData = NULL;  // optional data passed to peerConnectCallback
	PEERBool blocking = PEERTrue; // true means function runs synchronously
	PEERBool non_blocking = PEERFalse; // false means function runs asynchronously

	int newbiesGroupID = 2;

	gsi_char * serverName = _T("UberNoobServer");
	int maxPlayers = 2;
	gsi_char * noPassword = _T("");

	GSIACResult result; // used for backend availability check
	gsi_time startTime;

	// set our nickname to a random string so that we'll have different nicks when running multiple instances of peerc
	_tsnprintf(nick,NICK_SIZE,_T("peerc%u"),(unsigned int)current_time());
	nick[NICK_SIZE - 1] = '\0';

	// set the secret key, in a semi-obfuscated manner
	secret_key[0] = 'H';
	secret_key[1] = 'A';
	secret_key[2] = '6';
	secret_key[3] = 'z';
	secret_key[4] = 'k';
	secret_key[5] = 'S';
	secret_key[6] = '\0';

	// check that the game's backend is available
	GSIStartAvailableCheck(_T("gmtest"));
	while((result = GSIAvailableCheckThink()) == GSIACWaiting)
		msleep(5);
	if(result != GSIACAvailable)
	{
		_tprintf(_T("The backend is not available\n"));
		return 1;
	}

	// set the callbacks
	memset(&callbacks, 0, sizeof(PEERCallbacks));
	callbacks.disconnected = DisconnectedCallback;
	//callbacks.qrNatNegotiateCallback
	callbacks.gameStarted = GameStartedCallback;
	callbacks.playerChangedNick = PlayerChangedNickCallback;
	callbacks.playerJoined = PlayerJoinedCallback;
	callbacks.playerLeft = PlayerLeftCallback;
	callbacks.readyChanged = ReadyChangedCallback;
	callbacks.roomMessage = RoomMessageCallback;
	callbacks.playerMessage = PlayerMessageCallback;
	callbacks.roomUTM = RoomUTMCallback;
	callbacks.roomKeyChanged = RoomKeyChangedCallback;
	callbacks.qrKeyList = QRKeyListCallback;
	callbacks.qrServerKey = QRServerKeyCallback;
	callbacks.param = NULL;

	// initialize peer object, specifying the supported callbacks
	peer = peerInitialize(&callbacks);
	if(!peer)
	{
		_tprintf(_T("Failed to init\n"));
		return 1;
	}

	// ping/cross-ping in every room
	pingRooms[TitleRoom] = PEERTrue;
	pingRooms[GroupRoom] = PEERTrue;
	pingRooms[StagingRoom] = PEERTrue;
	crossPingRooms[TitleRoom] = PEERTrue;
	crossPingRooms[GroupRoom] = PEERTrue;
	crossPingRooms[StagingRoom] = PEERTrue;

	// set the title
	if(!peerSetTitle(peer, TITLE, secret_key, TITLE, secret_key, 0, maxUpdates, natNeg, pingRooms, crossPingRooms))
	{
		peerShutdown(peer);
		_tprintf(_T("Failed to set the title\n"));
		return 1;
	}

	// connect to the chat server
	_tprintf(_T("Connecting as %s..."), nick);
	peerConnect(peer, nick, profileID, NickErrorCallback, ConnectCallback, userData, blocking);
	if(!connectSuccess)
	{
		peerShutdown(peer);
		_tprintf(_T("Failed to connect\n"));
		return 1;
	}
	printf("Connected\n\n");

	// join the title room
	printf("Joining title room...");
	peerJoinTitleRoom(peer, NULL, JoinCallback, NULL, PEERTrue);
	if(!joinSuccess)
	{
		peerDisconnect(peer);
		peerShutdown(peer);
		_tprintf(_T("Failed to join the title room\n"));
		return 1;
	}
	printf("Joined\n\n");

	// list the group rooms
	printf("Listing group rooms:\n");
	peerListGroupRooms(peer, _T(""), ListGroupRoomsCallback, userData, non_blocking);

	while (!groupRoomCallbackDone)
	{
		peerThink(peer);
		msleep(10);
	}

	// send a chat message to the room
	printf("\nSending message to the Title Room...\n");
	peerMessageRoom(peer, TitleRoom, _T("Hi everyone in the Title Room!\n"), NormalMessage);

	// Loop for a while
	startTime = current_time();
	while((current_time() - startTime) < (1000))
	{
		peerThink(peer);
		msleep(10);
	} 

	_tprintf(_T("\nJoining Group Room 'Newbies'..."));
	peerJoinGroupRoom(peer, newbiesGroupID, JoinRoomCallback, userData, blocking);

	_tprintf(_T("\nPlayers in Group Room: \n"));
	peerEnumPlayers(peer, GroupRoom, EnumPlayersCallback, NULL);

	_tprintf(_T("Hosting Staging Room...\n"));
	peerCreateStagingRoom(peer, serverName, maxPlayers, noPassword, CreateStagingRoomCallback, userData, blocking);

	// Loop for a while
	startTime = current_time();
	while((current_time() - startTime) < (1000))
	{
		peerThink(peer);
		msleep(10);
	}

    //peerStartAutoMatch(peer, 3, _T(""), AutoMatchStatusCallback, AutoMatchRateCallback, NULL, PEERFalse);

	//peerStopListingGames(peer);

	// Leave the title room
	peerLeaveRoom(peer, TitleRoom, NULL);

	// Stop auto match if it's in progress
	//peerStopAutoMatch(peer);

	// disconnect local client from chat server (peerShutdown must still be called)
	peerDisconnect(peer);

	peerShutdown(peer); // clean up (free internal sdk memory) 

	GSI_UNUSED(argc);
	GSI_UNUSED(argv);
	return 0;
}