[omniORB] Problems with returning an object

Thomas Amsler tpamsler@ucdavis.edu
Fri, 03 Aug 2001 16:35:18 -0700


This is a multi-part message in MIME format.
--------------C2101EC2014D29A67BC3927D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I am having problems returning an object within a method.  In the method
authenticate, I try to return an AuthResponse object.  I am not sure on
how to do that.

Context from AuthenticationServerImpl.h:
--------------------------------------------------------------
class AuthenticationServer_i : public POA_RCT::AuthenticationServer,
                               public Server_i
{

private:

    AuthResponse_i *pr_auth_response;
    PortableServer::ObjectId_var pr_auth_resp_id;


public:

    // Constructpr:
    AuthenticationServer_i(const char *a_status = SM1),

    // Destructor:
    virtual inline ~AuthenticationServer_i() { }

    // IDL Method:
    // Returning the authentication result
    virtual AuthResponse_ptr authenticate(const char *a_userid,  const
char *a_password);
};
--------------------------------------------------------------

Context from AuthenticationServerImpl.cc
--------------------------------------------------------------
// Constructor:
AuthenticationServer_i::AuthenticationServer_i(const char *a_status)
    : Server_i(a_status)
{

    // Allocate memory for AuthResp obj
    pr_auth_response = new AuthResponse_i();

}

// IDL Method:
AuthResponse_ptr
AuthenticationServer_i::authenticate(const char *a_userid,
                                     const char *a_password)
{

    // Testing UserId and Password
    if(0 == strcmp("SomeUserID", a_userid) &&
       0 == strcmp("SomePassword", a_password)) {

        pr_auth_response->setGranted(TRUE);
        pr_auth_response->setReason("UserId and Password are correct");
    }
    else {
        pr_auth_response->setGranted(FALSE);
        pr_auth_response->setReason("UserId or Password is not
correct");
    }

    return (AuthResponse_ptr)pr_auth_response;
}
--------------------------------------------------------------

I am sure that this is not the correct way since it's not working.  The
server application stops working after the client makes a call to
authenticate.  I attached all the files that deal with this
functionality.  Can someone point me in the right directions on how to
do this correctly?
Thank you very much.

--
Thomas Amsler
amsler@cs.ucdavis.edu
http://tpa.dyndns.org/thomas

"Imagination is more important than knowledge."
        --Albert Einstein



--------------C2101EC2014D29A67BC3927D
Content-Type: text/plain; charset=us-ascii;
 name="AuthenticationServerImpl.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="AuthenticationServerImpl.cc"

/* $Id: AuthenticationServerImpl.cc,v 1.1.2.1 2001/08/03 01:25:22 thomas Exp $ */

#include "AuthenticationServerImpl.h"

// Constructor:
AuthenticationServer_i::AuthenticationServer_i(const char *a_status)
    : Server_i(a_status)
{
    
#ifdef DEBUG
    cout << "DEBUG: This is line " <<  __LINE__ << " of file " << __FILE__
         << " --> DEBUG: AuthenticationServer_i::AuthenticationServer_i" << endl;
#endif


    // Allocate memory for AuthResp obj
    pr_auth_response = new AuthResponse_i();

}

// IDL Method:
AuthResponse_ptr
AuthenticationServer_i::authenticate(const char *a_userid,
                                     const char *a_password)
{
    
#ifdef DEBUG
    cout << "DEBUG: This is line " <<  __LINE__ << " of file " << __FILE__
         << " --> DEBUG: AuthenticationServer_i::authenticate" << endl;
#endif

    // Testing UserId and Password
    if(0 == strcmp("SomeUserID", a_userid) &&
       0 == strcmp("SomePassword", a_password)) {

        pr_auth_response->setGranted(TRUE);
        pr_auth_response->setReason("UserId and Password are correct");
    }
    else {
        pr_auth_response->setGranted(FALSE);
        pr_auth_response->setReason("UserId or Password is not correct");
    }

    return (AuthResponse_ptr)pr_auth_response;
}












--------------C2101EC2014D29A67BC3927D
Content-Type: text/plain; charset=us-ascii;
 name="AuthenticationServerImpl.h"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="AuthenticationServerImpl.h"

/* $Id: AuthenticationServerImpl.h,v 1.1.2.1 2001/08/03 01:25:22 thomas Exp $ */

#ifndef __AUTHENTICATIONSERVERIMPL_H__
#define __AUTHENTICATIONSERVERIMPL_H__


#include <omniORB3/CORBA.h>
#include <stdlib.h>
#include <iostream.h>
#include "AuthenticationServer.hh"
#include "Server.hh"
#include "NameServerUtil.h"
#include "ServerImpl.h"
#include "AuthResponseImpl.h"
#include "AuthResponse.hh"
#include "Const.h"


using namespace RCT;
      
class AuthenticationServer_i : public POA_RCT::AuthenticationServer,
                               public Server_i
{

private:

    AuthResponse_i *pr_auth_response;
    PortableServer::ObjectId_var pr_auth_resp_id;

    
public:

    // Constructpr:
    AuthenticationServer_i(const char *a_status = SM1),

    // Destructor:      
    virtual inline ~AuthenticationServer_i() { }

    // IDL Method:
    // Returning the authentication result
    virtual AuthResponse_ptr authenticate(const char *a_userid,
                                          const char *a_password);
};


#endif //__AUTHENTICATIONSERVERIMPL_H__

--------------C2101EC2014D29A67BC3927D
Content-Type: text/plain; charset=us-ascii;
 name="AuthResponse.idl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="AuthResponse.idl"

/* $Id: AuthResponse.idl,v 1.2 2001/08/01 00:25:26 thomas Exp $ */

#ifndef __AUTHRESPONSE_IDL__
#define __AUTHRESPONSE_IDL__


/*
 * An AuthResponse object is returned for each user who
 * logs in. Also, on success we return references to relevant
 * objects such as Permission etc. We also include a message that
 * gives details about the login process such as "wrong password".
 */

module RCT {

    interface AuthResponse {

	/*
	 * Return the authentication result
	 */
	boolean getGranted();

	/*
	 * Return the reason if the login was not successful
	 * "Wrong Password"
	 * "Wrong User ID"
	 * "You are not allowd to login because: <other reason>"
	 */
	string getReason();
    };
};

#endif

--------------C2101EC2014D29A67BC3927D
Content-Type: text/plain; charset=us-ascii;
 name="AuthenticationServer.idl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="AuthenticationServer.idl"

/* $Id: AuthenticationServer.idl,v 1.2.2.1 2001/08/03 01:26:59 thomas Exp $ */

#ifndef __AUTHENTICATIONSERVER_IDL__
#define __AUTHENTICATIONSERVER_IDL__

#include "AuthResponse.idl"
#include "Server.idl"

/*
 * The AuthenticationServer will handle the login process.
 * It will retrun an AuthResponse object per login.
 */

module RCT {

    interface AuthenticationServer : Server {
	
	/*
	 * This method will be called during the authentication process
	 */
	AuthResponse authenticate(in string userid, in string password);
    };
};

#endif



--------------C2101EC2014D29A67BC3927D--