Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:25
erlang
4162-megaco-Types-and-spec-for-megaco_flex_scan...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 4162-megaco-Types-and-spec-for-megaco_flex_scanner-is_sca.patch of Package erlang
From 0ae75e225639e050d534056352de98e68ed61b7c Mon Sep 17 00:00:00 2001 From: Micael Karlberg <bmk@erlang.org> Date: Mon, 8 Jan 2024 15:59:56 +0100 Subject: [PATCH 42/46] [megaco] Types and spec for megaco_flex_scanner:is_scanner_port/2 OTP-18920 --- lib/megaco/doc/src/Makefile | 13 ++--- lib/megaco/doc/src/megaco_flex_scanner.xml | 34 ++++++++++--- lib/megaco/doc/src/specs.xml | 1 + lib/megaco/src/flex/megaco_flex_scanner.erl | 53 ++++++++++++++++----- 4 files changed, 76 insertions(+), 25 deletions(-) diff --git a/lib/megaco/doc/src/Makefile b/lib/megaco/doc/src/Makefile index 15c0c97a87..725156fdf3 100644 --- a/lib/megaco/doc/src/Makefile +++ b/lib/megaco/doc/src/Makefile @@ -49,7 +49,8 @@ SPECS_FILES = \ $(SPECDIR)/specs_megaco_encoder.xml \ $(SPECDIR)/specs_megaco_digit_map.xml \ $(SPECDIR)/specs_megaco_sdp.xml \ - $(SPECDIR)/specs_megaco_user.xml + $(SPECDIR)/specs_megaco_user.xml \ + $(SPECDIR)/specs_megaco_flex_scanner.xml TOP_SPECS_FILE = specs.xml NO_CHUNKS = megaco_edist_compress.xml \ @@ -72,8 +73,8 @@ $(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/app/%.erl $(TOP_SPECS_FILE) # $(gen_verbose)escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) -o$(dir $@) $< $(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/engine/%.erl $(TOP_SPECS_FILE) $(gen_verbose)escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) -o$(dir $@) $< -# $(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/flex/%.erl $(TOP_SPECS_FILE) -# $(gen_verbose)escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) -o$(dir $@) $< +$(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/flex/%.erl $(TOP_SPECS_FILE) + $(gen_verbose)escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) -o$(dir $@) $< # $(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/tcp/%.erl $(TOP_SPECS_FILE) # $(gen_verbose)escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) -o$(dir $@) $< # $(SPECDIR)/specs_%.xml: $(SPECS_ESRC)/udp/%.erl $(TOP_SPECS_FILE) @@ -98,9 +99,9 @@ $(SPECDIR)/specs_megaco_compress.xml: #$(SPECDIR)/specs_megaco_encoder.xml: # escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) \ # -o$(dir $@) -module megaco_encoder -$(SPECDIR)/specs_megaco_flex_scanner.xml: - escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) \ - -o$(dir $@) -module megaco_flex_scanner +# $(SPECDIR)/specs_megaco_flex_scanner.xml: +# escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) \ +# -o$(dir $@) -module megaco_flex_scanner $(SPECDIR)/specs_megaco_tcp.xml: escript $(SPECS_EXTRACTOR) $(SPECS_FLAGS) \ -o$(dir $@) -module megaco_tcp diff --git a/lib/megaco/doc/src/megaco_flex_scanner.xml b/lib/megaco/doc/src/megaco_flex_scanner.xml index 1d7c5a4477..2a04721b4b 100644 --- a/lib/megaco/doc/src/megaco_flex_scanner.xml +++ b/lib/megaco/doc/src/megaco_flex_scanner.xml @@ -4,7 +4,7 @@ <erlref> <header> <copyright> - <year>2001</year><year>2020</year> + <year>2001</year><year>2024</year> <holder>Ericsson AB. All Rights Reserved.</holder> </copyright> <legalnotice> @@ -57,6 +57,18 @@ </description> + <datatypes> + <datatype> + <name name="megaco_ports"/> + <desc> + <p> + Return value of a successful (flex) scanner start. + </p> + </desc> + </datatype> + </datatypes> + + <section> <title>DATA TYPES</title> <code type="none"><![CDATA[ @@ -80,14 +92,17 @@ megaco_version() = integer() >= 1 </type> <desc> <p>This function is used to start the flex scanner. - It locates the library and loads the linked in driver.</p> + It locates the library and loads the linked in driver.</p> - <p>On a single core system or if it's a non-reentrant scanner, - a single port is created. On a multi-core system with a reentrant - scanner, several ports will be created (one for each scheduler). </p> + <p>On a single core system or if it's a non-reentrant + scanner, a single port is created. On a multi-core + system with a reentrant scanner, several ports will + be created (one for each scheduler). </p> - <p>Note that the process that calls this function <em>must</em> - be permanent. If it dies, the port(s) will exit and the driver unload.</p> + <p>Note that the process that calls this function + <em>must</em> be permanent. + If it dies, the port(s) will exit and the driver + unload.</p> <marker id="stop"></marker> </desc> @@ -121,13 +136,18 @@ megaco_version() = integer() >= 1 </func> <func> + <name name="is_scanner_port" arity="2" clause_i="1" since=""/> + <!-- <name since="">is_scanner_port(Port, PortOrPorts) -> Boolean</name> + --> <fsummary></fsummary> + <!-- <type> <v>Port = port()</v> <v>PortOrPorts = megaco_ports()</v> <v>Boolean = boolean()</v> </type> + --> <desc> <p>Checks if a port is a flex scanner port or not (useful when if a port exits). </p> diff --git a/lib/megaco/doc/src/specs.xml b/lib/megaco/doc/src/specs.xml index 14393c70aa..619dbc084d 100644 --- a/lib/megaco/doc/src/specs.xml +++ b/lib/megaco/doc/src/specs.xml @@ -5,4 +5,5 @@ <xi:include href="../specs/specs_megaco_encoder.xml"/> <xi:include href="../specs/specs_megaco_sdp.xml"/> <xi:include href="../specs/specs_megaco_user.xml"/> + <xi:include href="../specs/specs_megaco_flex_scanner.xml"/> </specs> diff --git a/lib/megaco/src/flex/megaco_flex_scanner.erl b/lib/megaco/src/flex/megaco_flex_scanner.erl index bcc58b7e8d..4c0bac739e 100644 --- a/lib/megaco/src/flex/megaco_flex_scanner.erl +++ b/lib/megaco/src/flex/megaco_flex_scanner.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 2001-2023. All Rights Reserved. +%% Copyright Ericsson AB 2001-2024. All Rights Reserved. %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. @@ -27,10 +27,43 @@ -export([is_enabled/0, is_reentrant_enabled/0, is_scanner_port/2]). -export([start/0, start/1, stop/1, scan/2]). +-export_type([ + megaco_ports/0 + ]). + + +%%---------------------------------------------------------------------- + +-opaque megaco_ports() :: port() | tuple(). + + +%%---------------------------------------------------------------------- + -define(NUM_SCHED(), erlang:system_info(schedulers)). -define(SCHED_ID(), erlang:system_info(scheduler_id)). -define(SMP_SUPPORT_DEFAULT(), erlang:system_info(smp_support)). + +%%---------------------------------------------------------------------- + +-ifndef(ENABLE_MEGACO_FLEX_SCANNER). +%% This crap is hopefully temporary! +%% It is because our current doc build +%% script (specs file generation) has +%% no way to pass this value in as the +%% normal compilatrion (erlc) does. +-define(ENABLE_MEGACO_FLEX_SCANNER, true). +-endif. + +-ifndef(MEGACO_REENTRANT_FLEX_SCANNER). +%% This crap is hopefully temporary! +%% It is because our current doc build +%% script (specs file generation) has +%% no way to pass this value in as the +%% normal compilatrion (erlc) does. +-define(MEGACO_REENTRANT_FLEX_SCANNER, true). +-endif. + -dialyzer({nowarn_function, is_enabled/0}). -spec is_enabled() -> boolean(). is_enabled() -> @@ -41,6 +74,13 @@ is_enabled() -> is_reentrant_enabled() -> (true =:= ?MEGACO_REENTRANT_FLEX_SCANNER). + +%%---------------------------------------------------------------------- + +-spec is_scanner_port(Port, PortOrPorts) -> boolean() when + Port :: port(), + PortOrPorts :: megaco_ports(). + is_scanner_port(Port, Port) when is_port(Port) -> true; is_scanner_port(Port, Ports) when is_tuple(Ports) -> @@ -155,35 +195,24 @@ stop(Ports) when is_list(Ports) -> scan(Binary, Port) when is_port(Port) -> do_scan(Binary, Port); scan(Binary, Ports) when is_tuple(Ports) -> -%% p("scan -> entry with" -%% "~n Ports: ~p", [Ports]), do_scan(Binary, select_port(Ports)). do_scan(Binary, Port) -> -%% p("do_scan -> entry with" -%% "~n Port: ~p", [Port]), case erlang:port_control(Port, $s, Binary) of [] -> receive {tokens, Tokens, LatestLine} -> -%% p("do_scan -> OK with:" -%% "~n length(Tokens): ~p" -%% "~n LatestLine: ~p", [length(Tokens), LatestLine]), Vsn = version(Tokens), {ok, Tokens, Vsn, LatestLine} after 5000 -> -%% p("do_scan -> ERROR", []), {error, "Driver term send failure", 1} end; Reason -> -%% p("do_scan -> port control failed: " -%% "~n Reason: ~p", [Reason]), {error, Reason, 1} end. select_port(Ports) -> SchedId = ?SCHED_ID(), - %% lists:nth(SchedId, Ports). element(SchedId, Ports). version([]) -> -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor