Class: Portal::Connection

Inherits:
Object
  • Object
show all
Defined in:
ext/portalext.c,
ext/portalext.c

Overview

A single connection to Portal. Create a connection to execute opcodes. Send Hash that mimics the input FList. The response is a Hash. Errors usually result in an exception getting raised.

The connection has the following attributes:

ctxp

The Portal context for this current connection.

program_name

The program name. By default, it is the same name as the Ruby script.

log_level

The logging done through the Portal logging interface.

Instance Method Summary collapse

Constructor Details

#initializeObject



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'ext/portalext.c', line 1014

static VALUE
portal_initialize(VALUE self)
{
  if (rb_gv_get("$DEBUG")){
    PIN_ERR_SET_LEVEL(PIN_ERR_LEVEL_DEBUG);
    fprintf(stderr,"Portal logging set to debug\n");
  }

  return self;
}

Instance Method Details

#connectObject #connect(hash) ⇒ Object #connect(string) ⇒ Object

Create a connection to Portal in one of several ways based on the arg. If nil, then the pin.conf in the current directory is used. If hash, use those details. If string, then that is the location for our pin.conf

Connect using a pin.conf

Portal::Connection.new.connect("/usr/local/portal/sys/test")

You can supply the connection information in the request. This method avoids the need for a pin.conf. Note that this is a cm_proxy login type, so the password is not needed.

request = {
  :PIN_FLD_POID => "0.0.0.1 /service/pcm_client 1",
  :PIN_FLD_TYPE => 0,
  :PIN_FLD_CM_PTR => {
    0 => { :PIN_FLD_CM_PTR => "ip portal01.prod.example.com 11960"}
    1 => { :PIN_FLD_CM_PTR => "ip portal02.prod.example.com 11960"}
  }
Portal::Connection.new.connect(request)


915
916
917
# File 'ext/portalext.c', line 915

static VALUE
portal_connect(self,obj)
VALUE self, obj;

#connected?Boolean

Returns true is we are connected to Portal. This does not probe the connection. Use loopback to ping the CM.

ph.connect unless ph.connected?

Returns:

  • (Boolean)


983
984
985
# File 'ext/portalext.c', line 983

static VALUE
portal_connected(self)
VALUE self;

#disconnectObject

Disconnect from Portal. This is important to avoid mem leaks.

ph.disconnect() rescue nil


1001
1002
1003
# File 'ext/portalext.c', line 1001

static VALUE
portal_disconnect(self)
VALUE self;

#inspectxString of debug info

Connection.inspectx -> Dumps the associated C structs

Returns:

  • (String of debug info)


90
91
92
# File 'ext/portalext.c', line 90

static VALUE
portal_inspect(self)
VALUE self;

#loopbackHash

Calls PCM_OP_TEST_LOOPBACK to probe the CM connection. A bad test will raise an exception.

portal.loopback

Returns:

  • (Hash)


800
801
802
# File 'ext/portalext.c', line 800

static VALUE
portal_loopback(self)
VALUE self;

#robj(opcode, poid) ⇒ Hash #robj(opcode, poid, args) ⇒ Hash

Read an object. Returns the entire object.

Examples

portal.robj :PIN_FLD_POID => "0.0.0.1 /account 1"
portal.robj "0.0.0.1 /account 1"
portal.robj "0.0.0.1 /account 1", :return => :flist_string

Overloads:

  • #robj(opcode, poid) ⇒ Hash

    Returns:

    • (Hash)
  • #robj(opcode, poid, args) ⇒ Hash

    Returns:

    • (Hash)


863
864
865
# File 'ext/portalext.c', line 863

static VALUE
portal_robj(argc, argv, obj)
int argc;

#sessionString

Returns the session associated to the current context. Returns nil if not connected.

Returns:

  • (String)


822
823
824
825
826
827
828
829
830
# File 'ext/portalext.c', line 822

static VALUE
portal_get_session(self)
{
  PortalData *pd;
  PDataGet(self,pd);
  if (pd->ctxp == NULL)
    return Qnil;
  return portal_poid_to_val(pcm_get_session(pd->ctxp));
}

#useridString

Returns the user poid associated to the current context. Returns nil if not connected.

Returns:

  • (String)


839
840
841
842
843
844
845
846
847
848
# File 'ext/portalext.c', line 839

static VALUE
portal_get_userid(self)
{
  PortalData *pd;
  TRACE("start");
  PDataGet(self,pd);
  if (pd->ctxp == NULL)
    return Qnil;
  return portal_poid_to_val(pcm_get_userid(pd->ctxp));
}

#xop(opcode, request) ⇒ Hash #xop(opcode, request, args) ⇒ Hash

Perform a Portal opcode by converting a hash into a flist.

Options:

The options hash takes the following keys:

:return | :flist_string | Converts the results flist into an flist_to_str like testnap
:flags

Example:

ph.xop(:PCM_OP_READ_OBJ,{:PIN_FLD_POID=>"0.0.0.1 /account 1"},:return => :flist_string)

Overloads:

  • #xop(opcode, request) ⇒ Hash

    Returns:

    • (Hash)
  • #xop(opcode, request, args) ⇒ Hash

    Returns:

    • (Hash)


693
694
695
# File 'ext/portalext.c', line 693

static VALUE
portal_xop(argc, argv, self)
int argc;