summaryrefslogtreecommitdiff
path: root/CDAL/CommDevice.h
blob: 98979fe91fe2a97f3ce5fa607ecfd220772746db (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
/*
 * CommDevice.h
 *
 * Copyright (C) ST-Ericsson SA 2011
 * Authors: Srimanta Panda <srimanta.panda@stericsson.com>,
 *          Ola Borgelin <ola.borgelin@stericsson.com>,
 *          Karin Hedlund <karin.hedlund@stericsson.com>,
 *          Markus Andersson <markus.m.andersson@stericsson.com> for ST-Ericsson.
 * License terms: 3-clause BSD license
 *
 */

#pragma once

#include "AsyncCommunication.h"
#include "CDAL.h"
#include <cstring>

struct CommDevice {
public:
    enum Status {
        COMM_DEVICE_SUCCESS,
        COMM_DEVICE_CANCEL,
        COMM_DEVICE_ERROR,
        COMM_DEVICE_CLOSED
    };

    CommDevice();
    virtual ~CommDevice();

    virtual int read(void* buffer, size_t size) = 0;
    int readNoWait(void* buffer, size_t size, DataCallback_t cb, void* param);

    virtual int write(void* buffer, size_t size) = 0;
    int writeNoWait(void* buffer, size_t size, DataCallback_t cb, void* param);

    int cancel();

    virtual unsigned long getPhysicalAddress() = 0;

    void* getObject() {
        return object_;
    }
    void** getObjectStorage() {
        return &object_;
    }
protected:
    bool isReadCanceled_;
private:
    void* object_;
    AsyncCommunication* async_;
};