aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/java/m4/ax_prog_javadoc.m4
blob: bcb6045a828a8b4d5744d6121d9fb9aac6bbbfa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# ===========================================================================
#      http://www.gnu.org/software/autoconf-archive/ax_prog_javadoc.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_PROG_JAVADOC
#
# DESCRIPTION
#
#   AX_PROG_JAVADOC tests for an existing javadoc generator. It uses the
#   environment variable JAVADOC then tests in sequence various common
#   javadoc generator.
#
#   If you want to force a specific compiler:
#
#   - at the configure.in level, set JAVADOC=yourgenerator before calling
#   AX_PROG_JAVADOC
#
#   - at the configure level, setenv JAVADOC
#
#   You can use the JAVADOC variable in your Makefile.in, with @JAVADOC@.
#
#   Note: This macro depends on the autoconf M4 macros for Java programs. It
#   is VERY IMPORTANT that you download that whole set, some macros depend
#   on other. Unfortunately, the autoconf archive does not support the
#   concept of set of macros, so I had to break it for submission.
#
#   The general documentation of those macros, as well as the sample
#   configure.in, is included in the AX_PROG_JAVA macro.
#
# LICENSE
#
#   Copyright (c) 2008 Egon Willighagen <e.willighagen@science.ru.nl>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved. This file is offered as-is, without any
#   warranty.

#serial 8

AU_ALIAS([AC_PROG_JAVADOC], [AX_PROG_JAVADOC])
AC_DEFUN([AX_PROG_JAVADOC],[
AS_IF([test "x$JAVAPREFIX" = x],
      [test "x$JAVADOC" = x && AC_CHECK_PROGS([JAVADOC], [javadoc])],
      [test "x$JAVADOC" = x && AC_CHECK_PROGS([JAVADOC], [javadoc], [], [$JAVAPREFIX/bin])])
test "x$JAVADOC" = x && AC_MSG_ERROR([no acceptable javadoc generator found in \$PATH])
AC_PROVIDE([$0])dnl
])
String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/usr/bin/env python
#
# Copyright (c) 2016 Cisco and/or its affiliates.
# 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
# l
# 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.
#

import argparse
import importlib
import sys
import os

from jvppgen import callback_gen
from jvppgen import notification_gen
from jvppgen import dto_gen
from jvppgen import jvpp_callback_facade_gen
from jvppgen import jvpp_future_facade_gen
from jvppgen import jvpp_impl_gen
from jvppgen import jvpp_c_gen
from jvppgen import util

# Invocation:
# ~/Projects/vpp/vpp-api/jvpp/gen$ mkdir -p java/io/fd/vpp/jvpp && cd java/io/fd/vpp/jvpp
# ~/Projects/vpp/vpp-api/jvpp/gen/java/io/fd/vpp/jvpp$ ../../../../jvpp_gen.py -idefs_api_vpp_papi.py
#
# Compilation:
# ~/Projects/vpp/vpp-api/jvpp/gen/java/io/fd/vpp/jvpp$ javac *.java dto/*.java callback/*.java
#
# where
# defs_api_vpp_papi.py - vpe.api in python format (generated by vppapigen)
from jvppgen.util import vpp_2_jni_type_mapping

parser = argparse.ArgumentParser(description='VPP Java API generator')
parser.add_argument('-i', action="store", dest="inputfile")
parser.add_argument('--plugin_name', action="store", dest="plugin_name")
parser.add_argument('--control_ping_class', action="store", dest="control_ping_class", default="ControlPing")
args = parser.parse_args()

sys.path.append(".")

print "args.inputfile %s" % args.inputfile
importdir = os.path.dirname(args.inputfile)
print "importdir %s" % importdir
inputfile = os.path.basename(args.inputfile)
inputfile = inputfile.replace('.py', '')
print "inputfile %s" % inputfile
plugin_name = args.plugin_name
print "plugin_name %s" % plugin_name
control_ping_class = args.control_ping_class
print "control_ping_class %s" % control_ping_class
sys.path.append(importdir)
cfg = importlib.import_module(inputfile, package=None)


# FIXME: functions unsupported due to problems with vpe.api
def is_supported(f_name):
    return f_name not in {'vnet_ip4_fib_counters', 'vnet_ip6_fib_counters',
            'lisp_adjacencies_get_reply', 'lisp_adjacencies_get'}


def is_request_field(field_name):
    return field_name not in {'_vl_msg_id', 'client_index', 'context'}


def is_response_field(field_name):
    return field_name not in {'_vl_msg_id'}


def get_args(t, filter):
    arg_list = []
    for i in t:
        if not filter(i[1]):
            continue
        arg_list.append(i[1])
    return arg_list


def get_types(t, filter):
    types_list = []
    c_types_list = []
    lengths_list = []
    for i in t:
        if not filter(i[1]):
            continue
        if len(i) is 3:  # array type
            types_list.append(vpp_2_jni_type_mapping[i[0]] + 'Array')
            c_types_list.append(i[0] + '[]')
            lengths_list.append((i[2], False))
        elif len(i) is 4:  # variable length array type
            types_list.append(vpp_2_jni_type_mapping[i[0]] + 'Array')
            c_types_list.append(i[0] + '[]')
            lengths_list.append((i[3], True))
        else:  # primitive type
            types_list.append(vpp_2_jni_type_mapping[i[0]])
            c_types_list.append(i[0])
            lengths_list.append((0, False))
    return types_list, c_types_list, lengths_list


def get_definitions():
    # Pass 1
    func_list = []
    func_name = {}
    for a in cfg.messages:
        if not is_supported(a[0]):
            continue

        java_name = util.underscore_to_camelcase(a[0])

        # For replies include all the arguments except message_id
        if util.is_reply(java_name):
            types, c_types, lengths = get_types(a[1:], is_response_field)
            func_name[a[0]] = dict(
                [('name', a[0]), ('java_name', java_name),
                 ('args', get_args(a[1:], is_response_field)), ('full_args', get_args(a[1:], lambda x: True)),
                 ('types', types), ('c_types', c_types), ('lengths', lengths)])
        # For requests skip message_id, client_id and context
        else:
            types, c_types, lengths = get_types(a[1:], is_request_field)
            func_name[a[0]] = dict(
                [('name', a[0]), ('java_name', java_name),
                 ('args', get_args(a[1:], is_request_field)), ('full_args', get_args(a[1:], lambda x: True)),
                 ('types', types), ('c_types', c_types), ('lengths', lengths)])

        # Indexed by name
        func_list.append(func_name[a[0]])
    return func_list, func_name


func_list, func_name = get_definitions()

base_package = 'io.fd.vpp.jvpp'
plugin_package = base_package + '.' + plugin_name
dto_package = 'dto'
callback_package = 'callback'
notification_package = 'notification'
future_package = 'future'
# TODO find better package name
callback_facade_package = 'callfacade'
control_ping_class_fqn = "%s.%s.%s" % (plugin_package, dto_package, control_ping_class)

dto_gen.generate_dtos(func_list, base_package, plugin_package, plugin_name.title(), dto_package, args.inputfile)
jvpp_impl_gen.generate_jvpp(func_list, base_package, plugin_package, plugin_name, control_ping_class_fqn, dto_package, args.inputfile)
callback_gen.generate_callbacks(func_list, base_package, plugin_package, plugin_name.title(), callback_package, dto_package, args.inputfile)
notification_gen.generate_notification_registry(func_list, base_package, plugin_package, plugin_name.title(), notification_package, callback_package, dto_package, args.inputfile)
jvpp_c_gen.generate_jvpp(func_list, plugin_name, args.inputfile)
jvpp_future_facade_gen.generate_jvpp(func_list, base_package, plugin_package, plugin_name.title(), dto_package, callback_package, notification_package, future_package, args.inputfile)
jvpp_callback_facade_gen.generate_jvpp(func_list, base_package, plugin_package, plugin_name.title(), dto_package, callback_package, notification_package, callback_facade_package, args.inputfile)