1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
19
%% Purpose: Provide complete encode/and pre-decode of asn1.
24
-behaviour(gen_server).
26
-export([start_link/0,client_port/0]).
28
%% Internal exports, call-back functions.
29
-export([init/1,handle_call/3,handle_cast/2,handle_info/2,code_change/3,
35
{ asn1_drv01, asn1_drv02, asn1_drv03, asn1_drv04,
36
asn1_drv05, asn1_drv06, asn1_drv07, asn1_drv08,
37
asn1_drv09, asn1_drv10, asn1_drv11, asn1_drv12,
38
asn1_drv13, asn1_drv14, asn1_drv15, asn1_drv16 }).
39
%%% --------------------------------------------------------
40
%%% Interface Functions.
41
%%% --------------------------------------------------------
44
gen_server:start_link({local, asn1_server}, asn1_server, [], []).
47
process_flag(trap_exit, true),
49
PrivDir = code:priv_dir(asn1),
50
LibDir1 = filename:join([PrivDir, "lib"]),
51
case erl_ddll:load_driver(LibDir1, asn1_erl_drv) of
55
filename:join(LibDir1,
56
erlang:system_info(system_architecture)),
57
erl_ddll:load_driver(LibDir2, asn1_erl_drv)
59
open_ports("asn1_erl_drv",size(?port_names)).
64
Port = open_port({spawn, Cmd}, []),
65
%% check that driver is loaded, linked and working
66
case catch port_control(Port, 0, []) of
70
register(element(N,?port_names), Port),
75
element(erlang:system_info(scheduler_id) rem size(?port_names) + 1,
79
%%% --------------------------------------------------------
80
%%% The call-back functions.
81
%%% --------------------------------------------------------
83
handle_call(_, _, State) ->
86
handle_cast(_, State) ->
89
handle_info({'EXIT', Pid, _Reason}, State) when is_pid(Pid) ->
92
handle_info({'EXIT', Port, Reason}, State) when is_port(Port) ->
93
{stop, {port_died, Reason}, State};
94
handle_info(_, State) ->
97
code_change(_OldVsn, State, _Extra) ->
100
terminate(_Reason, _State) ->
101
close_ports(size(?port_names)).
106
element(N,?port_names) ! {self(), close}, %% almost same as port_close(Name)