-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
932 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
QT -= gui | ||
|
||
CONFIG -= app_bundle | ||
|
||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
SOURCES += \ | ||
main.cpp |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <QCoreApplication> | ||
#include <QDebug> | ||
#include <stdint.h> | ||
#include <string> | ||
#include <stdexcept> | ||
#include <sys/statvfs.h> | ||
#include <errno.h> | ||
|
||
uint64_t GetDiskUsage(const char* path) | ||
{ | ||
struct statvfs info = {}; | ||
if (statvfs(path, &info)) { | ||
int err_num = errno; | ||
qDebug() << "Error in statvfs : " << strerror(err_num); | ||
|
||
return 0; | ||
} | ||
|
||
uint64_t available = info.f_bavail * info.f_frsize / 1000000000; | ||
|
||
return available; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication a(argc, argv); | ||
qDebug() << "Available Disk Memory : " << GetDiskUsage("/home"); | ||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
QT -= gui | ||
|
||
CONFIG -= app_bundle | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
SOURCES += \ | ||
main.cpp \ | ||
datapacket.cpp \ | ||
base.cpp \ | ||
derived1.cpp \ | ||
derived2.cpp | ||
|
||
HEADERS += \ | ||
parameters.h \ | ||
customqueue.h \ | ||
datapacket.h \ | ||
base.h \ | ||
derived1.h \ | ||
derived2.h |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "base.h" | ||
|
||
void Base::Method1(int value) | ||
{ | ||
std::cout << "Base : Method-1 = " << value << std::endl; | ||
} | ||
|
||
void Base::Method2(bool value) | ||
{ | ||
std::cout << "Base : Method-2 = " << value << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef BASE_H | ||
#define BASE_H | ||
|
||
#include <iostream> | ||
|
||
class Base | ||
{ | ||
public: | ||
virtual void Method1(int value); | ||
virtual void Method2(bool value); | ||
}; | ||
|
||
#endif // BASE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifndef CUSTOMQUEUE_H | ||
#define CUSTOMQUEUE_H | ||
|
||
#include <QByteArray> | ||
#include <QSemaphore> | ||
#include <QMutex> | ||
#include <QQueue> | ||
|
||
template <class T, int SIZE = 1024> | ||
class CustomQueue | ||
{ | ||
public: | ||
CustomQueue(int size = SIZE); | ||
void putQueue(const T &item); | ||
T getQueue(); | ||
T peek(); | ||
bool isEmpty() const { return m_queue.count() == 0; } | ||
int count() const { return m_queue.count(); } | ||
void clear() { m_queue.clear(); } | ||
|
||
private: | ||
QQueue<T> m_queue; | ||
QSemaphore m_semProducer; | ||
QSemaphore m_semConsumer; | ||
QMutex m_mutex; | ||
int m_size; | ||
}; | ||
|
||
template <class T, int SIZE> | ||
CustomQueue<T, SIZE>::CustomQueue(int size) | ||
: m_semProducer(size), m_semConsumer(0), m_size(size) | ||
{ | ||
} | ||
|
||
template <class T, int SIZE> | ||
void CustomQueue<T, SIZE>::putQueue(const T &item) | ||
{ | ||
m_semProducer.acquire(); | ||
m_mutex.lock(); | ||
m_queue.enqueue(item); | ||
m_mutex.unlock(); | ||
m_semConsumer.release(); | ||
} | ||
|
||
template <class T, int SIZE> | ||
T CustomQueue<T, SIZE>::getQueue() | ||
{ | ||
T item; | ||
|
||
m_semConsumer.acquire(); | ||
m_mutex.lock(); | ||
item = m_queue.dequeue(); | ||
m_mutex.unlock(); | ||
m_semProducer.release(); | ||
|
||
return item; | ||
} | ||
|
||
template <class T, int SIZE> | ||
T CustomQueue<T, SIZE>::peek() | ||
{ | ||
T item; | ||
|
||
m_semConsumer.acquire(); | ||
m_mutex.lock(); | ||
item = m_queue.head(); | ||
m_mutex.unlock(); | ||
m_semProducer.release(); | ||
|
||
return item; | ||
} | ||
|
||
#endif // CUSTOMQUEUE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "datapacket.h" | ||
|
||
void DataPacket::SetValue1(int value) | ||
{ | ||
value_1 = value; | ||
} | ||
|
||
int DataPacket::GetValue1() | ||
{ | ||
return value_1; | ||
} | ||
|
||
void DataPacket::SetValue2(int value) | ||
{ | ||
value_2 = value; | ||
} | ||
|
||
int DataPacket::GetValue2() | ||
{ | ||
return value_2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef DATAPACKET_H | ||
#define DATAPACKET_H | ||
|
||
#include "customqueue.h" | ||
|
||
class DataPacket | ||
{ | ||
public: | ||
void SetValue1(int value); | ||
int GetValue1(); | ||
void SetValue2(int value); | ||
int GetValue2(); | ||
|
||
private: | ||
int value_1; | ||
int value_2; | ||
}; | ||
|
||
#endif // DATAPACKET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "derived1.h" | ||
|
||
void Derived1::Method1(int value) | ||
{ | ||
std::cout << "Derived-1 : Method-1 = " << value << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef DERIVED1_H | ||
#define DERIVED1_H | ||
|
||
#include <iostream> | ||
#include "base.h" | ||
|
||
class Derived1 : public Base | ||
{ | ||
public: | ||
void Method1(int value); | ||
}; | ||
|
||
#endif // DERIVED1_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "derived2.h" | ||
|
||
void Derived2::Method2(bool value) | ||
{ | ||
std::cout << "Derived-2 : Method-2 = " << value << std::endl; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef DERIVED2_H | ||
#define DERIVED2_H | ||
|
||
#include <iostream> | ||
#include "base.h" | ||
|
||
class Derived2 : public Base | ||
{ | ||
public: | ||
void Method2(bool value); | ||
}; | ||
|
||
#endif // DERIVED2_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <QCoreApplication> | ||
#include "base.h" | ||
#include "derived1.h" | ||
#include "derived2.h" | ||
#include "parameters.h" | ||
#include "datapacket.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication a(argc, argv); | ||
|
||
Base *base; | ||
if (Parameters::type == 0) { | ||
Derived1 derived_1; | ||
base = &derived_1; | ||
base->Method1(5); | ||
base->Method2(true); | ||
} else if (Parameters::type == 1) { | ||
Derived2 derived_2; | ||
base = &derived_2; | ||
base->Method1(3); | ||
base->Method2(false); | ||
} | ||
|
||
Parameters::data_packet.SetValue1(9); | ||
std::cout << "Value 1 = " << Parameters::data_packet.GetValue1() << std::endl; | ||
Parameters::data_packet.SetValue2(6); | ||
std::cout << "Value 2 = " << Parameters::data_packet.GetValue2() << std::endl; | ||
|
||
DataPacket data_packet; | ||
data_packet.SetValue1(7); | ||
data_packet.SetValue2(8); | ||
Parameters::custom_queue.putQueue(data_packet); | ||
std::cout << "Queue Size = " << Parameters::custom_queue.count() << std::endl; | ||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PARAMETERS_H | ||
#define PARAMETERS_H | ||
|
||
#include <iostream> | ||
#include "datapacket.h" | ||
#include "customqueue.h" | ||
|
||
class Parameters | ||
{ | ||
public: | ||
inline static int type = 1; | ||
inline static DataPacket data_packet; | ||
inline static CustomQueue<DataPacket> custom_queue; | ||
}; | ||
|
||
#endif // PARAMETERS_H |