Skip to content

Commit

Permalink
refactor: rename PassThroughStream to DuplexStream (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
grabbou committed Nov 12, 2024
1 parent 31d22a3 commit ede6f27
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class HybridPassThroughStream : HybridPassThroughStreamSpec {
class HybridDuplexStream : HybridDuplexStreamSpec {
var inputStream: (any HybridInputStreamSpec)
var outputStream: (any HybridOutputStreamSpec)

Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-fast-io/nitro.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"Network": {
"swift": "HybridNetwork"
},
"PassThroughStream": {
"swift": "HybridPassThroughStream"
"DuplexStream": {
"swift": "HybridDuplexStream"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_sources(
../nitrogen/generated/shared/c++/HybridNetworkSpec.cpp
../nitrogen/generated/shared/c++/HybridInputStreamSpec.cpp
../nitrogen/generated/shared/c++/HybridOutputStreamSpec.cpp
../nitrogen/generated/shared/c++/HybridPassThroughStreamSpec.cpp
../nitrogen/generated/shared/c++/HybridDuplexStreamSpec.cpp
../nitrogen/generated/shared/c++/HybridWebSocketSpec.cpp
../nitrogen/generated/shared/c++/HybridWebSocketManagerSpec.cpp
# Android-specific Nitrogen C++ sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

// Include C++ implementation defined types
#include "FastIO-Swift-Cxx-Umbrella.hpp"
#include "HybridDuplexStreamSpecSwift.hpp"
#include "HybridFileSystemSpecSwift.hpp"
#include "HybridInputStreamSpecSwift.hpp"
#include "HybridNetworkSpecSwift.hpp"
#include "HybridOutputStreamSpecSwift.hpp"
#include "HybridPassThroughStreamSpecSwift.hpp"
#include "HybridWebSocketManagerSpecSwift.hpp"
#include "HybridWebSocketSpecSwift.hpp"
#include <NitroModules/HybridContext.hpp>
Expand Down Expand Up @@ -84,20 +84,20 @@ namespace margelo::nitro::fastio::bridge::swift {
return FastIO::HybridOutputStreamSpecCxxUnsafe::toUnsafe(swiftPart);
}

// pragma MARK: std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec>
std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec> create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(void* _Nonnull swiftUnsafePointer) {
FastIO::HybridPassThroughStreamSpecCxx swiftPart = FastIO::HybridPassThroughStreamSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer);
return HybridContext::getOrCreate<margelo::nitro::fastio::HybridPassThroughStreamSpecSwift>(swiftPart);
// pragma MARK: std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec>
std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec> create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(void* _Nonnull swiftUnsafePointer) {
FastIO::HybridDuplexStreamSpecCxx swiftPart = FastIO::HybridDuplexStreamSpecCxxUnsafe::fromUnsafe(swiftUnsafePointer);
return HybridContext::getOrCreate<margelo::nitro::fastio::HybridDuplexStreamSpecSwift>(swiftPart);
}
void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ cppType) {
std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::fastio::HybridPassThroughStreamSpecSwift>(cppType);
void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ cppType) {
std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::fastio::HybridDuplexStreamSpecSwift>(cppType);
#ifdef NITRO_DEBUG
if (swiftWrapper == nullptr) [[unlikely]] {
throw std::runtime_error("Class \"HybridPassThroughStreamSpec\" is not implemented in Swift!");
throw std::runtime_error("Class \"HybridDuplexStreamSpec\" is not implemented in Swift!");
}
#endif
FastIO::HybridPassThroughStreamSpecCxx swiftPart = swiftWrapper->getSwiftPart();
return FastIO::HybridPassThroughStreamSpecCxxUnsafe::toUnsafe(swiftPart);
FastIO::HybridDuplexStreamSpecCxx swiftPart = swiftWrapper->getSwiftPart();
return FastIO::HybridDuplexStreamSpecCxxUnsafe::toUnsafe(swiftPart);
}

// pragma MARK: std::shared_ptr<margelo::nitro::fastio::HybridWebSocketSpec>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace NitroModules { class ArrayBufferHolder; }
// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
// Forward declaration of `HybridDuplexStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridDuplexStreamSpec; }
// Forward declaration of `HybridFileSystemSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridFileSystemSpec; }
// Forward declaration of `HybridInputStreamSpec` to properly resolve imports.
Expand All @@ -20,8 +22,6 @@ namespace margelo::nitro::fastio { class HybridInputStreamSpec; }
namespace margelo::nitro::fastio { class HybridNetworkSpec; }
// Forward declaration of `HybridOutputStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridOutputStreamSpec; }
// Forward declaration of `HybridPassThroughStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridPassThroughStreamSpec; }
// Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridWebSocketManagerSpec; }
// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
Expand All @@ -30,6 +30,8 @@ namespace margelo::nitro::fastio { class HybridWebSocketSpec; }
namespace margelo::nitro::fastio { struct NativeFilePickerOptions; }

// Forward declarations of Swift defined types
// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridDuplexStreamSpecCxx; }
// Forward declaration of `HybridFileSystemSpecCxx` to properly resolve imports.
namespace FastIO { class HybridFileSystemSpecCxx; }
// Forward declaration of `HybridInputStreamSpecCxx` to properly resolve imports.
Expand All @@ -38,19 +40,17 @@ namespace FastIO { class HybridInputStreamSpecCxx; }
namespace FastIO { class HybridNetworkSpecCxx; }
// Forward declaration of `HybridOutputStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridOutputStreamSpecCxx; }
// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridPassThroughStreamSpecCxx; }
// Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports.
namespace FastIO { class HybridWebSocketManagerSpecCxx; }
// Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports.
namespace FastIO { class HybridWebSocketSpecCxx; }

// Include C++ defined types
#include "HybridDuplexStreamSpec.hpp"
#include "HybridFileSystemSpec.hpp"
#include "HybridInputStreamSpec.hpp"
#include "HybridNetworkSpec.hpp"
#include "HybridOutputStreamSpec.hpp"
#include "HybridPassThroughStreamSpec.hpp"
#include "HybridWebSocketManagerSpec.hpp"
#include "HybridWebSocketSpec.hpp"
#include "NativeFilePickerOptions.hpp"
Expand Down Expand Up @@ -167,13 +167,13 @@ namespace margelo::nitro::fastio::bridge::swift {
std::shared_ptr<margelo::nitro::fastio::HybridOutputStreamSpec> create_std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_(void* _Nonnull swiftUnsafePointer);
void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridOutputStreamSpec_ cppType);

// pragma MARK: std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec>
// pragma MARK: std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec>
/**
* Specialized version of `std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec>`.
* Specialized version of `std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec>`.
*/
using std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ = std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec>;
std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec> create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(void* _Nonnull swiftUnsafePointer);
void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ cppType);
using std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ = std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec>;
std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec> create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(void* _Nonnull swiftUnsafePointer);
void* _Nonnull get_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ cppType);

// pragma MARK: std::function<void(const std::string& /* selectedProtocol */)>
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// Forward declarations of C++ defined types
// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }
// Forward declaration of `HybridDuplexStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridDuplexStreamSpec; }
// Forward declaration of `HybridFileSystemSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridFileSystemSpec; }
// Forward declaration of `HybridInputStreamSpec` to properly resolve imports.
Expand All @@ -18,8 +20,6 @@ namespace margelo::nitro::fastio { class HybridInputStreamSpec; }
namespace margelo::nitro::fastio { class HybridNetworkSpec; }
// Forward declaration of `HybridOutputStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridOutputStreamSpec; }
// Forward declaration of `HybridPassThroughStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridPassThroughStreamSpec; }
// Forward declaration of `HybridWebSocketManagerSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridWebSocketManagerSpec; }
// Forward declaration of `HybridWebSocketSpec` to properly resolve imports.
Expand All @@ -36,11 +36,11 @@ namespace margelo::nitro::fastio { struct RequestOptions; }
namespace margelo::nitro::fastio { enum class WellKnownDirectory; }

// Include C++ defined types
#include "HybridDuplexStreamSpec.hpp"
#include "HybridFileSystemSpec.hpp"
#include "HybridInputStreamSpec.hpp"
#include "HybridNetworkSpec.hpp"
#include "HybridOutputStreamSpec.hpp"
#include "HybridPassThroughStreamSpec.hpp"
#include "HybridWebSocketManagerSpec.hpp"
#include "HybridWebSocketSpec.hpp"
#include "Metadata.hpp"
Expand All @@ -66,6 +66,8 @@ namespace margelo::nitro::fastio { enum class WellKnownDirectory; }
#include <NitroModules/PromiseHolder.hpp>

// Forward declarations of Swift defined types
// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridDuplexStreamSpecCxx; }
// Forward declaration of `HybridFileSystemSpecCxx` to properly resolve imports.
namespace FastIO { class HybridFileSystemSpecCxx; }
// Forward declaration of `HybridInputStreamSpecCxx` to properly resolve imports.
Expand All @@ -74,8 +76,6 @@ namespace FastIO { class HybridInputStreamSpecCxx; }
namespace FastIO { class HybridNetworkSpecCxx; }
// Forward declaration of `HybridOutputStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridOutputStreamSpecCxx; }
// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridPassThroughStreamSpecCxx; }
// Forward declaration of `HybridWebSocketManagerSpecCxx` to properly resolve imports.
namespace FastIO { class HybridWebSocketManagerSpecCxx; }
// Forward declaration of `HybridWebSocketSpecCxx` to properly resolve imports.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "HybridWebSocketManagerSpecSwift.hpp"
#include "HybridFileSystemSpecSwift.hpp"
#include "HybridNetworkSpecSwift.hpp"
#include "HybridPassThroughStreamSpecSwift.hpp"
#include "HybridDuplexStreamSpecSwift.hpp"

@interface FastIOAutolinking : NSObject
@end
Expand Down Expand Up @@ -46,9 +46,9 @@ + (void) load {
}
);
HybridObjectRegistry::registerHybridObjectConstructor(
"PassThroughStream",
"DuplexStream",
[]() -> std::shared_ptr<HybridObject> {
std::shared_ptr<margelo::nitro::fastio::HybridPassThroughStreamSpec> hybridObject = FastIO::FastIOAutolinking::createPassThroughStream();
std::shared_ptr<margelo::nitro::fastio::HybridDuplexStreamSpec> hybridObject = FastIO::FastIOAutolinking::createDuplexStream();
return hybridObject;
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ public final class FastIOAutolinking {
}

/**
* Creates an instance of a Swift class that implements `HybridPassThroughStreamSpec`,
* and wraps it in a Swift class that can directly interop with C++ (`HybridPassThroughStreamSpecCxx`)
* Creates an instance of a Swift class that implements `HybridDuplexStreamSpec`,
* and wraps it in a Swift class that can directly interop with C++ (`HybridDuplexStreamSpecCxx`)
*
* This is generated by Nitrogen and will initialize the class specified
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridPassThroughStream`).
* in the `"autolinking"` property of `nitro.json` (in this case, `HybridDuplexStream`).
*/
public static func createPassThroughStream() -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ {
let hybridObject = HybridPassThroughStream()
return { () -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_ in
let __cxxWrapped = HybridPassThroughStreamSpecCxx(hybridObject)
let __pointer = HybridPassThroughStreamSpecCxxUnsafe.toUnsafe(__cxxWrapped)
return bridge.create_std__shared_ptr_margelo__nitro__fastio__HybridPassThroughStreamSpec_(__pointer)
public static func createDuplexStream() -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ {
let hybridObject = HybridDuplexStream()
return { () -> bridge.std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_ in
let __cxxWrapped = HybridDuplexStreamSpecCxx(hybridObject)
let __pointer = HybridDuplexStreamSpecCxxUnsafe.toUnsafe(__cxxWrapped)
return bridge.create_std__shared_ptr_margelo__nitro__fastio__HybridDuplexStreamSpec_(__pointer)
}()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
///
/// HybridPassThroughStreamSpecSwift.cpp
/// HybridDuplexStreamSpecSwift.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

#include "HybridPassThroughStreamSpecSwift.hpp"
#include "HybridDuplexStreamSpecSwift.hpp"

namespace margelo::nitro::fastio {
} // namespace margelo::nitro::fastio
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
///
/// HybridPassThroughStreamSpecSwift.hpp
/// HybridDuplexStreamSpecSwift.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
///

#pragma once

#include "HybridPassThroughStreamSpec.hpp"
#include "HybridDuplexStreamSpec.hpp"

// Forward declaration of `HybridPassThroughStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridPassThroughStreamSpecCxx; }
// Forward declaration of `HybridDuplexStreamSpecCxx` to properly resolve imports.
namespace FastIO { class HybridDuplexStreamSpecCxx; }

// Forward declaration of `HybridInputStreamSpec` to properly resolve imports.
namespace margelo::nitro::fastio { class HybridInputStreamSpec; }
Expand All @@ -32,25 +32,25 @@ namespace margelo::nitro::fastio { class HybridOutputStreamSpec; }
namespace margelo::nitro::fastio {

/**
* The C++ part of HybridPassThroughStreamSpecCxx.swift.
* The C++ part of HybridDuplexStreamSpecCxx.swift.
*
* HybridPassThroughStreamSpecSwift (C++) accesses HybridPassThroughStreamSpecCxx (Swift), and might
* HybridDuplexStreamSpecSwift (C++) accesses HybridDuplexStreamSpecCxx (Swift), and might
* contain some additional bridging code for C++ <> Swift interop.
*
* Since this obviously introduces an overhead, I hope at some point in
* the future, HybridPassThroughStreamSpecCxx can directly inherit from the C++ class HybridPassThroughStreamSpec
* the future, HybridDuplexStreamSpecCxx can directly inherit from the C++ class HybridDuplexStreamSpec
* to simplify the whole structure and memory management.
*/
class HybridPassThroughStreamSpecSwift: public virtual HybridPassThroughStreamSpec {
class HybridDuplexStreamSpecSwift: public virtual HybridDuplexStreamSpec {
public:
// Constructor from a Swift instance
explicit HybridPassThroughStreamSpecSwift(const FastIO::HybridPassThroughStreamSpecCxx& swiftPart):
HybridObject(HybridPassThroughStreamSpec::TAG),
explicit HybridDuplexStreamSpecSwift(const FastIO::HybridDuplexStreamSpecCxx& swiftPart):
HybridObject(HybridDuplexStreamSpec::TAG),
_swiftPart(swiftPart) { }

public:
// Get the Swift part
inline FastIO::HybridPassThroughStreamSpecCxx getSwiftPart() noexcept { return _swiftPart; }
inline FastIO::HybridDuplexStreamSpecCxx getSwiftPart() noexcept { return _swiftPart; }

public:
// Get memory pressure
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace margelo::nitro::fastio {


private:
FastIO::HybridPassThroughStreamSpecCxx _swiftPart;
FastIO::HybridDuplexStreamSpecCxx _swiftPart;
};

} // namespace margelo::nitro::fastio
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///
/// HybridPassThroughStreamSpec.swift
/// HybridDuplexStreamSpec.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2024 Marc Rousavy @ Margelo
Expand All @@ -9,12 +9,12 @@ import Foundation
import NitroModules

/**
* A Swift protocol representing the PassThroughStream HybridObject.
* Implement this protocol to create Swift-based instances of PassThroughStream.
* A Swift protocol representing the DuplexStream HybridObject.
* Implement this protocol to create Swift-based instances of DuplexStream.
*
* When implementing this protocol, make sure to initialize `hybridContext` - example:
* ```
* public class HybridPassThroughStream : HybridPassThroughStreamSpec {
* public class HybridDuplexStream : HybridDuplexStreamSpec {
* // Initialize HybridContext
* var hybridContext = margelo.nitro.HybridContext()
*
Expand All @@ -27,7 +27,7 @@ import NitroModules
* }
* ```
*/
public protocol HybridPassThroughStreamSpec: AnyObject, HybridObjectSpec {
public protocol HybridDuplexStreamSpec: AnyObject, HybridObjectSpec {
// Properties
var inputStream: (any HybridInputStreamSpec) { get set }
var outputStream: (any HybridOutputStreamSpec) { get set }
Expand Down
Loading

0 comments on commit ede6f27

Please sign in to comment.