Jazz 1.26.+
Loading...
Searching...
No Matches
api.h
1/* Jazz (c) 2018-2026 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 pBebop a_bebop,
130 pModelsAPI a_model);
131 ~API();
132
133 virtual pChar const id();
134
135 StatusCode start ();
137
138 // parsing methods
139
141 pChar p_url,
142 bool get_it = true);
143
144 // deliver http error pages
145
146 MHD_Result return_error_message(pMHD_Connection connection,
147 pChar p_url,
148 int http_status);
149
150 // Specific execution methods
151
152 MHD_StatusCode http_put (pChar p_upload,
153 size_t size,
154 ApiQueryState &q_state,
155 int sequence);
158 ApiQueryState &q_state);
159
160#ifndef CATCH_TEST
161 private:
162#endif
163
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
174
177};
178
179
180#ifdef CATCH_TEST
181
182// Instancing API
183// --------------
184
185extern API TT_API;
186
187#endif
188
189} // namespace jazz_main
190
191#endif // ifndef INCLUDED_JAZZ_MAIN_API
Bebop: The compiler.
Definition bebop.h:91
BaseAPI: The parent of API and Core.
Definition base_api.h:122
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:244
A configuration file as a key/value store.
Definition utils.h:218
A simple logger.
Definition utils.h:248
Persisted: A Service to manage data objects in LMDB.
Definition persisted.h:111
Volatile: A Service to manage data objects in RAM.
Definition volatile.h:243
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:554
Index www
A map from url to locators to serve static files.
Definition api.h:175
pCore p_core
The Core.
Definition api.h:171
pModelsAPI p_model
The ModelsAPI.
Definition api.h:173
MHD_StatusCode http_get(pMHD_Response &response, ApiQueryState &q_state)
Definition api.cpp:407
StatusCode shut_down()
Definition api.cpp:137
MHD_StatusCode get_static(pMHD_Response &response, pChar p_url, bool get_it=true)
Definition api.cpp:165
int remove_statics
A flag to remove the statics from persistence on shutdown configured by REMOVE_STATICS_ON_CLOSE.
Definition api.h:176
MHD_StatusCode http_delete(ApiQueryState &q_state)
Definition api.cpp:366
StatusCode start()
Definition api.cpp:100
bool expand_url_encoded(pChar p_buff, int buff_size, pChar p_url)
Definition api.cpp:728
pBebop p_bebop
The Bebop compiler.
Definition api.h:172
MHD_Result return_error_message(pMHD_Connection connection, pChar p_url, int http_status)
Definition api.cpp:214
MHD_StatusCode http_put(pChar p_upload, size_t size, ApiQueryState &q_state, int sequence)
Definition api.cpp:278
virtual pChar const id()
Definition api.cpp:83
ModelsAPI: The model API.
Definition models_api.h:61
The Bop compiler.
Definition bebop.cpp:115
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
char * pChar
A pointer to a char buffer.
Definition types.h:189
int StatusCode
Type returned by the Service API.
Definition utils.h:142
unsigned int MHD_StatusCode
A proper type for specifying http status codes.
Definition channel.h:158
std::map< String, String > Index
An Index kept in RAM by Volatile implemented as an stdlib map (string, string)
Definition types.h:243
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