summaryrefslogtreecommitdiffstats
blob: 7333c0b54fbf09349cf450c821df8544c937f3a9 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * 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.streamstack;

import com.isode.stroke.base.ByteArray;
import com.isode.stroke.network.Connection;
import com.isode.stroke.signals.Signal1;
import com.isode.stroke.signals.Slot1;

public class ConnectionLayer implements LowLayer {

    public ConnectionLayer(Connection connection) {
        this.connection = connection;
        connection.onDataRead.connect(new Slot1<ByteArray>() {

            public void call(ByteArray p1) {
                writeDataToParentLayer(p1);
            }
        });
    }

    public void writeData(ByteArray data) {
        connection.write(data);
    }

    private Connection connection;

    /* Work around multiple inheritance workaround again */
    StreamLayer fakeStreamLayer_ = new StreamLayer() {

        public void writeData(ByteArray data) {
            connection.write(data);
        }

        public void handleDataRead(ByteArray data) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };

    public HighLayer getParentLayer() {
        return fakeStreamLayer_.getParentLayer();
    }

    public void setParentLayer(HighLayer parentLayer) {
        fakeStreamLayer_.setParentLayer(parentLayer);
    }

    public void writeDataToParentLayer(ByteArray data) {
        fakeStreamLayer_.writeDataToParentLayer(data);
    }
}