Been looking for awhile and I cant find an answer. All paths are included. I'm referencing a class in another namespace in the class I'm creating.
I'm getting the following error:
src/app/Application.h:30:9: error: 'drv' does not name a type
Code Below. Any help is appreciated!
Main.cpp
int main(int argc, char** argv) {
app::Application program;
program.run();
return 0;
}
LEDs.h
#ifndef LEDS_H
#define LEDS_H
namespace drv {
class LEDs {
public:
LEDs();
void InitLEDs(void);
void SetLEDs(const uint8_t value);
private:
static const uint8_t NUM_LEDs = 5;
};
}
#endif /* LEDS_H */
Application.h
#ifndef APPLICATION_H
#define APPLICATION_H
namespace app {
enum State {
NORMAL = 0,
ZONE,
PAIRING,
STUCK,
BATT,
OFF
};
class Application {
public:
Application();
void run(void);
void execute_loop(void);
private:
bool IDLE;
State STATE;
drv::LEDs Leds; // LINE 30
};
}
#endif // APPLICATION_H
Application.cpp
#include "stdint.h"
#include "stdbool.h"
#include "../drv/LEDs.h"
#include "Application.h"
namespace app {
Application::Application() {
IDLE = false;
STATE = NORMAL;
}
void Application::run(void) {
Leds.InitLEDs();
while(1)
{
if(IDLE) {
PowerSaveIdle();
}
else {
execute_loop();
}
}
}
void Application::execute_loop(void)
{
}
}
LEDs.cpp
#include <stdint.h>
#include "LEDs.h"
namespace drv {
LEDs::LEDs() {
}
void LEDs::InitLEDs() {
SetLEDs(0xff);
}
void LEDs::SetLEDs(const uint8_t value) {
//Removed for readability
}
}
You're missing an #include ... line in Application.h. At the top of that file (or just after the inclusion guards) add the line
#include "LEDs.h"
Related
I am having issues when I try to create an application that simulates a restaurant. It needs to have 50 clients, 3 cooks, 1 waiter and 30 tables. When I try to start the threads of the clients, cooks and waiter it crashes and doesnt let me do anything, nor it gives me an error message or warning. I really don't know what to do. I hope you guys can help me with the answer.
Cook class.h:
`
#ifndef COOK_H
#define COOK_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Cook : public QThread
{
Q_OBJECT
public:
Cook(int id, QString name);
void makeFood(int queueTotal);
void startCook();
private:
int id;
QString name;
int orderId;
QSemaphore semaphore;
protected:
void run(); //makeFood
};
#endif // COOK_H
cook.cpp
#include "cook.h"
#include <QTextStream>
Cook::Cook(int id, QString name)
{
this->id = id;
this->name = name;
}
void Cook::startCook(){
run();
}
void Cook::run(){
QTextStream(stdout)<< "hello im a cook";
}
`
client.h
`
#ifndef CLIENT_H
#define CLIENT_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Order;
class Client : public QThread
{
Q_OBJECT
public:
Client(int id, QString name);
void setOrder(Order* order);
int getId();
void startClient();
private:
int id;
QString name;
QSemaphore semaphore;
Order* order;
protected:
void run();
};
#endif // CLIENT_H
`
client.cpp
`
#include "client.h"
#include <QTextStream>
Client::Client(int id, QString name)
{
this->id = id;
this->name = name;
}
void Client::startClient(){
run();
}
void Client::run(){
QTextStream(stdout)<< "hello im a client";
}
void Client::setOrder(Order* order){
this->order = order;
}
int Client::getId(){
return this->id;
}
`
order.cpp and .h
`
#ifndef ORDER_H
#define ORDER_H
class Order
{
public:
Order(int orderId, bool orderType);
private:
int orderId;
bool orderType; //true carne - false vegano
};
#endif // ORDER_H
`
order.cpp
`
#include "order.h"
Order::Order(int orderId, bool orderType)
{
this->orderId = orderId;
this->orderType = orderType;
}
table.h and cpp
#ifndef TABLE_H
#define TABLE_H
#include <QObject>
class Client;
class Table
{
public:
Table(int id, QString name, bool seat);
void clearClient();
void setClient(Client newClient);
private:
int id;
QString name;
bool seat;
int clientId;
};
#endif // TABLE_H
table.cpp
#include "table.h"
#include "client.h"
Table::Table(int id, QString name, bool seat)
{
this->seat = seat;
this->clientId = 0;
this->id = id;
this->name = name;
}
void Table::clearClient(){
this->seat = false;
this->clientId = -1;
}
void Table::setClient(Client newClient){
this->clientId = newClient.getId();
this->seat = true;
}
`
waiter.h
`
#ifndef WAITER_H
#define WAITER_H
#include <QObject>
#include <QThread>
#include <QSemaphore>
class Waiter : public QThread
{
Q_OBJECT
public:
Waiter(int id, QString name);
void startWaiter();
private:
int id;
QString name;
int orderId;
int tableId;
QSemaphore semaphore;
protected:
void run();
};
#endif // WAITER_H
`
waiter.cpp
`
#include "waiter.h"
#include <QTextStream>
Waiter::Waiter(int id, QString name)
{
this->id = id;
this->name = name;
}
void Waiter::startWaiter(){
run();
}
void Waiter::run(){
QTextStream(stdout)<< "hello im a waiter";
}
`
restaurant.h
`
#ifndef RESTAURANT_H
#define RESTAURANT_H
class Restaurant
{
public:
Restaurant();
void startRestaurant(int totalChefs, int totalTables, int totalWaiters, int totalClients);
};
#endif // RESTAURANT_H
`
restaurant.cpp
`
#include "restaurant.h"
#include <QThread>
#include "cook.h"
#include "client.h"
#include "waiter.h"
#include "table.h"
Restaurant::Restaurant()
{
}
void Restaurant::startRestaurant(int totalChefs, int totalTables, int totalWaiters, int totalClients){
QList <Cook*> cookList;
QList <Waiter*> waiterList;
QList <Client*> clientList;
QList <Table*> tables;
//start
for(int i=0; i<totalChefs; i++){
QString output = QStringLiteral("Cook %1").arg(i);
Cook cook(i, output);
cookList.append(&cook);
}
for(int i=0; i<totalWaiters; i++){
QString output = QStringLiteral("Waiter %1").arg(i);
Waiter waiter(i, output);
waiterList.append(&waiter);
}
for(int i=0; i<totalClients; i++){
QString output = QStringLiteral("Client %1").arg(i);
Client client(i, output);
clientList.append(&client);
}
for(int i=0; i<totalTables; i++){
QString output = QStringLiteral("Table %1").arg(i);
Table table(i, output, false);
tables.append(&table);
}
cookList.value(1)->startCook();
waiterList.value(1)->startWaiter();
clientList.value(1)->startClient();
}
`
I am new to QT so please bear that in mind, I hope you guys can help me!
I want to develop a logger class. So I decided put all related code to the read operation in the
dataLogger class.
In the dataLogger with a thread, I want to able write data in a buffer, which named “queue_”. In main class that contains an object of dataLogger, I want to able read from the “queue_” with another thread. Therefore, I use shared_pointer to access the buffer.
Is it possible to use one mutex to manage read and write operation?
Actually, I want to pass the mutex witch created in main class to the dataLogger class.
I used QtGuiApplication to illustrate my problem.
In main.cpp
#include "QtGuiApplication8.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication8 w;
w.show();
return a.exec();
}
In QtGuiApplication8.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication8.h"
#include <thread>
#include <mutex>
#include <vector>
#include "dataLogger.h"
using namespace std;
class QtGuiApplication8 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication8(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication8Class ui;
std::thread thread_;
bool thread_flag = false;
void thread_fn();
std::mutex mutex_;
shared_ptr < vector<std::shared_ptr<vector<uint8_t>>>> queue_;
dataLogger dataLogger_;
};
In QtGuiApplication8.cpp
#include "QtGuiApplication8.h"
QtGuiApplication8::QtGuiApplication8(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
queue_ = make_shared< vector<std::shared_ptr<vector<uint8_t>>>>();
dataLogger_.setQueue(queue_);
// setMutex(mutex_); //I want same thing like this line !
dataLogger_.run();
thread_flag = true;
thread_ = std::thread(&QtGuiApplication8::thread_fn, this);
}
void QtGuiApplication8::thread_fn()
{
while (thread_flag)
{
while (queue_->size() != 0)
{
{
std::lock_guard<std::mutex> f(mutex_);
// auto scan_raw = queue_->back(); // at this line I want to read queue_
}
}
Sleep(20);
}
}
dataLogger.h
#pragma once
#include <thread>
#include <mutex>
#include <vector>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
using namespace std;
class dataLogger
{
public:
void setQueue(shared_ptr<vector<shared_ptr<vector<uint8_t>>>> q) { queue_ = q; };
//void setMutex(mutex* m) { mutex_ = *m; }; //I want same thing like this line !
void run();
void stop();
private:
std::thread thread_;
bool thread_flag = false;
void thread_fn();
std::mutex mutex_;
shared_ptr<vector<std::shared_ptr<vector<uint8_t>>>> queue_;
};
dataLogger.cpp
#include "dataLogger.h"
void dataLogger::run()
{
thread_flag = true;
thread_ = std::thread(&dataLogger::thread_fn, this);
}
void dataLogger::stop()
{
thread_flag = false;
if (thread_.joinable())
thread_.join();
}
void dataLogger::thread_fn()
{
std::shared_ptr<vector<uint8_t>> rawData_;
rawData_ = std::make_shared<vector<uint8_t>>(10);
vector<uint8_t> sasaa;
while (thread_flag)
{
{
std::lock_guard<std::mutex> f(mutex_);
for (size_t i = 0; i < 10; i++)
rawData_->at(i) = i; // simulation data source
queue_->push_back(rawData_);
}
rawData_ = std::make_shared<vector<uint8_t>>(10);
Sleep(20);
}
}
I want to add event method to my arduino library something similar to cayenne or blynk framework.I have no C or C++ programming background.
CAYENNE_IN_DEFAULT() {
//to-do
}
Here is Fusi.h
#ifndef Fusi_h
#define Fusi_h
#define DEBUG true
#define MQTT_SERVER "192.168.31.10"
#define IOT_ENDPOINT "http://192.168.31.10:8069/iot"
class Fusi
{
public:
Fusi(String clientID,String clientSecret);
void setup();
void loop();
int digitalPinRead(int channel);
void addDigitalSwitch(String name, int channel);
private:
String clientID;
String clientSecret;
void digitalPinWrite(int channel, int value);
void virtualSwitchWrite(String name, int channel, int value);
};
#endif
Here is Fusi.cpp
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <PubSubClient.h>
#include "fusi.h"
#include <ArduinoJson.h>
HTTPClient http;
WiFiClient wifiClient;
ESP8266WebServer server(80);
PubSubClient mqtt(MQTT_SERVER, 1883, wifiClient);
Fusion::Fusion(String deviceID,String deviceSecret){
clientID = deviceID;
clientSecret = deviceSecret;
}
void Fusion::setup(){
//to-do
}
void Fusion::addDigitalSwitch(String name, int channel){
//to-do
}
int Fusion::digitalPinRead(int channel){
return 0;
}
void Fusion::loop(){
mqtt.loop();
//FUSI_IN_CHANNEL(5);
}
Now I want to notify on main sketch if some certain event occurred.
#include <Fusi.h>
Fusi fusi("4151b719-09bd-448e-9fc4-873807a66ba2","LSXJPBLW");
void setup() {
fusi.setup();
fusi.addDigitalSwitch("RELAY_0",D0);
fusi.addDigitalSwitch("RELAY_1",D1);
fusi.addDigitalSwitch("RELAY_2",D2);
fusi.addDigitalSwitch("RELAY_3",D3);
fusi.addDigitalSwitch("ONBOARD_LED",D4);
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
pinMode(D3,OUTPUT);
pinMode(D4,OUTPUT);
digitalWrite(D0,fusi.digitalPinRead(D0));
digitalWrite(D1,fusi.digitalPinRead(D1));
digitalWrite(D2,fusi.digitalPinRead(D2));
digitalWrite(D3,fusi.digitalPinRead(D3));
digitalWrite(D4,fusi.digitalPinRead(D4));
}
void loop() {
fusi.loop();
delay(200);
}
//This should notify from library
void FUSI_IN_CHANNEL(int channel){
//do update pins
}
}
Hey I'm a C++ beginner and trying to learn the basics. I tried to compile my code but it keeps telling me
error. (c2653) "Framework": no class or namespace in line 4.
Another error is
"sf":no class or namespace
but if I add #include <SFML\Graphics.hpp> to my Framework.cpp code it solve the problem. As I understand the .hpp headers include all the code to the cpp files. So why should I include the SFML\Graphics.hpp twice?
Here is my Code:
#ifndef FRAMEWORKK_H
#define FRAMEWORKK_H
#include <iostream>
#include <SFML\Graphics.hpp>
#include "stdafx.h"
class Framework
{
public:
Framework();
~Framework();
void run();
private:
void quit();
void update();
void handleEvent();
void render();
sf::RenderWindow * pRenderWindow;
sf::Event * pMainEvent;
bool mRun;
};#endif
and here is my .cpp code
#include "Frameworkk.h"
#include "stdafx.h"
Framework::Framework(){
pRenderWindow = new sf::RenderWindow(sf::VideoMode(800, 600, 32),
"Spiel");
pMainEvent = new sf::Event;
mRun = true;
}
Framework::~Framework()
{
}
void Framework::run()
{
while (mRun)
{
update();
handleEvent();
render();
quit();
}
}
void Framework::quit()
{
if (!mRun)
{
pRenderWindow->close();
}
}
void Framework::update()
{
}
void Framework::handleEvent()
{
while (pRenderWindow->pollEvent(*pMainEvent))
{
if (pMainEvent->type == sf::Event::Closed)
{
mRun = false;
}
}
}
void Framework::render()
{
pRenderWindow->clear(sf::Color(120, 120, 120));
pRenderWindow->display();
}
I really don't know why i have this redefinition error
GtkwidgetDef.h
#include <gtk/gtk.h>
class GtkwidgetDef
{
public:
GtkWidget* display;
GtkwidgetDef(GtkButton* button);
};
GtkwidgetDef.cpp
#include "GtkwidgetDef.h"
extern "C" GtkWidget* lookup_widget(GtkWidget* widget, const gchar* widgetName);
GtkwidgetDef::GtkwidgetDef(GtkButton* button){
display = lookup_widget(GTK_WIDGET(button), "display");
}
these two fonctions are juste definition and constructor
MesFonctions.cpp
#include "MesFonctions.h"
#include <math.h>
string str;
gchar str1[9] = "";
void showText(GtkwidgetDef widgets, gchar* label)
{
gtk_entry_set_text(GTK_ENTRY(widgets->display), label);
}
.........
CALCU.h
#include <gtk/gtk.h>
typedef enum Event{ SEVEN_CLICKED, PLUS_CLICKED, VALIDE } Event;
int processEvent(Event e, GtkButton* button);
CALCU.cpp
#include "CALCU.h"
#include "MesFonctions.h"
#include "GtkwidgetDef.h"
int processEvent(Event e, GtkButton* button)
{
//GtkwidgetDef* widgets = new GtkwidgetDef();
//label = gtk_button_get_label(button);
GtkwidgetDef widgets(button);
gchar* label;
strcpy(label, gtk_button_get_label(button));
string s;
switch(e)
{
case SEVEN_CLICKED:
//showText(*widgets, label);
showText(widgets, label);
s = "7";
pushValue(s);
break;
case PLUS_CLICKED:
//showText(*widgets, label);
showText(widgets, label);
s = "+";
pushValue(s);
break;
case VALIDE:
showResult();
break;
}
}
i wonder if i make an error here in this line GtkwidgetDef widgets(button);
I think the reason you are seeing this is that you include GtkwidgetDef.h twice at some point: once directly and once indirectly. You probably need to add an include guard to your header:
#ifndef GtkwidgetDef_h
#define GtkwidgetDef_h
#include <gtk/gtk.h>
class GtkwidgetDef
{
public:
GtkWidget* display;
GtkwidgetDef(GtkButton* button);
};
#endif