Hi everyone,
I have a unique case wherein i have list of devices(8 in mycase) and each device can have 4 possible states for each device and has 2 channels (4 possible states for each channel).
I have to search a device based on the below algorithm.
1. Not yet opened device (DEVICE_CONNECTED)
2. If step 1 is not available, Opened device with both channels not used (DEVICE_OPENED and check ChannelState of both Channels, and both channelstate should be CHANNEL_CLOSED)
3. If step 1 and 2 are not available, opened device with one channel not used (DEVICE_OPENED and check ChannelState of both Channels, and atleast one channelstate should be CHANNEL_CLOSED)
3a. If step 2 and 3 are not available, Opened device with both channels disabled (DEVICE_OPENED and check ChannelState of both Channels, and both channelstate should be CHANNEL_DISABLED)
3b. If step 2,3 and 3a are not available, opened device with one channel disabled (DEVICE_OPENED and check ChannelState of both Channels, and atleast one channelstate should be CHANNEL_DISABLED)
4. If step 1, 2 and 3 are not possible, DEVICE_IN_USE error message
What you have there is a list of priorities. All you need to do is keep a priority queue if you can detect priority changes, or a std::vector or other sortable collection where you code in those priorities inside operator< or a functor/lambda.