Class: OPCUA::Server::TypeSubNode

Inherits:
Node
  • Object
show all
Defined in:
lib/opcua/server.rb,
ext/opcua/server/server.c

Instance Method Summary collapse

Methods inherited from Node

#description, #description=, #exists?, #id, #name, #to_s

Instance Method Details

#add_method(*args) ⇒ Object

{{{



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'ext/opcua/server/server.c', line 296

static VALUE node_add_method(int argc, VALUE* argv, VALUE self) { //{{{
  node_struct *parent;

  VALUE name;
	VALUE opts;
	VALUE blk;
  rb_gc_register_address(&blk);

  if (argc < 1) { // there should be 1 or more arguments
    rb_raise(rb_eArgError, "wrong number of arguments");
  }
	rb_scan_args(argc, argv, "1:&", &name, &opts, &blk);
  if (NIL_P(opts)) opts = rb_hash_new();

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

  VALUE str = rb_obj_as_string(name);
  if (NIL_P(str) || TYPE(str) != T_STRING)
    rb_raise(rb_eTypeError, "cannot convert obj to string");
  char *nstr = (char *)StringValuePtr(str);

  return node_wrap(CLASS_OF(self),node_alloc(parent->master,node_add_method_ua_simple(nstr,parent,opts,blk)));
}

#add_object(*args) ⇒ Object

{{{



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'ext/opcua/server/server.c', line 446

static VALUE node_add_object(int argc, VALUE* argv, VALUE self) { //{{{
  node_struct *parent;
  node_struct *datatype;

  if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
    rb_raise(rb_eArgError, "wrong number of arguments");
  }

  UA_UInt32 type;
  if (argc == 3 && argv[2] != Qnil) {
    type = NUM2INT(argv[2]);
  } else {
    type = UA_NS0ID_MODELLINGRULE_MANDATORY;
  }

  if (!(rb_obj_is_kind_of(argv[1],cTypeTopNode) || rb_obj_is_kind_of(argv[1],cTypeSubNode))) {
    rb_raise(rb_eArgError, "argument 2 has to be a type.");
  }

  Data_Get_Struct(self, node_struct, parent);
  if (!parent->exists) rb_raise(rb_eRuntimeError, "Parent node does not exist anymore.");
  Data_Get_Struct(argv[1], node_struct, datatype);
  if (!datatype->exists) rb_raise(rb_eRuntimeError, "Datatype node does not exist anymore.");

  VALUE str = rb_obj_as_string(argv[0]);
  if (NIL_P(str) || TYPE(str) != T_STRING)
    rb_raise(rb_eTypeError, "cannot convert obj to string");
  char *nstr = (char *)StringValuePtr(str);

  return node_wrap(CLASS_OF(self),node_alloc(parent->master,node_add_object_ua_simple(type,nstr,parent,datatype,argv[2])));
}

#add_object_type(name) ⇒ Object

{{{



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'ext/opcua/server/server.c', line 71

static VALUE node_add_object_type(VALUE self, VALUE name) { //{{{
  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(name);
  if (NIL_P(str) || TYPE(str) != T_STRING)
    rb_raise(rb_eTypeError, "cannot convert obj to string");
  char *nstr = (char *)StringValuePtr(str);

  UA_NodeId n = UA_NODEID_NUMERIC(ns->master->default_ns, nodecounter++);

  UA_ObjectTypeAttributes dtAttr = UA_ObjectTypeAttributes_default;
                          dtAttr.displayName = UA_LOCALIZEDTEXT("en-US", nstr);
  UA_Server_addObjectTypeNode(ns->master->master,
                              n,
                              ns->id,
                              UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
                              UA_QUALIFIEDNAME(ns->master->default_ns, nstr),
                              dtAttr,
                              NULL,
                              NULL);

  return node_wrap(cTypeSubNode,node_alloc(ns->master,n));
}

#add_properties(*item) ⇒ Object



43
44
45
# File 'lib/opcua/server.rb', line 43

def add_properties(*item)
  item.each { |e| add_property e }
end

#add_property(name) ⇒ Object



37
38
39
# File 'lib/opcua/server.rb', line 37

def add_property(name)
  add_variable name, OPCUA::PROPERTYTYPE
end

#add_property_rw(*item) ⇒ Object



40
41
42
# File 'lib/opcua/server.rb', line 40

def add_property_rw
  add_variable_rw name, OPCUA::PROPERTYTYPE
end

#add_reference(to, type) ⇒ Object

{{{



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'ext/opcua/server/server.c', line 172

static VALUE node_add_reference(VALUE self, VALUE to, VALUE type) { //{{{
  node_struct *ns;
  node_struct *tos;
  node_struct *tys;

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

  if (!(rb_obj_is_kind_of(type,cReferenceSubNode) || rb_obj_is_kind_of(to,cTypeSubNode))) {
    rb_raise(rb_eArgError, "arguments have to be NodeIDs.");
  }
  Data_Get_Struct(to, node_struct, tos);
  if (!tos->exists) rb_raise(rb_eRuntimeError, "To (arg 1) node does not exist anymore.");
  Data_Get_Struct(type, node_struct, tys);
  if (!tys->exists) rb_raise(rb_eRuntimeError, "Type (arg 2) node does not exist anymore.");
  UA_NodeId n = UA_NODEID_NUMERIC(ns->master->default_ns, nodecounter++);

  UA_ExpandedNodeId toNodeId;
                    toNodeId.serverIndex = 0;
                    toNodeId.namespaceUri = UA_STRING_NULL;
                    toNodeId.nodeId = tos->id;

  UA_Server_addReference(ns->master->master,
                         n,
                         tys->id,
                         toNodeId,
                         true);

  return node_wrap(cReferenceNode,node_alloc(ns->master,n));
}

#add_variable(*args) ⇒ Object

{{{



378
379
380
# File 'ext/opcua/server/server.c', line 378

static VALUE node_add_variable(int argc, VALUE* argv, VALUE self) { //{{{
  return node_add_variable_wrap(argc,argv,self,UA_ACCESSLEVELMASK_READ,true);
}

#add_variable_rw(*args) ⇒ Object

{{{



381
382
383
# File 'ext/opcua/server/server.c', line 381

static VALUE node_add_variable_rw(int argc, VALUE* argv, VALUE self) { //{{{
  return node_add_variable_wrap(argc,argv,self,UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE,true);
}

#add_variables(*item) ⇒ Object



49
50
51
# File 'lib/opcua/server.rb', line 49

def add_variables(*item)
  item.each { |e| add_variable e }
end

#add_variables_rw(*item) ⇒ Object



52
53
54
# File 'lib/opcua/server.rb', line 52

def add_variables_rw(*item)
  item.each { |e| add_variable_rw e }
end

#delete!Object

{{{



744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
# File 'ext/opcua/server/server.c', line 744

static VALUE node_delete(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_StatusCode retval = UA_Server_deleteNode(ns->master->master, ns->id, true);

  if (retval == UA_STATUSCODE_GOOD) {
    ns->exists = false;
    return Qtrue;
  }

  return Qfalse;
}