4837c4945ad98dbdcc466158f970556db5095278
[src/app-framework-binder.git] / src / afb-session.h
1 /*
2  * Copyright (C) 2016-2019 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #pragma once
19
20 struct afb_session;
21
22 #define AFB_SESSION_TIMEOUT_INFINITE  -1
23 #define AFB_SESSION_TIMEOUT_DEFAULT   -2
24 #define AFB_SESSION_TIMEOUT_IS_VALID(x) ((x) >= AFB_SESSION_TIMEOUT_DEFAULT)
25
26 extern int afb_session_init(int max_session_count, int timeout);
27 extern void afb_session_purge();
28 extern void afb_session_foreach(void (*callback)(void *closure, struct afb_session *session), void *closure);
29
30 extern struct afb_session *afb_session_create (int timeout);
31 extern struct afb_session *afb_session_search (const char *uuid);
32 extern struct afb_session *afb_session_get (const char *uuid, int timeout, int *created);
33 extern const char *afb_session_uuid (struct afb_session *session);
34 extern uint16_t afb_session_id (struct afb_session *session);
35
36 extern struct afb_session *afb_session_addref(struct afb_session *session);
37 extern void afb_session_unref(struct afb_session *session);
38 extern void afb_session_set_autoclose(struct afb_session *session, int autoclose);
39
40 extern void afb_session_close(struct afb_session *session);
41 extern int afb_session_is_closed (struct afb_session *session);
42
43 extern int afb_session_timeout(struct afb_session *session);
44 extern int afb_session_what_remains(struct afb_session *session);
45
46 extern void *afb_session_get_cookie(struct afb_session *session, const void *key);
47 extern void *afb_session_cookie(struct afb_session *session, const void *key, void *(*makecb)(void *closure), void (*freecb)(void *item), void *closure, int replace);
48 extern int afb_session_set_cookie(struct afb_session *session, const void *key, void *value, void (*freecb)(void*));
49
50 extern int afb_session_set_language(struct afb_session *session, const char *lang);
51 extern const char *afb_session_get_language(struct afb_session *session, const char *lang);