-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/examples v0.6 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5271c1a
44da1ba
d4b9472
1e67a95
6b346c1
eb83099
0fafd54
b5a15c3
33b3752
cca8ea5
ed39e4f
ad407d5
f4b2a53
a5f03dc
ec07eb5
d02ccae
d27e326
cd757d5
a0d2f18
b4ed30e
2d836d1
7f63be8
d2b0566
1a84ccd
c9cbf11
2591238
36bcb0e
39204d3
568f656
b00df6e
481bbdb
72c0eb7
27b7ded
0c8b358
4033bfe
e5d530f
ef7e4af
9a1c2a7
e645142
8d033ba
034ddbb
72765da
a0ed3af
bf54bf4
a5fd85e
ced9806
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,384 @@ | ||
| /* | ||
| * In openDAQ devices are represented by a tree structure. Example demonstrates how to fully explore that tree and displays | ||
| * the type of the object alongside its name. After saving every object into an dictionary, example displays all of saved objects | ||
| * globalIds. | ||
| */ | ||
|
|
||
| #include <daq_utils.h> | ||
|
|
||
| enum ComponentType | ||
| { | ||
| Unk = 0, | ||
| Device, | ||
| FunctionBlock, | ||
| IOFolder, | ||
| Channel, | ||
| Server, | ||
| Signal, | ||
| Folder, | ||
| Component, | ||
| SyncComponent, | ||
| InputPort | ||
| }; | ||
|
|
||
| void componentTreePrintOut(daqDevice* headDevice, daqDict** listOfAvailableDevices, daqBool printout); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| void printDaqSignal(daqSignal* signal, daqDict* listOfAvailableDevices, daqBool printout); | ||
| void printInputPort(daqInputPort* inputPort, daqDict* listOfAvailableDevices, daqBool printout); | ||
| void printDaqSyncComponent(daqSyncComponent* syncComp, daqDict* listOfAvailableDevices, daqBool printout); | ||
|
Comment on lines
+26
to
+28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are duplicates. |
||
| void printDaqServer(daqServer* server, daqDict* listOfAvailableDevices, daqBool printout); | ||
| void printDaqFolder(daqFolder* folder, daqDict* listOfAvailableDevices, daqBool printout); | ||
| void printDaqFunctionBlock(daqFunctionBlock* functionBlock, daqDict* listOfAvailableDevices, daqBool printout); | ||
| void printDaqDevice(daqDevice* device, daqDict* listOfAvailableDevices, daqBool printout); | ||
|
|
||
| void addDaqComponentToDict(daqDict* listOfAvailableDevices, daqComponent* component); | ||
|
|
||
|
|
||
| void addDaqComponentToDict(daqDict* listOfAvailableDevices, daqComponent* component) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The last declaration is implemented first. The order of implementations should follow the declaration order. |
||
| { | ||
| daqString* globalId = NULL; | ||
| daqString* description = NULL; | ||
| daqComponent_getGlobalId(component, &globalId); | ||
| daqComponent_getDescription(component, &description); | ||
|
|
||
| daqDict_set(listOfAvailableDevices, globalId, description); | ||
|
Comment on lines
+41
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description is never used. |
||
|
|
||
| daqReleaseRef(globalId); | ||
| daqReleaseRef(description); | ||
| } | ||
|
|
||
| void componentTreePrintOut(daqDevice* headDevice, daqDict** listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqDict_createDict(listOfAvailableDevices); | ||
| printDaqDevice(headDevice, *listOfAvailableDevices, printout); | ||
| } | ||
|
Comment on lines
+50
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not need to be its own function. |
||
|
|
||
| void printObjectList(daqList* list, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqBaseObject* listMember = NULL; | ||
| daqSizeT count = 0; | ||
| daqList_getCount(list, &count); | ||
| if (count <= 0) | ||
| return; | ||
| daqList_getItemAt(list, 0, &listMember); | ||
| enum ComponentType componentType = Unk; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_DEVICE_INTF_ID) && (componentType == Unk)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These calls are redundant. Whenever the function is called, given the current structure, the type of objects in the list are already known. The component type should be passed as argument. |
||
| componentType = Device; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_SERVER_INTF_ID) && (componentType == Unk)) | ||
| componentType = Server; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_SYNC_COMPONENT_INTF_ID) && (componentType == Unk)) | ||
| componentType = SyncComponent; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_FUNCTION_BLOCK_INTF_ID) && (componentType == Unk)) | ||
| componentType = FunctionBlock; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_FOLDER_INTF_ID) && (componentType == Unk)) | ||
| componentType = Folder; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_INPUT_PORT_INTF_ID) && (componentType == Unk)) | ||
| componentType = InputPort; | ||
|
|
||
| if (DAQ_SUPPORTS_INTERFACE(listMember, DAQ_SIGNAL_INTF_ID) && (componentType == Unk)) | ||
| componentType = Signal; | ||
|
Comment on lines
+66
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be in its own function |
||
|
|
||
| daqSizeT numberOfObjects = 0; | ||
| daqList_getCount(list, &numberOfObjects); | ||
|
|
||
| for (daqSizeT i = 0; i < numberOfObjects; i++) | ||
| { | ||
| daqList_getItemAt(list, i, &listMember); | ||
|
|
||
| switch (componentType) | ||
| { | ||
| case Device: | ||
| { | ||
| daqDevice* device = NULL; | ||
| daqQueryInterface(listMember, DAQ_DEVICE_INTF_ID, &device); | ||
| printDaqDevice(device, listOfAvailableDevices, printout); | ||
| daqReleaseRef(device); | ||
| daqReleaseRef(listMember); | ||
|
Comment on lines
+98
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the query interfaces inside the print functions. It'll be more legible. |
||
| break; | ||
| } | ||
| case Server: | ||
| { | ||
| daqServer* server = NULL; | ||
| daqQueryInterface(listMember, DAQ_SERVER_INTF_ID, &server); | ||
| printDaqServer(server, listOfAvailableDevices, printout); | ||
| daqReleaseRef(server); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| case SyncComponent: | ||
| { | ||
| daqSyncComponent* syncComponent = NULL; | ||
| daqQueryInterface(listMember, DAQ_SYNC_COMPONENT_INTF_ID, &syncComponent); | ||
| printDaqSyncComponent(syncComponent, listOfAvailableDevices, printout); | ||
| daqReleaseRef(syncComponent); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| case FunctionBlock: | ||
| { | ||
| daqFunctionBlock* functionBlock = NULL; | ||
| daqQueryInterface(listMember, DAQ_FUNCTION_BLOCK_INTF_ID, &functionBlock); | ||
| printDaqFunctionBlock(functionBlock, listOfAvailableDevices, printout); | ||
| daqReleaseRef(functionBlock); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| case Folder: | ||
| { | ||
| daqFolder* folder = NULL; | ||
| daqQueryInterface(listMember, DAQ_FOLDER_INTF_ID, &folder); | ||
| printDaqFolder(folder, listOfAvailableDevices, printout); | ||
| daqReleaseRef(folder); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| case InputPort: | ||
| { | ||
| daqInputPort* inputPort = NULL; | ||
| daqQueryInterface(listMember, DAQ_INPUT_PORT_INTF_ID, &inputPort); | ||
| printInputPort(inputPort, listOfAvailableDevices, printout); | ||
| daqReleaseRef(inputPort); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| case Signal: | ||
| { | ||
| daqSignal* signal = NULL; | ||
| daqQueryInterface(listMember, DAQ_SIGNAL_INTF_ID, &signal); | ||
| printDaqSignal(signal, listOfAvailableDevices, printout); | ||
| daqReleaseRef(signal); | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| default: | ||
| { | ||
| daqReleaseRef(listMember); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void printDaqDevice(daqDevice* device, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)device, &name); | ||
|
|
||
| if (printout && name != NULL) | ||
| printDaqFormattedString("Device: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAvailableDevices, (daqComponent*) device); | ||
|
|
||
| daqFolder* ioFolder = NULL; | ||
| daqDevice_getInputsOutputsFolder(device, &ioFolder); | ||
| if (ioFolder != NULL) | ||
| { | ||
| printDaqFolder(ioFolder, listOfAvailableDevices, printout); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just have a method called |
||
| daqReleaseRef(ioFolder); | ||
| } | ||
|
|
||
| daqSyncComponent* syncComponent = NULL; | ||
| daqDevice_getSyncComponent(device, &syncComponent); | ||
| if (syncComponent != NULL) | ||
| { | ||
| printDaqSyncComponent(syncComponent, listOfAvailableDevices, printout); | ||
| daqReleaseRef(syncComponent); | ||
| } | ||
|
|
||
| daqList* devices = NULL; | ||
| daqDevice_getDevices(device, &devices, NULL); | ||
| if (devices != NULL) | ||
| { | ||
| printObjectList(devices, listOfAvailableDevices, printout); | ||
| daqReleaseRef(devices); | ||
| } | ||
|
|
||
| daqList* functionBlocks = NULL; | ||
| daqDevice_getFunctionBlocks(device, &functionBlocks, NULL); | ||
| if (functionBlocks != NULL) | ||
| { | ||
| printObjectList(functionBlocks, listOfAvailableDevices, printout); | ||
| daqReleaseRef(functionBlocks); | ||
| } | ||
|
|
||
| daqList* servers = NULL; | ||
| daqDevice_getServers(device, &servers); | ||
| if (servers != NULL) | ||
| { | ||
| printObjectList(servers, listOfAvailableDevices, printout); | ||
| daqReleaseRef(servers); | ||
| } | ||
| } | ||
|
|
||
| void printDaqFunctionBlock(daqFunctionBlock* functionBlock, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)functionBlock, &name); | ||
|
|
||
| if (printout && name != NULL) | ||
| printDaqFormattedString("Function block: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAvailableDevices, (daqComponent*) functionBlock); | ||
|
|
||
| daqList* functionBlocks = NULL; | ||
| daqFunctionBlock_getFunctionBlocks(functionBlock, &functionBlocks, NULL); | ||
| if (functionBlocks != NULL) | ||
| { | ||
| printObjectList(functionBlocks, listOfAvailableDevices, printout); | ||
| daqReleaseRef(functionBlocks); | ||
| } | ||
|
|
||
| daqList* inputPorts = NULL; | ||
| daqFunctionBlock_getInputPorts(functionBlock, &inputPorts, NULL); | ||
| if (inputPorts != NULL) | ||
| { | ||
| printObjectList(inputPorts, listOfAvailableDevices, printout); | ||
| daqReleaseRef(inputPorts); | ||
| } | ||
|
|
||
| daqList* listOfSignals = NULL; | ||
| daqFunctionBlock_getSignals(functionBlock, &listOfSignals, NULL); | ||
| if (listOfSignals != NULL) | ||
| { | ||
| printObjectList(listOfSignals, listOfAvailableDevices, printout); | ||
| daqReleaseRef(listOfSignals); | ||
| } | ||
| } | ||
|
|
||
| void printDaqFolder(daqFolder* folder, daqDict* listOfAllDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)folder, &name); | ||
|
|
||
|
|
||
| if (printout&& name!=NULL) | ||
| printDaqFormattedString("Folder: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAllDevices, (daqComponent*) folder); | ||
|
|
||
| daqList* listOfItems = NULL; | ||
| daqFolder_getItems(folder, &listOfItems, NULL); | ||
| if (listOfItems != NULL) | ||
| { | ||
| printObjectList(listOfItems, listOfAllDevices, printout); | ||
| daqReleaseRef(listOfItems); | ||
| } | ||
| } | ||
|
|
||
| void printDaqServer(daqServer* server, daqDict* listOfAllAvailableDevices, daqBool printout) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The argument name being |
||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)server, &name); | ||
|
|
||
| if(printout && name != NULL) | ||
| printDaqFormattedString("Server: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAllAvailableDevices, (daqComponent*) server); | ||
|
|
||
| daqList* listOfSignals = NULL; | ||
| daqServer_getSignals(server, &listOfSignals, NULL); | ||
| if (listOfSignals != NULL) | ||
| { | ||
| printObjectList(listOfSignals, listOfAllAvailableDevices, printout); | ||
| daqReleaseRef(listOfSignals); | ||
| } | ||
| } | ||
|
|
||
| void printDaqSyncComponent(daqSyncComponent* syncComp, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)syncComp, &name); | ||
|
|
||
| if(printout && name != NULL) | ||
| printDaqFormattedString("Sync component: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAvailableDevices, (daqComponent*) syncComp); | ||
| } | ||
|
|
||
| void printInputPort(daqInputPort* inputPort, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)inputPort, &name); | ||
|
|
||
| if (printout && name != NULL) | ||
| printDaqFormattedString("Input port: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAvailableDevices, (daqComponent*) inputPort); | ||
| } | ||
|
|
||
| void printDaqSignal(daqSignal* signal, daqDict* listOfAvailableDevices, daqBool printout) | ||
| { | ||
| daqString* name = NULL; | ||
| daqComponent_getName((daqComponent*)signal, &name); | ||
|
|
||
| if (printout && name != NULL) | ||
| printDaqFormattedString("Signal: %s\n", name); | ||
|
|
||
| daqReleaseRef(name); | ||
|
|
||
| addDaqComponentToDict(listOfAvailableDevices, (daqComponent*) signal); | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| daqInstance* simulatorInstance = NULL; | ||
| setupSimulator(&simulatorInstance); | ||
|
|
||
| daqInstance* instance = NULL; | ||
| daqDevice* simulator = NULL; | ||
| addSimulator(&simulator, &instance); | ||
|
|
||
| daqDict* listOfComponents = NULL; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the need why we would want to collect all components here. The goal is to do a DFS tree traversal and print out all component IDs and potentially names/other metadata. Caching all global IDs only to later just print them out seems redundant. |
||
|
|
||
| componentTreePrintOut((daqDevice*)instance, &listOfComponents, True); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this not just call |
||
|
|
||
| daqSizeT count = 0; | ||
| daqDict_getCount(listOfComponents, &count); | ||
| printf("\nNumber of components in the openDAQ tree: %llu\n\n", count); | ||
|
|
||
| daqList* keys = NULL; | ||
| daqDict_getKeyList(listOfComponents, &keys); | ||
| daqIterator* iterator = NULL; | ||
| daqList_createStartIterator(keys, &iterator); | ||
|
Comment on lines
+357
to
+360
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a dictionary if all that's being printed out are the global IDs? |
||
|
|
||
| while(daqIterator_moveNext(iterator) == DAQ_SUCCESS) | ||
| { | ||
| daqBaseObject* current = NULL; | ||
| daqIterator_getCurrent(iterator, ¤t); | ||
| daqString* comp = NULL; | ||
| if(DAQ_SUPPORTS_INTERFACE(current, DAQ_STRING_INTF_ID)) | ||
| { | ||
| daqQueryInterface(current, DAQ_STRING_INTF_ID, &comp); | ||
| daqConstCharPtr constChar = NULL; | ||
| daqString_getCharPtr(comp, &constChar); | ||
| printf("%s\n", constChar); | ||
| } | ||
| daqReleaseRef(current); | ||
| } | ||
|
|
||
| daqReleaseRef(iterator); | ||
| daqReleaseRef(keys); | ||
| daqReleaseRef(listOfComponents); | ||
| daqReleaseRef(simulator); | ||
| daqReleaseRef(instance); | ||
| daqReleaseRef(simulatorInstance); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use full words where abbreviations are redundant.