1%%--------------------------------------------------------------------
2%%
3%% %CopyrightBegin%
4%%
5%% Copyright Ericsson AB 1999-2016. All Rights Reserved.
6%%
7%% Licensed under the Apache License, Version 2.0 (the "License");
8%% you may not use this file except in compliance with the License.
9%% You may obtain a copy of the License at
10%%
11%%     http://www.apache.org/licenses/LICENSE-2.0
12%%
13%% Unless required by applicable law or agreed to in writing, software
14%% distributed under the License is distributed on an "AS IS" BASIS,
15%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16%% See the License for the specific language governing permissions and
17%% limitations under the License.
18%%
19%% %CopyrightEnd%
20%%
21%%
22%%----------------------------------------------------------------------
23%% File    : CosNotifyFilter_FilterFactory_impl.erl
24%% Purpose :
25%%----------------------------------------------------------------------
26
27-module('CosNotifyFilter_FilterFactory_impl').
28
29
30%%--------------- INCLUDES -----------------------------------
31%% Application files
32-include_lib("orber/include/corba.hrl").
33-include_lib("orber/include/ifr_types.hrl").
34%% Application files
35-include("CosNotification.hrl").
36-include("CosNotifyChannelAdmin.hrl").
37-include("CosNotifyComm.hrl").
38-include("CosNotifyFilter.hrl").
39-include("CosNotification_Definitions.hrl").
40
41%%--------------- IMPORTS ------------------------------------
42
43%%--------------- EXPORTS ------------------------------------
44%% External
45-export([create_filter/3,
46	 create_mapping_filter/4]).
47
48%%--------------- gen_server specific exports ----------------
49-export([handle_info/2, code_change/3]).
50-export([init/1, terminate/2]).
51
52%%--------------- LOCAL DEFINITIONS --------------------------
53%% Data structures
54-record(state, {adminProp,
55		etsR,
56		options}).
57
58%%-----------------------------------------------------------%
59%% function : handle_info, code_change
60%% Arguments: See gen_server documentation.
61%% Effect   : Functions demanded by the gen_server module.
62%%------------------------------------------------------------
63
64code_change(_OldVsn, State, _Extra) ->
65    {ok, State}.
66
67handle_info(_Info, State) ->
68    ?debug_print("INFO: ~p  DATA: ~p~n", [State, _Info]),
69    {noreply, State}.
70
71%%----------------------------------------------------------%
72%% function : init, terminate
73%% Arguments:
74%%-----------------------------------------------------------
75
76init(Options) ->
77    process_flag(trap_exit, true),
78    {ok, #state{options = Options}}.
79
80terminate(_Reason, _State) ->
81    ok.
82
83%%-----------------------------------------------------------
84%%------- Exported external functions -----------------------
85%%-----------------------------------------------------------
86%%----------------------------------------------------------%
87%% function : create_filter
88%% Arguments: InitGrammar - string()
89%% Returns  : CosNotifyFilter::Filter |
90%%            {'EXCEPTION', InvalidGrammar}
91%%-----------------------------------------------------------
92create_filter(OE_THIS, State, InitGrammar) ->
93    case lists:member(InitGrammar, ?not_SupportedGrammars) of
94	true ->
95	    SO = 'CosNotification_Common':get_option(server_options, State#state.options,
96						     ?not_DEFAULT_SETTINGS),
97	    Fi='CosNotifyFilter_Filter':oe_create_link([OE_THIS, self(),
98							InitGrammar],
99						       SO),
100	    {reply, Fi, State};
101	_ ->
102	    corba:raise(#'CosNotifyFilter_InvalidGrammar'{})
103    end.
104
105%%----------------------------------------------------------%
106%% function : create_mapping_filter
107%% Arguments: InitGrammar - string()
108%% Returns  : CosNotifyFilter::Filter |
109%%            {'EXCEPTION', InvalidGrammar}
110%%-----------------------------------------------------------
111create_mapping_filter(OE_THIS, State, InitGrammar, DefVal) ->
112    case lists:member(InitGrammar, ?not_SupportedGrammars) of
113	true ->
114	    SO = 'CosNotification_Common':get_option(server_options, State#state.options,
115						     ?not_DEFAULT_SETTINGS),
116	    Fi='CosNotifyFilter_MappingFilter':oe_create_link([OE_THIS, self(),
117							       InitGrammar, DefVal],
118							      SO),
119	    {reply, Fi, State};
120	_ ->
121	    corba:raise(#'CosNotifyFilter_InvalidGrammar'{})
122    end.
123
124%%--------------- LOCAL FUNCTIONS ----------------------------
125%%--------------- MISC FUNCTIONS, E.G. DEBUGGING -------------
126%%--------------- END OF MODULE ------------------------------
127