ProviewR Programmer's Reference Manual  V6.1.4
nmps_appl.c
Go to the documentation of this file.
1 /*
2  * ProviewR Open Source Process Control.
3  * Copyright (C) 2005-2025 SSAB EMEA AB.
4  *
5  * This file is part of ProviewR.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation, either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with ProviewR. If not, see <http://www.gnu.org/licenses/>
19  *
20  * Linking ProviewR statically or dynamically with other modules is
21  * making a combined work based on ProviewR. Thus, the terms and
22  * conditions of the GNU General Public License cover the whole
23  * combination.
24  *
25  * In addition, as a special exception, the copyright holders of
26  * ProviewR give you permission to, from the build function in the
27  * ProviewR Configurator, combine ProviewR with modules generated by the
28  * ProviewR PLC Editor to a PLC program, regardless of the license
29  * terms of these modules. You may copy and distribute the resulting
30  * combined work under the terms of your choice, provided that every
31  * copy of the combined work is accompanied by a complete copy of
32  * the source code of ProviewR (the version used to produce the
33  * combined work), being distributed under the terms of the GNU
34  * General Public License plus this exception.
35  */
36 
37 /*************************************************************************
38  *
39 * PROGRAM rs_nmps_appl
40 *
41 * Modifierad
42 * 971002 Claes Sjöfors Skapad
43 *
44 * Funktion: Applikationsgränssnitt mot Nmps.
45 **************************************************************************/
46 
51 /*_Include filer_________________________________________________________*/
52 
53 #include "pwr_nmpsclasses.h"
54 
55 #include "co_cdh.h"
56 #include "co_string.h"
57 
58 #include "rt_lck.h"
59 #include "rt_gdh_msg.h"
60 #include "rt_hash_msg.h"
61 #include "rs_nmps_msg.h"
62 
63 #include "nmps.h"
64 #include "nmps_appl.h"
65 
66 /* Global functions________________________________________________________*/
67 
68 typedef struct nmpsappl_s_data_list {
69  pwr_tObjid objid;
70  pwr_tString80 name;
71  unsigned int possession;
72  pwr_tAddress object_ptr;
73  gdh_tDlid subid;
74  int remove;
75  int pending_remove;
76  struct nmpsappl_s_data_list* prev_ptr;
77  struct nmpsappl_s_data_list* next_ptr;
78 } nmpsappl_t_data_list;
79 
80 typedef struct nmpsappl_s_basectx {
81  nmpsappl_t_cellist* cellist;
82  int cellist_count;
83  nmpsappl_t_ctx applctx_list;
84  int applctx_count;
85  nmpsappl_t_data_list* datalist;
86 } * nmpsappl_t_basectx;
87 
88 /*_Global variables______________________________________________________*/
89 
90 static nmpsappl_t_basectx nmpsappl_basectx = 0;
91 
92 /*_Local functions________________________________________________________*/
93 
94 static pwr_tStatus nmpsappl_data_db_create(nmpsappl_t_data_list** data_list,
95  pwr_tObjid objid, int options, nmpsappl_t_data_list** datalist_ptr);
96 static pwr_tStatus nmpsappl_data_db_delete(
97  nmpsappl_t_data_list** data_list, nmpsappl_t_data_list* data_ptr);
98 
99 /****************************************************************************
100 * Name: nmpsappl_data_db_create()
101 *
102 * Type pwr_tStatus
103 *
104 * Type Parameter IOGF Description
105 *
106 * Description:
107 * Create an entry in the datalist for an objid.
108 *
109 **************************************************************************/
110 static pwr_tStatus nmpsappl_data_db_create(nmpsappl_t_data_list** data_list,
111  pwr_tObjid objid, int options, nmpsappl_t_data_list** datalist_ptr)
112 {
113  nmpsappl_t_data_list* next_ptr;
114  pwr_tStatus sts;
115  char name[80];
116  pwr_sAttrRef attrref;
117  pwr_tAddress object_ptr;
118  gdh_tDlid subid;
119 
120  /* Get a direct link to the original object */
121  attrref = cdh_ObjidToAref(objid);
122  sts = gdh_DLRefObjectInfoAttrref(&attrref, &object_ptr, &subid);
123  if (EVEN(sts))
124  return sts;
125 
126  if (options & nmpsappl_mOption_NamePath)
127  sts = gdh_ObjidToName(objid, name, sizeof(name), cdh_mName_path);
128  else
129  sts = gdh_ObjidToName(objid, name, sizeof(name), cdh_mName_object);
130  if (EVEN(sts))
131  return sts;
132 
133  *datalist_ptr = calloc(1, sizeof(nmpsappl_t_data_list));
134  if (*datalist_ptr == 0)
135  return NMPS__NOMEMORY;
136 
137  (*datalist_ptr)->object_ptr = object_ptr;
138  (*datalist_ptr)->subid = subid;
139  (*datalist_ptr)->objid = objid;
140  strcpy((*datalist_ptr)->name, name);
141 
142  /* Insert first in list */
143  next_ptr = *data_list;
144  if (next_ptr != NULL)
145  next_ptr->prev_ptr = *datalist_ptr;
146  (*datalist_ptr)->next_ptr = next_ptr;
147 
148  *data_list = *datalist_ptr;
149 
150  return NMPS__SUCCESS;
151 }
152 
153 /****************************************************************************
154 * Name: nmpsappl_data_db_delete()
155 *
156 * Type pwr_tStatus
157 *
158 * Type Parameter IOGF Description
159 *
160 * Description:
161 * Delete an entry in the datalist.
162 *
163 **************************************************************************/
164 static pwr_tStatus nmpsappl_data_db_delete(
165  nmpsappl_t_data_list** data_list, nmpsappl_t_data_list* data_ptr)
166 {
167  int sts;
168 
169  sts = gdh_DLUnrefObjectInfo(data_ptr->subid);
170 
171  if (data_ptr == *data_list) {
172  /* Change the root */
173  *data_list = data_ptr->next_ptr;
174  if (*data_list)
175  (*data_list)->prev_ptr = 0;
176  }
177 
178  if (data_ptr->prev_ptr)
179  data_ptr->prev_ptr->next_ptr = data_ptr->next_ptr;
180  if (data_ptr->next_ptr)
181  data_ptr->next_ptr->prev_ptr = data_ptr->prev_ptr;
182 
183  free(data_ptr);
184 
185  return NMPS__SUCCESS;
186 }
187 
188 /****************************************************************************
189 * Name: nmpsappl_cell_init()
190 *
191 * Type pwr_tStatus
192 *
193 * Type Parameter IOGF Description
194 *
195 * Description:
196 *
197 **************************************************************************/
198 static pwr_tStatus nmpsappl_cell_init(char* cell_name, pwr_tObjid* orig_objid,
199  void** orig_cell, gdh_tSubid* orig_subid, pwr_tClassId* orig_class)
200 {
201  pwr_sAttrRef attrref;
202  pwr_tStatus sts;
203  pwr_tObjid cell_objid;
204 
205  sts = gdh_NameToObjid(cell_name, &cell_objid);
206  if (EVEN(sts))
207  return NMPS__APPLCELL;
208 
209  /* It might already have been stored */
210  memset(&attrref, 0, sizeof(attrref));
211  attrref = cdh_ObjidToAref(cell_objid);
212 
213  sts = gdh_GetObjectClass(attrref.Objid, orig_class);
214  if (EVEN(sts))
215  return sts;
216 
217  /* Link to object */
219  &attrref, (pwr_tAddress*)orig_cell, orig_subid);
220  if (EVEN(sts))
221  return NMPS__APPLCELL;
222 
223  return NMPS__SUCCESS;
224 }
225 
246  cell_array,
252  unsigned long options,
253  nmpsappl_t_ctx* ctx
254  )
255 {
256  pwr_tString80* cellname;
257  nmpsappl_t_basectx basectx;
258  nmpsappl_t_ctx applctx;
259  nmpsappl_t_cellist* cellist_ptr;
260  nmpsappl_t_cellist* c_ptr;
261  int found;
262  int sts;
263  int maxsize;
264  int i;
265 
266  if (nmpsappl_basectx == 0) {
267  /* Base context is not yet created */
268  nmpsappl_basectx = calloc(1, sizeof(*nmpsappl_basectx));
269  if (nmpsappl_basectx == 0)
270  return 0;
271  }
272  basectx = nmpsappl_basectx;
273 
274  if (basectx->applctx_count >= NMPSAPPL_APPLSESS_MAX)
275  return NMPS__APPLSESSMAX;
276 
277  /* Create a context for this applikation call */
278  applctx = calloc(1, sizeof(*applctx));
279  if (applctx == 0)
280  return 0;
281 
282  /* Insert applctx in basectx */
283  applctx->next = basectx->applctx_list;
284  basectx->applctx_list = applctx;
285  applctx->index = basectx->applctx_count;
286  applctx->index_mask = 1 << basectx->applctx_count;
287  basectx->applctx_count++;
288 
289  *ctx = applctx;
290 
291  /* Add cells to cellist */
292  cellname = cell_array;
293  while (!streq((char*)cellname, "")) {
294  str_ToUpper((char*)cellname, (char*)cellname);
295 
296  /* Check if cell already is inserted */
297  cellist_ptr = basectx->cellist;
298  found = 0;
299  while (cellist_ptr) {
300  if (streq((char*)cellname, cellist_ptr->name)) {
301  found = 1;
302  break;
303  }
304  cellist_ptr = cellist_ptr->next;
305  }
306  if (!found) {
307  /* Insert cell last position in cellist */
308 
309  cellist_ptr = calloc(1, sizeof(nmpsappl_t_cellist));
310  strcpy((char*)cellist_ptr->name, (char*)cellname);
311  sts = nmpsappl_cell_init(cellist_ptr->name, &cellist_ptr->objid,
312  &cellist_ptr->object_ptr, &cellist_ptr->subid, &cellist_ptr->classid);
313  if (EVEN(sts))
314  return sts;
315 
316  c_ptr = basectx->cellist;
317  if (!c_ptr)
318  basectx->cellist = cellist_ptr;
319  else {
320  while (c_ptr->next)
321  c_ptr++;
322  c_ptr->next = cellist_ptr;
323  }
324  basectx->cellist_count++;
325  }
326  if (applctx->cellist_count < NMPSAPPL_CELLIST_MAX) {
327  applctx->cellist[applctx->cellist_count] = cellist_ptr;
328  cellist_ptr->index_mask[applctx->index] = 1 << applctx->cellist_count;
329  applctx->cellist_count++;
330  } else
331  return NMPS__APPLCELLIST; /* Cellist to large */
332 
333  cellname++;
334  }
335 
336  /* Calculate the total size of the cell's in the list */
337  applctx->total_cellsize = 0;
338  for (i = 0; i < applctx->cellist_count; i++) {
339  cellist_ptr = applctx->cellist[i];
340  switch (cellist_ptr->classid) {
341  case pwr_cClass_NMpsCell:
342  case pwr_cClass_NMpsCell60:
343  case pwr_cClass_NMpsCell120:
344  case pwr_cClass_NMpsStoreCell:
345  case pwr_cClass_NMpsStoreCell60:
346  case pwr_cClass_NMpsStoreCell120:
347  maxsize = ((pwr_sClass_NMpsCell*)cellist_ptr->object_ptr)->MaxSize;
348  applctx->total_cellsize += maxsize;
349  cellist_ptr->tmp_size = sizeof(pwr_sClass_NMpsCell)
350  - sizeof(plc_t_DataInfo) * (30 - maxsize);
351  break;
352  case pwr_cClass_NMpsMirrorCell:
353  maxsize = ((pwr_sClass_NMpsMirrorCell*)cellist_ptr->object_ptr)->MaxSize;
354  applctx->total_cellsize += maxsize;
355  cellist_ptr->tmp_size = sizeof(pwr_sClass_NMpsMirrorCell)
356  - sizeof(plc_t_DataInfoMirCell) * (NMPS_CELLMIR_SIZE - maxsize)
357  - sizeof(nmps_t_mircell_copyarea);
358  break;
359  }
360  cellist_ptr->tmp_cell = (void*)calloc(1, cellist_ptr->tmp_size);
361  }
362 
363  /* Allocate memory for the data objects array in applctx */
364  if (options & nmpsappl_mOption_Remove)
365  /* Remove requires the double size */
366  applctx->datainfo = (nmpsappl_t_datainfo*)calloc(
367  applctx->total_cellsize * 2, sizeof(nmpsappl_t_datainfo));
368  else
369  applctx->datainfo = (nmpsappl_t_datainfo*)calloc(
370  applctx->total_cellsize, sizeof(nmpsappl_t_datainfo));
371 
372  lck_Create(&sts, lck_eLock_NMps);
373  if (EVEN(sts))
374  return sts;
375 
376  applctx->options = options;
377 
378  return NMPS__SUCCESS;
379 }
380 
450  nmpsappl_t_ctx applctx,
451  int* data_count,
453  datainfo
454  )
455 {
456  int i, j, k;
457  int found;
458  nmpsappl_t_cellist* cellist_ptr;
459  nmpsappl_t_data_list* data_ptr;
460  nmpsappl_t_data_list* data_next_ptr;
461  int sts;
462 
463  /* Copy cell-objects into the temporary buffer, and hope that
464  we will not be interuppted by the plc-program */
465  for (i = 0; i < applctx->cellist_count; i++) {
466  cellist_ptr = applctx->cellist[i];
467  lck_LockNMps;
468  memcpy(
469  cellist_ptr->tmp_cell, cellist_ptr->object_ptr, cellist_ptr->tmp_size);
470  lck_UnlockNMps;
471  }
472 
473  applctx->data_count = 0;
474  for (k = 0; k < applctx->cellist_count; k++) {
475  cellist_ptr = applctx->cellist[k];
476  switch (cellist_ptr->classid) {
477  case pwr_cClass_NMpsCell:
478  case pwr_cClass_NMpsCell60:
479  case pwr_cClass_NMpsCell120:
480  case pwr_cClass_NMpsStoreCell:
481  case pwr_cClass_NMpsStoreCell60:
482  case pwr_cClass_NMpsStoreCell120: {
483  pwr_sClass_NMpsCell* object_ptr;
484  plc_t_DataInfo* data_block_ptr;
485 
486  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->tmp_cell;
487  if (!(object_ptr->ReloadDone & NMPS_CELL_INITIALIZED))
488  continue;
489 
490  data_block_ptr = (plc_t_DataInfo*)&object_ptr->Data1P;
491  if (applctx->options & nmpsappl_mOption_ReverseOrder)
492  data_block_ptr += object_ptr->LastIndex - 1;
493  for (i = 0; i < object_ptr->LastIndex; i++) {
494  /* Check that objid is not already inserted */
495  found = 0;
496  for (j = 0; j < applctx->data_count; j++) {
497  if (cdh_ObjidIsEqual(applctx->datainfo[j].objid,
498  data_block_ptr->DataP.Aref.Objid)) {
499  found = 1;
500  break;
501  }
502  }
503  if (!found) {
504  applctx->datainfo[applctx->data_count].objid
505  = data_block_ptr->DataP.Aref.Objid;
506  applctx->datainfo[applctx->data_count].front
507  = data_block_ptr->Data_Front;
508  applctx->datainfo[applctx->data_count].back
509  = data_block_ptr->Data_Back;
510  applctx->datainfo[applctx->data_count].select
511  = data_block_ptr->Data_Select;
512  applctx->datainfo[applctx->data_count].cell_mask
513  = cellist_ptr->index_mask[applctx->index];
514  applctx->datainfo[applctx->data_count].removed = 0;
515  applctx->data_count++;
516  } else {
517  applctx->datainfo[applctx->data_count].front
518  |= data_block_ptr->Data_Front;
519  applctx->datainfo[applctx->data_count].back
520  |= data_block_ptr->Data_Back;
521  if (data_block_ptr->Data_Select)
522  applctx->datainfo[applctx->data_count].select = 1;
523  applctx->datainfo[applctx->data_count].cell_mask
524  |= cellist_ptr->index_mask[applctx->index];
525  }
526  if (applctx->options & nmpsappl_mOption_ReverseOrder)
527  data_block_ptr--;
528  else
529  data_block_ptr++;
530  }
531  break;
532  }
533  case pwr_cClass_NMpsMirrorCell: {
534  pwr_sClass_NMpsMirrorCell* object_ptr;
535  plc_t_DataInfoMirCell* data_block_ptr;
536 
537  object_ptr = (pwr_sClass_NMpsMirrorCell*)cellist_ptr->tmp_cell;
538 
539  data_block_ptr = (plc_t_DataInfoMirCell*)&object_ptr->Data1P;
540  for (i = 0; i < object_ptr->LastIndex; i++) {
541  /* Check that objid is not already inserted */
542  found = 0;
543  for (j = 0; j < i; j++) {
544  if (cdh_ObjidIsEqual(applctx->datainfo[j].objid,
545  data_block_ptr->DataP.Aref.Objid)) {
546  found = 1;
547  break;
548  }
549  }
550  if (!found) {
551  applctx->datainfo[applctx->data_count].objid
552  = data_block_ptr->DataP.Aref.Objid;
553  applctx->datainfo[applctx->data_count].select = 0;
554  applctx->datainfo[applctx->data_count].front = 0;
555  applctx->datainfo[applctx->data_count].back = 0;
556  applctx->datainfo[applctx->data_count].cell_mask
557  = cellist_ptr->index_mask[applctx->index];
558  applctx->datainfo[applctx->data_count].removed = 0;
559  applctx->data_count++;
560  } else {
561  applctx->datainfo[applctx->data_count].cell_mask
562  |= cellist_ptr->index_mask[applctx->index];
563  }
564  data_block_ptr++;
565  }
566  break;
567  }
568  }
569  }
570 
571  /* Insert new data-object in the data db, or find the old ones */
572 
573  /* Set the remove flag for all the dataobjects of this applctx */
574  data_ptr = nmpsappl_basectx->datalist;
575  while (data_ptr) {
576  if (data_ptr->possession & applctx->index_mask)
577  data_ptr->remove = 1;
578  data_ptr = data_ptr->next_ptr;
579  }
580 
581  for (i = 0; i < applctx->data_count; i++) {
582  /* Try to find the data-object */
583  found = 0;
584  data_ptr = nmpsappl_basectx->datalist;
585  while (data_ptr) {
586  if (cdh_ObjidIsEqual(applctx->datainfo[i].objid, data_ptr->objid)) {
587  if (data_ptr->possession & applctx->index_mask) {
588  /* It already belongs to this application session */
589  if (data_ptr->pending_remove)
590  /* The object has reappleard */
591  data_ptr->pending_remove = 0;
592 
593  applctx->datainfo[i].object_ptr = data_ptr->object_ptr;
594  data_ptr->remove = 0;
595  applctx->datainfo[i].newdata = 0;
596  } else {
597  /* A new object for this session, mark possession */
598  if (data_ptr->pending_remove) {
599  /* The object has reappleard from another session */
600  data_ptr->pending_remove = 0;
601  data_ptr->possession = 0;
602  }
603  data_ptr->possession |= applctx->index_mask;
604  applctx->datainfo[i].object_ptr = data_ptr->object_ptr;
605  applctx->datainfo[i].newdata = 1;
606  data_ptr->remove = 0;
607 
608  /* Insert in new data list */
609  }
610  strcpy(applctx->datainfo[i].name, data_ptr->name);
611  found = 1;
612  break;
613  }
614  data_ptr = data_ptr->next_ptr;
615  }
616  if (!found) {
617  /* A new object, insert it into the data database */
618  sts = nmpsappl_data_db_create(&nmpsappl_basectx->datalist,
619  applctx->datainfo[i].objid, applctx->options, &data_ptr);
620  if (EVEN(sts))
621  return sts;
622 
623  data_ptr->possession |= applctx->index_mask;
624  applctx->datainfo[i].object_ptr = data_ptr->object_ptr;
625  applctx->datainfo[i].newdata = 1;
626  strcpy(applctx->datainfo[i].name, data_ptr->name);
627 
628  /* Insert in new data list */
629  }
630  }
631 
632  /* Mark objects for remove that was previously possessed by this
633  session only */
634  data_ptr = nmpsappl_basectx->datalist;
635  while (data_ptr) {
636  if (data_ptr->remove && data_ptr->possession & applctx->index_mask) {
637  if (data_ptr->possession == applctx->index_mask
638  && data_ptr->pending_remove) {
639  /* Remove the object from the database */
640  data_next_ptr = data_ptr->next_ptr;
641  sts = nmpsappl_data_db_delete(&nmpsappl_basectx->datalist, data_ptr);
642  if (EVEN(sts))
643  return sts;
644  data_ptr = data_next_ptr;
645  continue;
646  } else {
647  /* Remove next scan */
648  if (data_ptr->possession == applctx->index_mask)
649  data_ptr->pending_remove = 1;
650  else
651  data_ptr->possession &= ~applctx->index_mask;
652  if (applctx->options & nmpsappl_mOption_Remove) {
653  /* Add the removed to the list */
654  applctx->datainfo[applctx->data_count].objid = data_ptr->objid;
655  applctx->datainfo[applctx->data_count].select = 0;
656  applctx->datainfo[applctx->data_count].front = 0;
657  applctx->datainfo[applctx->data_count].back = 0;
658  applctx->datainfo[applctx->data_count].cell_mask = 0;
659  applctx->datainfo[applctx->data_count].removed = 1;
660  applctx->datainfo[i].object_ptr = data_ptr->object_ptr;
661  applctx->datainfo[i].newdata = 0;
662  strcpy(applctx->datainfo[i].name, data_ptr->name);
663  applctx->data_count++;
664  }
665  }
666  }
667  data_ptr = data_ptr->next_ptr;
668  }
669 
670  *datainfo = applctx->datainfo;
671  *data_count = applctx->data_count;
672  return NMPS__SUCCESS;
673 }
674 
682  nmpsappl_t_ctx applctx,
683  pwr_tObjid objid
684  )
685 {
686  int k;
687  nmpsappl_t_cellist* cellist_ptr;
688 
689  for (k = 0; k < applctx->cellist_count; k++) {
690  cellist_ptr = applctx->cellist[k];
691  switch (cellist_ptr->classid) {
692  case pwr_cClass_NMpsCell:
693  case pwr_cClass_NMpsCell60:
694  case pwr_cClass_NMpsCell120:
695  case pwr_cClass_NMpsStoreCell:
696  case pwr_cClass_NMpsStoreCell60:
697  case pwr_cClass_NMpsStoreCell120: {
698  pwr_sClass_NMpsCell* object_ptr;
699 
700  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
701  object_ptr->ExternOpType = NMPS_OPTYPE_EXTDELETE_OBJID;
702  object_ptr->ExternObjId = objid;
703  object_ptr->ExternFlag = 1;
704  break;
705  }
706  default:
707  break;
708  }
709  }
710  return NMPS__SUCCESS;
711 }
712 
721  nmpsappl_t_ctx applctx,
722  pwr_tObjid objid
723  )
724 {
725  int sts, k;
726  nmpsappl_t_cellist* cellist_ptr;
727 
728  for (k = 0; k < applctx->cellist_count; k++) {
729  cellist_ptr = applctx->cellist[k];
730  switch (cellist_ptr->classid) {
731  case pwr_cClass_NMpsCell:
732  case pwr_cClass_NMpsCell60:
733  case pwr_cClass_NMpsCell120:
734  case pwr_cClass_NMpsStoreCell:
735  case pwr_cClass_NMpsStoreCell60:
736  case pwr_cClass_NMpsStoreCell120: {
737  pwr_sClass_NMpsCell* object_ptr;
738 
739  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
740  object_ptr->ExternOpType = NMPS_OPTYPE_EXTDELETE_OBJID;
741  object_ptr->ExternObjId = objid;
742  object_ptr->ExternFlag = 1;
743  break;
744  }
745  default:
746  break;
747  }
748  }
749  sts = gdh_DeleteObject(objid);
750  if (EVEN(sts))
751  return sts;
752 
753  return NMPS__SUCCESS;
754 }
755 
756 pwr_tStatus nmpsappl_SelectData(nmpsappl_t_ctx applctx, pwr_tObjid objid)
757 {
758  int k;
759  nmpsappl_t_cellist* cellist_ptr;
760 
761  for (k = 0; k < applctx->cellist_count; k++) {
762  cellist_ptr = applctx->cellist[k];
763  switch (cellist_ptr->classid) {
764  case pwr_cClass_NMpsStoreCell: {
765  pwr_sClass_NMpsCell* object_ptr;
766 
767  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
768  object_ptr->ExternOpType = NMPS_OPTYPE_EXTSELECT_OBJID;
769  object_ptr->ExternObjId = objid;
770  object_ptr->ExternFlag = 1;
771  break;
772  }
773  default:
774  break;
775  }
776  }
777 
778  return NMPS__SUCCESS;
779 }
780 
781 pwr_tStatus nmpsappl_TransportData(nmpsappl_t_ctx applctx, pwr_tObjid objid,
782  unsigned int from_cell_mask, unsigned int to_cell_mask)
783 {
784  int k;
785  unsigned int mask;
786  nmpsappl_t_cellist* cellist_ptr;
787 
788  /* Check that to cell is not busy or full */
789  mask = 1;
790  for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
791  if (!(mask & to_cell_mask))
792  continue;
793 
794  cellist_ptr = applctx->cellist[k];
795  switch (cellist_ptr->classid) {
796  case pwr_cClass_NMpsCell:
797  case pwr_cClass_NMpsCell60:
798  case pwr_cClass_NMpsCell120:
799  case pwr_cClass_NMpsStoreCell:
800  case pwr_cClass_NMpsStoreCell60:
801  case pwr_cClass_NMpsStoreCell120: {
802  pwr_sClass_NMpsCell* object_ptr;
803 
804  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
805  if (object_ptr->ExternFlag)
806  return NMPS__CELLEXTERNBUSY;
807  if (object_ptr->CellFull)
808  return NMPS__CELLFULL;
809  break;
810  }
811  default:
812  break;
813  }
814  break;
815  }
816 
817  /* Remove data first */
818  mask = 1;
819  for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
820  if (!(mask & from_cell_mask))
821  continue;
822 
823  cellist_ptr = applctx->cellist[k];
824  switch (cellist_ptr->classid) {
825  case pwr_cClass_NMpsCell:
826  case pwr_cClass_NMpsCell60:
827  case pwr_cClass_NMpsCell120:
828  case pwr_cClass_NMpsStoreCell:
829  case pwr_cClass_NMpsStoreCell60:
830  case pwr_cClass_NMpsStoreCell120: {
831  pwr_sClass_NMpsCell* object_ptr;
832 
833  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
834  if (object_ptr->ExternFlag)
835  return NMPS__CELLEXTERNBUSY;
836 
837  object_ptr->ExternOpType = NMPS_OPTYPE_EXTREMOVE_OBJID;
838  object_ptr->ExternObjId = objid;
839  object_ptr->ExternFlag = 1;
840  break;
841  }
842  default:
843  break;
844  }
845  }
846 
847  /* Insert data */
848  mask = 1;
849  for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
850  if (!(mask & to_cell_mask))
851  continue;
852 
853  cellist_ptr = applctx->cellist[k];
854  switch (cellist_ptr->classid) {
855  case pwr_cClass_NMpsCell:
856  case pwr_cClass_NMpsCell60:
857  case pwr_cClass_NMpsCell120:
858  case pwr_cClass_NMpsStoreCell:
859  case pwr_cClass_NMpsStoreCell60:
860  case pwr_cClass_NMpsStoreCell120: {
861  pwr_sClass_NMpsCell* object_ptr;
862 
863  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
864  if (object_ptr->ExternFlag)
865  return NMPS__CELLEXTERNBUSY;
866  if (object_ptr->CellFull)
867  return NMPS__CELLFULL;
868 
869  object_ptr->ExternOpType = NMPS_OPTYPE_EXTINSERT;
870  object_ptr->ExternObjId = objid;
871  object_ptr->ExternFlag = 1;
872  break;
873  }
874  default:
875  break;
876  }
877  break;
878  }
879 
880  return NMPS__SUCCESS;
881 }
882 
883 pwr_tStatus nmpsappl_InsertData(
884  nmpsappl_t_ctx applctx, pwr_tObjid objid, unsigned int cell_mask)
885 {
886  int k;
887  unsigned int mask;
888  nmpsappl_t_cellist* cellist_ptr;
889 
890  /* Insert data */
891  mask = 1;
892  for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
893  if (!(mask & cell_mask))
894  continue;
895 
896  cellist_ptr = applctx->cellist[k];
897  switch (cellist_ptr->classid) {
898  case pwr_cClass_NMpsCell:
899  case pwr_cClass_NMpsCell60:
900  case pwr_cClass_NMpsCell120:
901  case pwr_cClass_NMpsStoreCell:
902  case pwr_cClass_NMpsStoreCell60:
903  case pwr_cClass_NMpsStoreCell120: {
904  pwr_sClass_NMpsCell* object_ptr;
905 
906  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
907  if (object_ptr->ExternFlag)
908  return NMPS__CELLEXTERNBUSY;
909 
910  object_ptr->ExternOpType = NMPS_OPTYPE_EXTINSERT;
911  object_ptr->ExternObjId = objid;
912  object_ptr->ExternFlag = 1;
913  break;
914  }
915  default:
916  break;
917  }
918  break;
919  }
920 
921  return NMPS__SUCCESS;
922 }
923 
924 pwr_tStatus nmpsappl_RemoveAndKeepData(
925  nmpsappl_t_ctx applctx, pwr_tObjid objid, unsigned int cell_mask)
926 {
927  int k;
928  unsigned int mask;
929  nmpsappl_t_cellist* cellist_ptr;
930 
931  /* Remove data first */
932  mask = 1;
933  for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
934  if (!(mask & cell_mask))
935  continue;
936 
937  cellist_ptr = applctx->cellist[k];
938  switch (cellist_ptr->classid) {
939  case pwr_cClass_NMpsCell:
940  case pwr_cClass_NMpsCell60:
941  case pwr_cClass_NMpsCell120:
942  case pwr_cClass_NMpsStoreCell:
943  case pwr_cClass_NMpsStoreCell60:
944  case pwr_cClass_NMpsStoreCell120: {
945  pwr_sClass_NMpsCell* object_ptr;
946 
947  object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
948  if (object_ptr->ExternFlag)
949  return NMPS__CELLEXTERNBUSY;
950 
951  object_ptr->ExternOpType = NMPS_OPTYPE_EXTREMOVE_OBJID;
952  object_ptr->ExternObjId = objid;
953  object_ptr->ExternFlag = 1;
954  break;
955  }
956  default:
957  break;
958  }
959  }
960 
961  return NMPS__SUCCESS;
962 }
Include file for Cdh Class definition handler.
int cdh_ObjidIsEqual(pwr_tOid Object_1, pwr_tOid Object_2)
Test if two object identities are equal.
Definition: co_cdh.c:88
pwr_sAttrRef cdh_ObjidToAref(pwr_tObjid Objid)
Converts an objid to an attrref.
Definition: co_cdh.c:354
pwr_tStatus gdh_GetObjectClass(pwr_tObjid object, pwr_tClassId *classid)
Get the class identifier of an object.
Definition: rt_gdh.c:1107
pwr_tStatus gdh_ObjidToName(pwr_tObjid oid, char *namebuf, pwr_tUInt32 size, pwr_tBitMask nametype)
Get the name of an object identified by its object identity.
Definition: rt_gdh.c:2371
pwr_tStatus gdh_DeleteObject(pwr_tObjid objectId)
Remove a local object.
Definition: rt_gdh.c:513
pwr_tStatus gdh_NameToObjid(const char *objectName, pwr_tObjid *objid)
Get the object identity of an object with name 'name'.
Definition: rt_gdh.c:2202
pwr_tStatus gdh_DLUnrefObjectInfo(pwr_tDlid directLinkId)
Terminate direct linking of an object or an object attribute.
Definition: rt_gdh.c:637
pwr_tStatus gdh_DLRefObjectInfoAttrref(pwr_sAttrRef *addressOfAttributeReference, void **objectData, pwr_tDlid *directLinkId)
Request a direct link to the data denoted by an attribute reference.
Definition: rt_gdh.c:578
pwr_tStatus nmpsappl_MirrorInit(pwr_tString80 *cell_array, unsigned long options, nmpsappl_t_ctx *ctx)
Initialize mirroring.
Definition: nmps_appl.c:245
pwr_tStatus nmpsappl_RemoveAndDeleteData(nmpsappl_t_ctx applctx, pwr_tObjid objid)
Removes and deletes a dataobject from one of the cells that are mirrored.
Definition: nmps_appl.c:720
pwr_tStatus nmpsappl_Mirror(nmpsappl_t_ctx applctx, int *data_count, nmpsappl_t_datainfo **datainfo)
Update mirroring.
Definition: nmps_appl.c:449
pwr_tStatus nmpsappl_RemoveData(nmpsappl_t_ctx applctx, pwr_tObjid objid)
Removes a dataobject from one of the cells that are mirrored.
Definition: nmps_appl.c:681
Include file for NMpsAppl NMps API.
#define EVEN(a)
Check if value is even.
Definition: pwr.h:623
pwr_tCid pwr_tClassId
Class identity type.
Definition: pwr.h:274
char pwr_tString80[80]
80 byte string type.
Definition: pwr.h:412
int pwr_tStatus
Status type.
Definition: pwr.h:284
void * pwr_tAddress
Generic pointer type.
Definition: pwr.h:121
pwr_tString80 name
Definition: nmps_appl.h:84
pwr_tBoolean back
Definition: nmps_appl.h:94
pwr_tObjid objid
Definition: nmps_appl.h:83
unsigned long cell_mask
Definition: nmps_appl.h:103
pwr_tBoolean front
Definition: nmps_appl.h:90
pwr_tBoolean select
Definition: nmps_appl.h:86
pwr_tBoolean removed
Definition: nmps_appl.h:100
pwr_tBoolean newdata
Definition: nmps_appl.h:98
pwr_tAddress object_ptr
Definition: nmps_appl.h:85
Attribute reference.
Definition: pwr.h:557
pwr_tOid Objid
Object identity.
Definition: pwr.h:558
Object identity type.
Definition: pwr.h:263