[Yunq] Add ability to namespace declarations using "package".
This commit is contained in:
parent
9fdd670a23
commit
f1e09b2ae6
15 changed files with 153 additions and 10 deletions
|
|
@ -1,3 +1,5 @@
|
|||
package srv.file;
|
||||
|
||||
interface VFS {
|
||||
method open (OpenFileRequest) -> (File);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,20 @@
|
|||
|
||||
#include <glacier/buffer/byte_buffer.h>
|
||||
#include <glacier/buffer/cap_buffer.h>
|
||||
#include <mammoth/util/debug.h>
|
||||
#include <zcall.h>
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
|
||||
|
||||
VFSClient::~VFSClient() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -46,3 +57,7 @@ glcr::ErrorCode VFSClient::open(const OpenFileRequest& request, File& response)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
|
|
@ -8,11 +8,15 @@
|
|||
|
||||
#include "example.yunq.h"
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
class VFSClient {
|
||||
public:
|
||||
VFSClient(z_cap_t VFS_cap) : endpoint_(VFS_cap) {}
|
||||
VFSClient(const VFSClient&) = delete;
|
||||
VFSClient(VFSClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;};
|
||||
~VFSClient();
|
||||
|
||||
z_cap_t Capability() { return endpoint_; }
|
||||
|
||||
|
|
@ -28,3 +32,6 @@ class VFSClient {
|
|||
uint64_t kCapBufferSize = 0x10;
|
||||
glcr::CapBuffer cap_buffer_{kCapBufferSize};
|
||||
};
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
// Generated file -- DO NOT MODIFY.
|
||||
#include "example.yunq.h"
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
namespace {
|
||||
|
||||
const uint64_t header_size = 24; // 4x uint32, 1x uint64
|
||||
|
|
@ -201,4 +204,7 @@ uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::
|
|||
WriteHeader(bytes, offset, core_size, next_extension);
|
||||
|
||||
return next_extension;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
#include <glacier/container/vector.h>
|
||||
#include <glacier/string/string.h>
|
||||
#include <ztypes.h>
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
class OpenFileRequest {
|
||||
public:
|
||||
OpenFileRequest() {}
|
||||
|
|
@ -54,4 +58,7 @@ class File {
|
|||
|
||||
// Parses everything except for caps.
|
||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
#include <mammoth/util/debug.h>
|
||||
#include <zcall.h>
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
namespace {
|
||||
|
||||
const uint32_t kSentinel = 0xBEEFDEAD;
|
||||
|
|
@ -29,6 +32,18 @@ void VFSServerBaseThreadBootstrap(void* server_base) {
|
|||
((VFSServerBase*)server_base)->ServerThread();
|
||||
}
|
||||
|
||||
VFSServerBase::~VFSServerBase() {
|
||||
if (endpoint_ != 0) {
|
||||
check(ZCapRelease(endpoint_));
|
||||
}
|
||||
}
|
||||
|
||||
glcr::ErrorOr<z_cap_t> VFSServerBase::CreateClientCap() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
return client_cap;
|
||||
}
|
||||
|
||||
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
|
||||
uint64_t client_cap;
|
||||
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
|
||||
|
|
@ -101,7 +116,9 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
|||
RET_ERR(Handleopen(yunq_request, yunq_response));
|
||||
|
||||
|
||||
|
||||
resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps);
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
@ -110,3 +127,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
|||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
|
|
@ -9,13 +9,19 @@
|
|||
#include "example.yunq.client.h"
|
||||
|
||||
|
||||
namespace srv::file {
|
||||
|
||||
|
||||
|
||||
|
||||
class VFSServerBase {
|
||||
public:
|
||||
VFSServerBase(z_cap_t VFS_cap) : endpoint_(VFS_cap) {}
|
||||
VFSServerBase(const VFSServerBase&) = delete;
|
||||
VFSServerBase(VFSServerBase&&) = delete;
|
||||
virtual ~VFSServerBase();
|
||||
|
||||
glcr::ErrorOr<z_cap_t> CreateClientCap();
|
||||
glcr::ErrorOr<VFSClient> CreateClient();
|
||||
|
||||
[[nodiscard]] Thread RunServer();
|
||||
|
|
@ -37,3 +43,7 @@ class VFSServerBase {
|
|||
glcr::CapBuffer& resp_caps);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
} // namepace srv::file
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue