• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
  • datatypes
  • primitive
pointerdatainformation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Okteta Kasten Framework, made within the KDE community.
3  *
4  * Copyright 2012 Alessandro Di Federico <ale@clearmind.me>
5  * Copyright 2012 Alex Richardson <alex.richardosn@gmx.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) version 3, or any
11  * later version accepted by the membership of KDE e.V. (or its
12  * successor approved by the membership of KDE e.V.), which shall
13  * act as a proxy defined in Section 6 of version 3 of the license.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "pointerdatainformation.h"
25 #include "../topleveldatainformation.h"
26 #include "../primitivedatatype.h"
27 #include "../../allprimitivetypes.h"
28 #include "../../script/scripthandlerinfo.h"
29 #include "../../script/classes/pointerscriptclass.h"
30 #include "../../script/scriptlogger.h"
31 
32 #include <QScriptEngine>
33 #include <KLocalizedString>
34 
35 #include <limits>
36 
37 PointerDataInformation::PointerDataInformation(QString name, DataInformation* childType,
38  PrimitiveDataInformation* valueType, DataInformation* parent)
39  : PrimitiveDataInformationWrapper(name, valueType, parent), mPointerTarget(childType)
40 {
41  Q_CHECK_PTR(childType);
42 
43  //currently only absolute unsigned pointers are allowed
44  const PrimitiveDataType pdt = mValue->type();
45  Q_ASSERT(pdt == Type_UInt8 || pdt == Type_UInt16 || pdt == Type_UInt32 || pdt == Type_UInt64);
46  Q_UNUSED(pdt)
47  mPointerTarget->setParent(this);
48 }
49 
50 PointerDataInformation::~PointerDataInformation()
51 {
52 }
53 
54 PointerDataInformation::PointerDataInformation(const PointerDataInformation& d)
55  : PrimitiveDataInformationWrapper(d), mPointerTarget(d.mPointerTarget->clone())
56 {
57  mPointerTarget->setParent(this);
58 }
59 
60 qint64 PointerDataInformation::readData(Okteta::AbstractByteArrayModel* input, Okteta::Address address,
61  BitCount64 bitsRemaining, quint8* bitOffset)
62 {
63  qint64 ret = PrimitiveDataInformationWrapper::readData(input, address, bitsRemaining, bitOffset);
64  if (!mWasAbleToRead)
65  {
66  mPointerTarget->mWasAbleToRead = false;
67  }
68  // If the pointer it's outside the boundaries of the input simply ignore it
69  else if (mValue->value().value<quint64>() < quint64(input->size()))
70  {
71  // Enqueue for later reading of the destination
72  topLevelDataInformation()->enqueueReadData(this);
73  }
74  return ret;
75 }
76 
77 BitCount64 PointerDataInformation::childPosition(const DataInformation* child, Okteta::Address start) const
78 {
79  Q_UNUSED(start)
80  //TODO other pointer modes
81  Q_ASSERT(child == mPointerTarget.data());
82  return mWasAbleToRead ? mValue->value().value<quint64>() * 8 : 0;
83 }
84 
85 int PointerDataInformation::indexOf(const DataInformation* const data) const
86 {
87  Q_ASSERT(data == mPointerTarget.data());
88  return data == mPointerTarget.data() ? 0 : -1;
89 }
90 
91 void PointerDataInformation::delayedReadData(Okteta::AbstractByteArrayModel *input, Okteta::Address address)
92 {
93  Q_UNUSED(address); //TODO offsets
94  Q_ASSERT(mHasBeenUpdated); //update must have been called prior to reading
95  Q_ASSERT(mWasAbleToRead);
96  quint8 childBitOffset = 0;
97  // Compute the destination offset
98  const quint64 pointer = mValue->value().value<quint64>();
99  if (pointer > quint64(std::numeric_limits<Okteta::Address>::max()))
100  {
101  logError() << "Pointer" << mValue->valueString() << "does not point to an existing address.";
102  return;
103  }
104  Okteta::Address newAddress(pointer);
105  // If the computed destination it's outside the boundaries of the input ignore it
106  if (newAddress < 0 || newAddress >= input->size())
107  {
108  logError() << "Pointer" << mValue->valueString() << "does not point to an existing address.";
109  return;
110  }
111  //update the child now
112  DataInformation* oldTarget = mPointerTarget.data();
113  topLevelDataInformation()->scriptHandler()->updateDataInformation(mPointerTarget.data());
114  // Let the child do the work (maybe different than before now)
115  if (mPointerTarget.data() != oldTarget)
116  {
117  logInfo() << "Pointer target was replaced.";
118  topLevelDataInformation()->setChildDataChanged();
119  }
120  mPointerTarget->readData(input, newAddress, (input->size() - newAddress) * 8, &childBitOffset);
121 }
122 
123 QString PointerDataInformation::typeNameImpl() const
124 {
125  return i18nc("memory pointer with underlying type", "%1 pointer", mValue->typeName());
126 }
127 
128 QString PointerDataInformation::valueStringImpl() const
129 {
130  Q_ASSERT(mWasAbleToRead);
131  return mValue->valueString();
132 }
133 
134 uint PointerDataInformation::childCount() const
135 {
136  return 1;
137 }
138 
139 DataInformation* PointerDataInformation::childAt(uint index) const
140 {
141  Q_ASSERT(index == 0);
142  return index == 0 ? mPointerTarget.data() : 0;
143 }
144 
145 bool PointerDataInformation::setPointerType(DataInformation* type)
146 {
147  Q_CHECK_PTR(type);
148  if (!type->isPrimitive())
149  {
150  logError() << "New pointer type is not primitive!";
151  return false;
152  }
153  PrimitiveDataInformation* prim = type->asPrimitive();
154  const PrimitiveDataType pdt = prim->type();
155  if (pdt == Type_UInt8 || pdt == Type_UInt16 || pdt == Type_UInt32 || pdt == Type_UInt64)
156  {
157  mValue.reset(prim);
158  mValue->setParent(this);
159  return true;
160  }
161  else
162  {
163  logError() << "New pointer type is not an unsigned integer: " << pdt;
164  return false;
165  }
166 }
167 
168 QScriptClass* PointerDataInformation::scriptClass(ScriptHandlerInfo* handlerInfo) const
169 {
170  return handlerInfo->mPointerClass.data();
171 }
DataInformation
Interface that must be implemented by all datatypes.
Definition: datainformation.h:67
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
DataInformation::topLevelDataInformation
TopLevelDataInformation * topLevelDataInformation() const
Definition: datainformation.cpp:240
QScriptClass
PointerDataInformation
Definition: pointerdatainformation.h:30
BitCount64
quint64 BitCount64
Definition: datainformationbase.h:42
PointerDataInformation::~PointerDataInformation
virtual ~PointerDataInformation()
Definition: pointerdatainformation.cpp:50
PrimitiveDataInformation::type
virtual PrimitiveDataType type() const =0
Type_UInt32
Definition: primitivedatatype.h:42
PrimitiveDataType
Definition: primitivedatatype.h:54
Type_UInt16
Definition: primitivedatatype.h:39
DataInformation::mWasAbleToRead
bool mWasAbleToRead
Definition: datainformation.h:243
Type_UInt64
Definition: primitivedatatype.h:45
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
ScriptHandlerInfo::mPointerClass
QScopedPointer< PointerScriptClass > mPointerClass
Definition: scripthandlerinfo.h:56
PointerDataInformation::delayedReadData
void delayedReadData(Okteta::AbstractByteArrayModel *input, Okteta::Address address)
Called once the whole structure has been read.
Definition: pointerdatainformation.cpp:91
DataInformation::logInfo
QDebug logInfo() const
just a shorthand for logger->info(this)
Definition: datainformation.h:314
PointerDataInformation::setPointerType
bool setPointerType(DataInformation *type)
Set a new pointer target.
Definition: pointerdatainformation.cpp:145
TopLevelDataInformation::enqueueReadData
void enqueueReadData(PointerDataInformation *toRead)
Definition: topleveldatainformation.cpp:115
ScriptHandler::updateDataInformation
void updateDataInformation(DataInformation *data)
The pointer may be changed while updating, CHECK AS SOON AS FUNCTION RETURNS!
Definition: scripthandler.cpp:101
DataInformation::mHasBeenUpdated
bool mHasBeenUpdated
Definition: datainformation.h:242
PrimitiveDataInformationWrapper::mValue
QScopedPointer< PrimitiveDataInformation > mValue
Definition: primitivedatainformation.h:116
DataInformationBase::asPrimitive
PrimitiveDataInformation * asPrimitive()
PointerDataInformation::readData
virtual qint64 readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset)
Reads the necessary data from input and returns the number of bytes read.
Definition: pointerdatainformation.cpp:60
PointerDataInformation::indexOf
virtual int indexOf(const DataInformation *const data) const
Find the index of a DataInformation in this object, needed to calculate the row.
Definition: pointerdatainformation.cpp:85
PointerDataInformation::childAt
virtual DataInformation * childAt(uint index) const
Definition: pointerdatainformation.cpp:139
PrimitiveDataInformationWrapper::readData
virtual qint64 readData(Okteta::AbstractByteArrayModel *input, Okteta::Address address, BitCount64 bitsRemaining, quint8 *bitOffset)
Reads the necessary data from input and returns the number of bytes read.
Definition: primitivedatainformation.cpp:64
PointerDataInformation::childCount
virtual uint childCount() const
Definition: pointerdatainformation.cpp:134
PrimitiveDataInformationWrapper
A base class for data types which just wrap an underlying primitive data type.
Definition: primitivedatainformation.h:76
PointerDataInformation::childPosition
virtual BitCount64 childPosition(const DataInformation *child, Okteta::Address start) const
Definition: pointerdatainformation.cpp:77
ScriptHandlerInfo
Definition: scripthandlerinfo.h:39
pointerdatainformation.h
TopLevelDataInformation::scriptHandler
ScriptHandler * scriptHandler() const
Definition: topleveldatainformation.h:179
TopLevelDataInformation::setChildDataChanged
void setChildDataChanged()
Definition: topleveldatainformation.h:164
PointerDataInformation::PointerDataInformation
PointerDataInformation(QString name, DataInformation *childType, PrimitiveDataInformation *valueType, DataInformation *parent)
creates a new pointer takes ownership over childType and valueType
Definition: pointerdatainformation.cpp:37
Type_UInt8
Definition: primitivedatatype.h:35
PrimitiveDataInformation
A base class for all primitive data elements (e.g.
Definition: primitivedatainformation.h:34
DataInformationBase::isPrimitive
virtual bool isPrimitive() const
Definition: datainformationbase.cpp:45
PointerDataInformation::mPointerTarget
QScopedPointer< DataInformation > mPointerTarget
Definition: pointerdatainformation.h:71
DataInformation::logError
QDebug logError() const
just a shorthand for logger->error(this)
Definition: datainformation.h:324
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal