11.1.7.1 C++でのOracleWrapper Callbacksの使用

コールバック・オブジェクトに必要なコードは、コールバックをサポートするどのクライアントについてもほぼ同一であるため、共同クライアント/サーバー用のライブラリで提供されているOracleWrapperを使用すると便利なことがあります。

OracleWrappersについては、次のコード・スニペットに示すように、IDLで記述します。

// File: BEAWrapper
#ifndef _BEA_WRAPPER _IDL_
#define _BEA_WRAPPER _IDL_
#include <orb.idl>
#include <PortableServer.idll>

#pragma prefix “beasys.com”

module BEAWrapper {
  interface Callbacks
  {
      exception ServantAlreadyActive{ };
      exception ObjectAlreadyActive { };
      exception NotInRequest{ };

     // set up transient callback Object
    // -- prepare POA, activate object, return objref
       Object start_transient(
                     in PortableServer::Servant       Servant,
                     in CORBA::RepositoryId           rep_id)
       raises (ServantAlreadyActive);
    // set up persistent/systemid callback Object
    Object start_persistent_systemid(
           in PortableServer::Servant                servant,
           in CORBA::Repository                      rep_id,
           out string                                stroid)
      raises (ServantAlreadyActive);
// reinstate set up for persistent/systemid
// callback object
Object restart_persistent_systemid(
         in PortableServer::Servant                 servant,
         in CORBA::RepositoryId                     rep_id,
         in string                                  stroid)
    raises (ServantAlreadyActive, ObjectAlreadyActive);
// set up persistent/userid callback Object
  Object start_persistent_userid(
        in PortableServer::Servant                 servant,
        in CORBA::RepositoryId                     rep_id,
        in string                                  stroid)
  raises (ServantAlreadyActive, ObjectAlreadyActive);
// stop servicing a particular callback Object
// with the given servant
void stop_object( in PortableServer::Servant servant);
//Stop all callback Object processing
void stop_all_objects();
// get oid string for the current request
string get_string_oid() raises (NotInRequest);
};
}
#endif /* _BEA_WRAPPER _IDL_ */

OracleWrappersについては、次のコード・スニペットに示すように、C++で記述します。

#ifndef _BEAWRAPPER_H_
#define _BEAWRAPPER_H_
#include <PortableServer.h>
class BEAWrapper{
class Callbacks{
      public:
            Callbacks (CORBA::ORB_ptr init_orb);
            CORBA::Object_ptr start_transient (
                         PortableServer::Servant servant,
                         const char *       rep_id);
            CORBA::Object_ptr start_persistent_systemid (
                         PortableServer::Servant servant,
                         const char *       rep_id,
                         char *             & stroid);
           CORBA::Object_ptr restart_persistent_systemid (
                         PortableServer::Servant servant,
                         const char *      rep_id,
                         const char *      stroid);
          CORBA::Object_ptr start_persistent_userid (
                        PortableServer::Servant servant,
                        const char *       rep_id,
                        const char *       stroid);
            void stop_object(PortableServer::Servant servant);
            char* get_string_oid ();
            void stop_all_objects();
            ~Callbacks();
       private:
            static CORBA::ORB_var orb_ptr;

            static PortableServer::POA_var root_poa;
            static PortableServer::POA_var trasys_poa;
            static PortableServer::POA_var persys_poa;
            static PortableServer::POA_var peruser_poa;
        };
};
#endif // _BEAWRAPPER_H_