NextPrevUpTopContentsIndex

5.4 Defining the interfaces

Note: This section assumes some basic familiarity with the CAPI library. See the CAPI Reference Manual for details.

In this section, we define three CAPI interface classes account-interface , checkingAccount-interface , and bank-interface . These classes are used to present graphical interfaces to CORBA objects with the IDL interfaces account , checkingAccount , and bank .

We begin by defining the interface class account-interface :

(capi:define-interface account-interface ()
  ((account-ref :initarg :account-ref)
   (account-name :initarg :account-name :accessor account-name)
   (bank-interface :initarg :owner))
  (:panes
   (balance-field capi:display-pane 
                  :title (:initarg :account-name)
                  :visible-min-width '(:character 10)
                  :visible-max-width nil)
   (button-panel capi:push-button-panel 
                 :callbacks '(credit debit)
                 :items '("Credit" "Debit")
                 :callback-type :interface))
  (:layouts 
   (account-layout capi:column-layout '(balance-field 
                                        button-panel)))
  (:default-initargs :auto-menus nil :max-width t))

This is how we use an instance of class account-interface . We store the name of the customer owning this account in the title of the display pane (using initarg :title ).

The account-ref slot stores a CORBA object reference (of class BankingDemo:accoun t) to the corresponding CORBA account object on the server. The bank-interface slot stores a pointer to the bank interface for this object.

The pane balance-field reports the state of the CORBA object's balance attribute as a readonly text field. We delegate the initialization of this field value to an initialize-instance after method specialized on
account-interface . The value needs to be updated after each invocation of a CORBA debit or credit operation.

The button panel button-panel defines buttons to activate callbacks
debit-callback and credit-callback . These callbacks prompt the user for amounts and then invoke the corresponding CORBA operations debit and credit on the object reference stored in the account-ref field. We will implement these callbacks in a moment.

The buttons are laid out in a column layout account-layout . Mirroring the fact that the IDL interface checkingAccount inherits from account , we define the Common Lisp frame class checking-account-interface as a subclass of account-interface :

(capi:define-interface checking-account-interface 
    (account-interface) ()
  (:panes
   (limit-field capi:display-pane 
                :visible-min-width '(:character 10)
                :visible-max-width nil))
  (:layouts
   (checking-account-layout capi:column-layout 
                            '(account-layout limit-field))))

The pane limit-field reports the state of the CORBA object's limit attribute as a readonly text field. Again, we can delegate the initialization of this field's value to an initialize instance after method specialized on
checking-account-interface .

The layout checking-account-layout simply lays out the inherited layout account-layout , containing the account's balance, together with the additional limit-field .

The definition of bank-interface class follows the same pattern:

(capi:define-interface bank-interface ()
  ((bank-ref :initarg :bank-ref))
  (:menu-bar open-actions)
  (:menus
   (open-actions
    "Action"
    (("Open Account" :callback 'open-account-callback)
     ("Open Checking Account" :callback 
                              'open-checking-account-callback)
     ("Retrieve Account" :callback 'retrieve-account-callback)
     ("Close Account" :callback 'close-account-callback))
    :callback-type :interface))
  (:layouts 
   (accounts-area capi:row-layout () 
                  :accessor accounts-area
                  :horizontal-scroll t))
  (:default-initargs :auto-menus nil :best-width 400))

The accounts-area layout keeps track of the account-interfaces created by the bank interface as the result of invoking operations on the CORBA bank object. This list is maintained to prevent the user from obtaining more than one interface to the same account. We need to update it whenever an account interface is exited.

The interface menu items Open Account , Open Checking Account , Retrieve Account , and Close Account activate callbacks open-Account-callback ,
open-Checking-Account-callback , retrieve-Account-callback , and close-Account-callback .

These callbacks prompt the user for appropriate arguments and then invoke the corresponding CORBA operations openAccount , openCheckingAccount , retrieveAccount , and closeAccount on the object reference stored in the bank-ref slot. We will see the implementation of these callbacks in a moment.

5.4.1 Initializing and exiting account frames

5.4.2 Defining the callbacks

5.4.3 Initializing the ORB and obtaining the first object reference


Developing Component Software with CORBA - 30 Oct 2007

NextPrevUpTopContentsIndex