summaryrefslogtreecommitdiffstats
blob: d003b52707d466ac01f6284d90308120c1d47453 (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
/*
 * Copyright (c) 2010-2015, Isode Limited, London, England.
 * All rights reserved.
 */
package com.isode.stroke.streamstack;

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

public class ConnectionLayer implements LowLayer {

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

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

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

    private Connection connection;

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

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

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

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

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

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