/* * Copyright (C) 2016, 2017, 2018 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include /* ensure version */ #ifndef AFB_BINDING_VERSION # define AFB_BINDING_VERSION 3 #endif /* check the version */ #if AFB_BINDING_VERSION < 2 # error "AFB_BINDING_VERSION must be at least 2 but 3 is prefered" #endif /* get C definitions of bindings */ extern "C" { #include "afb-binding.h" } namespace afb { /*************************************************************************/ /* pre-declaration of classes */ /*************************************************************************/ class arg; class event; class req; /*************************************************************************/ /* declaration of functions */ /*************************************************************************/ int broadcast_event(const char *name, json_object *object = nullptr); event make_event(const char *name); void verbose(int level, const char *file, int line, const char * func, const char *fmt, va_list args); void verbose(int level, const char *file, int line, const char * func, const char *fmt, ...); int rootdir_get_fd(); int rootdir_open_locale_fd(const char *filename, int flags, const char *locale = nullptr); int queue_job(void (*callback)(int signum, void *arg), void *argument, void *group, int timeout); int require_api(const char *apiname, bool initialized = true); int add_alias(const char *apiname, const char *aliasname); int verbosity(); bool wants_errors(); bool wants_warnings(); bool wants_notices(); bool wants_infos(); bool wants_debugs(); #if AFB_BINDING_VERSION >= 3 void call(const char *api, const char *verb, struct json_object *args, void (*callback)(void*closure, int iserror, struct json_object *result, afb_api_t api), void *closure); template void call(const char *api, const char *verb, struct json_object *args, void (*callback)(T*closure, int iserror, struct json_object *result, afb_api_t api), T *closure); bool callsync(const char *api, const char *verb, struct json_object *args, struct json_object *&result); #else void call(const char *api, const char *verb, struct json_object *args, void (*callback)(void*closure, int iserror, struct json_object *result), void *closure); template void call(const char *api, const char *verb, struct json_object *args, void (*callback)(T*closure, int iserror, struct json_object *result), T *closure); #endif bool callsync(const char *api, const char *verb, struct json_object *args, struct json_object *&result); /*************************************************************************/ /* effective declaration of classes */ /*************************************************************************/ /* events */ class event { afb_event_t event_; public: event() { invalidate(); } event(afb_event_t e); event(const event &other); event &operator=(const event &other); operator afb_event_t() const; afb_event_t operator->() const; operator bool() const; bool is_valid() const; void invalidate(); int broadcast(json_object *object) const; int push(json_object *object) const; void unref(); void addref(); const char *name() const; }; /* args */ class arg { struct afb_arg arg_; public: arg() = delete; arg(const struct afb_arg &a); arg(const arg &other); arg &operator=(const arg &other); operator const struct afb_arg&() const; bool has_name() const; bool has_value() const; bool has_path() const; const char *name() const; const char *value() const; const char *path() const; }; /* req(uest) */ class req { afb_req_t req_; public: req() = delete; req(afb_req_t r); req(const req &other); req &operator=(const req &other); operator afb_req_t() const; afb_req_t operator->() const; operator bool() const; bool is_valid() const; arg get(const char *name) const; const char *value(const char *name) const; const char *path(const char *name) const; json_object *json() const; void reply(json_object *obj = nullptr, const char *error = nullptr, const char *info = nullptr) const; void replyf(json_object *obj, const char *error, const char *info, ...) const; void replyv(json_object *obj, const char *error, const char *info, va_list args) const; void success(json_object *obj = nullptr, const char *info = nullptr) const; void successf(json_object *obj, const char *info, ...) const; void successv(json_object *obj, const char *info, va_list args) const; void fail(const char *error = "failed", const char *info = nullptr) const; void failf(const char *error, const char *info, ...) const; void failv(const char *error, const char *info, va_list args) const; template < class T > T *context() const; void addref() const; void unref() const; void session_close() const; bool session_set_LOA(unsigned level) const; bool subscribe(const event &event) const; bool unsubscribe(const event &event) const; void subcall(const char *api, const char *verb, json_object *args, void (*callback)(void *closure, int iserror, json_object *result, afb_req_t req), void *closure) const; template void subcall(const char *api, const char *verb, json_object *args, void (*callback)(T *closure, int iserror, json_object *result, afb_req_t req), T *closure) const; bool subcallsync(const char *api, const char *verb, json_object *args, struct json_object *&result) const; #if AFB_BINDING_VERSION >= 3 void subcall(const char *api, const char *verb, json_object *args, int flags, void (*callback)(void *closure, json_object *object, const char *error, const char *info, afb_req_t req), void *closure) const; template void subcall(const char *api, const char *verb, json_object *args, int flags, void (*callback)(T *closure, json_object *object, const char *error, const char *info, afb_req_t req), T *closure) const; bool subcallsync(const char *api, const char *verb, json_object *args, int flags, struct json_object *&object, char *&error, char *&info) const; #endif void verbose(int level, const char *file, int line, const char * func, const char *fmt, va_list args) const; void verbose(int level, const char *file, int line, const char * func, const char *fmt, ...) const; bool has_permission(const char *permission) const; char *get_app
SUMMARY = "Useful bits an pieces to make 96Boards more standard across the board"
HOMEPAGE = "https://github.com/96boards/96boards-tools"
SECTION = "devel"

LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"

SRCREV = "ed0f0dbec02c1869a0c4fa0140b4aa5338c9d010"
SRC_URI = "git://github.com/96boards/96boards-tools;branch=master;protocol=https"

S = "${WORKDIR}/git"

inherit systemd allarch update-rc.d

do_install () {
    install -d ${D}${sysconfdir}/udev/rules.d
    install -m 0755 ${S}/*.rules ${D}${sysconfdir}/udev/rules.d/
    install -d ${D}${sysconfdir}/init.d
    install -m 0755 ${S}/resize-disk ${D}${sysconfdir}/init.d/

    install -d ${D}${systemd_unitdir}/system
    install -m 0644 ${S}/resize-helper.service ${D}${systemd_unitdir}/system

    install -d ${D}${sbindir}
    install -m 0755 ${S}/resize-helper ${D}${sbindir}
}

INITSCRIPT_NAME = "resize-disk"
INITSCRIPT_PARAMS = "start 99 5 2 . stop 20 0 1 6 ."

SYSTEMD_SERVICE:${PN} = "resize-helper.service"
RDEPENDS:${PN} += "e2fsprogs-resize2fs gptfdisk parted util-linux udev"
()); } inline bool wants_notices() { return AFB_SYSLOG_MASK_WANT_NOTICE(logmask()); } inline bool wants_infos() { return AFB_SYSLOG_MASK_WANT_INFO(logmask()); } inline bool wants_debugs() { return AFB_SYSLOG_MASK_WANT_DEBUG(logmask()); } #if AFB_BINDING_VERSION >= 3 inline void call(const char *api, const char *verb, struct json_object *args, void (*callback)(void*closure, int iserror, struct json_object *result, afb_api_t api), void *closure) { afb_service_call(api, verb, args, callback, closure); } template inline void call(const char *api, const char *verb, struct json_object *args, void (*callback)(T*closure, int iserror, struct json_object *result, afb_api_t api), T *closure) { afb_service_call(api, verb, args, reinterpret_cast(callback), reinterpret_cast(closure)); } #else inline void call(const char *api, const char *verb, struct json_object *args, void (*callback)(void*closure, int iserror, struct json_object *result), void *closure) { afb_service_call(api, verb, args, callback, closure); } template inline void call(const char *api, const char *verb, struct json_object *args, void (*callback)(T*closure, int iserror, struct json_object *result), T *closure) { afb_service_call(api, verb, args, reinterpret_cast(callback), reinterpret_cast(closure)); } #endif inline bool callsync(const char *api, const char *verb, struct json_object *args, struct json_object *&result) { return !!afb_service_call_sync(api, verb, args, &result); } /*************************************************************************/ /* declaration of the binding's authorization s */ /*************************************************************************/ constexpr afb_auth auth_no() { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_No; return r; } constexpr afb_auth auth_yes() { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_Yes; return r; } constexpr afb_auth auth_token() { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_Token; return r; } constexpr afb_auth auth_LOA(unsigned loa) { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_LOA; r.loa = loa; return r; } constexpr afb_auth auth_permission(const char *permission) { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_Permission; r.text = permission; return r; } constexpr afb_auth auth_not(const afb_auth *other) { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_Not; r.first = other; return r; } constexpr afb_auth auth_not(const afb_auth &other) { return auth_not(&other); } constexpr afb_auth auth_or(const afb_auth *first, const afb_auth *next) { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_Or; r.first = first; r.next = next; return r; } constexpr afb_auth auth_or(const afb_auth &first, const afb_auth &next) { return auth_or(&first, &next); } constexpr afb_auth auth_and(const afb_auth *first, const afb_auth *next) { afb_auth r = { afb_auth_No, 0, 0}; r.type = afb_auth_And; r.first = first; r.next = next; return r; } constexpr afb_auth auth_and(const afb_auth &first, const afb_auth &next) { return auth_and(&first, &next); } constexpr afb_verb_t verb( const char *name, void (*callback)(afb_req_t), const char *info = nullptr, uint16_t session = 0, const afb_auth *auth = nullptr #if AFB_BINDING_VERSION >= 3 , bool glob = false, void *vcbdata = nullptr #endif ) { #if AFB_BINDING_VERSION >= 3 afb_verb_t r = { 0, 0, 0, 0, 0, 0, 0 }; #else afb_verb_t r = { 0, 0, 0, 0, 0 }; #endif r.verb = name; r.callback = callback; r.info = info; r.session = session; r.auth = auth; #if AFB_BINDING_VERSION >= 3 r.glob = (unsigned)glob; r.vcbdata = vcbdata; #endif return r; } constexpr afb_verb_t verbend() { afb_verb_t r = verb(nullptr, nullptr); return r; } constexpr afb_binding_t binding( const char *name, const afb_verb_t *verbs, const char *info = nullptr, #if AFB_BINDING_VERSION >= 3 int (*init)(afb_api_t) = nullptr, const char *specification = nullptr, void (*onevent)(afb_api_t, const char*, struct json_object*) = nullptr, bool noconcurrency = false, int (*preinit)(afb_api_t) = nullptr, void *userdata = nullptr #else int (*init)() = nullptr, const char *specification = nullptr, void (*onevent)(const char*, struct json_object*) = nullptr, bool noconcurrency = false, int (*preinit)() = nullptr #endif ) { #if AFB_BINDING_VERSION >= 3 afb_binding_t r = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #else afb_binding_t r = { 0, 0, 0, 0, 0, 0, 0, 0 }; #endif r.api = name; r.specification = specification; r.info = info; r.verbs = verbs; r.preinit = preinit; r.init = init; r.onevent = onevent; r.noconcurrency = noconcurrency ? 1 : 0; #if AFB_BINDING_VERSION >= 3 r.userdata = userdata; #endif return r; }; /*************************************************************************/ /*** E N D ***/ /*************************************************************************/ }