-
Notifications
You must be signed in to change notification settings - Fork 5
/
HelloServer.cpp
58 lines (50 loc) · 1.47 KB
/
HelloServer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define LOG_TAG "aidl_cpp"
#include <log/log.h>
#include <stdlib.h>
#include <utils/RefBase.h>
#include <utils/Log.h>
#include <binder/TextOutput.h>
#include <binder/IInterface.h>
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include "com/yuandaima/IHello.h"
#include "com/yuandaima/BnHello.h"
#include "com/yuandaima/ICallback.h"
#include "com/yuandaima/BpCallback.h"
using namespace android;
class IHelloServer : public com::yuandaima::BnHello
{
private:
sp<com::yuandaima::ICallback> mCallback;
public:
binder::Status hello() override
{
ALOGI("hello");
return binder::Status();
}
binder::Status sum(int32_t v1, int32_t v2, int32_t *_aidl_return) override
{
ALOGI("server: sum: %d + %d", v1, v2);
*_aidl_return = v1 + v2;
if(mCallback.get() != nullptr) {
mCallback->onCallback(String16("str from server"));
}
return binder::Status();
}
binder::Status registerCallback(const sp<::com::yuandaima::ICallback>& cb) override
{
ALOGI("Server registerCallback");
mCallback = cb;
return binder::Status();
}
};
int main(int argc, char const *argv[])
{
ALOGD("HelloServer is running");
defaultServiceManager()->addService(String16("IHello"), new IHelloServer());
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
return 0;
}