Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
caijw committed Mar 31, 2020
1 parent 54253f3 commit 5b1a433
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
27 changes: 27 additions & 0 deletions binder/binder_test/IBasicService.h
@@ -0,0 +1,27 @@
#ifndef BASIC_SERVICE
#define BASIC_SERVICE
#include <stdio.h>
#include <utils/RefBase.h>
#include <binder/IInterface.h>
#include <binder/Parcel.h>
#include <binder/IBinder.h>
#include <binder/Binder.h>
#include <binder/ProcessState.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>

using namespace android;

class IBasicService: public IInterface {
public:
DECLARE_META_INTERFACE(BasicService);
virtual void sayHello() = 0;
virtual int32_t random() = 0;
};

class BnBasicService: public BnInterface<IBasicService> {
public:
virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0);
};

#endif
17 changes: 14 additions & 3 deletions binder/binder_test/client.cc
Expand Up @@ -12,14 +12,15 @@ Client::Client(const Client &)
{
}

Client::Client &operator=(const Client &)
Client & Client::operator=(const Client &)
{
return getInstance();
}

static Client &Client::getInstance()
Client &Client::getInstance()
{
static Client instance;
return Client;
return instance;
}

void Client::sayHello()
Expand All @@ -31,4 +32,14 @@ void Client::sayHello()
std::cout << "[log][c++]before Client::sayHello" << std::endl;
service_->sayHello();
std::cout << "[log][c++]after Client::sayHello" << std::endl;
}

void sayHello(){
Client &client = Client::getInstance();
client.sayHello();
}

void hello_world() {
Client &client = Client::getInstance();
client.sayHello();
}
21 changes: 20 additions & 1 deletion binder/binder_test/client.h
Expand Up @@ -13,7 +13,26 @@ class Client {
public:
static Client& getInstance();
void sayHello();
}
};

// PLUGIN_EXPORT 宏: 编译的时候不要隐藏该符号,暴露给调用者
#define PLUGIN_EXPORT __attribute__((visibility("default")))

#if defined(__cplusplus)
extern "C" {
#endif

// 暴露给 dart 调用的 c 函数
PLUGIN_EXPORT void sayHello();

PLUGIN_EXPORT void hello_world();



#if defined(__cplusplus)
} // extern "C"
#endif


#endif

16 changes: 0 additions & 16 deletions binder/binder_test/main.cc
@@ -1,20 +1,4 @@
#include "client.h"

// PLUGIN_EXPORT 宏: 编译的时候不要隐藏该符号,暴露给调用者
#define PLUGIN_EXPORT __attribute__((visibility("default")))

#if defined(__cplusplus)
extern "C" {
#endif
// 暴露给 dart 调用的 c 函数
PLUGIN_EXPORT void sayHello();

#if defined(__cplusplus)
} // extern "C"
#endif


void sayHello(){
Client client = Client::getInstance();
client.sayHello();
}
6 changes: 1 addition & 5 deletions binder/linux/Makefile
Expand Up @@ -78,7 +78,7 @@ $(info [log] DEPENDENCY_FILES: ${DEPENDENCY_FILES})

.PHONY: all

all: $(PLUGIN_NAME) hello_lib
all: $(PLUGIN_NAME)

.PHONY: $(PLUGIN_NAME)

Expand All @@ -96,10 +96,6 @@ $(OBJ_DIR)/%.o : %.cc
mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MMD -c $< -o $@

.PHONY: hello_lib
hello_lib:
cd ../hello_library && cmake . && make

.PHONY: clean
clean:
rm -f $(LIBRARY_OUT)
Expand Down

0 comments on commit 5b1a433

Please sign in to comment.