1#ifndef APP_INSTANCE_MANAGER_H
2#define APP_INSTANCE_MANAGER_H
11#include <QPropertyAnimation>
102 const QPoint &window_position);
151 bool ProcessMessage(
const QByteArray &message, QLocalSocket *sender =
nullptr);
std::atomic< bool > is_being_absorbed_
Atomic flag indicating if this client instance is currently being absorbed.
Definition app_instance_manager.h:212
static constexpr double kAbsorptionDistance
Distance (in pixels) at which absorption starts.
Definition app_instance_manager.h:210
void InitAttractionThread()
Initializes and starts the background thread responsible for attraction logic.
Definition app_instance_manager.cpp:291
void instanceDisconnected(QString instance_id)
Emitted when a client instance disconnects (on the server) or when the connection to the server is lo...
bool Start()
Starts the instance manager.
Definition app_instance_manager.cpp:36
static constexpr double kAttractionForce
Deprecated attraction force constant (logic now uses kSmoothForce).
Definition app_instance_manager.h:208
QMainWindow * main_window_
Pointer to the main application window.
Definition app_instance_manager.h:187
static constexpr int kUpdateIntervalMs
Interval (in ms) for sending position updates.
Definition app_instance_manager.h:205
MessageType
Defines the types of messages exchanged between instances.
Definition app_instance_manager.h:129
@ kPositionUpdate
Message containing position and size data.
Definition app_instance_manager.h:130
@ kIdentify
Message sent by a client to identify itself to the server.
Definition app_instance_manager.h:131
@ kIdentifyResponse
Message sent by the server in response to an Identify message.
Definition app_instance_manager.h:132
bool IsCreator() const
Checks if this instance is the creator (server - was opened first).
Definition app_instance_manager.h:74
void ApplyAttractionForce(const QPointF &target_position)
Applies a force to the client window, pulling it towards the target position (creator window).
Definition app_instance_manager.cpp:342
bool ProcessMessage(const QByteArray &message, QLocalSocket *sender=nullptr)
Processes an incoming message received from a socket.
Definition app_instance_manager.cpp:181
void StartAbsorptionAnimation()
Starts the animation sequence for absorbing a client instance. This involves moving the client window...
Definition app_instance_manager.cpp:373
QLocalSocket * socket_
Local socket instance (used only by clients).
Definition app_instance_manager.h:190
~AppInstanceManager() override
Destructor. Cleans up the resources.
Definition app_instance_manager.cpp:21
QString GetInstanceId() const
Gets the unique identifier for this instance.
Definition app_instance_manager.h:68
static const QString kServerName
Name used for the local server discovery.
Definition app_instance_manager.h:206
QLocalServer * server_
Local server instance (used only by the creator).
Definition app_instance_manager.h:189
QTimer absorption_check_timer_
Timer potentially used for absorption checks (currently seems unused).
Definition app_instance_manager.h:192
void ConnectToServer()
Establishes a connection to the server instance for a client instance.
Definition app_instance_manager.cpp:163
void instanceConnected(QString instance_id)
Emitted when a new client instance connects (on the server) or when connection to the server is estab...
std::atomic< bool > is_creator_
Atomic flag indicating if this instance is the creator.
Definition app_instance_manager.h:195
void otherInstancePositionHasChanged(QString instance_id, const QPointF &blob_center, const QPoint &window_position)
Emitted when position data from another instance is received.
QByteArray CreatePositionMessage() const
Creates a QByteArray message containing the current instance's position data.
Definition app_instance_manager.cpp:278
void clientDisconnected()
Slot called when a connected socket disconnects. Handles cleanup and potential role change (the clien...
Definition app_instance_manager.cpp:73
void SendToAllClients(const QByteArray &message)
Sends a message to all connected clients (only applicable for the creator instance).
Definition app_instance_manager.cpp:268
AppInstanceManager(QMainWindow *window, BlobAnimation *blob, QObject *parent=nullptr)
Constructs an AppInstanceManager.
Definition app_instance_manager.cpp:12
std::atomic< bool > is_thread_running
Atomic flag to control the attraction thread's loop.
Definition app_instance_manager.h:203
QVector< InstanceInfo > connected_instances_
List of currently known connected instances. Protected by instances_mutex_.
Definition app_instance_manager.h:198
QTimer position_timer_
Timer to periodically send position updates.
Definition app_instance_manager.h:191
QMutex instances_mutex_
Mutex to protect access to connected_instances_.
Definition app_instance_manager.h:193
void readData()
Slot called when data can be read from a connected socket.
Definition app_instance_manager.cpp:131
void FinalizeAbsorption()
Finalizes the absorption process by quitting the client application.
Definition app_instance_manager.cpp:417
QHash< QLocalSocket *, QString > client_ids_
Maps client sockets to their instance IDs (used only by the creator).
Definition app_instance_manager.h:200
std::unique_ptr< std::thread > attraction_thread_
Background thread for attraction logic.
Definition app_instance_manager.h:202
static bool IsAnotherInstanceRunning()
Statically checks if another instance of the application is already running.
Definition app_instance_manager.cpp:56
void sendPositionUpdate()
Slot called periodically by position_timer_ to send the current instance's position data.
Definition app_instance_manager.cpp:141
void SetupServer()
Sets up the QLocalServer for the creator instance.
Definition app_instance_manager.cpp:151
QString instance_id_
Unique identifier for this application instance.
Definition app_instance_manager.h:196
BlobAnimation * blob_
Pointer to the BlobAnimation object.
Definition app_instance_manager.h:188
void onNewConnection()
Slot called when a new client attempts to connect to the server.
Definition app_instance_manager.cpp:66
Main widget responsible for rendering and animating the dynamic blob.
Definition blob_animation.h:30
Structure holding information about a connected application instance.
Definition app_instance_manager.h:21
QString instance_id
Unique identifier for the instance.
Definition app_instance_manager.h:22
QPoint window_position
Global position of the instance's window.
Definition app_instance_manager.h:24
bool is_creator
Flag indicating if this instance is the creator (was opened first).
Definition app_instance_manager.h:26
QPointF blob_center
Center position of the blob within its window.
Definition app_instance_manager.h:23
QSize window_size
Size of the instance's window.
Definition app_instance_manager.h:25