595cd384d3
This allows the program to get at the singleton component context for the currently running component. The component context can be meaningfully instantiated only once; and since dart doesn't have a predefined way to wire platform-specific values into platform-specific code, we instantiate a singleton here, so all code that is interested can use it. The users of this functionality will be the dart and flutter fuchsia runners. See issue https://github.com/dart-lang/sdk/issues/41523 for details. Tested: manual compile for fuchsia, check behavior. Change-Id: Ib4e15af376ecb932c2d2b28d6f099383d53ccc84 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136524 Commit-Queue: Filip Filmar <fmil@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
63 lines
1.6 KiB
C++
63 lines
1.6 KiB
C++
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
#ifndef RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|
|
#define RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|
|
|
|
#include <endian.h>
|
|
|
|
namespace sys {
|
|
|
|
// From Fuchsia SDK.
|
|
class ComponentContext;
|
|
|
|
} // namespace sys
|
|
|
|
namespace dart {
|
|
|
|
inline uint16_t Utils::HostToBigEndian16(uint16_t value) {
|
|
return htobe16(value);
|
|
}
|
|
|
|
inline uint32_t Utils::HostToBigEndian32(uint32_t value) {
|
|
return htobe32(value);
|
|
}
|
|
|
|
inline uint64_t Utils::HostToBigEndian64(uint64_t value) {
|
|
return htobe64(value);
|
|
}
|
|
|
|
inline uint16_t Utils::HostToLittleEndian16(uint16_t value) {
|
|
return htole16(value);
|
|
}
|
|
|
|
inline uint32_t Utils::HostToLittleEndian32(uint32_t value) {
|
|
return htole32(value);
|
|
}
|
|
|
|
inline uint64_t Utils::HostToLittleEndian64(uint64_t value) {
|
|
return htole64(value);
|
|
}
|
|
|
|
inline char* Utils::StrError(int err, char* buffer, size_t bufsize) {
|
|
if (strerror_r(err, buffer, bufsize) != 0) {
|
|
snprintf(buffer, bufsize, "%s", "strerror_r failed");
|
|
}
|
|
return buffer;
|
|
}
|
|
|
|
// Returns the singleton component context for this process.
|
|
//
|
|
// The returned pointer is never null. The caller must not take ownership of
|
|
// the context.
|
|
//
|
|
// The context is a singleton as it can be meaningfully instantiated only once
|
|
// during the lifetime of the program. If you use this function, you MUST NOT
|
|
// call sys::ComponentContext::Create().
|
|
sys::ComponentContext* ComponentContext();
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_PLATFORM_UTILS_FUCHSIA_H_
|