blob: fc033310b3e17bdf6adee3e7df95a1c04a5cfb47 [file] [log] [blame]
Christopher Piro094823a2007-07-18 00:26:12 +00001%%% Copyright (c) 2007- Facebook
2%%% Distributed under the Thrift Software License
David Reiss0c90f6f2008-02-06 22:18:40 +00003%%%
Christopher Piro094823a2007-07-18 00:26:12 +00004%%% See accompanying file LICENSE or visit the Thrift site at:
5%%% http://developers.facebook.com/thrift/
6
7-module(tServer).
8
9-include("oop.hrl").
10
11-include("thrift.hrl").
12-include("server/tServer.hrl").
13-include("transport/tTransportFactory.hrl").
14-include("protocol/tBinaryProtocolFactory.hrl").
15
16-behavior(oop).
17
18-export([attr/4, super/0, inspect/1]).
19
20-export([new/5, new/4, new/3, serve/1]).
21
22%%%
23%%% define attributes
24%%% 'super' is required unless ?MODULE is a base class
25%%%
26
27?DEFINE_ATTR(handler);
28?DEFINE_ATTR(processor);
29?DEFINE_ATTR(serverTransport);
30?DEFINE_ATTR(transportFactory);
31?DEFINE_ATTR(protocolFactory).
David Reiss0c90f6f2008-02-06 22:18:40 +000032
Christopher Piro094823a2007-07-18 00:26:12 +000033%%%
34%%% behavior callbacks
35%%%
David Reiss0c90f6f2008-02-06 22:18:40 +000036
Christopher Piro094823a2007-07-18 00:26:12 +000037%%% super() -> SuperModule = atom()
38%%% | none
39
40super() ->
41 none.
42
43%%% inspect(This) -> string()
44
45inspect(This) ->
46 ?FORMAT_ATTR(handler) ++ ", " ++
47 ?FORMAT_ATTR(processor) ++ ", " ++
48 ?FORMAT_ATTR(serverTransport) ++ ", " ++
49 ?FORMAT_ATTR(transportFactory) ++ ", " ++
50 ?FORMAT_ATTR(protocolFactory).
51
52%%%
53%%% class methods
54%%%
55
56new(Handler, Processor, ServerTransport, TransportFactory, ProtocolFactory) ->
57 #?MODULE{handler=Handler, processor=Processor, serverTransport=ServerTransport,
58
59 %% much ado about nothing but
60 %% subclasses pass nil too
David Reiss0c90f6f2008-02-06 22:18:40 +000061 transportFactory =
Christopher Piro094823a2007-07-18 00:26:12 +000062 case TransportFactory of
63 nil -> tTransportFactory:new();
64 _ -> TransportFactory
65 end,
David Reiss0c90f6f2008-02-06 22:18:40 +000066
67 protocolFactory =
Christopher Piro094823a2007-07-18 00:26:12 +000068 case ProtocolFactory of
69 nil -> tBinaryProtocolFactory:new();
70 _ -> ProtocolFactory
David Reiss0c90f6f2008-02-06 22:18:40 +000071 end
Christopher Piro094823a2007-07-18 00:26:12 +000072}.
73
74new(Handler, Processor, ServerTransport) ->
75 new(Handler, Processor, ServerTransport, nil, nil).
76
77new(Handler, Processor, ServerTransport, TransportFactory) ->
78 new(Handler, Processor, ServerTransport, TransportFactory, nil).
79
80serve(_This) ->
81 ok.