1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include "flutter/fml/logging.h" 8 #include "flutter/fml/unique_object.h" 9 #include "lib/fdio/namespace.h" 10 11 namespace flutter_runner { 12 13 struct UniqueFDIONSTraits { InvalidValueUniqueFDIONSTraits14 static fdio_ns_t* InvalidValue() { return nullptr; } 15 IsValidUniqueFDIONSTraits16 static bool IsValid(fdio_ns_t* ns) { return ns != InvalidValue(); } 17 FreeUniqueFDIONSTraits18 static void Free(fdio_ns_t* ns) { 19 auto status = fdio_ns_destroy(ns); 20 FML_DCHECK(status == ZX_OK); 21 } 22 }; 23 24 using UniqueFDIONS = fml::UniqueObject<fdio_ns_t*, UniqueFDIONSTraits>; 25 UniqueFDIONSCreate()26inline UniqueFDIONS UniqueFDIONSCreate() { 27 fdio_ns_t* ns = nullptr; 28 if (fdio_ns_create(&ns) == ZX_OK) { 29 return UniqueFDIONS{ns}; 30 } 31 return UniqueFDIONS{nullptr}; 32 } 33 34 } // namespace flutter_runner 35