diff --git a/03_day.pptx b/03_day.pptx index 790262a..2def9ae 100644 Binary files a/03_day.pptx and b/03_day.pptx differ diff --git a/03_day/binder_3/Android.bp b/03_day/binder_3/Android.bp new file mode 100644 index 0000000..a44bf50 --- /dev/null +++ b/03_day/binder_3/Android.bp @@ -0,0 +1,7 @@ +cc_binary { + name: "my_server_cpp_1", + shared_libs: ["liblog", "libutils", "libbinder"], + srcs: [ + "my_server.cpp", + ], +} diff --git a/03_day/binder_3/ProcessState.cpp b/03_day/binder_3/ProcessState.cpp new file mode 100644 index 0000000..07b6867 --- /dev/null +++ b/03_day/binder_3/ProcessState.cpp @@ -0,0 +1,54 @@ +#if 1 +#include +class ProcessState +{ + static ProcessState *gProcess; + ProcessState() + { + printf("fd=open(\"/dev/binder\", O_RDWR)\n"); + } + public: + static ProcessState *self() + { + if( gProcess == 0 ) + gProcess = new ProcessState; + return gProcess; + } + ~ProcessState() + { + printf("close(fd)\n"); + } +}; +ProcessState *ProcessState::gProcess = 0; + +int main() +{ + ProcessState *p1 = ProcessState::self(); + ProcessState *p2 = ProcessState::self(); + //ProcessState process; + return 0; +} +#endif + +#if 0 +#include +class ProcessState +{ + public: + ProcessState() + { + printf("fd=open(\"/dev/binder\", O_RDWR)\n"); + } + ~ProcessState() + { + printf("close(fd)\n"); + } +}; + +int main() +{ + ProcessState p1; + ProcessState p2; + return 0; +} +#endif diff --git a/03_day/binder_3/my_server.cpp b/03_day/binder_3/my_server.cpp new file mode 100644 index 0000000..26c61af --- /dev/null +++ b/03_day/binder_3/my_server.cpp @@ -0,0 +1,21 @@ + +#include +#include +#include +#include +#include + +using namespace android; + +int main() +{ + sp proc(ProcessState::self()); + sp sm(defaultServiceManager()); + sm->addService( String16("led.service"), new BBinder ); + IPCThreadState::self()->joinThreadPool(); + + return 0; +} + + +