28
28
class EmbAJAXOutputDriverBase ;
29
29
class EmbAJAXElement ;
30
30
class EmbAJAXContainerBase ;
31
+ class EmbAJAXPageBase ;
31
32
32
33
/* * @brief Abstract base class for anything shown on an EmbAJAXPage
33
34
*
@@ -117,6 +118,13 @@ class EmbAJAXOutputDriverBase {
117
118
virtual void printHeader (bool html) = 0;
118
119
virtual void printContent (const char *content) = 0;
119
120
virtual const char * getArg (const char * name, char * buf, int buflen) = 0;
121
+ /* * Set up the given page to be served on the given path.
122
+ *
123
+ * @param change_callback See EmbAJAXPage::handleRequest() for details.
124
+ */
125
+ virtual void installPage (EmbAJAXPageBase *page, const char *path, void (*change_callback)()=0) = 0;
126
+ /* * Insert this hook into loop(). Takes care of the appropriate server calls, if needed. */
127
+ virtual void loopHook () = 0;
120
128
121
129
uint16_t revision () const {
122
130
return _revision;
@@ -163,17 +171,6 @@ class EmbAJAXOutputDriverBase {
163
171
uint16_t next_revision;
164
172
};
165
173
166
- // If the user has not #includ'ed a specific output driver implementation, make a good guess, here
167
- #if not defined (EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION)
168
- #if defined (ESP8266)
169
- #include < EmbAJAXOutputDriverESP8266.h>
170
- #elif defined (ESP32)
171
- #include < EmbAJAXOutputDriverESP32.h>
172
- #else
173
- #error No output driver available for this hardware (yet). Please implement your own (it is easy!) and submit a patch.
174
- #endif
175
- #endif
176
-
177
174
/* * Convenience macro to set up an EmbAJAXPage, without counting the number of elements for the template. See EmbAJAXPage::EmbAJAXPage()
178
175
* @param name Variable name of the page instance
179
176
* @param title HTML Title
@@ -546,7 +543,7 @@ template<size_t NUM> class EmbAJAXHideableContainer : public EmbAJAXElement {
546
543
547
544
/* * @brief A set of radio buttons (mutally exclusive buttons), e.g. for on/off, or low/mid/high, etc.
548
545
*
549
- * You can insert either the whole group into an ArudJAXPage at once, or - for more flexbile
546
+ * You can insert either the whole group into an EmbAJAXPage at once, or - for more flexbile
550
547
* layouting - retrieve the individual buttons using() button, and insert them into the page
551
548
* as independent elements. */
552
549
template <size_t NUM> class EmbAJAXRadioGroup : public EmbAJAXContainer <NUM>, public EmbAJAXRadioGroupBase {
@@ -643,13 +640,22 @@ template<size_t NUM> class EmbAJAXOptionSelect : public EmbAJAXOptionSelectBase
643
640
const char * _labels[NUM];
644
641
};
645
642
643
+ /* * @brief Absrract internal helper class
644
+ *
645
+ * Needed for internal reasons. Refer to EmbAJAXPage, instead. */
646
+ class EmbAJAXPageBase {
647
+ public:
648
+ virtual void handleRequest (void (*change_callback)()=0) = 0;
649
+ virtual void printPage () = 0;
650
+ };
651
+
646
652
/* * @brief The main interface class
647
653
*
648
654
* This is the main interface class. Create a web-page with a list of elements on it, and arrange for
649
655
* print() (for page loads) adn handleRequest() (for AJAX calls) to be called on requests. By default,
650
656
* both page loads, and AJAX are handled on the same URL, but the first via GET, and the second
651
657
* via POST. */
652
- template <size_t NUM> class EmbAJAXPage : public EmbAJAXContainer <NUM> {
658
+ template <size_t NUM> class EmbAJAXPage : public EmbAJAXContainer <NUM>, public EmbAJAXPageBase {
653
659
public:
654
660
/* * Create a web page.
655
661
* @param children list of elements on the page
@@ -659,6 +665,10 @@ template<size_t NUM> class EmbAJAXPage : public EmbAJAXContainer<NUM> {
659
665
_title = title;
660
666
_header_add = header_add;
661
667
}
668
+ /* * Duplication of print(), needed for internal reasons. Use print(), instead! */
669
+ void printPage () override {
670
+ print ();
671
+ }
662
672
/* * Serve the page including headers and all child elements. You should arrange for this function to be called, whenever
663
673
* there is a GET request to the desired URL. */
664
674
void print () const override {
@@ -672,12 +682,23 @@ template<size_t NUM> class EmbAJAXPage : public EmbAJAXContainer<NUM> {
672
682
* response to the change, you should specify this function, and handle the change inside it.
673
683
* This way, an update can be sent back to the client, immediately, for a smooth UI experience.
674
684
* (Otherwise the client will be updated on the next poll). */
675
- void handleRequest (void (*change_callback)()=0) {
685
+ void handleRequest (void (*change_callback)()=0) override {
676
686
EmbAJAXBase::handleRequest (EmbAJAXContainer<NUM>::_children, NUM, change_callback);
677
687
}
678
688
protected:
679
689
const char * _title;
680
690
const char * _header_add;
681
691
};
682
692
693
+ // If the user has not #includ'ed a specific output driver implementation, make a good guess, here
694
+ #if not defined (EMBAJAX_OUTUPUTDRIVER_IMPLEMENTATION)
695
+ #if defined (ESP8266)
696
+ #include < EmbAJAXOutputDriverESP8266.h>
697
+ #elif defined (ESP32)
698
+ #include < EmbAJAXOutputDriverESP32.h>
699
+ #else
700
+ #error No output driver available for this hardware (yet). Please implement your own (it is easy!) and submit a patch.
701
+ #endif
702
+ #endif
703
+
683
704
#endif
0 commit comments