Subversion Repositories delphiutils

Rev

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


Illegal statuscodes: 0xFFFFFFFF, 0x00000000, 0x00000001

+-----------------------------------------------+
|     |     |     |     |     |     |     |     |
+-----+-----------------+-----------------------+
|31 28|27             16|15                    0|
|Cat. |Authority        |Message                |
+-----+-----------------+-----------------------+

Category (1 nibble, 4 bits; bits 28..31)

0x0 = Success
0x1 = Not available
0x2 = Error
0x3..0xF are reserved

Authority (3 nibbles, 12 bits; bits 16..27)

0x000 .. 0x0FF = reserved
0x100          = generic status codes (you can use them)
0x101 .. 0xEFF = by ViaThinkSoft assigned organizations (please see below)
0xF00 .. 0xFEF = experimental codes
0xFF0 .. 0xFFF = status codes for documentation purposes

Message (4 nibbles, 16 bits; bits 0..15)

0x0000           = An unspecified status on category "C", issued by authority "A"
0x0001 .. 0xFFFF = the status on category "C", issued by authority "A".

---

Assigned generic status codes:

0 100 0000 = Unspecified success code
0 100 0001 = Success, one identifier returned
0 100 0002 = Success, multiple identifier returned

1 100 0000 = Not available, Unspecified
1 100 0001 = Operating system not supported
1 100 0002 = Hardware not supported
1 100 0003 = No entities available (e.g. no network interfaces for identifing MAC addresses)
1 100 0004 = An API call has failed (possible operating system not supported)

2 100 0000 = Unspecified error
2 100 0001 = Buffer too small
2 100 0002 = Invalid arguments passed to function
2 100 0003 = The plugin is not licensed




type
  UD2_STATUS = DWORD;

type
  UD2_STATUSCAT = $0..$F;
const
  UD2_STATUSCAT_SUCCESS = $0;
  UD2_STATUSCAT_NOT_AVAIL = $1;
  UD2_STATUSCAT_ERROR = $2;

type
  UD2_STATUSAUTH = $000..$FFF;
const
  UD2_STATUSAUTH_GENERIC = $100;

type
  UD2_STATUSMSG = $0000..$FFFF;

const
  UD2_STATUS_OK_UNSPECIFIED = $01000000;
  UD2_STATUS_OK_ONE_ID      = $01000001;
  UD2_STATUS_OK_IDLIST      = $01000002;

  UD2_STATUS_NOTAVAIL_UNSPECIFIED      = $11000000;
  UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED = $11000001;
  UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED = $11000002;
  UD2_STATUS_NOTAVAIL_NO_ENTITIES      = $11000003;
  UD2_STATUS_NOTAVAIL_API_CALL_FAILURE = $11000004;

  UD2_STATUS_ERROR_UNSPECIFIED         = $21000000;
  UD2_STATUS_ERROR_BUFFER_TOO_SMALL    = $21000001;
  UD2_STATUS_ERROR_INVALID_ARGS        = $21000002;
  UD2_STATUS_ERROR_PLUGIN_NOT_LICENSED = $21000003;

function UD2_STATUS_Construct(cat: UD2_STATUSCAT;
  auth: UD2_STATUSAUTH; msg: UD2_STATUSMSG): UD2_STATUS;
begin
  result := (cat shl 28) + (auth shl 16) + msg;
end;

function UD2_STATUS_GetCategory(dwStatus: UD2_STATUS): UD2_STATUSCAT;
begin
  result := (dwStatus and $F0000000) shr 28;
end;

function UD2_STATUS_GetAuthority(dwStatus: UD2_STATUS): UD2_STATUSAUTH;
begin
  result := (dwStatus and $0FFF0000) shr 16;
end;

function UD2_STATUS_GetMessage(dwStatus: UD2_STATUS): UD2_STATUSMSG;
begin
  result := dwStatus and $0000FFFF;
end;

function UD2_STATUS_Successful(dwStatus: UD2_STATUS): boolean;
begin
  result := UD2_STATUS_GetCategory(dwStatus) = UD2_STATUSCAT_SUCCESS;
end;

function UD2_STATUS_NotAvail(dwStatus: UD2_STATUS): boolean;
begin
  result := UD2_STATUS_GetCategory(dwStatus) = UD2_STATUSCAT_NOT_AVAIL;
end;

function UD2_STATUS_Failed(dwStatus: UD2_STATUS): boolean;
begin
  result := UD2_STATUS_GetCategory(dwStatus) = UD2_STATUSCAT_ERROR;
end;

function UD2_STATUS_FormatStatusCode(dwStatus: UD2_STATUS): string;
begin
  result := IntToHex(UD2_STATUS_GetCategory(dwStatus), 1) + ' ' +
            IntToHex(UD2_STATUS_GetAuthority(dwStatus), 3) + ' ' +
            IntToHex(UD2_STATUS_GetMessage(dwStatus), 4);
end;


To aquire an own Authority-ID, please follow these steps:
1. Register a free OID from ViaThinkSoft: www.viathinksoft.de/freeoid 
   Although these OIDs are for private non-commercial individuals, you can also register it as commercial organization.
2. The last arc in your OID + 0x100 is your Authority ID.
For example:
1.3.6.1.4.1.37476.9000.99 -> 99 + 0x100 = 0x63 + 0x100 = 0x163 ,
so you can assign the status codes 0x-0163----
Beside the usage as Authority Identifier for the status codes, you can use your OID for every other purpose. More information about OIDs at oid-info.com