Project

General

Profile

Support Request #14449 » iodevice.cpp

hidden, 2021-06-09 06:06

 
1
/**
2
 *
3
 * Base I/O device implementation.
4
 *
5
 * @file
6
 * Copyright © Audi Electronics Venture GmbH. All rights reserved.
7
 *
8
 * $Author: ANOAFR4 $
9
 * $Date: 2014-06-27 16:33:30 +0200 (Fre, 27 Jun 2014) $
10
 * $Revision: 48654 $
11
 * @remarks
12
 *
13
 */
14
#include "stdafx.h"
15
#include <adtf_plugin_sdk.h>
16

    
17
namespace adtf
18
{
19
/**************************************************************************/
20
/* Private implementation to provide object compatibility                 */
21
/**************************************************************************/
22
class cBaseIODevice::cBaseIODevicePrivate : public cADTFD<cBaseIODevice, cBaseIODevice::cBaseIODevicePrivate>
23
{
24
    friend class cBaseIODevice;
25
    public:
26
        cBaseIODevicePrivate(){};
27
        virtual ~cBaseIODevicePrivate(){};
28
    protected:
29
        ucom::cReferenceCounter m_oReferenceCounter;
30
};
31

    
32
/**************************************************************************/
33
/* Base IO Device */
34
/**************************************************************************/
35
cBaseIODevice::cBaseIODevice()
36
{
37
    //d-pointer only used for reference counter at the moment
38
    ADTF_D_CREATE(cBaseIODevice);
39

    
40
    m_pEventHandler     = NULL;
41
}
42

    
43
cBaseIODevice::~cBaseIODevice()
44
{
45
    Close();
46
}
47

    
48
tResult cBaseIODevice::GetInterface(const tChar* idInterface, void ** ppvObject)
49
{
50
    if (ppvObject == NULL)
51
    {
52
        RETURN_ERROR(ERR_POINTER);
53
    }
54

    
55
    if (idmatch(idInterface, IID_DEVICE))
56
    {
57
        *ppvObject = static_cast<IDevice*> (this);
58
    }
59
    else if (idmatch(idInterface, IID_OBJECT))
60
    {
61
        *ppvObject = static_cast<IObject*> (static_cast<IDevice*> (this));
62
    }
63
    else
64
    {
65
        *ppvObject = NULL;
66
        RETURN_ERROR(ERR_NO_INTERFACE);
67
    }
68

    
69
    Ref();
70

    
71
    return ERR_NOERROR;
72
}
73

    
74
tUInt cBaseIODevice::Ref()
75
{
76
    return _d->m_oReferenceCounter.Inc();
77
}
78

    
79
tUInt cBaseIODevice::Unref()
80
{
81
    return _d->m_oReferenceCounter.Dec(this);
82
}
83

    
84
tVoid cBaseIODevice::Destroy()
85
{
86
    delete this;
87
}
88

    
89
tResult cBaseIODevice::Open(const tChar* strDevice, tInt nMode, __exception)
90
{
91
    return 0;
92
}
93

    
94
tResult cBaseIODevice::Close(__exception)
95
{
96
    return 0;
97
}
98

    
99
tInt cBaseIODevice::Read(tVoid* pvBuffer, tInt nBufferSize)
100
{
101
    return -1;
102
}
103

    
104
tInt cBaseIODevice::Write(const tVoid* pvBuffer, tInt nBufferSize)
105
{
106
    return -1;
107
}
108

    
109
tInt cBaseIODevice::IOCtl(tInt nCommand, tVoid* pvData, tInt nDataSize)
110
{
111
    switch (nCommand)
112
    {
113
        case IOCTL_GetDeviceInfo:
114
        {
115
            if (nDataSize >= (tInt)sizeof(tDeviceInfo))
116
            {
117
                tDeviceInfo* psDeviceInfo = (tDeviceInfo*) pvData;
118
                cMemoryBlock::MemSet(psDeviceInfo, 0, sizeof(tDeviceInfo));
119
                return sizeof(tDeviceInfo);
120
            }
121
            else
122
            {
123
                return -1;
124
            }
125
            break;
126
        }
127
        case IOCTL_RegisterHandler:
128
        {
129
            break;
130
        }
131
        case IOCTL_UnregisterHandler:
132
        {
133
            break;
134
        }
135
        default:
136
        {
137
            return -1;
138
        }
139
    }
140

    
141
    return 0;
142
}
143

    
144
tResult cBaseIODevice::SetDeviceEvent(tInt nEventId, tInt nParam1, tInt nParam2, tVoid* pvData, tInt nDataSize)
145
{
146
    if (m_pEventHandler != NULL)
147
    {
148
        return m_pEventHandler->OnDeviceEvent(nEventId, nParam1, nParam2, pvData, nDataSize);
149
    }
150

    
151
    RETURN_ERROR(ERR_NOT_SUPPORTED);
152
}
153

    
154
} // namespace adtf
(4-4/7)