Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Djinni Interface Inheritance #270

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions example/generated-src/cpp/sort_items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <memory>
#include <string>

namespace textsort {

Expand All @@ -15,6 +16,33 @@ class SortItems {
public:
virtual ~SortItems() {}

/**
* Defines the name of the JNI C++ proxy class. Used to convert a
* C++ implemented object to a Java object when the type of the object being
* converted is unknown to the JniInterface (see djinni_support.hpp).
*
* The proxy class name is only used for converting Djinni interfaces that
* are implemented in C++. Java implemented interfaces are converted differently.
* However, the C++ class of an interface implemented in Java must still have a
* jniProxyClassName method in order for Djinni's JniInterface::fromCpp method to compile.
*
* @return The name of the class's associated JNI proxy class.
*
* @see JniInterface in djinni_support.hpp
*/
virtual const std::string jniProxyClassName() { return "com/dropbox/textsort/SortItems$CppProxy"; }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jniProxyClassName and objcProxyClassName are now generated for each interface to workaround type slicing when creating the Java and the Objective-C proxies. I would love to come up with a better approach to this, but I think it will require a large change to Djinni's proxy caching. This was a "good enough" solution for our needs.


/**
* Defines the name of the Objective-C type for the class. Used to convert a
* C++ object to an Objective-C object when the type of the object being
* converted is unknown to the C++ wrapper cache (see DJICppWrapperCache+Private.hpp).
*
* @return The name of the Objective C type associated with the class.
*
* @see get_cpp_proxy function in DJICppWrapperCache+Private.hpp
*/
virtual const std::string objcProxyClassName() { return "TXSSortItems"; }

/** For the iOS / Android demo */
virtual void sort(sort_order order, const ItemList & items) = 0;

Expand Down
29 changes: 29 additions & 0 deletions example/generated-src/cpp/textbox_listener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#pragma once

#include <string>

namespace textsort {

struct ItemList;
Expand All @@ -11,6 +13,33 @@ class TextboxListener {
public:
virtual ~TextboxListener() {}

/**
* Defines the name of the JNI C++ proxy class. Used to convert a
* C++ implemented object to a Java object when the type of the object being
* converted is unknown to the JniInterface (see djinni_support.hpp).
*
* The proxy class name is only used for converting Djinni interfaces that
* are implemented in C++. Java implemented interfaces are converted differently.
* However, the C++ class of an interface implemented in Java must still have a
* jniProxyClassName method in order for Djinni's JniInterface::fromCpp method to compile.
*
* @return The name of the class's associated JNI proxy class.
*
* @see JniInterface in djinni_support.hpp
*/
virtual const std::string jniProxyClassName() { return nullptr; }

/**
* Defines the name of the Objective-C type for the class. Used to convert a
* C++ object to an Objective-C object when the type of the object being
* converted is unknown to the C++ wrapper cache (see DJICppWrapperCache+Private.hpp).
*
* @return The name of the Objective C type associated with the class.
*
* @see get_cpp_proxy function in DJICppWrapperCache+Private.hpp
*/
virtual const std::string objcProxyClassName() { return "TXSTextboxListener"; }

virtual void update(const ItemList & items) = 0;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public final class ItemList {
/*package*/ final class ItemList {


/*package*/ final ArrayList<String> mItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public abstract class SortItems {
/*package*/ abstract class SortItems {
/** For the iOS / Android demo */
public abstract void sort(@Nonnull SortOrder order, @Nonnull ItemList items);

Expand Down Expand Up @@ -41,6 +41,8 @@ protected void finalize() throws java.lang.Throwable
super.finalize();
}

// SortItems methods

@Override
public void sort(SortOrder order, ItemList items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public enum SortOrder {
/*package*/ enum SortOrder {
ASCENDING,
DESCENDING,
RANDOM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public abstract class TextboxListener {
/*package*/ abstract class TextboxListener {
public abstract void update(@Nonnull ItemList items);
}
1 change: 0 additions & 1 deletion example/generated-src/jni/NativeSortItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "NativeSortItems.hpp" // my header
#include "NativeItemList.hpp"
#include "NativeSortItems.hpp"
#include "NativeSortOrder.hpp"
#include "NativeTextboxListener.hpp"

Expand Down
21 changes: 14 additions & 7 deletions example/generated-src/objc/TXSSortItems+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#import "TXSSortItems.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "TXSItemList+Private.h"
#import "TXSSortItems+Private.h"
#import "TXSSortOrder+Private.h"
#import "TXSTextboxListener+Private.h"
#include <exception>
#include <stdexcept>
#include <utility>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
Expand All @@ -32,6 +32,13 @@ - (id)initWithCpp:(const std::shared_ptr<::textsort::SortItems>&)cppRef
return self;
}

- (const std::shared_ptr<::textsort::SortItems>&) cppRef
{
return _cppRefHandle.get();
}

// TXSSortItems methods

- (void)sort:(TXSSortOrder)order
items:(nonnull TXSItemList *)items {
try {
Expand All @@ -42,15 +49,15 @@ - (void)sort:(TXSSortOrder)order

+ (nullable TXSSortItems *)createWithListener:(nullable id<TXSTextboxListener>)listener {
try {
auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener));
return ::djinni_generated::SortItems::fromCpp(r);
auto objcpp_result_ = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener));
return ::djinni_generated::SortItems::fromCpp(objcpp_result_);
} DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items {
try {
auto r = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items));
return ::djinni_generated::ItemList::fromCpp(r);
auto objcpp_result_ = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items));
return ::djinni_generated::ItemList::fromCpp(objcpp_result_);
} DJINNI_TRANSLATE_EXCEPTIONS()
}

Expand All @@ -61,7 +68,7 @@ + (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items {
if (!objc) {
return nullptr;
}
return objc->_cppRefHandle.get();
return [objc cppRef];
}

auto SortItems::fromCppOpt(const CppOptType& cpp) -> ObjcType
Expand Down
6 changes: 6 additions & 0 deletions example/generated-src/objc/TXSSortOrder+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni

#include "sort_order.hpp"
#import "DJIMarshal+Private.h"

3 changes: 3 additions & 0 deletions example/generated-src/objc/TXSTextboxListener+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "TXSTextboxListener.h"
#import "DJIObjcWrapperCache+Private.h"
#import "TXSItemList+Private.h"
#include <stdexcept>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

Expand All @@ -16,6 +17,8 @@
{
public:
using Handle::Handle;

// TextboxListener methods
void update(const ::textsort::ItemList & c_items) override
{
@autoreleasepool {
Expand Down
2 changes: 1 addition & 1 deletion example/generated-src/objc/TXSTextboxListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>


@protocol TXSTextboxListener
@protocol TXSTextboxListener <NSObject>

- (void)update:(nonnull TXSItemList *)items;

Expand Down
5 changes: 4 additions & 1 deletion example/objc/TextSort.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = TXS;
LastUpgradeCheck = 0510;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Dropbox, Inc.";
};
buildConfigurationList = 65834DD819AC599E0061AD3F /* Build configuration list for PBXProject "TextSort" */;
Expand Down Expand Up @@ -236,6 +236,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -301,6 +302,7 @@
GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch";
INFOPLIST_FILE = "TextSort/TextSort-Info.plist";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand All @@ -316,6 +318,7 @@
GCC_PREFIX_HEADER = "TextSort/TextSort-Prefix.pch";
INFOPLIST_FILE = "TextSort/TextSort-Info.plist";
LIBRARY_SEARCH_PATHS = "$(inherited)";
PRODUCT_BUNDLE_IDENTIFIER = "Dropbox.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,10 +23,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
Expand All @@ -38,17 +38,21 @@
ReferencedContainer = "container:TextSort.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "65834DDC19AC599E0061AD3F"
Expand All @@ -61,12 +65,13 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "65834DDC19AC599E0061AD3F"
Expand Down
2 changes: 1 addition & 1 deletion example/objc/TextSort/TextSort-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>Dropbox.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
1 change: 1 addition & 0 deletions example/run_djinni.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fi
"$base_dir/../src/run-assume-built" \
--java-out "$temp_out/java" \
--java-package $java_package \
--java-class-access-modifier "package" \
--java-nullable-annotation "javax.annotation.CheckForNull" \
--java-nonnull-annotation "javax.annotation.Nonnull" \
--ident-java-field mFooBar \
Expand Down
7 changes: 4 additions & 3 deletions src/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/sbt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading