+/**
+ * \brief Update the status of all coke slots
+ * \note Uses goto to reduce the chance of the lock being kept
+ */
+void Coke_int_UpdateSlotStatuses(void)
+{
+ int i, len;
+ char tmp[40];
+
+ if( giCoke_SerialFD == -1 ) return ;
+
+ pthread_mutex_lock(&gCoke_Mutex);
+
+ WaitForColon();
+ Writef("d7\r\n"); // Update slot statuses
+ if( WaitForColon() ) goto ret;
+ Writef("s\n");
+ ReadLine(sizeof tmp, tmp); // Read back what we just said
+
+ for( i = 0; i <= 6; i ++ )
+ {
+ len = ReadLine(sizeof tmp, tmp);
+ if( len == -1 ) {
+ #if TRACE_COKE
+ printf("Coke_int_UpdateSlotStatuses: Read failed on slot %i\n", i);
+ #endif
+ goto ret; // I give up :(
+ }
+ Coke_int_GetSlotStatus(tmp, i);
+ }
+
+ret:
+ pthread_mutex_unlock(&gCoke_Mutex);
+}
+
+int Coke_CanDispense(int UNUSED(User), int Item)
+{
+ // Sanity please
+ if( Item < 0 || Item > 6 ) return -1; // -EYOURBAD
+
+ // Can't dispense if the machine is not connected
+ if( giCoke_SerialFD == -1 )
+ return -2;
+
+ return gaCoke_CachedStatus[Item];