real PoC of autocode

This commit is contained in:
2025-12-01 18:51:38 +07:00
parent 64a3e637d5
commit adbb2c374b
13 changed files with 520 additions and 76 deletions
+7 -2
View File
@@ -1,7 +1,12 @@
#pragma once
class [[annotate("export")]] MyService {
#include <rpc_export.h>
// annotate with clang attribute or via comment annotation recognized by libclang
// Use ANNOTATE attribute supported by clang: __attribute__((annotate("export")))
class RPC_EXPORT MyService {
public:
[[annotate("export")]]
RPC_EXPORT
int add(int a, int b);
int minus(int a, int b);
};
-22
View File
@@ -1,22 +0,0 @@
#include "MyService.proxy.h"
#include <unistd.h>
#include <fcntl.h>
#include <sstream>
MyServiceProxy::MyServiceProxy(const char* pipeIn, const char* pipeOut) {
fdIn = open(pipeIn, O_WRONLY);
fdOut = open(pipeOut, O_RDONLY);
}
int MyServiceProxy::add(int a, int b) {
std::ostringstream out;
out << "add " << a << " " << b << "\n";
write(fdIn, out.str().c_str(), out.str().size());
char buf[128];
int n = read(fdOut, buf, sizeof(buf)-1);
buf[n] = 0;
return std::atoi(buf);
}
-13
View File
@@ -1,13 +0,0 @@
#pragma once
#include <string>
class MyServiceProxy {
public:
MyServiceProxy(const char* pipeIn, const char* pipeOut);
int add(int a, int b);
private:
int fdIn; // клиент пишет сюда → сервер читает
int fdOut; // сервер пишет сюда → клиент читает
};
-19
View File
@@ -1,19 +0,0 @@
#include "MyService.skeleton.h"
#include <sstream>
MyServiceSkeleton::MyServiceSkeleton(MyService& o) : obj(o) {}
std::string MyServiceSkeleton::handleRequest(const std::string& req) {
std::istringstream in(req);
std::string method;
in >> method;
if (method == "add") {
int a, b;
in >> a >> b;
int r = obj.add(a, b);
return std::to_string(r);
}
return "ERR";
}
-14
View File
@@ -1,14 +0,0 @@
#pragma once
#include "MyService.h"
#include <string>
class MyServiceSkeleton {
public:
MyServiceSkeleton(MyService& obj);
// обработка одной строки запроса и возврат ответа
std::string handleRequest(const std::string& req);
private:
MyService& obj;
};
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#ifdef __clang__
# define RPC_EXPORT __attribute__((annotate("export")))
#else
# define RPC_EXPORT
#endif