mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Move pending command, adjust CmakeLists.
Took 24 minutes
This commit is contained in:
parent
c5bf87dfed
commit
eb7c4cae6c
33 changed files with 96 additions and 43 deletions
|
|
@ -2,12 +2,31 @@
|
|||
|
||||
add_subdirectory(libcockatrice/protocol/pb)
|
||||
|
||||
add_library(libcockatrice_protocol_wrapper STATIC)
|
||||
add_library(libcockatrice_protocol STATIC)
|
||||
|
||||
set(SOURCES
|
||||
libcockatrice/protocol/pending_command.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
libcockatrice/protocol/pending_command.h
|
||||
)
|
||||
|
||||
target_sources(libcockatrice_protocol
|
||||
PRIVATE
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
)
|
||||
|
||||
add_dependencies(libcockatrice_protocol libcockatrice_protocol_pb)
|
||||
|
||||
# Link the actual generated protobuf library
|
||||
target_link_libraries(libcockatrice_protocol_wrapper PUBLIC libcockatrice_protocol)
|
||||
target_link_libraries(libcockatrice_protocol PUBLIC ${COCKATRICE_QT_MODULES} libcockatrice_protocol_pb)
|
||||
|
||||
# Expose the pb/ folder so consumers can do #include <libcockatrice/protocol/pb/header.pb.h>
|
||||
# Expose include paths
|
||||
target_include_directories(
|
||||
libcockatrice_protocol_wrapper PUBLIC ${CMAKE_CURRENT_BINARY_DIR} # points to the generated headers
|
||||
libcockatrice_protocol
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR} # points to the generated headers
|
||||
)
|
||||
|
|
|
|||
32
libcockatrice_protocol/libcockatrice/protocol/CMakeLists.txt
Normal file
32
libcockatrice_protocol/libcockatrice/protocol/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Top-level wrapper for the protobuf library
|
||||
|
||||
add_subdirectory(pb)
|
||||
|
||||
add_library(libcockatrice_protocol STATIC)
|
||||
|
||||
set(SOURCES
|
||||
pending_command.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
pending_command.h
|
||||
)
|
||||
|
||||
target_sources(libcockatrice_protocol
|
||||
PRIVATE
|
||||
${SOURCES}
|
||||
${HEADERS}
|
||||
)
|
||||
|
||||
add_dependencies(libcockatrice_protocol libcockatrice_protocol_pb)
|
||||
|
||||
# Link the actual generated protobuf library
|
||||
target_link_libraries(libcockatrice_protocol PUBLIC ${COCKATRICE_QT_MODULES} libcockatrice_protocol_pb)
|
||||
|
||||
# Expose include paths
|
||||
target_include_directories(
|
||||
libcockatrice_protocol
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}/pb # generated pb headers
|
||||
)
|
||||
|
|
@ -171,12 +171,12 @@ if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
|
|||
include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
|
||||
|
||||
add_library(libcockatrice_protocol ${PROTO_SRCS} ${PROTO_HDRS})
|
||||
set(libcockatrice_protocol_LIBS ${PROTOBUF_LIBRARIES})
|
||||
add_library(libcockatrice_protocol_pb ${PROTO_SRCS} ${PROTO_HDRS})
|
||||
set(libcockatrice_protocol_pb_LIBS ${PROTOBUF_LIBRARIES})
|
||||
if(UNIX)
|
||||
set(libcockatrice_protocol_LIBS ${libcockatrice_protocol_LIBS} -lpthread)
|
||||
set(libcockatrice_protocol_pb_LIBS ${libcockatrice_protocol_pb_LIBS} -lpthread)
|
||||
endif(UNIX)
|
||||
target_link_libraries(libcockatrice_protocol ${libcockatrice_protocol_LIBS})
|
||||
target_link_libraries(libcockatrice_protocol_pb ${libcockatrice_protocol_pb_LIBS})
|
||||
|
||||
# ubuntu uses an outdated package for protobuf, 3.1.0 is required
|
||||
if(${Protobuf_VERSION} VERSION_LESS "3.1.0")
|
||||
|
|
@ -188,10 +188,10 @@ if(${Protobuf_VERSION} VERSION_LESS "3.21.0.0")
|
|||
)
|
||||
endif()
|
||||
else()
|
||||
add_library(libcockatrice_protocol ${PROTO_FILES})
|
||||
target_link_libraries(libcockatrice_protocol PUBLIC protobuf::libprotobuf)
|
||||
add_library(libcockatrice_protocol_pb ${PROTO_FILES})
|
||||
target_link_libraries(libcockatrice_protocol_pb PUBLIC protobuf::libprotobuf)
|
||||
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
target_include_directories(libcockatrice_protocol PUBLIC "${PROTOBUF_INCLUDE_DIRS}")
|
||||
target_include_directories(libcockatrice_protocol_pb PUBLIC "${PROTOBUF_INCLUDE_DIRS}")
|
||||
|
||||
protobuf_generate(TARGET libcockatrice_protocol IMPORT_DIRS "." PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
|
||||
protobuf_generate(TARGET libcockatrice_protocol_pb IMPORT_DIRS "." PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
#include "pending_command.h"
|
||||
|
||||
PendingCommand::PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData)
|
||||
: commandContainer(_commandContainer), extraData(_extraData), ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
CommandContainer &PendingCommand::getCommandContainer()
|
||||
{
|
||||
return commandContainer;
|
||||
}
|
||||
|
||||
void PendingCommand::setExtraData(const QVariant &_extraData)
|
||||
{
|
||||
extraData = _extraData;
|
||||
}
|
||||
|
||||
QVariant PendingCommand::getExtraData() const
|
||||
{
|
||||
return extraData;
|
||||
}
|
||||
|
||||
void PendingCommand::processResponse(const Response &response)
|
||||
{
|
||||
emit finished(response, commandContainer, extraData);
|
||||
}
|
||||
|
||||
int PendingCommand::tick()
|
||||
{
|
||||
return ++ticks;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @file pending_command.h
|
||||
* @ingroup Messages
|
||||
* @brief TODO: Document this.
|
||||
*/
|
||||
|
||||
#ifndef PENDING_COMMAND_H
|
||||
#define PENDING_COMMAND_H
|
||||
|
||||
#include <QVariant>
|
||||
#include <libcockatrice/protocol/pb/commands.pb.h>
|
||||
#include <libcockatrice/protocol/pb/response.pb.h>
|
||||
|
||||
class PendingCommand : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void finished(const Response &response, const CommandContainer &commandContainer, const QVariant &extraData);
|
||||
|
||||
private:
|
||||
CommandContainer commandContainer;
|
||||
QVariant extraData;
|
||||
int ticks;
|
||||
|
||||
public:
|
||||
explicit PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData = QVariant());
|
||||
CommandContainer &getCommandContainer();
|
||||
void setExtraData(const QVariant &_extraData);
|
||||
QVariant getExtraData() const;
|
||||
void processResponse(const Response &response);
|
||||
int tick();
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue