Skip to content

Commit

Permalink
- Refactored ALSAdaptorAscii: removed unnecessary members, fixed mis…
Browse files Browse the repository at this point in the history
…sing initializations and simplified the constructor.

 - Fixed fd leak from TouchAdaptor and did some minor refactorings.
 - Fixed memory leak and removed unnecessary members from OrientationChain.
 - NodeBase didn't initialize all members.
 - SysfsAdaptor leaked fd in case of error.
 - ProximitySensorChannelAdaptor::dataAvailable() now passes value by ref.
 - Minor refactoring to test cases.
  • Loading branch information
Antti Virtanen committed Jan 3, 2011
1 parent f25b44e commit 41cfeb9
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 50 deletions.
28 changes: 9 additions & 19 deletions adaptors/alsadaptor-ascii/alsadaptor-ascii.cpp
Expand Up @@ -40,34 +40,24 @@
#include <stdlib.h>
#include <linux/types.h>

#define SYSFS_RANGE_PATH "/sys/bus/i2c/devices/5-0029/apds9802als/sensing_range"
#define SYSFS_LUX_PATH "/sys/bus/i2c/devices/5-0029/apds9802als/lux_output"
#define DEFAULT_RANGE 65535

ALSAdaptorAscii::ALSAdaptorAscii(const QString& id) : SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
{
int range = DEFAULT_RANGE;
QFile sysFile;
QString devPath;
const unsigned int DEFAULT_RANGE = 65535;

// Check if a file has been provided as range source
sysFile.setFileName(Config::configuration()->value("als-ascii_range_sysfs_path").toString());
int range = DEFAULT_RANGE;
QFile sysFile(Config::configuration()->value("als-ascii_range_sysfs_path").toString());

if (sysFile.size() > 0)
{
if (!(sysFile.exists() && sysFile.open(QIODevice::ReadOnly))) {
sensordLogW() << "Unable to config ALS range from sysfs, using default value: " << DEFAULT_RANGE;
} else {
sysFile.readLine(buf, sizeof(buf));
range = QString(buf).toInt();
}
if (!(sysFile.open(QIODevice::ReadOnly))) {
sensordLogW() << "Unable to config ALS range from sysfs, using default value: " << DEFAULT_RANGE;
} else {
sysFile.readLine(buf, sizeof(buf));
range = QString(buf).toInt();
}

sensordLogT() << "Ambient light range: " << range;


// Locate the actual handle
devPath = Config::configuration()->value("als-ascii_sysfs_path").toString();
QString devPath = Config::configuration()->value("als-ascii_sysfs_path").toString();

if (devPath.isEmpty())
{
Expand Down
5 changes: 2 additions & 3 deletions adaptors/alsadaptor-ascii/alsadaptor-ascii.h
Expand Up @@ -31,11 +31,11 @@
#ifndef ALSADAPTOR_ASCII_H
#define ALSADAPTOR_ASCII_H

#include <QObject>
#include <QString>
#include "sysfsadaptor.h"
#include "sensord/deviceadaptorringbuffer.h"
#include "datatypes/timedunsigned.h"
#include <QTime>


class ALSAdaptorAscii : public SysfsAdaptor
{
Expand All @@ -54,7 +54,6 @@ class ALSAdaptorAscii : public SysfsAdaptor
private:

void processSample(int pathId, int fd);
int devId;
char buf[16];

DeviceAdaptorRingBuffer<TimedUnsigned>* alsBuffer_;
Expand Down
Expand Up @@ -37,14 +37,14 @@
#define SYSFS_MAGNET_PATH "/sys/bus/i2c/devices/5-000f/ak8974/curr_pos"

MagnetometerAdaptorAscii::MagnetometerAdaptorAscii(const QString& id) :
SysfsAdaptor(id, SysfsAdaptor::IntervalMode)
SysfsAdaptor(id, SysfsAdaptor::IntervalMode),
devId(0)
{
if (access(SYSFS_MAGNET_PATH, R_OK) < 0) {
sensordLogW() << SYSFS_MAGNET_PATH << ": "<< strerror(errno);
return;
}
introduceAvailableDataRange(DataRange(-2048, 2048, 1));
devId = 0;
addPath(SYSFS_MAGNET_PATH, devId);
magnetBuffer_ = new DeviceAdaptorRingBuffer<TimedXyzData>(16);
addAdaptedSensor("magnetometer", "ak8974 ascii", magnetBuffer_);
Expand Down
14 changes: 8 additions & 6 deletions adaptors/touchadaptor/touchadaptor.cpp
Expand Up @@ -31,11 +31,7 @@
#include <fcntl.h>
#include <linux/input.h>

#define TOUCH_SYS_PATH_STR "/dev/input/event%1"
#define HARD_MAX_TOUCH_POINTS 5

#define X_RESOLUTION 800
#define Y_RESOLUTION 480
const int TouchAdaptor::HARD_MAX_TOUCH_POINTS = 5;

TouchAdaptor::TouchAdaptor(const QString& id) : InputDevAdaptor(id, HARD_MAX_TOUCH_POINTS), rangeInfo_(*this)
{
Expand Down Expand Up @@ -79,23 +75,27 @@ bool TouchAdaptor::checkInputDevice(QString path, QString matchString)
ioctl(fd, EVIOCGNAME(sizeof(deviceName)), deviceName);

if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0) {
qWarning() << __PRETTY_FUNCTION__ << deviceName << "EVIOCGBIT error";
sensordLogW() << __PRETTY_FUNCTION__ << deviceName << "EVIOCGBIT error";
close(fd);
return false;
}

#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8)))

if (!test_bit(EV_ABS, evtype_bitmask)) {
close(fd);
return false;
}

if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(evtype_bitmask)), evtype_bitmask) < 0) {
sensordLogW() << __PRETTY_FUNCTION__ << deviceName << "EVIOGBIT EV_ABS error.";
close(fd);
return false;
}

if (!test_bit(ABS_X, evtype_bitmask) || !test_bit(ABS_Y, evtype_bitmask)) {
sensordLogW() << __PRETTY_FUNCTION__ << deviceName << "Testbit ABS_X or ABS_Y failed.";
close(fd);
return false;
}

Expand All @@ -114,6 +114,8 @@ bool TouchAdaptor::checkInputDevice(QString path, QString matchString)

rangeInfo_(rInfo);

close(fd);

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions adaptors/touchadaptor/touchadaptor.h
Expand Up @@ -30,7 +30,6 @@
#include "inputdevadaptor.h"
#include "sensord/deviceadaptorringbuffer.h"
#include <sensord/filterproperty.h>
#include <QTime>
#include <QObject>
#include "touchdata.h"

Expand Down Expand Up @@ -66,6 +65,8 @@ class TouchAdaptor : public InputDevAdaptor

private:

static const int HARD_MAX_TOUCH_POINTS;

/**
* Holds values read from the driver.
*/
Expand Down Expand Up @@ -111,7 +112,6 @@ class TouchAdaptor : public InputDevAdaptor

void interpretSync(int src);

QTime time;
DeviceAdaptorRingBuffer<TouchData>* outputBuffer_;
TouchValues touchValues_[5];
FilterProperty<RangeInfo> rangeInfo_;
Expand Down
1 change: 1 addition & 0 deletions chains/orientationchain/orientationchain.cpp
Expand Up @@ -83,6 +83,7 @@ OrientationChain::~OrientationChain()
disconnectFromSource(accelerometerChain_, "accelerometer", accelerometerReader_);

delete accelerometerReader_;
delete orientationInterpreterFilter_;
delete topEdgeOutput_;
delete faceOutput_;
delete orientationOutput_;
Expand Down
2 changes: 0 additions & 2 deletions chains/orientationchain/orientationchain.h
Expand Up @@ -90,8 +90,6 @@ public Q_SLOTS:

AbstractChain* accelerometerChain_;
BufferReader<AccelerationData>* accelerometerReader_;
FilterBase* topEdgeInterpreterFilter_;
FilterBase* faceInterpreterFilter_;
FilterBase* orientationInterpreterFilter_;
RingBuffer<PoseData>* topEdgeOutput_;
RingBuffer<PoseData>* faceOutput_;
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
Expand Up @@ -2,6 +2,13 @@ sensord (0.6.34) unstable; urgency=low

[Antti Virtanen]
* propertyChanged signals aren't anymore sent through dbus to apps since qmSystem nor QtMob Sensors API supports property notifications. Fixes: NB#216173.
* Refactored ALSAdaptorAscii: removed unnecessary members, fixed missing initializations and simplified the constructor.
* Fixed fd leak from TouchAdaptor and did some minor refactorings.
* Fixed memory leak and removed unnecessary members from OrientationChain.
* NodeBase didn't initialize all members.
* SysfsAdaptor leaked fd in case of error.
* ProximitySensorChannelAdaptor::dataAvailable() now passes value by ref.
* Minor refactoring to test cases.

-- Antti Virtanen <antti.i.virtanen@nokia.com> Mon, 03 Jan 2011 16:25:22 +0200

Expand Down
2 changes: 1 addition & 1 deletion sensord/nodebase.h
Expand Up @@ -51,7 +51,7 @@ class NodeBase : public QObject
Q_PROPERTY(unsigned int interval READ getInterval);

protected:
NodeBase(QObject* parent = 0) : QObject(parent), m_dataRangeSource(NULL), m_intervalSource(NULL), m_hasDefault(false), m_defaultInterval(0) {}
NodeBase(QObject* parent = 0) : QObject(parent), m_bufferSize(0), m_bufferInterval(0), m_dataRangeSource(NULL), m_intervalSource(NULL), m_hasDefault(false), m_defaultInterval(0) {}
virtual ~NodeBase() {}

public Q_SLOTS:
Expand Down
1 change: 1 addition & 0 deletions sensord/sysfsadaptor.cpp
Expand Up @@ -342,6 +342,7 @@ bool SysfsAdaptor::writeToFile(QString path, QString content)
}

if (write(fd, content.toLocal8Bit().constData(), path.size()*sizeof(char)) == -1) {
close(fd);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion sensors/proximitysensor/proximitysensor_a.h
Expand Up @@ -43,7 +43,7 @@ class ProximitySensorChannelAdaptor : public AbstractSensorChannelAdaptor
ProximitySensorChannelAdaptor(QObject* parent);

Q_SIGNALS:
void dataAvailable(const Unsigned data);
void dataAvailable(const Unsigned& data);
};

#endif
4 changes: 0 additions & 4 deletions tests/dataflow/dataflowtests.cpp
Expand Up @@ -143,7 +143,6 @@ void DataFlowTest::testChainSharing()
{
SensorManager& sm = SensorManager::instance();


QCOMPARE(sm.loadPlugin("accelerometerchain"), true);

AbstractChain* chainA = NULL;
Expand Down Expand Up @@ -185,9 +184,6 @@ void DataFlowTest::testChainSharing()
// release second time
sm.releaseChain("accelerometerchain");
// check that does not exist


}


QTEST_MAIN(DataFlowTest)
6 changes: 2 additions & 4 deletions tests/dataflow/dataflowtests.h
Expand Up @@ -32,6 +32,8 @@
class DataFlowTest : public QObject
{
Q_OBJECT;
public:
DataFlowTest() : sm(0) {};

private:
SensorManager* sm;
Expand All @@ -47,10 +49,6 @@ private slots:
void cleanupTestCase();
};





class TestSensorManager2: public SensorManager
{
public:
Expand Down
7 changes: 1 addition & 6 deletions tests/gyroclient/gyroclient.cpp
Expand Up @@ -28,7 +28,6 @@
#include "qt-api/sensormanagerinterface.h"
#include "gyroclient.h"


GyroClient::GyroClient()
{
QDBusReply<void> reply;
Expand All @@ -55,18 +54,14 @@ GyroClient::~GyroClient()
delete m_sensorIfc;
}


void GyroClient::slotDataAvailable(const XYZ& data)
{
qDebug() << "raw gyro data: (" << data.x() << data.y() << data.z() << ")";
}


int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);

GyroClient *gyro = new GyroClient();

GyroClient gyro;
return app.exec();
}

0 comments on commit 41cfeb9

Please sign in to comment.