Subversion Repositories delphiutils

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef _UD2_STATUS_H_
  2. #define _UD2_STATUS_H_
  3.  
  4. #include <stdio.h>
  5.  
  6. typedef DWORD UD2_STATUS;
  7. typedef BYTE UD2_STATUSCAT; // 0x0..0xF; only 1 nibble!
  8. typedef WORD UD2_STATUSAUTH; // 0x000..0xFFF; only 3 nibbles!
  9. typedef WORD UD2_STATUSMSG;
  10.  
  11. const UD2_STATUSCAT UD2_STATUSCAT_SUCCESS   = 0x8;
  12. const UD2_STATUSCAT UD2_STATUSCAT_NOT_AVAIL = 0x9;
  13. const UD2_STATUSCAT UD2_STATUSCAT_ERROR     = 0xA;
  14.  
  15. const UD2_STATUSAUTH UD2_STATUSAUTH_GENERIC = 0x100;
  16.  
  17. const UD2_STATUS UD2_STATUS_OK_UNSPECIFIED  = 0x81000000;
  18. const UD2_STATUS UD2_STATUS_OK_SINGLELINE   = 0x81000001;
  19. const UD2_STATUS UD2_STATUS_OK_MULTILINE    = 0x81000002;
  20. const UD2_STATUS UD2_STATUS_OK_LICENSED     = 0x81000003;
  21.  
  22. const UD2_STATUS UD2_STATUS_NOTAVAIL_UNSPECIFIED       = 0x91000000;
  23. const UD2_STATUS UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED  = 0x91000001;
  24. const UD2_STATUS UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED  = 0x91000002;
  25. const UD2_STATUS UD2_STATUS_NOTAVAIL_NO_ENTITIES       = 0x91000003;
  26. const UD2_STATUS UD2_STATUS_NOTAVAIL_API_CALL_FAILURE  = 0x91000004;
  27.  
  28. const UD2_STATUS UD2_STATUS_ERROR_UNSPECIFIED          = 0xA1000000;
  29. const UD2_STATUS UD2_STATUS_ERROR_BUFFER_TOO_SMALL     = 0xA1000001;
  30. const UD2_STATUS UD2_STATUS_ERROR_INVALID_ARGS         = 0xA1000002;
  31. const UD2_STATUS UD2_STATUS_ERROR_PLUGIN_NOT_LICENSED  = 0xA1000003;
  32.  
  33. UD2_STATUS UD2_STATUS_Construct(UD2_STATUSCAT cat, UD2_STATUSAUTH auth, UD2_STATUSMSG msg) {
  34.         return (cat << 28) + (auth << 16) + msg;
  35. }
  36.  
  37. UD2_STATUSCAT UD2_STATUS_GetCategory(UD2_STATUS dwStatus) {
  38.         return (dwStatus & 0xF0000000) >> 28;
  39. }
  40.  
  41. UD2_STATUSAUTH UD2_STATUS_GetAuthority(UD2_STATUS dwStatus) {
  42.         return (dwStatus & 0x0FFF0000) >> 16;
  43. }
  44.  
  45. UD2_STATUSMSG UD2_STATUS_GetMessage(UD2_STATUS dwStatus) {
  46.         return dwStatus & 0x0000FFFF;
  47. }
  48.  
  49. BOOL UD2_STATUS_Successful(UD2_STATUS dwStatus) {
  50.         return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_SUCCESS;
  51. }
  52.  
  53. BOOL UD2_STATUS_NotAvail(UD2_STATUS dwStatus) {
  54.         return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_NOT_AVAIL;
  55. }
  56.  
  57. BOOL UD2_STATUS_Failed(UD2_STATUS dwStatus) {
  58.         return UD2_STATUS_GetCategory(dwStatus) == UD2_STATUSCAT_ERROR;
  59. }
  60.  
  61. int UD2_STATUS_FormatStatusCode(char* szStr, size_t cchLen, UD2_STATUS dwStatus) {
  62.         if (cchLen < 11) szStr = NULL;
  63.         return sprintf(szStr, "%01x %03x %04x", UD2_STATUS_GetCategory(dwStatus),
  64.                                                 UD2_STATUS_GetAuthority(dwStatus),
  65.                                                 UD2_STATUS_GetMessage(dwStatus));
  66. }
  67.  
  68. BOOL UD2_STATUS_IsSpecific(UD2_STATUS dwStatus) {
  69.         return (dwStatus & 0x0000FFFF) != 0;
  70. }
  71.  
  72. #endif
  73.