Skip to content

Conversation

illidanstormrange
Copy link
Collaborator

初始化提交,增加起始页面。

CMakeLists.txt Outdated
list(APPEND TGFX_INSPECTOR_LIBS Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::WebSockets Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Qml Qt${QT_VERSION_MAJOR}::Quick
Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::QuickControls2 Qt${QT_VERSION_MAJOR}::Core5Compat)
if (${QT_VERSION} VERSION_LESS "5.15")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

统一升级到QT6吧,和PAG那边的工具保持一致

Comment on lines 46 to 51
std::atomic<bool> exit;
std::mutex mutex;
std::condition_variable conditionVariable;
std::vector<QueueItem> queue;
uint16_t port;
std::thread thread;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些变量都初始化一下

#include "Socket.h"

namespace inspector {
ClientData::ClientData(int64_t time, uint32_t protoVer, int32_t activeTime, uint16_t port,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

构造方法参数太多了,可以封装到结构体中

}

QList<QObject*> StartView::getFileItems() const {
QList<QObject*> items;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

构造的时候可以把初始容量传进去或者QList::reserve指定容量,避免append的过程中QList扩容

src/StartView.h Outdated
Comment on lines 73 to 75
std::string procName;
std::string address;
uint8_t type;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

成员变量都初始化下

src/StartView.h Outdated
Comment on lines 101 to 103
QString filesPath;
QString filesName;
QDateTime lastOpened;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

成员变量初始化

src/StartView.h Outdated
Comment on lines 164 to 167
QString lastOpenFile;
QStringList recentFiles;
QList<FileItem*> fileItems;
std::mutex resolvLock;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初始化

vendor.json Outdated
"-DKDDockWidgets_QT6=ON",
"-DKDDockWidgets_STATIC=ON",
"-DKDDW_FRONTEND_QTQUICK=ON",
"-DCMAKE_PREFIX_PATH=\"/Users/lifengdy/Qt/6.8.1/macos/lib/cmake\""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里写死了你的本地路径

#endif

namespace inspector {
ResolvService::ResolvService(uint16_t port) : port(port), thread([this] { worker(); }) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worker()最好不要写在这里

};

public:
ResolvService() = default;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认构造可以不写,感觉这块应该禁用默认构造

std::condition_variable conditionVariable = {};
std::vector<QueueItem> queue = {};
uint16_t port = 0;
std::thread thread;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看在构造函数中初始化,这里也可以使用std::shared_ptrstd::thread

}

void StartView::loadRecentFiles() {
QSettings settings("MyCompany", "Inspector");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个设置项叫MyCompany吗

tgfx::debug::IpAddress addr;
size_t len = 0;
for (;;) {
auto msg = broadcastListen->readData(len, addr, 0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readData返回的是data,变量取名为msg不太合适

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里读取的是broadcastMessage,我把命名补全

thread.join();
}

void ResolvService::query(uint32_t ip, const std::function<void(std::string&&)>& callback) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结合上下文看了下,std::function<void(std::string&&)中使用const char*应该就可以了,没必要使用右值引用

tgfx::debug::BroadcastMessage bm = {};
memcpy(&bm, msg, len);
auto protoVer = bm.protocolVersion;
char procname[tgfx::debug::WelcomeMessageProgramNameSize];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初始化下

#include "tgfx/core/Clock.h"

namespace inspector {
ClientData::ClientData(Data data) : data(std::move(data)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的ClientData和Data可以合并吗?两个都是表示一个Data数据结构

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个之前是说构造函数太多,封装到结构体中了

src/StartView.h Outdated
}

private:
QString filesPath = {};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QString filesPath = "";

for (;;) {
std::unique_lock<std::mutex> lock(mutex);
conditionVariable.wait(
lock, [this] { return !queue.empty() || exit.load(std::memory_order_relaxed); });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的代码已经加锁,可以不使用atomic变量

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个锁是为了保护队列,atomic变量是判断是否退出的

}

void StartView::connectToClientByLayerInspector(QObject* object) {
auto client = dynamic_cast<ClientData*>(object);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把rtti关掉,使用static_cast转换

resolv = std::make_unique<ResolvService>(port);
loadRecentFiles();

broadcastTimer = new QTimer(this);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

起始页在后台的时候,可以暂停定时器

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还没做后台的功能,后面合入完善的功能后改下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants