Skip to content

Conversation

@JBHarvey
Copy link
Contributor

@JBHarvey JBHarvey commented Feb 15, 2019

!!! IMPORTANT!!! not final DO NOT MERGE YET

  • Created to minimize the review work

Introduit beaucoup de changements majeurs (en terme de comportement). Entre-autre :

  • Ajout de thread dans ServerCommunicator pour permettre de faire la reception async de Request
  • Ajout d'Assembler pour faire la logique, le traitement et les validations des requetes (mostly empty for now, but really helpful to clarify the code)
  • Ajout de nouvelles structures et chemins de produce/consume pour les Request/Response -> notament : RequestHandler
  • Ajout d'une nouvelle structure utilitaire tres utile et importante: Parameters -> Permet de batch les parametres et de les traiter facilement (mais la classe en elle meme est pas super belle)
  • Ajout d'un nouveau type: StringLiterals qui permet de creer des Strings a la compilation et de les passer en template parameters --> (ca c'est un brin de metaprog :success-kid: )
  • Introduction des std::tuple et fonctions utilitaires qui vont avec pour faciliter les listes de differents template parameters

#define SENSORGATEWAY_CONSTANTFUNCTIONSDEFINITION_H

#include "ConstantValuesDefinition.h"
#include "StaticTupleFunctions.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le nom est pas super parlant.

auto currentPad = firstPad;
RingBufferPad<T>* nextPad;
for (auto i = 1; i < RING_BUFFER_SIZE; ++i) {
for (size_t i = 1; i < RING_BUFFER_SIZE; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi tu laisses des auto partout et tu modifies celui la?

typedef Byte AWL;
typedef Byte GUARDIAN;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

espace inutile

}

namespace DataFlow {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

espace inutile

using Text = std::string;
}
namespace Units {
// TODO: Use UCUM to correctly encode units
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Laisser un TODO pour un code open source?

struct ExtractedType {
using type = T;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Espace en trop

public:

explicit Parameter()
// : value(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi value() en commentaire


using ServerCommunicator = SensorAccessLinkElement::ServerCommunicator<SERVER_STRUCTURES>;

using ThisClass = ResponseWriter<SENSOR_STRUCTURES, SERVER_STRUCTURES>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThisClass, Cela represente quoi ?


namespace Details {

template<typename N>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis plus trop a jours avec les templates mais typename N ( est ce que pour les template on s oblige a mettre des majuscules pour les typename ou est ce que c<est parce que tu as juste voulu mettre N? ) Par la suite tu mets quelques lignes plus loins typename ValueType

// TODO : Validate request is allowed --> throw if not
// TODO : Assemble Request
// TODO : Pass to RequestHandler
// for (auto messageIndex = 0; messageIndex < messages.size(); ++messageIndex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ne pas laisser de TODO dans le master en open source je pense que cela pourrait etre une bonne chose?

auto message = messages[j];
std::fprintf(file,
"=================================================================================== \n");
std::fprintf(file, "SENSOR_ID : %" PRIu64 "\n", message.id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je fais la remarque seulement a cet endroit mais pourquoi tu met pas using namespace std en haut ah lieu de devoir le reecrire a chaque fois?

[&](auto... Is) { return f(std::get<Is>(t)...); }
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

espace inutile

}
}

// template<typename Communicator, typename Strategy>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En commentaire?

};
}

//TEST_F(RequestHandlerTest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention test commentés


namespace ResponseWriterTestMock {

// using RealisticDataStructures = Sensor::Test::RealisticImplementation::Structures;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JE suppose que c est en WIP d'ou les commentaires ?

bool hasToReturnSpecificGetParameterValueContents;
GetParameterValueContentList getParameterValueContentsToReturn;

// TODO: Create a template class to inherit from when implementing this :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention comment

Copy link
Contributor

@Sebdevar Sebdevar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai fait mon possible dans la review, mais l'implementation du gateway est beaucoup trop deep dans la technicalite du C++ pour ma comprehension.

}
namespace Units {
// TODO: Use UCUM to correctly encode units
using not_applicable = StringLiteral<decltype("n/a"_ToString)>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce serais bon d'avoir aussi none = "". Ca eviterait d'avoir a gerer inutilement un n/a et de juste passer directement la valeur.

typename GatewayParameterDefinition,
Byte SENSOR_INTERNAL_COMMAND,
Byte SENSOR_INTERNAL_ADDRESS,
uint8_t SENSOR_INTERNAL_TOTAL_LENGTH_IN_BITS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sensor Internal total length in bits? Ca represente quoi?

return nameTuple;
}

struct NameEquals {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi une struct pour une egalite de nom... dont la seule utlite c'est de verifier l'egalite de deux string.... tu pourrait pas juste... valider l'egalite des strings la ou necessaire, ou au pire faire juste une fonction, pas besoin d'une struct pour ca.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pareil pour les autres cas semblables comme type name equals

struct StringLiteral;

template<char... elements>
struct StringLiteral<StringType<elements...>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un template de template de templates o__O? C'est vraiment nécessaire ca?


static inline DataFlow::Intensity const convertIntensityToSNR(DataFlow::Intensity const& intensity) noexcept {
DataFlow::Intensity const snr = ((intensity / 1024) / 2.0) - 21; // w+f
DataFlow::Intensity const snr = (intensity / 2.0) - 21; // w+f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// w+f ???

responseWriter(responseWriter),
dataTranslator(dataTranslator) {}

~RequestHandler() noexcept {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
~RequestHandler() noexcept {};
~RequestHandler() noexcept override = default;

Category category = COMMUNICATION_ERROR;
Severity severity;
std::string errorMessage;
if (errorCode == BAD_REQUEST) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c'est le troisieme if else que je vois pour le error handling... pourquoi tu utilise pas un switch case? c'est beaucoup plus clair a la lecture.

https://www.geeksforgeeks.org/switch-vs-else/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Va voir la section 6, c'est la base de trucs a faire / eviter dans le gateway. Certains ne sont pas respectes pour de bonnes raisons, mais on essaie de les suivres pour la plupart

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

es-tu sure de l'avoir bien lu, la switch est valide et compliant dans ce que tu m'as link.

std::string const SEPARATOR = " - ";
std::string const EMPTY_MESSAGE = "";

std::string const PARAMETER_NOT_AVAILABLE = "Parameter is not available";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang-Tidy: Initialization of 'PARAMETER_NOT_AVAILABLE' with static storage duration may throw an exception that cannot be caught

Warning Message for all const created in this file.

dataTranslator(dataTranslator),
responseControlMessageScheduler(this) {}

~SensorParameterController() noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
~SensorParameterController() noexcept {
~SensorParameterController() noexcept override {


public:

explicit SensorParameterController(RequestHandler* requestHandler,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used.

DataTranslator* dataTranslator;

SensorControlMessages sensorControlMessageRequests;
SensorControlMessagePointers sensorControlMessageRequestPointers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both fields never used.

namespace Details {

template<typename N, typename ValueType, ValueType v>
struct NameValuePayload {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never Used.


public:

explicit StringPayload(std::string const& value) noexcept : value(value) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Clang-Tidy: Pass by value and use std::move

Not sure how to fix, I tried following this link

return value;
}

Type const& getValue() const noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used.

return value;
}

static constexpr bool isSuccess() noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used.

//
// virtual void sendResponse(RealNumberParameterResponse&& realNumberParameterResponse) = 0;
//
// virtual void sendResponse(BooleanParameterResponse&& booleanParameterResponse) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented code?


public:

explicit ServerRequest(PayloadType const& payload) noexcept :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badRequest et CausedAnError sont pas initialises dans le constructor

return badRequest;
}

bool const& hasCausedAnError() const noexcept {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants