JoinSession() public method

public JoinSession ( string sessionHost, ushort sessionPort, SessionListener listener, uint &sessionId, SessionOpts opts ) : QStatus
sessionHost string
sessionPort ushort
listener SessionListener
sessionId uint
opts SessionOpts
return QStatus
コード例 #1
0
		public void TestSessionJoined()
		{
			AllJoyn.QStatus status = AllJoyn.QStatus.FAIL;

			// create+start+connect bus attachment
			AllJoyn.BusAttachment servicebus = null;
			servicebus = new AllJoyn.BusAttachment("SessionTestService", true);
			Assert.NotNull(servicebus);

			status = servicebus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = servicebus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Create session
			AllJoyn.SessionOpts opts = new AllJoyn.SessionOpts(
				AllJoyn.SessionOpts.TrafficType.Messages, false,
				AllJoyn.SessionOpts.ProximityType.Any, AllJoyn.TransportMask.Any);
			ushort sessionPort = SERVICE_PORT;

			// create the session port listener
			AllJoyn.SessionPortListener sessionPortListener = new TestSessionPortListener(this);

			// bind to the session port
			status = servicebus.BindSessionPort(ref sessionPort, opts, sessionPortListener);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// request name
			status = servicebus.RequestName(OBJECT_NAME, AllJoyn.DBus.NameFlags.ReplaceExisting | AllJoyn.DBus.NameFlags.DoNotQueue);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// Advertise name
			status = servicebus.AdvertiseName(OBJECT_NAME, opts.Transports);
			Assert.Equal(AllJoyn.QStatus.OK, status);

			///////////////////////////////////////////////////////////
			foundAdvertisedNameFlag = false;
			acceptSessionJoinerFlag = false;
			sessionJoinedFlag = false;

			// try to join the session & verify callbacks are called
			AllJoyn.BusAttachment bus = null;
			bus = new AllJoyn.BusAttachment("SessionTest", true);
			Assert.NotNull(bus);

			status = bus.Start();
			Assert.Equal(AllJoyn.QStatus.OK, status);

			status = bus.Connect(AllJoynTestCommon.GetConnectSpec());
			Assert.Equal(AllJoyn.QStatus.OK, status);

			// register the bus listener
			AllJoyn.BusListener busListener = new TestBusListener(this);
			bus.RegisterBusListener(busListener);

			// find the advertised name from the "servicebus"
			status = bus.FindAdvertisedName(OBJECT_NAME);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "FoundAdvertisedName");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, foundAdvertisedNameFlag);

			// try to join & verify that the sessionedJoined callback was called
			uint sSessionId;
			status = bus.JoinSession(OBJECT_NAME, SERVICE_PORT, null, out sSessionId, opts);
			Assert.Equal(AllJoyn.QStatus.OK, status);
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset, "SessionJoined");
			ewh.WaitOne(MaxWaitTime);
			Assert.Equal(true, acceptSessionJoinerFlag);
			Assert.Equal(true, sessionJoinedFlag);
			servicebus.ReleaseName(OBJECT_NAME);
			servicebus.Dispose();
			bus.Dispose();

		}