标签:size gen 继承 hashtable 标识 log udp res iii
在整套Sipdroid源码中, 类SipProvider是最靠近TCP/UDP的一层, 在Sipdroid实现的SIP协议栈中扮演底层枢纽的角色(前一篇文章中介绍的SipdroidEngine扮演的是上层枢纽), 这一角色也可以从该类是Configurable, TransportListener, TcpServerListener的继承体现出来.
向下层, SipProvider和通信传输层进行交互, 包括接收Transport的回调, 向Transport传递要发送的msg
向上层, SipProvider和UI交互, 包括根据msg触发指定Transaction回调, 从而通知Call再到UserAgent
如果接收到的msg, 没有与其匹配的method_id, transaction_id或dialog_id, 就用ANY标识
public static final Identifier ANY = new Identifier("ANY");
public static final Identifier PROMISQUE = new Identifier("PROMISQUE");
在SipProviderListener中, 简单的接口定义和回调方法声明, 接口的对象listeners将会在SipProvider类中发挥重要的作用.
public void onReceivedMessage(SipProvider sip_provider, Message message);
listeners对象很关键, SipProvider提供的上下层枢纽功能都是要经过对应listener的被动触发和任务派发, Indentifier的值会在下面介绍.
Hashtable<Identifier, SipProviderListener> listeners = null;
/*TCP/UDP相关*/ String[] transport_protocols = null; boolean transport_udp = false; boolean transport_tcp = false; static UdpTransport udp = null; TcpServer tcp_server = null; /*Socket相关*/ SocketAddress outbound_proxy = null; private String outbound_addr = null; private int outbound_port = -1;
从宏观上把握下SipProvider类, 只需要明确以下问题:
我删掉了和SipProviderListener无关的代码, 这样就能够显著看到Listener HashTable的变化情况: 在注册前逐个增加listeners, 当注册成功后, 和Register有关的listeners都被删除.
I/System.out: SipProvider: adding SipProviderListener: 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975 I/System.out: SipProvider: SipProviderListener: size=1, listeners=412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, I/System.out: SipProvider: adding SipProviderListener: INVITE I/System.out: SipProvider: SipProviderListener: size=2, listeners=INVITE, 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, I/System.out: SipProvider: adding SipProviderListener: OPTIONS I/System.out: SipProvider: SipProviderListener: size=3, listeners=INVITE, OPTIONS, 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, I/System.out: SipProvider: adding SipProviderListener: 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870 I/System.out: SipProvider: SipProviderListener: size=4, listeners=INVITE, OPTIONS, 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I/System.out: SipProvider: removing SipProviderListener: NOTIFY I/System.out: SipProvider: WARNING: trying to remove a missed SipProviderListener. I/System.out: SipProvider: SipProviderListener: size=4, listeners=INVITE, OPTIONS, 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870, I/System.out: SipProvider: adding SipProviderListener: NOTIFY I/System.out: SipProvider: SipProviderListener: size=5, listeners=INVITE, OPTIONS, NOTIFY, 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975, 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870, I/System.out: SipProvider: removing SipProviderListener: 412269425175@10.15.3.73-1-REGISTER-null-z9hG4bK26975 I/System.out: SipProvider: SipProviderListener: size=4, listeners=INVITE, OPTIONS, NOTIFY, 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870, I/System.out: SipProvider: removing SipProviderListener: 412269425175@10.15.3.73-2-REGISTER-null-z9hG4bK84870 I/System.out: SipProvider: SipProviderListener: size=3, listeners=INVITE, OPTIONS, NOTIFY,
I/System.out: SipProvider: removing SipProviderListener: INVITE I/System.out: SipProvider: SipProviderListener: size=2, listeners=OPTIONS, NOTIFY, I/System.out: SipProvider: adding SipProviderListener: 847642009035@10.15.3.73-z9hG4bK06452429-null I/System.out: SipProvider: SipProviderListener: size=3, listeners=OPTIONS, NOTIFY, 847642009035@10.15.3.73-z9hG4bK06452429-null, I/System.out: SipProvider: adding SipProviderListener: 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053 I/System.out: SipProvider: SipProviderListener: size=4, listeners=OPTIONS, NOTIFY, 847642009035@10.15.3.73-z9hG4bK06452429-null, 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053, I/System.out: SipProvider: adding SipProviderListener: 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097 I/System.out: SipProvider: SipProviderListener: size=5, listeners=OPTIONS, NOTIFY, 847642009035@10.15.3.73-z9hG4bK06452429-null, 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053, 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I/System.out: SipProvider: removing SipProviderListener: 847642009035@10.15.3.73-z9hG4bK06452429-null I/System.out: SipProvider: SipProviderListener: size=4, listeners=OPTIONS, NOTIFY, 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053, 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097, I/System.out: SipProvider: adding SipProviderListener: INVITE I/System.out: SipProvider: SipProviderListener: size=5, listeners=INVITE, OPTIONS, NOTIFY, 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053, 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097, I/System.out: SipProvider: adding SipProviderListener: OPTIONS I/System.out: SipProvider: WARNING: trying to add a SipProviderListener with a id that is already in use. I/System.out: SipProvider: SipProviderListener: size=5, listeners=INVITE, OPTIONS, NOTIFY, 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053, 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097, I/System.out: SipProvider: removing SipProviderListener: 847642009035@10.15.3.73-1-INVITE-null-z9hG4bK26053 I/System.out: SipProvider: SipProviderListener: size=4, listeners=INVITE, OPTIONS, NOTIFY, 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097, I/System.out: SipProvider: removing SipProviderListener: 847642009035@10.15.3.73-2-INVITE-null-z9hG4bK50097 I/System.out: SipProvider: SipProviderListener: size=3, listeners=INVITE, OPTIONS, NOTIFY,
Sipdroid实现SIP(四): 传输层和应用层之间的枢纽SipProvider
标签:size gen 继承 hashtable 标识 log udp res iii
原文地址:http://www.cnblogs.com/elsarong/p/6227485.html