2023-06-12 19:20:51 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-06-16 15:58:50 -07:00
|
|
|
#include "capability/capability.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "lib/linked_list.h"
|
2023-06-12 20:56:25 -07:00
|
|
|
#include "lib/mutex.h"
|
2023-06-16 15:58:50 -07:00
|
|
|
#include "lib/shared_ptr.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "object/kernel_object.h"
|
2023-06-12 20:56:25 -07:00
|
|
|
#include "object/thread.h"
|
2023-06-12 19:20:51 -07:00
|
|
|
#include "usr/zcall_internal.h"
|
|
|
|
|
2023-06-16 14:53:57 -07:00
|
|
|
class Port;
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct KernelObjectTag<Port> {
|
|
|
|
static const uint64_t type = KernelObject::PORT;
|
|
|
|
};
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
class Port : public KernelObject {
|
|
|
|
public:
|
2023-06-16 14:53:57 -07:00
|
|
|
uint64_t TypeTag() override { return KernelObject::PORT; }
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
Port();
|
|
|
|
|
|
|
|
z_err_t Write(const ZMessage& msg);
|
|
|
|
z_err_t Read(ZMessage& msg);
|
|
|
|
|
2023-06-17 00:07:58 -07:00
|
|
|
void WriteKernel(uint64_t init, RefPtr<Capability> cap);
|
|
|
|
|
2023-06-16 23:15:28 -07:00
|
|
|
bool HasMessages();
|
|
|
|
|
2023-06-12 19:20:51 -07:00
|
|
|
private:
|
|
|
|
struct Message {
|
|
|
|
uint64_t num_bytes;
|
|
|
|
uint8_t* bytes;
|
2023-06-16 15:58:50 -07:00
|
|
|
|
|
|
|
LinkedList<RefPtr<Capability>> caps;
|
2023-06-12 19:20:51 -07:00
|
|
|
};
|
|
|
|
|
2023-06-16 15:58:50 -07:00
|
|
|
LinkedList<SharedPtr<Message>> pending_messages_;
|
2023-06-12 20:56:25 -07:00
|
|
|
|
|
|
|
LinkedList<RefPtr<Thread>> blocked_threads_;
|
|
|
|
|
|
|
|
Mutex mutex_{"Port"};
|
2023-06-12 19:20:51 -07:00
|
|
|
};
|