Skip to content
Snippets Groups Projects
Select Git revision
  • 877f8cd210e097eda649487bca81fcaa73517ea8
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

bindings.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    bindings.cpp 2.55 KiB
    /*
     *  Copyright (C) 2021 Savoir-faire Linux Inc.
     *
     *  Author: Olivier Dion <olivier.dion@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program is distributed in the hope that it will be useful,
     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     *  GNU General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program; if not, write to the Free Software
     *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
     */
    
    /* Agent */
    #include "bindings/bindings.h"
    
    /* Include module's bindings here */
    #include "bindings/account.h"
    #include "bindings/call.h"
    #include "bindings/signal.h"
    
    void
    install_scheme_primitives()
    {
        /* Define modules here */
        scm_c_define_module("jami account", install_account_primitives, NULL);
        scm_c_define_module("jami call", install_call_primitives, NULL);
        scm_c_define_module("jami signal", install_signal_primitives, NULL);
    }
    
    /*
     * Register Guile bindings here.
     *
     * 1. Name of the binding
     * 2. Number of required argument to binding
     * 3. Number of optional argument to binding
     * 4. Number of rest argument to binding
     * 5. Pointer to C function to call
     *
     * See info guile:
     *
     * Function: SCM scm_c_define_gsubr(const char *name, int req, int opt, int rst, fcn):
     *
     * Register a C procedure FCN as a “subr” — a primitive subroutine that can be
     * called from Scheme.  It will be associated with the given NAME and bind it in
     * the "current environment".  The arguments REQ, OPT and RST specify the number
     * of required, optional and “rest” arguments respectively.  The total number of
     * these arguments should match the actual number of arguments to FCN, but may
     * not exceed 10.  The number of rest arguments should be 0 or 1.
     * ‘scm_c_make_gsubr’ returns a value of type ‘SCM’ which is a “handle” for the
     * procedure.
     */
    void
    define_primitive(const char* name, int req, int opt, int rst, void* func)
    {
            AGENT_ASSERT(req + opt + rst <= 10, "Primitive binding `%s` has too many argument", name);
    
            AGENT_ASSERT(0 == rst or 1 == rst, "Rest argument for binding `%s` must be 0 or 1", name);
    
            scm_c_define_gsubr(name, req, opt, rst, func);
            scm_c_export(name, NULL);
    }