001 /*----------------------------------------------------------------------------*/
002 /* Copyright (c) FIRST 2008-2012. All Rights Reserved. */
003 /* Open Source Software - may be modified and shared by FRC teams. The code */
004 /* must be accompanied by the FIRST BSD license file in the root directory of */
005 /* the project. */
006 /*----------------------------------------------------------------------------*/
007
008 package edu.wpi.first.wpilibj.communication;
009
010 /**
011 *
012 * @author dtjones
013 */
014 public class SemaphoreException extends Exception {
015 public static final int M_semLib = 22 << 16;
016 public static final int M_objLib = 61 << 16;
017
018 public final static int S_objLib_OBJ_ID_ERROR = (M_objLib | 1);
019 public final static int S_objLib_OBJ_UNAVAILABLE = (M_objLib | 2);
020 public final static int S_objLib_OBJ_DELETED = (M_objLib | 3);
021 public final static int S_objLib_OBJ_TIMEOUT = (M_objLib | 4);
022
023 public final static int S_semLib_INVALID_STATE = (M_semLib | 101);
024 public final static int S_semLib_INVALID_OPTION = (M_semLib | 102);
025 public final static int S_semLib_INVALID_QUEUE_TYPE = (M_semLib | 103);
026 public final static int S_semLib_INVALID_OPERATION = (M_semLib | 104);
027 public final static int S_semLib_INVALID_INITIAL_COUNT = (M_semLib | 105);
028 public final static int S_semLib_COUNT_OVERFLOW = (M_semLib | 106);
029
030 /**
031 * Generate a new SemaphoreException from the given status code.
032 * @param status The status code describing the error.
033 */
034 public SemaphoreException (int status) {
035 super(lookUpCode(status));
036 }
037
038 private static String lookUpCode(int status) {
039 switch (status) {
040 case S_objLib_OBJ_ID_ERROR:
041 return "OBJ_ID_ERROR";
042
043 case S_objLib_OBJ_UNAVAILABLE:
044 return "OBJ_UNAVAILABLE";
045
046 case S_objLib_OBJ_DELETED:
047 return "OBJ_DELETED";
048
049 case S_objLib_OBJ_TIMEOUT:
050 return "OBJ_TIMEOUT";
051
052 case S_semLib_INVALID_STATE:
053 return "Invalid semaphore state";
054 case S_semLib_INVALID_OPTION:
055 return "Invalid semaphore option";
056 case S_semLib_INVALID_QUEUE_TYPE:
057 return "Invalid semaphore queue type";
058 case S_semLib_INVALID_OPERATION:
059 return "Invalid semaphore operation";
060 case S_semLib_INVALID_INITIAL_COUNT:
061 return "Invalid semaphore initial count";
062 case S_semLib_COUNT_OVERFLOW:
063 return "Semaphore count overflow";
064 default:
065 return "Unrecognized status code";
066 }
067 }
068 }