David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 1 | // Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // User management API. Platforms that do not have users must still implement |
| 16 | // this API, always reporting a single user current and signed in. |
| 17 | |
| 18 | // These APIs are NOT expected to be thread-safe, so either call them from a |
| 19 | // single thread, or perform proper synchronization around all calls. |
| 20 | |
| 21 | #ifndef STARBOARD_USER_H_ |
| 22 | #define STARBOARD_USER_H_ |
| 23 | |
| 24 | #include "starboard/export.h" |
David Ghandehari | 8c5039b | 2016-08-17 19:39:30 -0700 | [diff] [blame] | 25 | #include "starboard/time.h" |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 26 | #include "starboard/types.h" |
| 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
| 32 | // Private structure representing a device user. |
| 33 | typedef struct SbUserPrivate SbUserPrivate; |
| 34 | |
| 35 | // A handle to a user. |
| 36 | typedef SbUserPrivate* SbUser; |
| 37 | |
| 38 | // A set of string properties that can be queried on a user. |
| 39 | typedef enum SbUserPropertyId { |
| 40 | // The URL to the avatar for a user. Avatars are not provided on all |
| 41 | // platforms. |
| 42 | kSbUserPropertyAvatarUrl, |
| 43 | |
| 44 | // The path to a user's home directory, if supported on this platform. |
| 45 | kSbUserPropertyHomeDirectory, |
| 46 | |
| 47 | // The username of a user, which may be the same as the User ID, or it may be |
| 48 | // friendlier. |
| 49 | kSbUserPropertyUserName, |
| 50 | |
| 51 | // A unique user ID of a user. |
| 52 | kSbUserPropertyUserId, |
| 53 | } SbUserPropertyId; |
| 54 | |
David Ghandehari | 8c5039b | 2016-08-17 19:39:30 -0700 | [diff] [blame] | 55 | #if SB_HAS(USER_APPLICATION_LINKING_SUPPORT) |
| 56 | // Information about an application-specific authorization token. |
| 57 | typedef struct SbUserApplicationTokenResults { |
| 58 | // The size of the buffer pointed to by |token_buffer|. Call |
| 59 | // SbUserMaxAuthenticationTokenSizeInBytes() to get an appropriate size. |
| 60 | // |token_buffer_size| must be set to a value greater than zero. |
| 61 | size_t token_buffer_size; |
| 62 | |
| 63 | // Pointer to a buffer into which the token will be copied. |
| 64 | // |token_buffer| must not be NULL. |
| 65 | char* token_buffer; |
| 66 | |
| 67 | // If true, |expiry| will be set. If false, the token never expires. |
| 68 | bool has_expiry; |
| 69 | |
| 70 | // The absolute time that this token expires. It is valid to use the value of |
| 71 | // |expiry| only if |has_expiry| is true. |
| 72 | SbTime expiry; |
| 73 | } SbUserApplicationTokenResults; |
| 74 | #endif |
| 75 | |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 76 | // Well-defined value for an invalid user. |
| 77 | #define kSbUserInvalid (SbUser) NULL |
| 78 | |
| 79 | // Returns whether the given user handle is valid. |
| 80 | static SB_C_INLINE bool SbUserIsValid(SbUser user) { |
| 81 | return user != kSbUserInvalid; |
| 82 | } |
| 83 | |
| 84 | // Gets a list of up to |users_size| signed-in users, placing the results in |
| 85 | // |out_users|, and returning the number of actual users signed in, whether |
| 86 | // greater or less than |users_size|. It is expected that there will be a unique |
| 87 | // SbUser per signed in user, and that the referenced objects will persist for |
| 88 | // the lifetime of the app. |
| 89 | SB_EXPORT int SbUserGetSignedIn(SbUser* out_users, int users_size); |
| 90 | |
| 91 | // Gets the current primary user, if any. This is the user that is determined, |
| 92 | // in a platform specific way, to be the primary user controlling the |
| 93 | // application. This may be because that user launched the app, or using |
| 94 | // whatever criteria is appropriate for the platform. It is expected that there |
| 95 | // will be a unique SbUser per signed in user, and that the referenced objects |
| 96 | // will persist for the lifetime of the app. |
| 97 | SB_EXPORT SbUser SbUserGetCurrent(); |
| 98 | |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 99 | // Gets the size of the value of |property_id| for |user|, INCLUDING the |
| 100 | // terminating null character. Returns 0 if if |user| is invalid, |property_id| |
| 101 | // isn't recognized, supported, or set for |user|. |
| 102 | SB_EXPORT int SbUserGetPropertySize(SbUser user, SbUserPropertyId property_id); |
| 103 | |
| 104 | // Gets the value of |property_id| for |user|, and places it in |out_value|, |
| 105 | // returning false if |user| is invalid, |property_id| isn't recognized, |
| 106 | // supported, or set for |user|, or if |value_size| is too small. |
| 107 | SB_EXPORT bool SbUserGetProperty(SbUser user, |
| 108 | SbUserPropertyId property_id, |
| 109 | char* out_value, |
| 110 | int value_size); |
David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 111 | #ifdef __cplusplus |
| 112 | } // extern "C" |
| 113 | #endif |
| 114 | |
| 115 | #endif // STARBOARD_USER_H_ |