Skip to content

Commit

Permalink
add proof of concept with weather data
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoegel committed Jul 16, 2023
1 parent f90d8e2 commit 84a30ce
Show file tree
Hide file tree
Showing 20 changed files with 1,340 additions and 6 deletions.
222 changes: 222 additions & 0 deletions .clang-format
@@ -0,0 +1,222 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: true
AlignConsecutiveBitFields:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveDeclarations:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignConsecutiveMacros:
Enabled: false
AcrossEmptyLines: false
AcrossComments: false
AlignCompound: false
PadOperators: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments:
Kind: Always
OverEmptyLines: 0
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: true
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: true
AfterStruct: false
AfterUnion: true
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterAttributes: Never
BreakAfterJavaFieldAnnotations: false
BreakArrays: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: Always
BreakBeforeBraces: Custom
BreakBeforeInlineASMColon: OnlyMultiline
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: true
IndentPPDirectives: None
IndentRequiresClause: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertBraces: false
InsertNewlineAtEOF: true
InsertTrailingCommas: None
IntegerLiteralSeparator:
Binary: 0
Decimal: 0
Hex: 0
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
LineEnding: DeriveLF
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyIndentedWhitespace: 0
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
PPIndentWidth: -1
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: true
RemoveBracesLLVM: false
RemoveSemicolon: false
RequiresClausePosition: OwnLine
RequiresExpressionIndentation: OuterScope
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortJavaStaticImport: Before
SortUsingDeclarations: LexicographicNumeric
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- CF_SWIFT_NAME
- NS_SWIFT_NAME
- PP_STRINGIZE
- STRINGIZE
...

2 changes: 2 additions & 0 deletions .gitignore
@@ -1,4 +1,6 @@
build
.env
.cache

debian/.debhelper
debian/chestnut*
Expand Down
26 changes: 25 additions & 1 deletion chestnut/CMakeLists.txt
@@ -1,7 +1,31 @@
add_executable(chestnut
chestnut.cpp
chestnut.m.cpp
config.cpp
weather/weatherclient.cpp
weather/weatherdata.cpp
weather/weatherdatapublisher.cpp
)
target_include_directories(chestnut PUBLIC .)
target_link_libraries(chestnut pthread)
target_link_libraries(chestnut pthread fwoopbasis fwoophttp fwoopbasis fwoopencoding fwoopobserve)

install(TARGETS chestnut DESTINATION /opt/bin)

include(GoogleTest)
add_executable(chestnut_test
chestnut.g.cpp
config.g.cpp
weather/weatherclient.g.cpp
weather/weatherdata.g.cpp
weather/weatherdatapublisher.g.cpp

chestnut.cpp
config.cpp
weather/weatherclient.cpp
weather/weatherdata.cpp
weather/weatherdatapublisher.cpp
)
target_include_directories(chestnut_test PUBLIC .)
target_link_libraries(chestnut_test fwoopobserve fwoopbasis fwoophttp fwoopbasis fwoopencoding fwoopobserve gtest gtest_main pthread)

gtest_add_tests(TARGET chestnut_test)
53 changes: 53 additions & 0 deletions chestnut/chestnut.cpp
@@ -0,0 +1,53 @@
#include <chestnut.h>

#include <chrono>
#include <config.h>
#include <functional>
#include <memory>
#include <publisher.h>
#include <thread>

#include <fwoop_log.h>

namespace chestnut {

Chestnut::Chestnut()
: d_publisher(std::make_shared<OpenMetricsPublisher>(Config::metricsPort())),
d_weatherClient(std::make_shared<WeatherClient>(Config::weatherBaseURL(), Config::weatherLat(),
Config::weatherLon(), Config::weatherAPIKey())),
d_needStop(false)
{
}

Chestnut::Chestnut(std::shared_ptr<Publisher> publisher) : d_publisher(publisher), d_needStop(false) {}

void Chestnut::refresh()
{
while (!d_needStop) {
if (Config::isWeatherEnabled()) {
d_weatherClient->refresh();
}
std::this_thread::sleep_for(std::chrono::seconds(Config::refreshInterval()));
}
}

int Chestnut::start()
{
if (!Config::debug()) {
fwoop::Log::SetThreshold(fwoop::Log::e_Info);
}

d_publisher->start();
d_weatherClient->setPublisher(d_publisher);
refresh();
return 0;
}

void Chestnut::stop()
{
d_needStop = true;
d_publisher->stop();
d_refreshThread.join();
}

} // namespace chestnut
1 change: 1 addition & 0 deletions chestnut/chestnut.g.cpp
@@ -0,0 +1 @@
#include <chestnut.h>
36 changes: 36 additions & 0 deletions chestnut/chestnut.h
@@ -0,0 +1,36 @@
#pragma once

#include <memory.h>

#include <memory>
#include <publisher.h>
#include <thread>
#include <weather/weatherclient.h>

namespace chestnut {

class Chestnut {
private:
std::shared_ptr<Publisher> d_publisher;
std::shared_ptr<WeatherClient> d_weatherClient;
std::thread d_refreshThread;
bool d_needStop;

void refresh();

public:
Chestnut();
Chestnut(std::shared_ptr<Publisher> publisher);

~Chestnut();
Chestnut(const Chestnut &rhs) = delete;
Chestnut &operator=(const Chestnut &rhs) = delete;
Chestnut(Chestnut &&rhs) = default;

int start();
void stop();
};

inline Chestnut::~Chestnut() { stop(); }

} // namespace chestnut
8 changes: 3 additions & 5 deletions chestnut/chestnut.m.cpp
@@ -1,7 +1,5 @@
#include "chestnut.h"
#include <fwoop_log.h>
#include <iostream>

int main(int argc, char* argv[])
{
std::cout << "hello\n";
return 0;
}
int main(int argc, char *argv[]) { return chestnut::Chestnut().start(); }

0 comments on commit 84a30ce

Please sign in to comment.