1:- module(aop_inspection,[
    2
    3  enable_aspect/1,
    4  disable_aspect/1,
    5
    6  enable_extension/3,
    7  disable_extension/3,
    8
    9  current_enabled_aspect/1,
   10  current_enabled_aspect/2,
   11  current_disabled_aspect/1,
   12  current_aspect/1,
   13  current_object/1,
   14  current_method/1
   15  ]).   16
   17% 
   18% Essential definitions for objects,  actions, methods, events
   19% 
   20
   21% aspect(Name)
   22:- dynamic(aop:aspect/1).   23:- multifile(aop:aspect/1).   24
   25% aspect_module(Name,Module)
   26:- dynamic(aop:aspect_module/2).   27:- multifile(aop:aspect_module/2).   28
   29:- dynamic(aop:aspect_enabled/2).   30:- multifile(aop:aspect_enabled/2).   31
   32% object(Aspect,Object,Module) -- used to record objects
   33:- dynamic(aop:object/3).   34:- multifile(aop:object/3).   35
   36% augmented(Aspect,Object,Module) -- used to record augmentation to objects
   37:- dynamic(aop:augmented/3).   38:- multifile(aop:augmented/3).   39
   40% method(Aspect, Object, Message)
   41:- dynamic(aop:method/3).   42:- multifile(aop:method/3).   43
   44% method_signature(Aspect, Object, Name/MethodArity, Signature, VariableNames)
   45:- dynamic(aop:method_signature/5).   46:- multifile(aop:method_signature/5).   47
   48% extended(Aspect, Object, Name/MethodArity)
   49:- dynamic(aop:extension/3).   50:- multifile(aop:extension/3).   51
   52% Enable extensions (e.g., events and actions)
   53enable_extension(Aspect, Object, Name/Arity) :-
   54  aop:extension(Aspect, Object, Name/Arity)
   55  -> true
   56  ; assertz(aop:extension(Aspect, Object, Name/Arity)).
   57
   58% Disable extensions (e.g., events and actions)
   59disable_extension(Aspect, Object, Name/Arity) :-
   60  retractall(aop:extension(Aspect, Object, Name/Arity)).
   61
   62% 
   63% Toggle aspect status -- disabled aspects do not execute
   64% 
   65enable_aspect(Aspect) :-
   66    retractall(aop:aspect_enabled(Aspect,_)),
   67    assertz(aop:aspect_enabled(Aspect, true)).
   68
   69disable_aspect(Aspect) :-
   70    retractall(aop:aspect_enabled(Aspect,_)),
   71    assertz(aop:aspect_enabled(Aspect, false)).
   72
   73% 
   74% Enumerators
   75% 
   76current_enabled_aspect(Aspect) :-
   77  current_aspect(Aspect),
   78  aop:aspect_enabled(Aspect,true).
   79
   80current_enabled_aspect(Aspect, Module) :-
   81  current_enabled_aspect(Aspect),
   82  aop:aspect_module(Aspect, Module),
   83  aop:aspect_enabled(Aspect,true).
   84
   85current_disabled_aspect(Aspect) :-
   86  current_aspect(Aspect),
   87  aop:aspect_enabled(Aspect,false).
   88
   89current_aspect(Aspect) :-
   90  aop:aspect(Aspect).
   91
   92current_object(Def) :-
   93  aop:object(Aspect, Object, Module),
   94  Def = aop:object(Aspect, Object, Module).
   95
   96current_method(Def) :-
   97  aop:method(Aspect, Object, Message),
   98  Def = aop:method(Aspect, Object, Message)