-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathkafkaStringTrans.cxx
138 lines (107 loc) · 4.07 KB
/
kafkaStringTrans.cxx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** © Copyright 2019 CERN
*
* This software is distributed under the terms of the
* GNU Lesser General Public Licence version 3 (LGPL Version 3),
* copied verbatim in the file “LICENSE”
*
* In applying this licence, CERN does not waive the privileges
* and immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*
* Author: Alexandru Savulescu (HSE-CEN-CO)
*
**/
// Our transformation class PVSS <--> Hardware
#include "kafkaStringTrans.hxx"
#include <ErrHdl.hxx> // The Error handler Basics/Utilities
#include <TextVar.hxx>
#include "kafkaHWMapper.hxx"
#include "Common/Logger.hxx"
//----------------------------------------------------------------------------
namespace Transformations {
//kafkaStringTrans::kafkaStringTrans() : Transformation() { }
TransformationType kafkaStringTrans::isA() const
{
return (TransformationType) kafkaDrvStringTransType;
}
TransformationType kafkaStringTrans::isA(TransformationType type) const {
if (type == isA())
return type;
else
return Transformation::isA(type);
}
//----------------------------------------------------------------------------
Transformation *kafkaStringTrans::clone() const
{
return new kafkaStringTrans;
}
//----------------------------------------------------------------------------
// Our item size. The max we will use is 256 Bytes.
// This is an arbitrary value! A Transformation for a long e.g. would return 4
int kafkaStringTrans::itemSize() const
{
// TODO - check maximum possible size
return _size;
}
//----------------------------------------------------------------------------
// Our preferred Variable type. Data will be converted to this type
// before toPeriph is called.
VariableType kafkaStringTrans::getVariableType() const
{
return TEXT_VAR;
}
//----------------------------------------------------------------------------
// Convert data from PVSS to Hardware.
PVSSboolean kafkaStringTrans::toPeriph(PVSSchar *buffer, PVSSuint len,
const Variable &var, const PVSSuint subix) const
{
// Be paranoic, check variable type
if ( var.isA() != TEXT_VAR )
{
// Throw error message
ErrHdl::error(
ErrClass::PRIO_SEVERE, // Data will be lost
ErrClass::ERR_PARAM, // Wrong parametrization
ErrClass::UNEXPECTEDSTATE, // Nothing else appropriate
"kafkaStringTrans", "toPeriph", // File and function name
"Wrong variable type for data" // Unfortunately we don't know which DP
);
return PVSS_FALSE;
}
// Check data len. TextVar::getString returns a CharString
const TextVar& tv = static_cast<const TextVar &>(var);
if (len < tv.getString().len() + 1)
{
// Throw error message
ErrHdl::error(
ErrClass::PRIO_SEVERE, // Data will be lost
ErrClass::ERR_IMPL, // Mus be implementation
ErrClass::UNEXPECTEDSTATE, // Nothing else appropriate
"kafkaStringTrans::toPeriph", // File and function name
"Data buffer too small; need:" +
CharString(tv.getString().len() + 1) +
" have:" + CharString(len)
);
return PVSS_FALSE;
}
if(tv.getString().len() > _size){
ErrHdl::error(ErrClass::PRIO_SEVERE, // Data will be lost
ErrClass::ERR_PARAM, // Wrong parametrization
ErrClass::UNEXPECTEDSTATE, // Nothing else appropriate
"kafkaStringTrans::toPeriph", // File and function name
"String too long" // Unfortunately we don't know which DP
);
return PVSS_FALSE;
}
sprintf((char*)buffer, "%s", tv.getValue());
return PVSS_TRUE;
}
//----------------------------------------------------------------------------
// Conversion from Hardware to PVSS
VariablePtr kafkaStringTrans::toVar(const PVSSchar *buffer, const PVSSuint dlen,
const PVSSuint /* subix */) const
{
return new TextVar((const char *)buffer, dlen);
}
//----------------------------------------------------------------------------
}