acadia/zion/object/channel.h

49 lines
1.2 KiB
C
Raw Normal View History

#pragma once
2023-06-21 20:47:40 -07:00
#include <glacier/container/pair.h>
2023-06-21 15:07:40 -07:00
#include <glacier/memory/ref_ptr.h>
#include "capability/capability.h"
#include "include/ztypes.h"
#include "lib/message_queue.h"
2023-06-21 23:42:21 -07:00
#include "object/ipc_object.h"
#include "object/kernel_object.h"
class Channel;
template <>
struct KernelObjectTag<Channel> {
static const uint64_t type = KernelObject::CHANNEL;
};
2023-06-21 23:42:21 -07:00
class Channel : public IpcObject {
public:
uint64_t TypeTag() override { return KernelObject::CHANNEL; }
static uint64_t DefaultPermissions() {
return kZionPerm_Read | kZionPerm_Write | kZionPerm_Duplicate |
kZionPerm_Transmit;
}
2023-06-21 20:47:40 -07:00
static glcr::Pair<glcr::RefPtr<Channel>, glcr::RefPtr<Channel>>
CreateChannelPair();
2023-06-21 15:07:40 -07:00
glcr::RefPtr<Channel> peer() { return peer_; }
2023-06-21 23:42:21 -07:00
virtual MessageQueue& GetSendMessageQueue() override {
return peer_->message_queue_;
}
virtual MessageQueue& GetRecvMessageQueue() override {
return message_queue_;
}
private:
// FIXME: We will likely never close the channel based on this
// circular dependency.
2023-06-21 15:07:40 -07:00
glcr::RefPtr<Channel> peer_{nullptr};
UnboundedMessageQueue message_queue_;
2023-06-15 16:20:29 -07:00
Channel() {}
2023-06-21 15:07:40 -07:00
void SetPeer(const glcr::RefPtr<Channel>& peer) { peer_ = peer; }
};