[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference pamsrc::objectbroker_development

Title:ObjectBroker Development - BEA Systems' CORBA
Notice:See note 2 for kit locations; note 4 for training
Moderator:RECV::GUMBELd
Created:Thu Dec 27 1990
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2482
Total number of notes:13057

2441.0. "QuickStart question" by STKAI1::T_ANDERSSON (Tomas Andersson) Mon Feb 24 1997 09:17

 While experimenting with an OLE interface for the BANK.IDL example, I got
 confused when trying to generate an object server with QuickStart.

 In the IDL file, we have

	interface AcctFactory
	{
		Account   CreateAcct  (	in  ACCT_TYPES  acctType,
					in  Money  amount,
					out AccountId  acctId);

 which should create an Account object.

 When looking at the C file, it appears that CORBA_BOA_create actually creates
 an AcctFactory-object, rather than an Account object?!? Is this really the
 way it's supposed to be?

 This is OBB v2.7-11 on NT v4.0. IDL and C files follow.

 Thanks for your time,

 - Tomas A -



<<File: MLBANK.IDL>>

//
==============================================================================
// ===  IDL NUMBER 5.                                                        
===
//
==============================================================================
//
// Used in BANK EXAMPLES 7, 9, 10, 11 & 12.
//
// Description:
//
//     The Account interface defines an abstract object. An abstract object
//     is not modeled after a specific real-world object, but rather represents
//     general characteristics common to a group of real-world objects.  In
//     this case, the operations common to both CheckAcct and SaveAcct are
//     defined under Account.
//
//     The operations are not defined again under CheckAcct and SaveAcct,
//     because these interfaces inherit them from the Account interface.
//     Inheritance allows objects to inherit bahavior from one or more
//     interfaces.
//
//     Inheritance makes polymorphism possible. Polymorphism allows the server
//     to respond in more than one way to the same request.  In our example,
//     the client can request that an operation be performed on an Account
//     object (ie. BANK_Account_Deposit).  However, there are no instances
//     of Account, because it is an abstract object.  But there are instances
//     of both CheckAcct and SaveAcct, which inherit all the behavior defined
//     under the Account interface.  While in this example the processing logic
//     for a deposit operation in the CheckAcct implementation is the same as
//     that in the SaveAcct implementation, the fact is different methods are
//     called and the logic could easily differ between checking and savings.
//     ObjectBroker uses the object reference passed in the request to
//     determine which method to use to satisfy the request.
//
//
//  Notes:
//
//     We followed standard practice by using uppercase letters in the module
//     name, and initial capital letters when naming the interfaces and
//     operations.
//
//     To avoid possible confusion, we did not use underscores in any names,
//     because the IDL compiler uses underscores as separators when
constructing
//     the fully scoped names of the interface and its operations.  A fully
//     scoped name takes the form MODULE_INTERFACE_OPERATION.  For instance,
//     the following names are generated from this IDL file, and are used by
//     both the client and the server when they reference the interface and
//     operations.
//
//     BANK_CheckAcct will be generated for the CheckAcct interface.
//     BANK_CheckAcct_Deposit will be generated for the Deposit operation.
//
//     If CheckAcct were named Check_Acct, a programmer seeing BANK_Check_Acct
//     might mistakenly believe Acct to be an operation.
//
//     In addition, some compilers truncate names longer than 31 characters,
//     so greater portability is achieved when the constructed names are
//     unique within the first 31 characters.
//
//==============================================================================
//  While CORBA does not require the use of modules, it is good programming
//  practice to group related interface definitions together within a module.
//  For our examples, we shall define all our interfaces within the module
//  BANK.module MLBANK
// 

module declaration
{   

//  Data types defined within the module but before the interface   
//  definitions are global to the module, so are available to all   
//  interfaces within the module.                                                 

	typedef float Money;
	typedef long AccountId;
	enum ACCT_TYPES { Savings, Checking };
	enum ERR_TYPES { AcctNoExist, AcctNoFunds };
	exception WrongAcctId { AccountID acctId; };
	exception InsuffFunds { Money balance; };   

// For each interface defined in the IDL, ObjectBroker generates a typedef
//  casting the interface name as a "CORBA_Object" data type.  So for
//  Account, ObjectBroker generates: "typedef CORBA_Object Account".
// This allows us to use Account as the data type for the return value
//  of the CreateAcct and LookupAcct operations.  However, the IDL compiler   
//  needs to know that Account will be defined as an interface before   
//  we can use it as a data type, which means we must define the Account   
//  interface before the AcctFactory interface.
// Account is an abstract object, which means there are no real-world
//  instances of account.  There are real-world instances of CheckAcct
//  and SaveAcct, which inherit all the properties of Account.

	interface Account
	{
		readonly attribute Money balance;   	// Define "fetch"
operations to
		readonly attribute ACCT_TYPES acctType;	//   get current
balance and                                               
							//   account type.
		void Deposit (in Money amount,   	// Deposit amount, and
the new
                      out Money	newBalance);    	//   balance of the
account.
		void Withdraw (in Money amount,         // Withdrawal amount,
and the                     
		out Money newBalance)     		//   new balance of the
account.       
		raises (InsuffFunds);         		// Withdraw can return
an error
							//   for insufficient
funds.
	};

	interface AcctFactory
	{
		Account CreateAcct (in ACCT_TYPES  acctType,
			    in  Money      amount,
                            out AccountId  acctId);
		Account   LookupAcct (in AccountId   acctId)
			raises (WrongAcctId);
	};

// The "interface CheckAcct:Account" declaration not only defines the
// interface CheckAcct, but also indicates that CheckAcct inherits all
// the attributes and operations defined under Account.

interface CheckAcct:Account
	{
		void StopPayment (in  long  checkNum);   // Pass in check
number to stop
	        	                                 // payment.
	};

// The "interface SaveAcct:Account" declaration not only defines the
// interface SaveAcct, but also indicates that SaveAcct inherits all
// the attributes and operations defined under Account.

	interface SaveAcct:Account
	{
	};

	interface ServerMgr
	{
		void StopServer ( );			// Shutdown the server.
	};

};

// end of module BANK

#pragma repository_id("MLBANK::Money",
	"6fc6f613964c.02.c7.7d.48.6d.00.00.00")
#pragma repository_id("MLBANK::AccountId",
	"6fc6f6139928.02.c7.7d.48.6d.00.00.00")
#pragma repository_id("MLBANK::ACCT_TYPES",
	"6fc6f6139a1c.02.c7.7d.48.6d.00.00.00")
#pragma repository_id("MLBANK::ERR_TYPES", 
	"6fc6f6139b10.02.c7.7d.48.6d.00.00.00")
#pragma repository_id("MLBANK::WrongAcctId",
	"6fc6f6139c04.02.c7.7d.48.6d.00.00.00")
#pragma repository_id("MLBANK::InsuffFunds",
	"6fc6f6139cf8.02.c7.7d.48.6d.00.00.00")
#pragma interface_id("MLBANK::AcctFactory",
	"6fc6f6139dec.02.c7.7d.48.6d.00.00.00")
#pragma operation_id("MLBANK::AcctFactory::CreateAcct",
	"6fc6f6139ded.02.c7.7d.48.6d.00.00.00", 1)
#pragma operation_id("MLBANK::AcctFactory::LookupAcct",
	"6fc6f6139ee0.02.c7.7d.48.6d.00.00.00", 2)
#pragma interface_id("MLBANK::Account",
	"6fc6f6139fd4.02.c7.7d.48.6d.00.00.00")
#pragma attribute_id("MLBANK::Account::balance",
	"6fc6f613a1bc.02.c7.7d.48.6d.00.00.00", 1,
	"6fc6f613a2b0.02.c7.7d.48.6d.00.00.00", 2)
#pragma attribute_id("MLBANK::Account::acctType",
	"6fc6f613a3a4.02.c7.7d.48.6d.00.00.00", 3,
	"6fc6f613a3a5.02.c7.7d.48.6d.00.00.00", 4)
#pragma operation_id("MLBANK::Account::Deposit",
	"6fc6f613a498.02.c7.7d.48.6d.00.00.00", 5)
#pragma operation_id("MLBANK::Account::Withdraw",
	"6fc6f613a58c.02.c7.7d.48.6d.00.00.00", 6)
#pragma interface_id("MLBANK::CheckAcct",
	"6fc6f613a680.02.c7.7d.48.6d.00.00.00")
#pragma attribute_id("MLBANK::CheckAcct::balance",
	"6fc6f613a1bc.02.c7.7d.48.6d.00.00.00", 1,
	"6fc6f613a2b0.02.c7.7d.48.6d.00.00.00", 2)
#pragma attribute_id("MLBANK::CheckAcct::acctType",
	"6fc6f613a3a4.02.c7.7d.48.6d.00.00.00", 3,
	"6fc6f613a3a5.02.c7.7d.48.6d.00.00.00", 4)
#pragma operation_id("MLBANK::CheckAcct::Deposit",
	"6fc6f613a498.02.c7.7d.48.6d.00.00.00", 5)
#pragma operation_id("MLBANK::CheckAcct::Withdraw",
	"6fc6f613a58c.02.c7.7d.48.6d.00.00.00", 6)
#pragma operation_id("MLBANK::CheckAcct::StopPayment",
	"6fc6f613a868.02.c7.7d.48.6d.00.00.00", 7)
#pragma interface_id("MLBANK::SaveAcct",
	"6fc6f613a95c.02.c7.7d.48.6d.00.00.00")
#pragma attribute_id("MLBANK::SaveAcct::balance",
	"6fc6f613a1bc.02.c7.7d.48.6d.00.00.00", 1,
	"6fc6f613a2b0.02.c7.7d.48.6d.00.00.00", 2)
#pragma attribute_id("MLBANK::SaveAcct::acctType",
	"6fc6f613a3a4.02.c7.7d.48.6d.00.00.00", 3,
	"6fc6f613a3a5.02.c7.7d.48.6d.00.00.00", 4)
#pragma operation_id("MLBANK::SaveAcct::Deposit",
	"6fc6f613a498.02.c7.7d.48.6d.00.00.00", 5)
#pragma operation_id("MLBANK::SaveAcct::Withdraw",
	"6fc6f613a58c.02.c7.7d.48.6d.00.00.00", 6)
#pragma interface_id("MLBANK::ServerMgr",
	"6fc6f613aa50.02.c7.7d.48.6d.00.00.00")
#pragma operation_id("MLBANK::ServerMgr::StopServer",
	"6fc6f613ab44.02.c7.7d.48.6d.00.00.00", 1)



<<File: MLBANKMETHOD_ERROR.C>>

/*
 *
 *  ROUTINE NAME:       AcctFactoryImpl_CreateAcct
 *
 *  FUNCTIONAL DESCRIPTION:
 *
 *      Method routine for CreateAcct.
 *       (Implementation : AcctFactoryImpl)
 *
 */

 MLBANK_Account AcctFactoryImpl_CreateAcct (CORBA_Object object,
CORBA_Environment * ev,
    MLBANK_ACCT_TYPES acctType,
    MLBANK_Money amount,
    MLBANK_AccountId * acctId)

{

#if defined(OBB_QUICK)

    /* Local Data Declaration */
    MLBANK_Account ret_object1;
    OBB_memptr memptr = NULL;
    ORB_ReferenceData   ref_data;
    CORBA_string        ref_buf;
    CORBA_ImplementationDef impl_def;
    CORBA_long          len;
    OBB_QUICK_LOGTXT ("\n\n***** CreateAcct Method *****");

    /*  Initialize this method's OUT arguments */
    impl_def = CORBA_Object_get_implementation (object, ev);
    len = strlen ("This is MLBANK_AcctFactory__OBJ")+1;
    ref_buf = (CORBA_string) OBBarg_malloc (ev, &memptr, len);
    strcpy (ref_buf, "This is MLBANK_AcctFactory__OBJ");
   ref_data . _maximum = len;
    ref_data . _length = len;
    ref_data . _buffer = (CORBA_octet *) ref_buf;
    ret_object1 = CORBA_BOA_create (CORBA_DEC_BOA_OBJECT,
                            ev,
                            & ref_data,
                            MLBANK_AcctFactory__OBJ,
                            impl_def);
    /* Report any errors */
    IsException (ev,
        (CORBA_string)"CORBA_BOA_create failed\n");

    /* Free memory allocated locally */
    CORBA_Object_release ((CORBA_Object)impl_def, 
                           ev);
        /* Indicate memory needs to be deallocated 
    when the method is completed */
    OBBarg_set_objref(ev, 
                      NULL,
                      ret_object1);
    /*  Initialize this method's OUT arguments */
    *acctId = 1;
#endif   /* OBB_QUICK */

/* OBB_PRESERVE_BEGIN(AcctFactoryImpl_CreateAcct) */
    /* Insert code that you want preserved here */
/* OBB_PRESERVE_END(AcctFactoryImpl_CreateAcct) */

#if defined(OBB_QUICK)
    return (ret_object1);
#else
    return;
#endif   /* OBB_QUICK */
}

T.RTitleUserPersonal
Name
DateLines
2441.1PTR 16-3-244REQUE::BOWERPeter Bower, ObjectBrokerMon Feb 24 1997 21:367
    
    You are correct. It should be an Account object. BOA_create should
    use the AccountImpl implementationdef and the declaration_Account__Obj
    interfacedef.
    
    
    
2441.2STKAI1::T_ANDERSSONTomas AnderssonWed Mar 05 1997 02:596
 If this is a bug in QuickStart, is it possible to say when it'll
 be fixed, under "normal" circumstances?

 - Tomas A -

2441.3SEND::SLAVINWed Mar 05 1997 10:112
This will be considered for ObjectBroker Bryce. Where it comes in the 
priority list will determine if it gets completed fro Bryce.
2441.4STKAI1::T_ANDERSSONTomas AnderssonMon Mar 24 1997 03:483
    About Bryce, can you say when it is due for release?
    
    - Tomas A -
2441.5REQUE::whocrz.zko.dec.com::GumbelDick GumbelMon Mar 24 1997 08:137
By the end of the calendar year 1997.



   Dick Gumbel