Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 1 | %%% Copyright (c) 2007- Facebook |
| 2 | %%% Distributed under the Thrift Software License |
| 3 | %%% |
| 4 | %%% See accompanying file LICENSE or visit the Thrift site at: |
| 5 | %%% http://developers.facebook.com/thrift/ |
| 6 | |
| 7 | -module(tErlProcessor). |
| 8 | |
Christopher Piro | 5b3a8f7 | 2007-08-01 22:27:37 +0000 | [diff] [blame] | 9 | -include("thrift.hrl"). |
Christopher Piro | 094823a | 2007-07-18 00:26:12 +0000 | [diff] [blame] | 10 | -include("oop.hrl"). |
| 11 | -include("tErlProcessor.hrl"). |
| 12 | |
| 13 | -behavior(oop). |
| 14 | |
| 15 | -export([attr/4, super/0, inspect/1]). |
| 16 | |
| 17 | -export([new/2, process/3]). |
| 18 | |
| 19 | %%% |
| 20 | %%% define attributes |
| 21 | %%% 'super' is required unless ?MODULE is a base class |
| 22 | %%% |
| 23 | |
| 24 | ?DEFINE_ATTR(super); |
| 25 | ?DEFINE_ATTR(generatedProcessor); |
| 26 | ?DEFINE_ATTR(handler). |
| 27 | |
| 28 | %%% |
| 29 | %%% behavior callbacks |
| 30 | %%% |
| 31 | |
| 32 | %%% super() -> SuperModule = atom() |
| 33 | %%% | none |
| 34 | |
| 35 | super() -> |
| 36 | tProcessor. |
| 37 | |
| 38 | %%% inspect(This) -> string() |
| 39 | |
| 40 | inspect(This) -> |
| 41 | ?FORMAT_ATTR(generatedProcessor) ++ ", " ++ |
| 42 | ?FORMAT_ATTR(handler). |
| 43 | |
| 44 | %%% |
| 45 | %%% class methods |
| 46 | %%% |
| 47 | |
| 48 | new(GP, Handler) -> |
| 49 | Super = (super()):new(), |
| 50 | #?MODULE{super = Super, generatedProcessor = GP, handler = Handler}. |
| 51 | |
| 52 | %% processor is generated code |
| 53 | %% handler is user code |
| 54 | |
| 55 | %%% |
| 56 | %%% instance methods |
| 57 | %%% |
| 58 | |
| 59 | process(This, Iprot, Oprot) -> |
| 60 | GP = oop:get(This, generatedProcessor), |
| 61 | Handler = oop:get(This, handler), |
Christopher Piro | 5b3a8f7 | 2007-08-01 22:27:37 +0000 | [diff] [blame] | 62 | |
Christopher Piro | ee59884 | 2007-08-03 23:34:55 +0000 | [diff] [blame] | 63 | GP:process(Handler, Iprot, Oprot). |