Class: OPCUA::Server::Node

Inherits:
Object
  • Object
show all
Defined in:
ext/opcua/server/server.c

Instance Method Summary collapse

Instance Method Details

#descriptionObject

{{{



783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
# File 'ext/opcua/server/server.c', line 783

static VALUE node_description(VALUE self) { //{{{
  node_struct *ns;

  Data_Get_Struct(self, node_struct, ns);
  if (!ns->exists) rb_raise(rb_eRuntimeError, "Node does not exist anymore.");

  UA_LocalizedText value;
  UA_LocalizedText_init(&value);
  UA_StatusCode retval = UA_Server_readDescription(ns->master->master, ns->id, &value);

  VALUE ret = Qnil;
  if (retval == UA_STATUSCODE_GOOD) {
    ret = rb_str_export_locale(rb_str_new((char *)(value.text.data),value.text.length));
  }

  UA_LocalizedText_clear(&value);
  return ret;
}

#description=(value) ⇒ Object

{{{



769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'ext/opcua/server/server.c', line 769

static VALUE node_description_set(VALUE self, VALUE value) { //{{{
  node_struct *ns;
  Data_Get_Struct(self, node_struct, ns);
  if (!ns->exists) rb_raise(rb_eRuntimeError, "Node does not exist anymore.");

  VALUE str = rb_obj_as_string(value);
  if (NIL_P(str) || TYPE(str) != T_STRING)
    rb_raise(rb_eTypeError, "cannot convert obj to string");
  char *nstr = (char *)StringValuePtr(str);
  UA_LocalizedText lt = UA_LOCALIZEDTEXT("en-US",nstr);

  UA_Server_writeDescription(ns->master->master, ns->id, lt);
  return self;
}

#exists?Boolean

{{{

Returns:

  • (Boolean)


760
761
762
763
764
765
766
767
768
# File 'ext/opcua/server/server.c', line 760

static VALUE node_exists(VALUE self) { //{{{
  node_struct *ns;

  Data_Get_Struct(self, node_struct, ns);
  if (ns->exists)
    return Qtrue;
  else
    return Qfalse;
}

#idObject

{{{



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'ext/opcua/server/server.c', line 126

static VALUE node_id(VALUE self) { //{{{
  node_struct *ns;

  Data_Get_Struct(self, node_struct, ns);
  if (!ns->exists) rb_raise(rb_eRuntimeError, "Node does not exist anymore.");

  VALUE ret = rb_ary_new();

  rb_ary_push(ret,UINT2NUM(ns->id.namespaceIndex));
  if (ns->id.identifierType == UA_NODEIDTYPE_NUMERIC) {
    VALUE id = UINT2NUM((UA_UInt32)(ns->id.identifier.numeric));
    rb_ary_push(ret,id);
  } else if (ns->id.identifierType == UA_NODEIDTYPE_STRING) {
    rb_ary_push(ret,rb_str_new((const char *)ns->id.identifier.string.data,ns->id.identifier.string.length));
  } else if (ns->id.identifierType == UA_NODEIDTYPE_BYTESTRING) {
    rb_ary_push(ret,rb_str_new((const char *)ns->id.identifier.byteString.data,ns->id.identifier.byteString.length));
  }
  return ret;
}

#nameObject

{{{



145
146
147
148
149
150
151
152
153
154
155
# File 'ext/opcua/server/server.c', line 145

static VALUE node_name(VALUE self) { //{{{
  node_struct *ns;

  Data_Get_Struct(self, node_struct, ns);
  if (!ns->exists) rb_raise(rb_eRuntimeError, "Node does not exist anymore.");

  UA_QualifiedName qn;  UA_QualifiedName_init(&qn);
  UA_Server_readBrowseName(ns->master->master, ns->id, &qn);

  return rb_sprintf("%.*s", (int)qn.name.length, qn.name.data);
}

#to_sObject

{{{



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'ext/opcua/server/server.c', line 156

static VALUE node_to_s(VALUE self) { //{{{
  node_struct *ns;
  VALUE ret;

  Data_Get_Struct(self, node_struct, ns);
  if (!ns->exists) rb_raise(rb_eRuntimeError, "Node does not exist anymore.");

  if (ns->id.identifierType == UA_NODEIDTYPE_NUMERIC) {
    ret = rb_sprintf("ns=%d;i=%d", ns->id.namespaceIndex, ns->id.identifier.numeric);
  } else if(ns->id.identifierType == UA_NODEIDTYPE_STRING) {
    ret = rb_sprintf("ns=%d;s=%.*s", ns->id.namespaceIndex, (int)ns->id.identifier.string.length, ns->id.identifier.string.data);
  } else {
    ret = rb_sprintf("ns=%d;unsupported",ns->id.namespaceIndex);
  }
  return ret;
}