blob: 1d85cc97ce0a0b1f1e266340f9dc37779d4fd859 [file] [log] [blame]
// Copyright 2019 The Cobalt Authors. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdint.h>
#include "starboard/configuration.h"
#ifdef __cplusplus
extern "C" {
typedef struct CobaltExtensionPlatformServicePrivate
typedef CobaltExtensionPlatformServicePrivate* CobaltExtensionPlatformService;
// Well-defined value for an invalid |Service|.
#define kCobaltExtensionPlatformServiceInvalid \
#define kCobaltExtensionPlatformServiceName \
// Checks whether a |CobaltExtensionPlatformService| is valid.
static SB_C_INLINE bool CobaltExtensionPlatformServiceIsValid(
CobaltExtensionPlatformService service) {
return service != kCobaltExtensionPlatformServiceInvalid;
// When a client receives a message from a service, the service will be passed
// in as the |context| here, with |data|, which has length |length|.
typedef void (*ReceiveMessageCallback)(void* context, void* data,
uint64_t length);
typedef struct CobaltExtensionPlatformServiceApi {
// Name should be the string kCobaltExtensionPlatformServiceName.
// This helps to validate that the extension API is correct.
const char* name;
// This specifies the version of the API that is implemented.
uint32_t version;
// The fields below this point were added in version 1 or later.
// Return whether the platform has service indicated by |name|.
bool (*Has)(const char* name);
// Open and return a service by name.
// |context|: pointer to context object for callback.
// |name|: name of the service.
// |receive_callback|: callback to run when Cobalt should receive data.
CobaltExtensionPlatformService (*Open)(
void* context, const char* name, ReceiveMessageCallback receive_callback);
// Close the service passed in as |service|.
void (*Close)(CobaltExtensionPlatformService service);
// Send |data| of length |length| to |service|. If there is a synchronous
// response, it will be returned via void* and |output_length| will be set
// to its length. The returned void* will be owned by the caller, and must
// be deallocated via SbMemoryDeallocate() by the caller when appropriate.
// If there is no synchronous response, NULL will be returned and
// |output_length| will be 0. The |invalid_state| will be set to true if the
// service is not currently able to accept data, and otherwise will be set to
// false.
void* (*Send)(CobaltExtensionPlatformService service, void* data,
uint64_t length, uint64_t* output_length, bool* invalid_state);
} CobaltExtensionPlatformServiceApi;
#ifdef __cplusplus
} // extern "C"