Jazz 1.25.+
All Data Structures Namespaces Functions Variables Typedefs Pages
api.h
1/* Jazz (c) 2018-2025 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques Basaldúa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques Basaldúa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include <map>
36
37#include "src/include/jazz_models.h"
38
39#ifdef CATCH_TEST
40#ifndef INCLUDED_JAZZ_CATCH2
41#define INCLUDED_JAZZ_CATCH2
42
43#include "src/catch2/catch.hpp"
44
45#endif
46#endif
47
48
49#ifndef INCLUDED_JAZZ_MAIN_API
50#define INCLUDED_JAZZ_MAIN_API
51
52
53#define MHD_PLATFORM_H // Following recommendation in: 1.5 Including the microhttpd.h header
54
55
56#include <microhttpd.h>
57
58#if MHD_VERSION < 0x00097000
66typedef int MHD_Result;
67#endif
68
69
75namespace jazz_main
76{
77
78//TODO: Create interface for ACTOR model (as described in develop/rfc2/jazz_actor_model.html)
79
80using namespace jazz_elements;
81using namespace jazz_bebop;
82using namespace jazz_models;
83
84#define MAX_RECURSE_LEVEL_ON_STATICS 16
85
86// Values of http_put(sequence)
87#define SEQUENCE_FIRST_CALL 0
88#define SEQUENCE_INCREMENT_CALL 1
89#define SEQUENCE_FINAL_CALL 2
90
92
93#define HTTP_NOTUSED 0
94#define HTTP_OPTIONS 1
95#define HTTP_HEAD 2
96#define HTTP_GET 3
97#define HTTP_PUT 4
98#define HTTP_DELETE 5
99
100typedef struct MHD_Response *pMHD_Response;
101typedef struct MHD_Connection *pMHD_Connection;
102
103extern MHD_Result http_request_callback(void *cls,
104 struct MHD_Connection *connection,
105 const char *url,
106 const char *method,
107 const char *version,
108 const char *upload_data,
109 size_t *upload_data_size,
110 void **con_cls);
111
112
119class API : public BaseAPI {
120
121 public:
122
123 API(pLogger a_logger,
124 pConfigFile a_config,
125 pChannels a_channels,
126 pVolatile a_volatile,
127 pPersisted a_persisted,
128 pCore a_core,
129 pModelsAPI a_model);
130 ~API();
131
132 virtual pChar const id();
133
134 StatusCode start ();
136
137 // parsing methods
138
140 pChar p_url,
141 bool get_it = true);
142
143 // deliver http error pages
144
145 MHD_Result return_error_message(pMHD_Connection connection,
146 pChar p_url,
147 int http_status);
148
149 // Specific execution methods
150
151 MHD_StatusCode http_put (pChar p_upload,
152 size_t size,
153 ApiQueryState &q_state,
154 int sequence);
157 ApiQueryState &q_state);
158
159#ifndef CATCH_TEST
160 private:
161#endif
162
163 bool find_myself ();
164 StatusCode load_statics (pChar p_base_path,
165 pChar p_relative_path,
166 int rec_level);
167 bool expand_url_encoded (pChar p_buff,
168 int buff_size,
169 pChar p_url);
170
173
176};
177
178#ifdef CATCH_TEST
179
180// Instancing API
181// --------------
182
183extern API TT_API;
184
185#endif
186
187} // namespace jazz_main
188
189#endif // ifndef INCLUDED_JAZZ_MAIN_API
BaseAPI: The parent of API and Core.
Definition base_api.h:121
Core: The execution unit is now a wrapper around onnx-runtime.
Definition core.h:89
Channels: A Container doing block transactions across media (files, folders, shell,...
Definition channel.h:227
A configuration file as a key/value store.
Definition utils.h:217
A simple logger.
Definition utils.h:245
Persisted: A Service to manage data objects in LMDB.
Definition persisted.h:93
Volatile: A Service to manage data objects in RAM.
Definition volatile.h:244
API: A Service to manage the REST API.
Definition api.h:119
StatusCode load_statics(pChar p_base_path, pChar p_relative_path, int rec_level)
Definition api.cpp:569
Index www
A map from url to locators to serve static files.
Definition api.h:174
pCore p_core
The Core.
Definition api.h:171
pModelsAPI p_model
The ModelsAPI.
Definition api.h:172
MHD_StatusCode http_get(pMHD_Response &response, ApiQueryState &q_state)
Definition api.cpp:417
StatusCode shut_down()
Definition api.cpp:147
bool find_myself()
Definition api.cpp:810
MHD_StatusCode get_static(pMHD_Response &response, pChar p_url, bool get_it=true)
Definition api.cpp:175
int remove_statics
A flag to remove the statics from persistence on shutdown configured by REMOVE_STATICS_ON_CLOSE.
Definition api.h:175
MHD_StatusCode http_delete(ApiQueryState &q_state)
Definition api.cpp:376
StatusCode start()
Definition api.cpp:97
bool expand_url_encoded(pChar p_buff, int buff_size, pChar p_url)
Definition api.cpp:743
MHD_Result return_error_message(pMHD_Connection connection, pChar p_url, int http_status)
Definition api.cpp:224
MHD_StatusCode http_put(pChar p_upload, size_t size, ApiQueryState &q_state, int sequence)
Definition api.cpp:288
virtual pChar const id()
Definition api.cpp:80
ModelsAPI: The model API.
Definition models_api.h:61
A language to access any container by base using locators.
Definition base_api.cpp:39
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
std::map< std::string, std::string > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:238
char * pChar
A pointer to a char buffer.
Definition types.h:185
int StatusCode
Type returned by the Service API.
Definition utils.h:141
unsigned int MHD_StatusCode
A proper type for specifying http status codes.
Definition channel.h:141
The http API, instancing and building the server.
Definition api.cpp:42
struct MHD_Connection * pMHD_Connection
Pointer to a MHD_Connection.
Definition api.h:101
MHD_Result http_request_callback(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls)
Definition instances.cpp:136
struct MHD_Response * pMHD_Response
Pointer to a MHD_Response.
Definition api.h:100
Concepts: A tree of Snippets with support fro blending that populates a semantic space.
Definition concept.cpp:39
A buffer to keep the state while parsing/executing a query.
Definition base_api.h:99