Next Previous Up Top Contents Index

5 The Bank Client

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 classesaccount-interface,checkingAccount-interface, andbank-interface. These classes are used to present graphical interfaces to CORBA objects with the IDL interfacesaccount,checkingAccount, andbank.

We begin by defining the interface classaccount-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)
                  :min-width '(:character 10)
                  :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 classaccount-interface. We store the name of the customer owning this account in the title of the display pane (usinginitarg :title).

Theaccount-ref slot stores a CORBA object reference (of classBankingDemo:account) to the corresponding CORBAaccount object on the server. Thebank-interface slot stores a pointer to thebank interface for this object.

The panebalance-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 aninitialize-instance after method specialized on
account-interface. The value needs to be updated after each invocation of a CORBAdebit orcredit operation.

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

The buttons are laid out in a column layoutaccount-layout. Mirroring the fact that the IDL interfacecheckingAccount inherits fromaccount, we define the Common Lisp frame classchecking-account-interface as a subclass ofaccount-interface:

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

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

The layoutchecking-account-layout simply lays out the inherited layoutaccount-layout, containing the account's balance, together with the additionallimit-field.

The definition ofbank-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))

Theaccounts-area layout keeps track of theaccount-interfaces created by thebank interface as the result of invoking operations on the CORBAbank 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 callbacksopen-Account-callback,
open-Checking-Account-callback,retrieve-Account-callback, andclose-Account-callback.

These callbacks prompt the user for appropriate arguments and then invoke the corresponding CORBA operationsopenAccount,openCheckingAccount,retrieveAccount, andcloseAccount on the object reference stored in thebank-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 - 22 Jan 1999

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker