mirror of
https://github.com/f4exb/sdrangel.git
synced 2026-06-01 13:47:01 -04:00
git clone git://git.osmocom.org/sdrangelove.git
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2012 by Hoernchen <la@tfc-server.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __SDRANGELOVE_EXPORT_H
|
||||
#define __SDRANGELOVE_EXPORT_H
|
||||
|
||||
#if defined __GNUC__
|
||||
# if __GNUC__ >= 4
|
||||
# define __SDR_EXPORT __attribute__((visibility("default")))
|
||||
# define __SDR_IMPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
# define __SDR_EXPORT
|
||||
# define __SDR_IMPORT
|
||||
# endif
|
||||
#elif _MSC_VER
|
||||
# define __SDR_EXPORT __declspec(dllexport)
|
||||
# define __SDR_IMPORT __declspec(dllimport)
|
||||
#else
|
||||
# define __SDR_EXPORT
|
||||
# define __SDR_IMPORT
|
||||
#endif
|
||||
|
||||
#ifndef sdrangelove_STATIC
|
||||
# ifdef sdrangelove_EXPORTS
|
||||
# define SDRANGELOVE_API __SDR_EXPORT
|
||||
# else
|
||||
# define SDRANGELOVE_API __SDR_IMPORT
|
||||
# endif
|
||||
#else
|
||||
#define SDRANGELOVE_API
|
||||
#endif
|
||||
#endif /* __SDRANGELOVE_EXPORT_H */
|
||||
@@ -0,0 +1,58 @@
|
||||
#ifndef INCLUDE_MESSAGE_H
|
||||
#define INCLUDE_MESSAGE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <QAtomicInt>
|
||||
#include "util/export.h"
|
||||
|
||||
class MessageQueue;
|
||||
class QWaitCondition;
|
||||
class QMutex;
|
||||
|
||||
class SDRANGELOVE_API Message {
|
||||
public:
|
||||
Message();
|
||||
virtual ~Message();
|
||||
|
||||
virtual const char* getIdentifier() const;
|
||||
virtual bool matchIdentifier(const char* identifier) const;
|
||||
static bool match(Message* message);
|
||||
|
||||
void* getDestination() const { return m_destination; }
|
||||
|
||||
void submit(MessageQueue* queue, void* destination = NULL);
|
||||
int execute(MessageQueue* queue, void* destination = NULL);
|
||||
|
||||
void completed(int result = 0);
|
||||
|
||||
protected:
|
||||
// addressing
|
||||
static const char* m_identifier;
|
||||
void* m_destination;
|
||||
|
||||
// stuff for synchronous messages
|
||||
bool m_synchronous;
|
||||
QWaitCondition* m_waitCondition;
|
||||
QMutex* m_mutex;
|
||||
QAtomicInt m_complete;
|
||||
int m_result;
|
||||
};
|
||||
|
||||
#define MESSAGE_CLASS_DECLARATION \
|
||||
public: \
|
||||
const char* getIdentifier() const; \
|
||||
bool matchIdentifier(const char* identifier) const; \
|
||||
static bool match(Message* message); \
|
||||
protected: \
|
||||
static const char* m_identifier; \
|
||||
private:
|
||||
|
||||
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass) \
|
||||
const char* Name::m_identifier = #Name; \
|
||||
const char* Name::getIdentifier() const { return m_identifier; } \
|
||||
bool Name::matchIdentifier(const char* identifier) const {\
|
||||
return (m_identifier == identifier) ? true : BaseClass::matchIdentifier(identifier); \
|
||||
} \
|
||||
bool Name::match(Message* message) { return message->matchIdentifier(m_identifier); }
|
||||
|
||||
#endif // INCLUDE_MESSAGE_H
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef INCLUDE_MESSAGEQUEUE_H
|
||||
#define INCLUDE_MESSAGEQUEUE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include "spinlock.h"
|
||||
#include "util/export.h"
|
||||
|
||||
class Message;
|
||||
|
||||
class SDRANGELOVE_API MessageQueue : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MessageQueue(QObject* parent = NULL);
|
||||
~MessageQueue();
|
||||
|
||||
void submit(Message* message);
|
||||
Message* accept();
|
||||
|
||||
int countPending();
|
||||
|
||||
signals:
|
||||
void messageEnqueued();
|
||||
|
||||
private:
|
||||
Spinlock m_lock;
|
||||
QQueue<Message*> m_queue;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_MESSAGEQUEUE_H
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef INCLUDE_MINIZ_H
|
||||
#define INCLUDE_MINIZ_H
|
||||
|
||||
#define MINIZ_HEADER_FILE_ONLY
|
||||
#include "../../sdrapp/util/miniz.cpp"
|
||||
|
||||
#endif // INCLUDE_MINIZ_H
|
||||
@@ -0,0 +1,112 @@
|
||||
#ifndef INCLUDE_SIMPLESERIALIZER_H
|
||||
#define INCLUDE_SIMPLESERIALIZER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include "dsp/dsptypes.h"
|
||||
#include "util/export.h"
|
||||
|
||||
class SDRANGELOVE_API SimpleSerializer {
|
||||
public:
|
||||
SimpleSerializer(quint32 version);
|
||||
|
||||
void writeS32(quint32 id, qint32 value);
|
||||
void writeU32(quint32 id, quint32 value);
|
||||
void writeS64(quint32 id, qint64 value);
|
||||
void writeU64(quint32 id, quint64 value);
|
||||
void writeFloat(quint32 id, float value);
|
||||
void writeDouble(quint32 id, double value);
|
||||
void writeReal(quint32 id, Real value)
|
||||
{
|
||||
if(sizeof(Real) == 4)
|
||||
writeFloat(id, value);
|
||||
else writeDouble(id, value);
|
||||
}
|
||||
void writeBool(quint32 id, bool value);
|
||||
void writeString(quint32 id, const QString& value);
|
||||
void writeBlob(quint32 id, const QByteArray& value);
|
||||
|
||||
const QByteArray& final();
|
||||
|
||||
protected:
|
||||
enum Type {
|
||||
TSigned32 = 0,
|
||||
TUnsigned32 = 1,
|
||||
TSigned64 = 2,
|
||||
TUnsigned64 = 3,
|
||||
TFloat = 4,
|
||||
TDouble = 5,
|
||||
TBool = 6,
|
||||
TString = 7,
|
||||
TBlob = 8,
|
||||
TVersion = 9
|
||||
};
|
||||
|
||||
QByteArray m_data;
|
||||
bool m_finalized;
|
||||
|
||||
bool writeTag(Type type, quint32 id, quint32 length);
|
||||
};
|
||||
|
||||
class SDRANGELOVE_API SimpleDeserializer {
|
||||
public:
|
||||
SimpleDeserializer(const QByteArray& data);
|
||||
|
||||
bool readS32(quint32 id, qint32* result, qint32 def = 0) const;
|
||||
bool readU32(quint32 id, quint32* result, quint32 def = 0) const;
|
||||
bool readS64(quint32 id, qint64* result, qint64 def = 0) const;
|
||||
bool readU64(quint32 id, quint64* result, quint64 def = 0) const;
|
||||
bool readFloat(quint32 id, float* result, float def = 0) const;
|
||||
bool readDouble(quint32 id, double* result, double def = 0) const;
|
||||
bool readReal(quint32 id, Real* result, Real def = 0) const;
|
||||
bool readBool(quint32 id, bool* result, bool def = false) const;
|
||||
bool readString(quint32 id, QString* result, const QString& def = QString::null) const;
|
||||
bool readBlob(quint32 id, QByteArray* result, const QByteArray& def = QByteArray()) const;
|
||||
|
||||
bool isValid() const { return m_valid; }
|
||||
quint32 getVersion() const { return m_version; }
|
||||
void dump() const;
|
||||
|
||||
private:
|
||||
enum Type {
|
||||
TSigned32 = 0,
|
||||
TUnsigned32 = 1,
|
||||
TSigned64 = 2,
|
||||
TUnsigned64 = 3,
|
||||
TFloat = 4,
|
||||
TDouble = 5,
|
||||
TBool = 6,
|
||||
TString = 7,
|
||||
TBlob = 8,
|
||||
TVersion = 9
|
||||
};
|
||||
|
||||
struct Element {
|
||||
Type type;
|
||||
quint32 ofs;
|
||||
quint32 length;
|
||||
|
||||
Element(Type _type, quint32 _ofs, quint32 _length) :
|
||||
type(_type),
|
||||
ofs(_ofs),
|
||||
length(_length)
|
||||
{ }
|
||||
};
|
||||
typedef QMap<quint32, Element> Elements;
|
||||
|
||||
QByteArray m_data;
|
||||
bool m_valid;
|
||||
Elements m_elements;
|
||||
quint32 m_version;
|
||||
|
||||
bool parseAll();
|
||||
bool readTag(uint* readOfs, uint readEnd, Type* type, quint32* id, quint32* length) const;
|
||||
quint8 readByte(uint* readOfs) const
|
||||
{
|
||||
quint8 res = m_data[*readOfs];
|
||||
(*readOfs)++;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SIMPLESERIALIZER_H
|
||||
@@ -0,0 +1,39 @@
|
||||
#ifndef INCLUDE_SPINLOCK_H
|
||||
#define INCLUDE_SPINLOCK_H
|
||||
|
||||
#include <QAtomicInt>
|
||||
|
||||
class Spinlock {
|
||||
public:
|
||||
void lock()
|
||||
{
|
||||
while(!m_atomic.testAndSetAcquire(0, 1)) ;
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
while(!m_atomic.testAndSetRelease(1, 0)) ;
|
||||
}
|
||||
|
||||
protected:
|
||||
QAtomicInt m_atomic;
|
||||
};
|
||||
|
||||
class SpinlockHolder {
|
||||
public:
|
||||
SpinlockHolder(Spinlock* spinlock) :
|
||||
m_spinlock(spinlock)
|
||||
{
|
||||
m_spinlock->lock();
|
||||
}
|
||||
|
||||
~SpinlockHolder()
|
||||
{
|
||||
m_spinlock->unlock();
|
||||
}
|
||||
|
||||
protected:
|
||||
Spinlock* m_spinlock;
|
||||
};
|
||||
|
||||
#endif // INCLUDE_SPINLOCK_H
|
||||
Reference in New Issue
Block a user