1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * Copyright (C) 2016 Mopria Alliance, Inc. 4 * Copyright (C) 2013 Hewlett-Packard Development Company, L.P. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 #ifndef __WTYPES_H__ 19 #define __WTYPES_H__ 20 21 #include <stddef.h> 22 #include <stdbool.h> 23 #include <stdint.h> 24 25 /* 26 * A return type for functions. 27 */ 28 typedef enum { 29 /* Request succeeded */ 30 OK = 0, 31 32 /* Request failed due to an unspecified error */ 33 ERROR = -1, 34 35 /* Request failed because it was cancelled */ 36 CANCELLED = -2, 37 38 /* Request failed because corrupt data was detected */ 39 CORRUPT = -3, 40 41 /* Request failed because unexpected ssl certificate received */ 42 BAD_CERTIFICATE = -4 43 } status_t; 44 45 #define ARRAY_SIZE(X) (sizeof(X)/sizeof(X[0])) 46 47 #ifndef MIN 48 #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 49 #endif 50 51 #ifndef MAX 52 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 53 #endif 54 55 /* 56 * Return a the pointer of an enclosing structure from the address of one of its members, where 57 * "class" is the enclosing structure type, "member" is the name of structure member, and 58 * "pointer" is that member's pointer. 59 */ 60 #define IMPL(class, member, pointer) ( (class *)( ((uint32)pointer) - offsetof(class, member) ) ) 61 62 typedef unsigned char ubyte; 63 typedef unsigned char uint8; 64 typedef unsigned short uint16; 65 typedef signed short sint16; 66 typedef signed long sint32; 67 typedef unsigned long uint32; 68 typedef unsigned long long uint64; 69 70 /** A job handle */ 71 typedef unsigned long wJob_t; 72 typedef uintptr_t wStatus_t; 73 74 #endif // __WTYPES_H__