mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 18:57:07 -07:00
Display Server Info
This commit is contained in:
parent
446ddd0071
commit
696cf7823f
6 changed files with 58 additions and 24 deletions
|
@ -20,6 +20,8 @@
|
|||
|
||||
#include <QFrame>
|
||||
|
||||
class QLabel;
|
||||
|
||||
class ServerIconWidget;
|
||||
class DisplayServer;
|
||||
|
||||
|
@ -30,6 +32,8 @@ class ServerItemWidget : public QFrame
|
|||
private:
|
||||
bool selected;
|
||||
|
||||
QLabel *top_label;
|
||||
QLabel *bottom_label;
|
||||
ServerIconWidget *icon_widget;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -61,8 +61,6 @@ void DiscoveryManager::DiscoveryServiceHosts(QList<DiscoveryHost> hosts)
|
|||
emit HostsUpdated();
|
||||
}
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class DiscoveryManagerPrivate
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -87,8 +87,10 @@ void DynamicGridWidget::UpdateLayout()
|
|||
if(columns == 0)
|
||||
return;
|
||||
|
||||
for(unsigned int i=0; i<widgets.length(); i++)
|
||||
layout->addWidget(widgets[i], i / columns, i % columns);
|
||||
Qt::Alignment alignment = widgets.count() == 1 ? Qt::AlignLeft : Qt::AlignCenter;
|
||||
|
||||
for(unsigned int i=0; i<widgets.count(); i++)
|
||||
layout->addWidget(widgets[i], i / columns, i % columns, alignment);
|
||||
|
||||
setMinimumWidth(item_width);
|
||||
}
|
||||
|
|
|
@ -30,14 +30,16 @@ ServerItemWidget::ServerItemWidget(QWidget *parent) : QFrame(parent)
|
|||
auto layout = new QVBoxLayout(this);
|
||||
this->setLayout(layout);
|
||||
|
||||
auto label = new QLabel("Server", this);
|
||||
layout->addWidget(label);
|
||||
top_label = new QLabel(this);
|
||||
top_label->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(top_label);
|
||||
|
||||
icon_widget = new ServerIconWidget(this);
|
||||
layout->addWidget(icon_widget);
|
||||
|
||||
auto label2 = new QLabel("Server2", this);
|
||||
layout->addWidget(label2);
|
||||
bottom_label = new QLabel(this);
|
||||
bottom_label->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(bottom_label);
|
||||
|
||||
this->selected = true;
|
||||
SetSelected(false);
|
||||
|
@ -68,9 +70,16 @@ void ServerItemWidget::Update(const DisplayServer &display_server)
|
|||
if(display_server.discovered)
|
||||
{
|
||||
icon_widget->SetState(display_server.discovery_host.state);
|
||||
top_label->setText(tr("%1\nID: %2\nAddress: %3").arg(
|
||||
display_server.discovery_host.host_name,
|
||||
display_server.discovery_host.host_id,
|
||||
display_server.discovery_host.host_addr));
|
||||
bottom_label->setText(tr("State: %1").arg(chiaki_discovery_host_state_string(display_server.discovery_host.state)));
|
||||
}
|
||||
else
|
||||
{
|
||||
icon_widget->SetState(CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN);
|
||||
top_label->setText("");
|
||||
bottom_label->setText("");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,24 +53,11 @@ typedef enum chiaki_discovery_host_state_t
|
|||
|
||||
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state);
|
||||
|
||||
typedef struct chiaki_discovery_host_t
|
||||
{
|
||||
// All string members here must be in sync with CHIAKI_DISCOVERY_HOST_STRING_FOREACH
|
||||
ChiakiDiscoveryHostState state;
|
||||
const char *system_version;
|
||||
const char *device_discovery_protocol_version;
|
||||
uint16_t host_request_port;
|
||||
const char *host_name;
|
||||
const char *host_type;
|
||||
const char *host_id;
|
||||
const char *running_app_titleid;
|
||||
const char *running_app_name;
|
||||
} ChiakiDiscoveryHost;
|
||||
|
||||
/**
|
||||
* Apply A on all names of string members in ChiakiDiscoveryHost
|
||||
*/
|
||||
#define CHIAKI_DISCOVERY_HOST_STRING_FOREACH(A) \
|
||||
A(host_addr); \
|
||||
A(system_version); \
|
||||
A(device_discovery_protocol_version); \
|
||||
A(host_name); \
|
||||
|
@ -79,6 +66,17 @@ typedef struct chiaki_discovery_host_t
|
|||
A(running_app_titleid); \
|
||||
A(running_app_name);
|
||||
|
||||
typedef struct chiaki_discovery_host_t
|
||||
{
|
||||
// All string members here must be in sync with CHIAKI_DISCOVERY_HOST_STRING_FOREACH
|
||||
ChiakiDiscoveryHostState state;
|
||||
uint16_t host_request_port;
|
||||
#define STRING_MEMBER(name) const char *name;
|
||||
CHIAKI_DISCOVERY_HOST_STRING_FOREACH(STRING_MEMBER)
|
||||
#undef STRING_MEMBER
|
||||
} ChiakiDiscoveryHost;
|
||||
|
||||
|
||||
CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, ChiakiDiscoveryPacket *packet);
|
||||
|
||||
typedef struct chiaki_discovery_t
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state)
|
||||
{
|
||||
|
@ -51,7 +52,7 @@ CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, Chiaki
|
|||
}
|
||||
}
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscoveryHost *response, char *buf, size_t buf_size)
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscoveryHost *response, struct sockaddr *addr, char *buf, size_t buf_size)
|
||||
{
|
||||
ChiakiHttpResponse http_response;
|
||||
ChiakiErrorCode err = chiaki_http_response_parse(&http_response, buf, buf_size);
|
||||
|
@ -60,6 +61,28 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_discovery_srch_response_parse(ChiakiDiscove
|
|||
|
||||
memset(response, 0, sizeof(*response));
|
||||
|
||||
size_t host_addr_str_size = 40;
|
||||
char *host_addr_str = malloc(host_addr_str_size);
|
||||
if(!host_addr_str)
|
||||
return CHIAKI_ERR_MEMORY;
|
||||
void *addr_src;
|
||||
switch(addr->sa_family)
|
||||
{
|
||||
case AF_INET:
|
||||
addr_src = &((struct sockaddr_in *)addr)->sin_addr;
|
||||
break;
|
||||
case AF_INET6:
|
||||
addr_src = &((struct sockaddr_in6 *)addr)->sin6_addr;
|
||||
break;
|
||||
default:
|
||||
addr_src = NULL;
|
||||
break;
|
||||
}
|
||||
if(addr_src)
|
||||
response->host_addr = inet_ntop(addr->sa_family, addr_src, host_addr_str, host_addr_str_size);
|
||||
if(!response->host_addr)
|
||||
free(host_addr_str);
|
||||
|
||||
switch(http_response.code)
|
||||
{
|
||||
case 200:
|
||||
|
@ -245,7 +268,7 @@ static void *discovery_thread_func(void *user)
|
|||
//chiaki_log_hexdump_raw(discovery->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, n);
|
||||
|
||||
ChiakiDiscoveryHost response;
|
||||
err = chiaki_discovery_srch_response_parse(&response, buf, n);
|
||||
err = chiaki_discovery_srch_response_parse(&response, &client_addr, buf, n);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGI(discovery->log, "Discovery Response invalid");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue