Allow passing raw pointers to C wrapper functions, I think

pull/1669/head
idk 3 years ago
parent ed53cbb7b7
commit b962a330ad
No known key found for this signature in database
GPG Key ID: D75C03B39B5E14E1

@ -136,3 +136,8 @@ doxygen:
.PHONY: mk_obj_dir .PHONY: mk_obj_dir
.PHONY: install .PHONY: install
.PHONY: strip .PHONY: strip
##TODO: delete this before a PR
testc: api api_client
g++ -Ii18n -c test.c -o test.o
g++ test.o libi2pd.so libi2pdclient.so -o test.main

@ -28,6 +28,10 @@
#include "Datagram.h" #include "Datagram.h"
#include "util.h" #include "util.h"
#ifdef __cplusplus
extern "C" {
#endif
namespace i2p namespace i2p
{ {
namespace client namespace client
@ -312,4 +316,8 @@ namespace client
} }
} }
#ifdef __cplusplus
}
#endif
#endif #endif

@ -22,9 +22,10 @@ void C_TerminateI2P ()
return i2p::api::TerminateI2P(); return i2p::api::TerminateI2P();
} }
void C_StartI2P (std::shared_ptr<std::ostream> logStream) void C_StartI2P (std::ostream *logStream)
{ {
return i2p::api::StartI2P(logStream); std::shared_ptr<std::ostream> cppLogStream(logStream);
return i2p::api::StartI2P(cppLogStream);
} }
void C_StopI2P () void C_StopI2P ()
@ -37,41 +38,46 @@ void C_RunPeerTest ()
return i2p::api::RunPeerTest(); return i2p::api::RunPeerTest();
} }
std::shared_ptr<i2p::client::ClientDestination> C_CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic, i2p::client::ClientDestination *C_CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic,
const std::map<std::string, std::string> * params) const std::map<std::string, std::string> * params)
{ {
return i2p::api::CreateLocalDestination(keys, isPublic, params); return i2p::api::CreateLocalDestination(keys, isPublic, params).get();
} }
std::shared_ptr<i2p::client::ClientDestination> C_CreateTransientLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType, i2p::client::ClientDestination *C_CreateTransientLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType,
const std::map<std::string, std::string> * params) const std::map<std::string, std::string> * params)
{ {
return i2p::api::CreateLocalDestination(isPublic, sigType, params); return i2p::api::CreateLocalDestination(isPublic, sigType, params).get();
} }
void C_DestroyLocalDestination (std::shared_ptr<i2p::client::ClientDestination> dest) void C_DestroyLocalDestination (i2p::client::ClientDestination *dest)
{ {
return i2p::api::DestroyLocalDestination(dest); std::shared_ptr<i2p::client::ClientDestination> cppDest(dest);
return i2p::api::DestroyLocalDestination(cppDest);
} }
void C_RequestLeaseSet (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::data::IdentHash& remote) void C_RequestLeaseSet (i2p::client::ClientDestination *dest, const i2p::data::IdentHash& remote)
{ {
return i2p::api::RequestLeaseSet(dest, remote); std::shared_ptr<i2p::client::ClientDestination> cppDest(dest);
return i2p::api::RequestLeaseSet(cppDest, remote);
} }
std::shared_ptr<i2p::stream::Stream> C_CreateStream (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::data::IdentHash& remote) i2p::stream::Stream *C_CreateStream (i2p::client::ClientDestination *dest, const i2p::data::IdentHash& remote)
{ {
return i2p::api::CreateStream(dest, remote); std::shared_ptr<i2p::client::ClientDestination> cppDest(dest);
return i2p::api::CreateStream(cppDest, remote).get();
} }
void C_AcceptStream (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::stream::StreamingDestination::Acceptor& acceptor) void C_AcceptStream (i2p::client::ClientDestination *dest, const i2p::stream::StreamingDestination::Acceptor& acceptor)
{ {
return i2p::api::AcceptStream(dest, acceptor); std::shared_ptr<i2p::client::ClientDestination> cppDest(dest);
return i2p::api::AcceptStream(cppDest, acceptor);
} }
void C_DestroyStream (std::shared_ptr<i2p::stream::Stream> stream) void C_DestroyStream (i2p::stream::Stream *stream)
{ {
return i2p::api::DestroyStream(stream); std::shared_ptr<i2p::stream::Stream> cppStream(stream);
return i2p::api::DestroyStream(cppStream);
} }
#ifdef __cplusplus #ifdef __cplusplus

@ -11,6 +11,7 @@
#include "api.h" #include "api.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -18,23 +19,23 @@ extern "C" {
// initialization start and stop // initialization start and stop
void C_InitI2P (int argc, char* argv[], const char * appName); void C_InitI2P (int argc, char* argv[], const char * appName);
void C_TerminateI2P (); void C_TerminateI2P ();
void C_StartI2P (std::shared_ptr<std::ostream> logStream = nullptr); void C_StartI2P (std::ostream *logStream = nullptr);
// write system log to logStream, if not specified to <appName>.log in application's folder // write system log to logStream, if not specified to <appName>.log in application's folder
void C_StopI2P (); void C_StopI2P ();
void C_RunPeerTest (); // should be called after UPnP void C_RunPeerTest (); // should be called after UPnP
// destinations // destinations
std::shared_ptr<i2p::client::ClientDestination> C_CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true, i2p::client::ClientDestination *C_CreateLocalDestination (const i2p::data::PrivateKeys& keys, bool isPublic = true,
const std::map<std::string, std::string> * params = nullptr); const std::map<std::string, std::string> * params = nullptr);
std::shared_ptr<i2p::client::ClientDestination> C_CreateTransientLocalDestination (bool isPublic = false, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256, i2p::client::ClientDestination *C_CreateTransientLocalDestination (bool isPublic = false, i2p::data::SigningKeyType sigType = i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256,
const std::map<std::string, std::string> * params = nullptr); // transient destinations usually not published const std::map<std::string, std::string> * params = nullptr); // transient destinations usually not published
void C_DestroyLocalDestination (std::shared_ptr<i2p::client::ClientDestination> dest); void C_DestroyLocalDestination (i2p::client::ClientDestination *dest);
// streams // streams
void C_RequestLeaseSet (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::data::IdentHash& remote); void C_RequestLeaseSet (i2p::client::ClientDestination *dest, const i2p::data::IdentHash& remote);
std::shared_ptr<i2p::stream::Stream> C_CreateStream (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::data::IdentHash& remote); i2p::stream::Stream *C_CreateStream (i2p::client::ClientDestination *dest, const i2p::data::IdentHash& remote);
void C_AcceptStream (std::shared_ptr<i2p::client::ClientDestination> dest, const i2p::stream::StreamingDestination::Acceptor& acceptor); void C_AcceptStream (i2p::client::ClientDestination *dest, const i2p::stream::StreamingDestination::Acceptor& acceptor);
void C_DestroyStream (std::shared_ptr<i2p::stream::Stream> stream); void C_DestroyStream (i2p::stream::Stream *stream);
#ifdef __cplusplus #ifdef __cplusplus
} }

Loading…
Cancel
Save