summaryrefslogtreecommitdiffstats
blob: 8b878a835f75131fa044e69af8430705d3c4ab45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2010 Remko Tronçon
 * Licensed under the GNU General Public License v3.
 * See Documentation/Licenses/GPLv3.txt for more information.
 */
/*
 * Copyright (c) 2010, Isode Limited, London, England.
 * All rights reserved.
 */
package com.isode.stroke.session;

import com.isode.stroke.base.SafeByteArray;
import com.isode.stroke.signals.Slot1;

public class SessionTracer {

    public SessionTracer(Session session) {
        this.session = session;
        session.onDataRead.connect(new Slot1<SafeByteArray>() {

            public void call(SafeByteArray p1) {
                printData('<', p1);
            }
        });

        session.onDataWritten.connect(new Slot1<SafeByteArray>() {

            public void call(SafeByteArray p1) {
                printData('>', p1);
            }
        });
    }

    private void printData(char direction, SafeByteArray data) {
        System.err.print("" + direction + direction + " " + session.getLocalJID().toString() + " ");
        for (int i = 0; i < 72 - session.getLocalJID().toString().length() - session.getRemoteJID().toString().length(); ++i) {
            System.err.print(direction);
        }
        System.err.println(" " + session.getRemoteJID().toString() + " " + direction + direction);
        System.err.println(data);
    }
    private Session session;
}