Fledge
An open source edge computing platform for industrial users
north_service.h
1 #ifndef _NORTH_SERVICE_H
2 #define _NORTH_SERVICE_H
3 /*
4  * Fledge north service.
5  *
6  * Copyright (c) 2020 Dianomic Systems
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 
13 #include <logger.h>
14 #include <north_plugin.h>
15 #include <service_handler.h>
16 #include <storage_client.h>
17 #include <config_category.h>
18 #include <filter_plugin.h>
19 #include <mutex>
20 #include <condition_variable>
21 #include <audit_logger.h>
22 #include <perfmonitors.h>
23 
24 #define SERVICE_NAME "Fledge North"
25 
26 class DataLoad;
27 class DataSender;
28 
35  public:
36  NorthService(const std::string& name,
37  const std::string& token = "");
38  virtual ~NorthService();
39  void start(std::string& coreAddress,
40  unsigned short corePort);
41  void stop();
42  void shutdown();
43  void restart();
44  void configChange(const std::string&, const std::string&);
45  void configChildCreate(const std::string& , const std::string&, const std::string&){};
46  void configChildDelete(const std::string& , const std::string&){};
47  bool isRunning() { return !m_shutdown; };
48  const std::string& getName() { return m_name; };
49  const std::string& getPluginName() { return m_pluginName; };
50  void pause();
51  void release();
52  bool write(const std::string& name, const std::string& value, const ControlDestination);
53  bool write(const std::string& name, const std::string& value, const ControlDestination, const std::string& arg);
54  int operation(const std::string& name, int paramCount, char *names[], char *parameters[], const ControlDestination);
55  int operation(const std::string& name, int paramCount, char *names[], char *parameters[], const ControlDestination, const std::string& arg);
56  void setDryRun() { m_dryRun = true; };
57  bool getDryRun() { return m_dryRun; };
58  void alertFailures();
59  void clearFailures();
60  private:
61  void addConfigDefaults(DefaultConfigCategory& defaults);
62  bool loadPlugin();
63  void createConfigCategories(DefaultConfigCategory configCategory, std::string parent_name,std::string current_name);
64  void restartPlugin();
65  private:
66  std::string controlSource();
67  bool sendToService(const std::string& southService, const std::string& name, const std::string& value);
68  bool sendToDispatcher(const std::string& path, const std::string& payload);
69  DataLoad *m_dataLoad;
70  DataSender *m_dataSender;
71  NorthPlugin *northPlugin;
72  std::string m_pluginName;
73  Logger *logger;
74  AssetTracker *m_assetTracker;
75  volatile bool m_shutdown;
76  ConfigCategory m_config;
77  ConfigCategory m_configAdvanced;
78  StorageClient *m_storage;
79  std::mutex m_mutex;
80  std::condition_variable m_cv;
81  PluginData *m_pluginData;
82  bool m_restartPlugin;
83  const std::string m_token;
84  bool m_allowControl;
85  bool m_dryRun;
86  bool m_requestRestart;
87  AuditLogger *m_auditLogger;
88  PerformanceMonitor *m_perfMonitor;
89 };
90 #endif
Fledge Logger class used to log to syslog.
Definition: logger.h:26
The NorthService class.
Definition: north_service.h:34
DefaultConfigCategory.
Definition: config_category.h:236
A class used in the North service to load data from the buffer.
Definition: data_load.h:24
Definition: config_category.h:56
virtual ~NorthService()
Destructor for the north service.
Definition: north.cpp:320
Definition: data_sender.h:25
void stop()
Stop the storage service/.
Definition: north.cpp:603
Class to handle the performance monitors.
Definition: perfmonitors.h:35
void configChange(const std::string &, const std::string &)
Configuration change notification.
Definition: north.cpp:789
Definition: plugin_data.h:15
NorthService(const std::string &name, const std::string &token="")
Constructor for the north service.
Definition: north.cpp:296
A singleton class for access to the audit logger within services.
Definition: audit_logger.h:21
Class that represents a north plugin.
Definition: north_plugin.h:33
Client for accessing the storage service.
Definition: storage_client.h:43
void start(std::string &coreAddress, unsigned short corePort)
Start the north service.
Definition: north.cpp:346
void shutdown()
Shutdown request.
Definition: north.cpp:757
void restart()
Restart request.
Definition: north.cpp:772
void alertFailures()
Raise an alert that we are having issues sending data.
Definition: north.cpp:1325
void clearFailures()
Clear the failure alert for sending data.
Definition: north.cpp:1339
The AssetTracker class provides the asset tracking functionality.
Definition: asset_tracking.h:239
ServiceAuthHandler adds security to the base class ServiceHandler.
Definition: service_handler.h:35