void IedConnection_getDeviceModelFromServer(IedConnection self, IedClientError* error) { MmsError mmsError = MMS_ERROR_NONE; *error = IED_ERROR_OK; LinkedList logicalDeviceNames = MmsConnection_getDomainNames(self->connection, &mmsError); if (logicalDeviceNames != NULL) { if (self->logicalDevices != NULL) { LinkedList_destroyDeep(self->logicalDevices, (LinkedListValueDeleteFunction) ICLogicalDevice_destroy); self->logicalDevices = NULL; } LinkedList logicalDevice = LinkedList_getNext(logicalDeviceNames); LinkedList logicalDevices = LinkedList_create(); while (logicalDevice != NULL) { char* name = (char*) logicalDevice->data; ICLogicalDevice* icLogicalDevice = ICLogicalDevice_create(name); LinkedList variables = MmsConnection_getDomainVariableNames(self->connection, &mmsError, name); if (variables != NULL) ICLogicalDevice_setVariableList(icLogicalDevice, variables); else { *error = iedConnection_mapMmsErrorToIedError(mmsError); break; } LinkedList dataSets = MmsConnection_getDomainVariableListNames(self->connection, &mmsError, name); if (dataSets != NULL) ICLogicalDevice_setDataSetList(icLogicalDevice, dataSets); else { *error = iedConnection_mapMmsErrorToIedError(mmsError); break; } LinkedList_add(logicalDevices, icLogicalDevice); logicalDevice = LinkedList_getNext(logicalDevice); } self->logicalDevices = logicalDevices; LinkedList_destroy(logicalDeviceNames); } else { *error = iedConnection_mapMmsErrorToIedError(mmsError); } }
int main(int argc, char** argv) { char* hostname; int tcpPort = 102; if (argc > 1) hostname = argv[1]; else hostname = "localhost"; if (argc > 2) tcpPort = atoi(argv[2]); MmsConnection con = MmsConnection_create(); MmsIndication indication; indication = MmsConnection_connect(con, hostname, tcpPort); if (indication != MMS_OK) { printf("MMS connect failed!\n"); goto exit; } else printf("MMS connected.\n\n"); printf("Domains present on server:\n--------------------------\n"); LinkedList nameList = MmsConnection_getDomainNames(con); LinkedList_printStringList(nameList); LinkedList_destroy(nameList); printf("\n"); exit: MmsConnection_destroy(con); }