01: /**
02: * $Revision$
03: * $Date$
04: *
05: * Copyright (C) 2006-2007 Jive Software. All rights reserved.
06: *
07: * This software is published under the terms of the GNU Public License (GPL),
08: * a copy of which is included in this distribution.
09: *
10: * Heavily inspired by joscardemo of the Joust Project: http://joust.kano.net/
11: */package org.jivesoftware.openfire.gateway.protocols.oscar;
12:
13: import net.kano.joscar.flap.ClientFlapConn;
14: import net.kano.joscar.flap.FlapPacketEvent;
15: import net.kano.joscar.ByteBlock;
16: import net.kano.joscar.flapcmd.SnacCommand;
17: import net.kano.joscar.snaccmd.conn.RateInfoCmd;
18: import net.kano.joscar.snac.SnacPacketEvent;
19: import net.kano.joscar.snac.SnacResponseEvent;
20: import net.kano.joscar.net.ClientConnEvent;
21: import net.kano.joscar.net.ConnDescriptor;
22: import org.apache.log4j.Logger;
23:
24: /**
25: * Represents a connection to a particular OSCAR service.
26: *
27: * @author Daniel Henninger
28: * Heavily inspired by joscardemo from the joscar project.
29: */
30: public class ServiceConnection extends BasicFlapConnection {
31:
32: static Logger Log = Logger.getLogger(ServiceConnection.class);
33:
34: protected int serviceFamily;
35:
36: public ServiceConnection(ConnDescriptor cd,
37: OSCARSession mainSession, ByteBlock cookie,
38: int serviceFamily) {
39: super (cd, mainSession, cookie);
40: this .serviceFamily = serviceFamily;
41: }
42:
43: protected void clientReady() {
44: getMainSession().serviceReady(this );
45: super .clientReady();
46: }
47:
48: protected void handleStateChange(ClientConnEvent e) {
49: Log.debug("OSCAR service state change from " + e.getOldState()
50: + " to " + e.getNewState());
51: if (e.getNewState() == ClientFlapConn.STATE_FAILED) {
52: getMainSession().serviceFailed(this );
53: } else if (e.getNewState() == ClientFlapConn.STATE_CONNECTED) {
54: getMainSession().serviceConnected(this );
55: } else if (e.getNewState() == ClientFlapConn.STATE_NOT_CONNECTED) {
56: getMainSession().serviceDied(this );
57: }
58: }
59:
60: protected void handleFlapPacket(FlapPacketEvent e) {
61: super .handleFlapPacket(e);
62: }
63:
64: protected void handleSnacPacket(SnacPacketEvent e) {
65: super .handleSnacPacket(e);
66: }
67:
68: protected void handleSnacResponse(SnacResponseEvent e) {
69: super .handleSnacResponse(e);
70:
71: SnacCommand cmd = e.getSnacCommand();
72:
73: if (cmd instanceof RateInfoCmd) {
74: // this is all we need.
75: clientReady();
76: }
77: }
78:
79: }
|