Class: Portal::Connection
- Inherits:
-
Object
- Object
- Portal::Connection
- 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
-
#connect ⇒ Object
Create a connection to Portal in one of several ways based on the arg.
-
#connected? ⇒ Boolean
Returns true is we are connected to Portal.
-
#disconnect ⇒ Object
Disconnect from Portal.
- #initialize ⇒ Object constructor
-
#inspectx ⇒ String of debug info
Connection.inspectx -> Dumps the associated C structs.
-
#loopback ⇒ Hash
Calls PCM_OP_TEST_LOOPBACK to probe the CM connection.
-
#robj ⇒ Object
Read an object.
-
#session ⇒ String
Returns the session associated to the current context.
-
#userid ⇒ String
Returns the user poid associated to the current context.
-
#xop ⇒ Object
Perform a Portal opcode by converting a hash into a flist.
Constructor Details
#initialize ⇒ Object
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
#connect ⇒ Object #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?
983 984 985 |
# File 'ext/portalext.c', line 983 static VALUE portal_connected(self) VALUE self; |
#disconnect ⇒ Object
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; |
#inspectx ⇒ String of debug info
Connection.inspectx -> Dumps the associated C structs
90 91 92 |
# File 'ext/portalext.c', line 90 static VALUE portal_inspect(self) VALUE self; |
#loopback ⇒ Hash
Calls PCM_OP_TEST_LOOPBACK to probe the CM connection. A bad test will raise an exception.
portal.loopback
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
863 864 865 |
# File 'ext/portalext.c', line 863 static VALUE portal_robj(argc, argv, obj) int argc; |
#session ⇒ String
Returns the session associated to the current context. Returns nil if not connected.
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));
}
|
#userid ⇒ String
Returns the user poid associated to the current context. Returns nil if not connected.
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)
693 694 695 |
# File 'ext/portalext.c', line 693 static VALUE portal_xop(argc, argv, self) int argc; |