예제 #1
0
        private void joinTestChannel(int interfaceType)
        {
            /// <summary>
            /// 5. Join my channel
            /// </summary>
            addLogView(interfaceType, "    joinChannel()");

            SchordChannel channel        = null;
            SchordManager currentManager = null;

            currentManager = getSchordManager(interfaceType);

            switch (interfaceType)
            {
            case SchordManager.INTERFACE_TYPE_WIFI:
                channel = currentManager.joinChannel(CHORD_HELLO_TEST_CHANNEL, mWifi_ChannelListener);
                break;

            case SchordManager.INTERFACE_TYPE_WIFI_P2P:
                channel = currentManager.joinChannel(CHORD_HELLO_TEST_CHANNEL, mWifiDirect_ChannelListener);
                break;

            case SchordManager.INTERFACE_TYPE_WIFI_AP:
                channel = currentManager.joinChannel(CHORD_HELLO_TEST_CHANNEL, mMobileAP_ChannelListener);
                break;
            }

            if (channel == null)
            {
                addLogView(interfaceType, "    Fail to joinChannel");
            }
        }
예제 #2
0
        private void onNodeCallbackCommon(bool isJoin, int interfaceType, string fromNode)
        {
            string interfaceName = getInterfaceName(interfaceType);

            if (isJoin)
            {
                if (mNodeNumberMap.ContainsKey(interfaceName + fromNode))
                {
                    addLogView(interfaceType, "    > onNodeJoined(Node" + mNodeNumberMap[interfaceName + fromNode] + " : " + fromNode + ")");
                }
                else
                {
                    mNodeNumber++;
                    mNodeNumberMap[interfaceName + fromNode] = mNodeNumber;
                    addLogView(interfaceType, "    > onNodeJoined(Node" + mNodeNumber + " : " + fromNode + ")");
                }

                /// <summary>
                /// 6. Send data to joined node
                /// </summary>
                sbyte[][] payload = new sbyte[1][];
                payload[0] = "Hello chord!".GetBytes();

                SchordChannel channel = getJoinedChannelByIfcType(interfaceType);

                if (channel == null)
                {
                    addLogView(interfaceType, "    Fail to get the joined Channel");
                    return;
                }

                try
                {
                    channel.sendData(fromNode, CHORD_SAMPLE_MESSAGE_TYPE, payload);
                }
                catch (Exception e)
                {
                    addLogView(interfaceType, "    " + e.Message);
                    return;
                }

                addLogView(interfaceType, "    sendData( Node " + mNodeNumberMap[interfaceName + fromNode] + ", " + new string(payload[0]) + ")");
            }
            else
            {
                addLogView(interfaceType, "    > onNodeLeft(Node" + mNodeNumberMap[interfaceName + fromNode] + " : " + fromNode + ")");
            }
        }
예제 #3
0
        private SchordChannel getJoinedChannelByIfcType(int ifcType)
        {
            int           managerIndex = 0;
            SchordChannel channel      = null;

            managerIndex = mInterfaceMap.get(ifcType);

            switch (managerIndex)
            {
            case 1:
                channel = mSchordManager_1.getJoinedChannel(CHORD_HELLO_TEST_CHANNEL);
                break;

            case 2:
                channel = mSchordManager_2.getJoinedChannel(CHORD_HELLO_TEST_CHANNEL);
                break;

            case 3:
                channel = mSchordManager_3.getJoinedChannel(CHORD_HELLO_TEST_CHANNEL);
                break;
            }

            return(channel);
        }