53 #include "pwr_nmpsclasses.h"
56 #include "co_string.h"
59 #include "rt_gdh_msg.h"
60 #include "rt_hash_msg.h"
61 #include "rs_nmps_msg.h"
68 typedef struct nmpsappl_s_data_list {
71 unsigned int possession;
76 struct nmpsappl_s_data_list* prev_ptr;
77 struct nmpsappl_s_data_list* next_ptr;
78 } nmpsappl_t_data_list;
80 typedef struct nmpsappl_s_basectx {
85 nmpsappl_t_data_list* datalist;
86 } * nmpsappl_t_basectx;
90 static nmpsappl_t_basectx nmpsappl_basectx = 0;
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);
97 nmpsappl_t_data_list** data_list, nmpsappl_t_data_list* data_ptr);
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)
113 nmpsappl_t_data_list* next_ptr;
126 if (options & nmpsappl_mOption_NamePath)
133 *datalist_ptr = calloc(1,
sizeof(nmpsappl_t_data_list));
134 if (*datalist_ptr == 0)
135 return NMPS__NOMEMORY;
137 (*datalist_ptr)->object_ptr = object_ptr;
138 (*datalist_ptr)->subid = subid;
139 (*datalist_ptr)->objid = objid;
140 strcpy((*datalist_ptr)->name, name);
143 next_ptr = *data_list;
144 if (next_ptr != NULL)
145 next_ptr->prev_ptr = *datalist_ptr;
146 (*datalist_ptr)->next_ptr = next_ptr;
148 *data_list = *datalist_ptr;
150 return NMPS__SUCCESS;
165 nmpsappl_t_data_list** data_list, nmpsappl_t_data_list* data_ptr)
171 if (data_ptr == *data_list) {
173 *data_list = data_ptr->next_ptr;
175 (*data_list)->prev_ptr = 0;
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;
185 return NMPS__SUCCESS;
199 void** orig_cell, gdh_tSubid* orig_subid,
pwr_tClassId* orig_class)
207 return NMPS__APPLCELL;
210 memset(&attrref, 0,
sizeof(attrref));
221 return NMPS__APPLCELL;
223 return NMPS__SUCCESS;
252 unsigned long options,
257 nmpsappl_t_basectx basectx;
266 if (nmpsappl_basectx == 0) {
268 nmpsappl_basectx = calloc(1,
sizeof(*nmpsappl_basectx));
269 if (nmpsappl_basectx == 0)
272 basectx = nmpsappl_basectx;
274 if (basectx->applctx_count >= NMPSAPPL_APPLSESS_MAX)
275 return NMPS__APPLSESSMAX;
278 applctx = calloc(1,
sizeof(*applctx));
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++;
292 cellname = cell_array;
293 while (!streq((
char*)cellname,
"")) {
294 str_ToUpper((
char*)cellname, (
char*)cellname);
297 cellist_ptr = basectx->cellist;
299 while (cellist_ptr) {
300 if (streq((
char*)cellname, cellist_ptr->name)) {
304 cellist_ptr = cellist_ptr->next;
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);
316 c_ptr = basectx->cellist;
318 basectx->cellist = cellist_ptr;
322 c_ptr->next = cellist_ptr;
324 basectx->cellist_count++;
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++;
331 return NMPS__APPLCELLIST;
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);
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);
360 cellist_ptr->tmp_cell = (
void*)calloc(1, cellist_ptr->tmp_size);
364 if (options & nmpsappl_mOption_Remove)
372 lck_Create(&sts, lck_eLock_NMps);
376 applctx->options = options;
378 return NMPS__SUCCESS;
459 nmpsappl_t_data_list* data_ptr;
460 nmpsappl_t_data_list* data_next_ptr;
465 for (i = 0; i < applctx->cellist_count; i++) {
466 cellist_ptr = applctx->cellist[i];
469 cellist_ptr->tmp_cell, cellist_ptr->object_ptr, cellist_ptr->tmp_size);
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;
486 object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->tmp_cell;
487 if (!(object_ptr->ReloadDone & NMPS_CELL_INITIALIZED))
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++) {
496 for (j = 0; j < applctx->data_count; j++) {
498 data_block_ptr->DataP.Aref.Objid)) {
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++;
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];
526 if (applctx->options & nmpsappl_mOption_ReverseOrder)
533 case pwr_cClass_NMpsMirrorCell: {
534 pwr_sClass_NMpsMirrorCell* object_ptr;
535 plc_t_DataInfoMirCell* data_block_ptr;
537 object_ptr = (pwr_sClass_NMpsMirrorCell*)cellist_ptr->tmp_cell;
539 data_block_ptr = (plc_t_DataInfoMirCell*)&object_ptr->Data1P;
540 for (i = 0; i < object_ptr->LastIndex; i++) {
543 for (j = 0; j < i; j++) {
545 data_block_ptr->DataP.Aref.Objid)) {
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++;
561 applctx->datainfo[applctx->data_count].
cell_mask
562 |= cellist_ptr->index_mask[applctx->index];
574 data_ptr = nmpsappl_basectx->datalist;
576 if (data_ptr->possession & applctx->index_mask)
577 data_ptr->remove = 1;
578 data_ptr = data_ptr->next_ptr;
581 for (i = 0; i < applctx->data_count; i++) {
584 data_ptr = nmpsappl_basectx->datalist;
587 if (data_ptr->possession & applctx->index_mask) {
589 if (data_ptr->pending_remove)
591 data_ptr->pending_remove = 0;
593 applctx->datainfo[i].
object_ptr = data_ptr->object_ptr;
594 data_ptr->remove = 0;
595 applctx->datainfo[i].
newdata = 0;
598 if (data_ptr->pending_remove) {
600 data_ptr->pending_remove = 0;
601 data_ptr->possession = 0;
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;
610 strcpy(applctx->datainfo[i].
name, data_ptr->name);
614 data_ptr = data_ptr->next_ptr;
618 sts = nmpsappl_data_db_create(&nmpsappl_basectx->datalist,
619 applctx->datainfo[i].
objid, applctx->options, &data_ptr);
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);
634 data_ptr = nmpsappl_basectx->datalist;
636 if (data_ptr->remove && data_ptr->possession & applctx->index_mask) {
637 if (data_ptr->possession == applctx->index_mask
638 && data_ptr->pending_remove) {
640 data_next_ptr = data_ptr->next_ptr;
641 sts = nmpsappl_data_db_delete(&nmpsappl_basectx->datalist, data_ptr);
644 data_ptr = data_next_ptr;
648 if (data_ptr->possession == applctx->index_mask)
649 data_ptr->pending_remove = 1;
651 data_ptr->possession &= ~applctx->index_mask;
652 if (applctx->options & nmpsappl_mOption_Remove) {
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++;
667 data_ptr = data_ptr->next_ptr;
670 *datainfo = applctx->datainfo;
671 *data_count = applctx->data_count;
672 return NMPS__SUCCESS;
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;
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;
710 return NMPS__SUCCESS;
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;
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;
753 return NMPS__SUCCESS;
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;
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;
778 return NMPS__SUCCESS;
782 unsigned int from_cell_mask,
unsigned int to_cell_mask)
790 for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
791 if (!(mask & to_cell_mask))
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;
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;
819 for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
820 if (!(mask & from_cell_mask))
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;
833 object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
834 if (object_ptr->ExternFlag)
835 return NMPS__CELLEXTERNBUSY;
837 object_ptr->ExternOpType = NMPS_OPTYPE_EXTREMOVE_OBJID;
838 object_ptr->ExternObjId = objid;
839 object_ptr->ExternFlag = 1;
849 for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
850 if (!(mask & to_cell_mask))
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;
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;
869 object_ptr->ExternOpType = NMPS_OPTYPE_EXTINSERT;
870 object_ptr->ExternObjId = objid;
871 object_ptr->ExternFlag = 1;
880 return NMPS__SUCCESS;
892 for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
893 if (!(mask & cell_mask))
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;
906 object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
907 if (object_ptr->ExternFlag)
908 return NMPS__CELLEXTERNBUSY;
910 object_ptr->ExternOpType = NMPS_OPTYPE_EXTINSERT;
911 object_ptr->ExternObjId = objid;
912 object_ptr->ExternFlag = 1;
921 return NMPS__SUCCESS;
933 for (k = 0; k < applctx->cellist_count; k++, mask = mask << 1) {
934 if (!(mask & cell_mask))
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;
947 object_ptr = (pwr_sClass_NMpsCell*)cellist_ptr->object_ptr;
948 if (object_ptr->ExternFlag)
949 return NMPS__CELLEXTERNBUSY;
951 object_ptr->ExternOpType = NMPS_OPTYPE_EXTREMOVE_OBJID;
952 object_ptr->ExternObjId = objid;
953 object_ptr->ExternFlag = 1;
961 return NMPS__SUCCESS;
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.
pwr_sAttrRef cdh_ObjidToAref(pwr_tObjid Objid)
Converts an objid to an attrref.
pwr_tStatus gdh_GetObjectClass(pwr_tObjid object, pwr_tClassId *classid)
Get the class identifier of an object.
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.
pwr_tStatus gdh_DeleteObject(pwr_tObjid objectId)
Remove a local object.
pwr_tStatus gdh_NameToObjid(const char *objectName, pwr_tObjid *objid)
Get the object identity of an object with name 'name'.
pwr_tStatus gdh_DLUnrefObjectInfo(pwr_tDlid directLinkId)
Terminate direct linking of an object or an object attribute.
pwr_tStatus gdh_DLRefObjectInfoAttrref(pwr_sAttrRef *addressOfAttributeReference, void **objectData, pwr_tDlid *directLinkId)
Request a direct link to the data denoted by an attribute reference.
pwr_tStatus nmpsappl_MirrorInit(pwr_tString80 *cell_array, unsigned long options, nmpsappl_t_ctx *ctx)
Initialize mirroring.
pwr_tStatus nmpsappl_RemoveAndDeleteData(nmpsappl_t_ctx applctx, pwr_tObjid objid)
Removes and deletes a dataobject from one of the cells that are mirrored.
pwr_tStatus nmpsappl_Mirror(nmpsappl_t_ctx applctx, int *data_count, nmpsappl_t_datainfo **datainfo)
Update mirroring.
pwr_tStatus nmpsappl_RemoveData(nmpsappl_t_ctx applctx, pwr_tObjid objid)
Removes a dataobject from one of the cells that are mirrored.
Include file for NMpsAppl NMps API.
#define EVEN(a)
Check if value is even.
pwr_tCid pwr_tClassId
Class identity type.
char pwr_tString80[80]
80 byte string type.
int pwr_tStatus
Status type.
void * pwr_tAddress
Generic pointer type.
pwr_tOid Objid
Object identity.