提交 b1eb09a0 编写于 作者: 指向BIOS的野指针's avatar 指向BIOS的野指针

rename

上级 ea08ecb6
......@@ -3,5 +3,5 @@
int main(int argc, char **argv)
{
switch_to_daemon();
start_rwl_server();
start_bwl_server();
}
#ifndef __server_hh_
#define __server_hh_
#define __rwl_server
#define __bwl_server
#include <iostream>
#include <unistd.h>
......@@ -18,10 +18,7 @@
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <dirent.h>
#include <cstdlib>
#include "../dbg/logs.hh"
......@@ -31,21 +28,21 @@
*/
void switch_to_daemon()
{
rwl::log("switching to daemon...\nyou can see logs in ~/.rwl/rwl-log and ~/.rwl/rwl-err");
bwl::log("switching to daemon...\nyou can see logs in ~/.bwl/bwl-log and ~/.bwl/bwl-err");
daemon(1, 1);
std::string dir = std::string("/home/") + getpwuid(getuid())->pw_name + "/";
chdir(dir.c_str());
mkdir(".rwl", 0755);
freopen("./.rwl/rwl-log", "w", stdout);
freopen("./.rwl/rwl-err", "w", stderr);
mkdir(".bwl", 0755);
freopen("./.bwl/bwl-log", "w", stdout);
freopen("./.bwl/bwl-err", "w", stderr);
}
/**
* @brief 启动rwl显示服务器
* @brief 启动bwl显示服务器
*/
void start_rwl_server()
void start_bwl_server()
{
}
......
cmake_minimum_required(VERSION 3.18)
project(RWLserver)
project(BadWayland)
set(CMAKE_CXX_STANDARD 20)
add_executable(rwl-server RWLserver/server.cc dbg/logs.cc)
add_library(rwl SHARED libs/rwl.cc)
add_executable(bwl-server BWLserver/server.cc dbg/logs.cc)
add_library(bwl SHARED libs/bwl.cc)
# RWS Wayland
# BWS Wayland
`这是一个Wayland混成器的简单实现,用于BiliOS项目的图形环境`
#include "logs.hh"
#define RWLSV_GR "[rwl-server] "
#define RWLSV_RD "[rwl-server] "
#define BWLSV_GR "[bwl-server] "
#define BWLSV_RD "[bwl-server] "
namespace rwl
namespace bwl
{
void rwl_exit(int code)
void bwl_exit(int code)
{
std::cout << RWLSV_GR << "exit with code " << code << std::endl;
std::cout << BWLSV_GR << "exit with code " << code << std::endl;
exit(code);
}
void log(std::string log)
{
std::cout << RWLSV_GR << log << std::endl;
std::cout << BWLSV_GR << log << std::endl;
}
void err(std::string err)
{
std::cerr << RWLSV_RD << err << std::endl;
std::cerr << BWLSV_RD << err << std::endl;
}
};
......@@ -3,11 +3,11 @@
#include <iostream>
namespace rwl
namespace bwl
{
void log(std::string);
void err(std::string);
void rwl_exit(int);
void bwl_exit(int);
};
#endif
#ifndef __bwl_hh_
#define __bwl_hh_
#include "types.hh"
namespace bwl
{
};
#endif
#ifndef __rwl_hh_
#define __rwl_hh_
#include "types.hh"
namespace rwl
{
/**
* @brief 通过进程名获取pid
*
* @param task_name
* @return int
*/
int get_pid_by_name(const char *task_name);
class Frame
{
private:
id_t fid; //窗口id
pid_t pid; //进程id
std::string name; //窗口名
void *mbuf; //主缓冲
int64_t pos[2]; //窗口位置
uint64_t size[2]; //窗口大小
void *userbuf; //用户缓冲
int64_t ofset[2]; //用户缓冲位置
uint64_t usersize[2]; //用户缓冲大小
int pixel_depth;//像素深度
void __Frame();
/**
* @brief 向rwl服务器申请新的缓冲区
*
* @param buff
* @param size
* @return void*
*/
void *realloc_buff(void *buff, size_t size);
public:
Frame();
Frame(std::string name);
Frame(uint64_t size[2]);
Frame(int64_t position[2], uint64_t size[2]);
Frame(std::string name, uint64_t size[2]);
Frame(std::string name, int64_t position[2], uint64_t size[2]);
~Frame();
void setName(std::string name);
std::string getName();
/**
* 一系列getter函数
*
* 这组函数获取的位置是主缓冲的位置
* 大小是用户缓冲的大小
*/
int64_t getX();
int64_t getY();
int64_t getWidth();
int64_t getHeight();
/**
* @brief 获取主缓冲信息
*
* @param buffer 缓冲区
* @param position 位置
* @param size 大小
* @return int 错误码
*/
int getMainBufferInfo(void *&buffer, int64_t *&position, uint64_t *&size);
/**
* @brief 获取用户缓冲信息
*
* @param buffer 缓冲区
* @param position 位置
* @param size 大小
* @return int 错误码
*/
int getUserBufferInfo(void *&buffer, int64_t *&position, uint64_t *&size);
/**
* 一系列setter函数
*
* 这组函数设置的位置是主缓冲的位置
* 大小是用户缓冲的大小
*/
void setX(int64_t x);
void setY(int64_t y);
int setWidth(uint64_t width);
int setHeight(uint64_t height);
/**
* @brief 设置主缓冲信息
*
* @param buffer 缓冲区
* @param position 窗口位置
* @param size 大小
* @return int 错误码
*/
int setMainBufferInfo(void *buffer, int64_t position[2], uint64_t size[2]);
/**
* @brief 设置用户缓冲信息
*
* @param buffer 缓冲区
* @param position 用户缓冲位置
* @param size 用户缓冲大小
* @return int 错误码
*/
int setUserBufferInfo(void *buffer, int64_t position[2], uint64_t size[2]);
/**
* @brief 根据路径移动窗口
*
* @param path 路径
* @param freq 频率
* @return int 错误码
*/
int moveByPath(std::vector<int[2]> path, uint64_t freq);
#ifndef __rwl_server
/**
* @brief 将窗口附加到rwl显示服务器上
*
* @return Frame*
*/
Frame *attach_to_rwl_server();
#endif
};
class Page
{
private:
id_t pgid; //页id
std::vector<pid_t> owners; //所属进程
void *layerbg; //背景层
std::vector<Frame *> layer0; // 0层
std::vector<Frame *> layer1; // 1层
public:
Page();
~Page();
/**
* @brief 添加本进程pid至owners
*
*/
void addOwner();
/**
* @brief 添加窗口
*
* @param frame 窗口id
*/
void addFrame(id_t frame, int layer);
/**
* @brief 添加窗口
*
* @param frame 窗口
*/
void addFrame(Frame *frame, int layer);
/**
* @brief 将窗口提前
*
* @param frame 提前的窗口id
* @return bool 页中是否存在
*/
bool pushFrame(id_t frame);
/**
* @brief 将窗口提前
*
* @param frame 提前的窗口
* @return bool 页中是否存在
*/
bool pushFrame(Frame *frame);
};
};
#endif
......@@ -3,7 +3,7 @@
#include <iostream>
#include <vector>
namespace rwl
namespace bwl
{
typedef unsigned long long id_t;
};
......
#define __bwl_server
#include "../includes/bwl.hh"
#include <iostream>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include <dirent.h>
namespace bwl
{
};
#define __rwl_server
#include "../includes/rwl.hh"
#include <iostream>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <pwd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#include <dirent.h>
namespace rwl
{
/**
* @brief 通过进程名获取pid
*
* @param task_name
* @return int
*/
int get_pid_by_name(const char *task_name)
{
int pid_value = -1;
DIR *dir;
struct dirent *ptr;
FILE *fp;
char filepath[512] = {0};
char cur_task_name[512] = {0};
char buf[1024] = {0};
dir = opendir("/proc");
if (NULL != dir)
{
while ((ptr = readdir(dir)) != NULL)
{
if ((strcmp(ptr->d_name, ".") == 0) || (strcmp(ptr->d_name, "..") == 0))
continue;
if (DT_DIR != ptr->d_type)
continue;
sprintf(filepath, "/proc/%s/status", ptr->d_name);
fp = fopen(filepath, "r");
if (NULL != fp)
{
if (fgets(buf, 1023, fp) == NULL)
{
fclose(fp);
continue;
}
sscanf(buf, "%*s %s", cur_task_name);
if (!strcmp(task_name, cur_task_name))
{
printf("PID:%s\n", ptr->d_name);
pid_value = atoi(ptr->d_name);
}
fclose(fp);
}
}
closedir(dir);
}
else
{
return -1;
}
return pid_value;
}
void Frame::__Frame()
{
this->pid = getpid();
}
Frame::Frame()
{
this->__Frame();
}
Frame::Frame(std::string name)
{
this->name = name;
this->__Frame();
}
Frame::Frame(uint64_t size[2])
{
memcpy(this->size, size, 2 * sizeof(uint64_t));
pos[0] = 0;
pos[1] = 0;
this->__Frame();
}
Frame::Frame(int64_t position[2], uint64_t size[2])
{
memcpy(this->pos, position, 2 * sizeof(int64_t));
memcpy(this->size, size, 2 * sizeof(uint64_t));
this->__Frame();
}
Frame::Frame(std::string name, uint64_t size[2])
{
this->name = name;
memcpy(this->size, size, 2 * sizeof(uint64_t));
pos[0] = 0;
pos[1] = 0;
this->__Frame();
}
Frame::Frame(std::string name, int64_t position[2], uint64_t size[2])
{
this->name = name;
memcpy(this->pos, position, 2 * sizeof(int64_t));
memcpy(this->size, size, 2 * sizeof(uint64_t));
this->__Frame();
}
void Frame::setName(std::string name)
{
this->name = name;
}
std::string Frame::getName()
{
return name;
}
int64_t Frame::getX()
{
return pos[0];
}
int64_t Frame::getY()
{
return pos[1];
}
int64_t Frame::getWidth()
{
return usersize[0];
}
int64_t Frame::getHeight()
{
return usersize[1];
}
int Frame::getMainBufferInfo(void *&buffer, int64_t *&position, uint64_t *&size)
{
buffer = this->mbuf;
position = this->pos;
size = this->size;
}
int Frame::getUserBufferInfo(void *&buffer, int64_t *&position, uint64_t *&size)
{
buffer = this->userbuf;
position = this->ofset;
size = this->usersize;
}
void Frame::setX(int64_t x)
{
this->pos[0] = x;
}
void Frame::setY(int64_t y)
{
this->pos[1] = y;
}
int Frame::setWidth(uint64_t width)
{
int increment = width - usersize[0];
size[0] += increment;
usersize[0] += increment;
mbuf = realloc_buff(mbuf, size[0] * size[1] * pixel_depth);
userbuf = realloc_buff(userbuf, usersize[0] * usersize[1] * pixel_depth);
}
int Frame::setHeight(uint64_t height)
{
int increment = height - usersize[1];
size[1] += increment;
usersize[1] += increment;
mbuf = realloc_buff(mbuf, size[0] * size[1] * pixel_depth);
userbuf = realloc_buff(userbuf, usersize[0] * usersize[1] * pixel_depth);
}
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册