Display Server Info

This commit is contained in:
Florian Märkl 2019-08-14 19:58:44 +02:00
commit 696cf7823f
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
6 changed files with 58 additions and 24 deletions

View file

@ -20,6 +20,8 @@
#include <QFrame> #include <QFrame>
class QLabel;
class ServerIconWidget; class ServerIconWidget;
class DisplayServer; class DisplayServer;
@ -30,6 +32,8 @@ class ServerItemWidget : public QFrame
private: private:
bool selected; bool selected;
QLabel *top_label;
QLabel *bottom_label;
ServerIconWidget *icon_widget; ServerIconWidget *icon_widget;
protected: protected:

View file

@ -61,8 +61,6 @@ void DiscoveryManager::DiscoveryServiceHosts(QList<DiscoveryHost> hosts)
emit HostsUpdated(); emit HostsUpdated();
} }
#include <QDebug>
class DiscoveryManagerPrivate class DiscoveryManagerPrivate
{ {
public: public:

View file

@ -87,8 +87,10 @@ void DynamicGridWidget::UpdateLayout()
if(columns == 0) if(columns == 0)
return; return;
for(unsigned int i=0; i<widgets.length(); i++) Qt::Alignment alignment = widgets.count() == 1 ? Qt::AlignLeft : Qt::AlignCenter;
layout->addWidget(widgets[i], i / columns, i % columns);
for(unsigned int i=0; i<widgets.count(); i++)
layout->addWidget(widgets[i], i / columns, i % columns, alignment);
setMinimumWidth(item_width); setMinimumWidth(item_width);
} }

View file

@ -30,14 +30,16 @@ ServerItemWidget::ServerItemWidget(QWidget *parent) : QFrame(parent)
auto layout = new QVBoxLayout(this); auto layout = new QVBoxLayout(this);
this->setLayout(layout); this->setLayout(layout);
auto label = new QLabel("Server", this); top_label = new QLabel(this);
layout->addWidget(label); top_label->setAlignment(Qt::AlignCenter);
layout->addWidget(top_label);
icon_widget = new ServerIconWidget(this); icon_widget = new ServerIconWidget(this);
layout->addWidget(icon_widget); layout->addWidget(icon_widget);
auto label2 = new QLabel("Server2", this); bottom_label = new QLabel(this);
layout->addWidget(label2); bottom_label->setAlignment(Qt::AlignCenter);
layout->addWidget(bottom_label);
this->selected = true; this->selected = true;
SetSelected(false); SetSelected(false);
@ -68,9 +70,16 @@ void ServerItemWidget::Update(const DisplayServer &display_server)
if(display_server.discovered) if(display_server.discovered)
{ {
icon_widget->SetState(display_server.discovery_host.state); 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 else
{ {
icon_widget->SetState(CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN); icon_widget->SetState(CHIAKI_DISCOVERY_HOST_STATE_UNKNOWN);
top_label->setText("");
bottom_label->setText("");
} }
} }

View file

@ -53,24 +53,11 @@ typedef enum chiaki_discovery_host_state_t
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state); 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 * Apply A on all names of string members in ChiakiDiscoveryHost
*/ */
#define CHIAKI_DISCOVERY_HOST_STRING_FOREACH(A) \ #define CHIAKI_DISCOVERY_HOST_STRING_FOREACH(A) \
A(host_addr); \
A(system_version); \ A(system_version); \
A(device_discovery_protocol_version); \ A(device_discovery_protocol_version); \
A(host_name); \ A(host_name); \
@ -79,6 +66,17 @@ typedef struct chiaki_discovery_host_t
A(running_app_titleid); \ A(running_app_titleid); \
A(running_app_name); 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); CHIAKI_EXPORT int chiaki_discovery_packet_fmt(char *buf, size_t buf_size, ChiakiDiscoveryPacket *packet);
typedef struct chiaki_discovery_t typedef struct chiaki_discovery_t

View file

@ -24,6 +24,7 @@
#include <netdb.h> #include <netdb.h>
#include <stdio.h> #include <stdio.h>
#include <fcntl.h> #include <fcntl.h>
#include <arpa/inet.h>
const char *chiaki_discovery_host_state_string(ChiakiDiscoveryHostState state) 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; ChiakiHttpResponse http_response;
ChiakiErrorCode err = chiaki_http_response_parse(&http_response, buf, buf_size); 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)); 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) switch(http_response.code)
{ {
case 200: 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); //chiaki_log_hexdump_raw(discovery->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, n);
ChiakiDiscoveryHost response; 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) if(err != CHIAKI_ERR_SUCCESS)
{ {
CHIAKI_LOGI(discovery->log, "Discovery Response invalid"); CHIAKI_LOGI(discovery->log, "Discovery Response invalid");