~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/cosTransactions/test/etrap_test_server_impl.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%%
 
4
%% Copyright Ericsson AB 1999-2010. All Rights Reserved.
 
5
%%
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%%
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%%
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%
 
20
-module(etrap_test_server_impl).
 
21
 
 
22
%%--------------- INCLUDES -----------------------------------
 
23
-include_lib("orber/include/corba.hrl").
 
24
-include_lib("orber/include/ifr_types.hrl").
 
25
%% Local
 
26
-include_lib("cosTransactions/src/ETraP_Common.hrl").
 
27
-include_lib("cosTransactions/include/CosTransactions.hrl").
 
28
%%--------------- IMPORTS-------------------------------------
 
29
%%--------------- EXPORTS-------------------------------------
 
30
-export([prepare/2, 
 
31
         rollback/2, 
 
32
         commit/2, 
 
33
         commit_one_phase/2, 
 
34
         forget/2,
 
35
%        before_completion/2,
 
36
%        after_completion/3,
 
37
         commit_subtransaction/3,
 
38
         rollback_subtransaction/2]).
 
39
 
 
40
 
 
41
%%--------------- gen_server specific ------------------------
 
42
-export([init/1, terminate/2]).
 
43
-export([handle_call/3, handle_cast/2, handle_info/2, code_change/3]).
 
44
 
 
45
%%------------------------------------------------------------
 
46
%% function : init, terminate
 
47
%%------------------------------------------------------------
 
48
init(State) ->
 
49
    process_flag(trap_exit,true),
 
50
    io:format("etrap_test_server:init ~p~n", [State]),
 
51
    ?debug_print("STARTING etrap_test_server( ~p )~n", [State]),
 
52
    {ok, State}.
 
53
 
 
54
terminate(Reason, _State) ->
 
55
    io:format("etrap_test_server:terminate ~p~n", [Reason]),
 
56
    ?debug_print("STOPREASON etrap_test_server( ~p )~n", [Reason]),
 
57
    ok.
 
58
 
 
59
code_change(_OldVsn, State, _Extra) ->
 
60
    {ok, State}.
 
61
handle_call(_,_, State) ->
 
62
    {noreply, State}.
 
63
handle_cast(_, State) ->
 
64
    {noreply, State}.
 
65
handle_info(_Info, State) ->
 
66
    {noreply, State}.
 
67
 
 
68
%%-- Inherit from CosTransactions::SubtransactionAwareResource --
 
69
prepare(_Self, State) ->    
 
70
    case ?is_debug_compiled of
 
71
        true ->
 
72
            io:format("etrap_test_server:prepare ~p~n", [State]);
 
73
        _->
 
74
            ok
 
75
    end,
 
76
%    ?debug_print("etrap_test_server:prepare ~p~n", [State]),
 
77
    action(prepare, State, {reply, 'VoteCommit', State}).
 
78
 
 
79
rollback(_Self, State) ->
 
80
    case ?is_debug_compiled of
 
81
        true ->
 
82
            io:format("etrap_test_server:rollback ~p~n", [State]);
 
83
        _->
 
84
            ok
 
85
    end,
 
86
%    ?debug_print("etrap_test_server:rollback ~p~n", [State]),
 
87
    case sync_test(State) of
 
88
        true ->
 
89
            action(rollback, State, {reply, ok, State});
 
90
        _->
 
91
            action(rollback, State, {stop, normal, ok, State})
 
92
    end.
 
93
 
 
94
commit(_Self, State) ->
 
95
    case ?is_debug_compiled of
 
96
        true ->
 
97
            io:format("etrap_test_server:commit ~p~n", [State]);
 
98
        _->
 
99
            ok
 
100
    end,
 
101
%    ?debug_print("etrap_test_server:commit ~p~n", [State]),
 
102
    case sync_test(State) of
 
103
        true ->
 
104
            action(commit, State, {reply, ok, State});
 
105
        _->
 
106
            action(commit, State, {stop, normal, ok, State})
 
107
    end.
 
108
 
 
109
commit_one_phase(_Self, State) ->
 
110
    case ?is_debug_compiled of
 
111
        true ->
 
112
            io:format("etrap_test_server:commit_one_phase ~p~n", [State]);
 
113
        _->
 
114
            ok
 
115
    end,
 
116
%    ?debug_print("etrap_test_server:commit_one_phase ~p~n", [State]),
 
117
    case sync_test(State) of
 
118
        true ->
 
119
            {reply, ok, State};
 
120
        _->
 
121
            {stop, normal, ok, State}
 
122
    end.
 
123
 
 
124
forget(_Self, State) ->
 
125
    case ?is_debug_compiled of
 
126
        true ->
 
127
            io:format("etrap_test_server:forget ~p~n", [State]);
 
128
        _->
 
129
            ok
 
130
    end,
 
131
%    ?debug_print("etrap_test_server:forget ~p~n", [State]),
 
132
    case sync_test(State) of
 
133
        true ->
 
134
            {reply, ok, State};
 
135
        _->
 
136
            {stop, normal, ok, State}
 
137
    end.
 
138
 
 
139
commit_subtransaction(_Self, State, Parent) ->
 
140
    case ?is_debug_compiled of
 
141
        true ->
 
142
            io:format("etrap_test_server:commit_subtransaction( ~p )~n", [Parent]);
 
143
        _->
 
144
            ok
 
145
    end,
 
146
%    ?debug_print("etrap_test_server:commit_subtransaction( ~p )~n", [Parent]),
 
147
    {reply, ok, State}.
 
148
rollback_subtransaction(_Self, State) ->
 
149
    case ?is_debug_compiled of
 
150
        true ->
 
151
            io:format("etrap_test_server:rollback_subtransaction()~n", []);
 
152
        _->
 
153
            ok
 
154
    end,
 
155
%    ?debug_print("etrap_test_server:rollback_subtransaction()~n", []),
 
156
    {reply, ok, State}.
 
157
 
 
158
%before_completion(_Self, State) ->
 
159
%    case ?is_debug_compiled of
 
160
%       true ->
 
161
%           io:format("etrap_test_server:before_completion()~n", []);
 
162
%       _->
 
163
%           ok
 
164
%    end,
 
165
%%    ?debug_print("etrap_test_server:before_completion()~n", []),
 
166
%    {reply, ok, State}.
 
167
%after_completion(_Self, State, Status) ->
 
168
%    case ?is_debug_compiled of
 
169
%       true ->
 
170
%           io:format("etrap_test_server:after_completion( ~p )~n", [Status]);
 
171
%       _->
 
172
%           ok
 
173
%    end,
 
174
%%    ?debug_print("etrap_test_server:after_completion( ~p )~n", [Status]),
 
175
%    {stop, normal, ok, State}.
 
176
 
 
177
%%--------------- LOCAL FUNCTIONS ----------------------------
 
178
action(Key, State, Default) ->
 
179
    case catch lists:keysearch(Key, 1, State) of
 
180
        {value,{Key, stop_reply, R}} ->
 
181
            case sync_test(State) of
 
182
                true ->
 
183
                    {reply, R, State};
 
184
                _->
 
185
                    {stop, normal, R, State}
 
186
            end;
 
187
        {value,{Key, reply, R}} ->
 
188
            {reply, R, State};
 
189
        {value,{Key, exc, E}} ->
 
190
            corba:raise(E);
 
191
        {value,{Key, delay, Time}} ->
 
192
            timer:sleep(Time*1000),
 
193
            Default;
 
194
        {value,{Key,Value}} ->
 
195
            Value;
 
196
        _ ->
 
197
            Default
 
198
    end.
 
199
 
 
200
sync_test(State) ->
 
201
    case catch lists:keysearch(sync, 1, State) of
 
202
        {value,{sync, true}} ->
 
203
            true;
 
204
        _ ->
 
205
            false
 
206
    end.
 
207
 
 
208
 
 
209
%%--------------- END OF MODULE ------------------------------
 
210