Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidaobing committed Jul 14, 2024
1 parent 3ba5eb1 commit 0ece922
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ IncludeCategories:
- Regex: '^"config\.h"'
Priority: -1
# The main header for a source file automatically gets category 0
- Regex: '^<.*>'
- Regex: '^<[^.]*>'
Priority: 1
- Regex: '.*'
- Regex: '^<.*>'
Priority: 2
- Regex: '.*'
Priority: 3
16 changes: 10 additions & 6 deletions src/api/iptux-core/CoreThread.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#ifndef IPTUX_CORETHREAD_H
#define IPTUX_CORETHREAD_H

#include "iptux-core/Models.h"
#include <atomic>
#include <cstdint>
#include <memory>
#include <netinet/in.h>
#include <vector>

#include <netinet/in.h>
#include <sigc++/signal.h>

#include "iptux-core/Const.h"
#include "iptux-core/Event.h"
#include "iptux-core/Models.h"
#include "iptux-core/ProgramData.h"
#include "iptux-core/TransFileModel.h"

Expand Down Expand Up @@ -126,14 +125,19 @@ class CoreThread {
* @return false if send failed
*/
bool SendMessage(CPPalInfo pal, const std::string& message);
bool SendMessage(CPPalInfo pal, std::shared_ptr<ChipData> chipData);
bool SendMessage(CPPalInfo pal,
enum GroupMsgOption opttype,
std::shared_ptr<ChipData> chipData);
bool SendMsgPara(std::shared_ptr<MsgPara> msgPara);
bool SendMsgPara(CPPalInfo pal,
enum GroupMsgOption opttype,
std::shared_ptr<MsgPara> msgPara);
void AsyncSendMsgPara(std::shared_ptr<MsgPara> msgPara);
void SendUnitMessage(const PalKey& palKey,
uint32_t opttype,
const std::string& message);
void SendUnitMessage(const PalKey& palKey,
uint32_t opttype,
enum GroupMsgOption opttype,
std::shared_ptr<MsgPara> msgPara);
void SendGroupMessage(const PalKey& palKey, const std::string& message);
void SendGroupMessage(const PalKey& palKey, std::shared_ptr<MsgPara> msgPara);
Expand Down
12 changes: 7 additions & 5 deletions src/iptux-core/Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const int MAX_PHOTOSIZE = 300;
const int MAX_UDPLEN = 8192;
const int MAX_SHAREDFILE = 10000;

const uint32_t IPTUX_REGULAROPT = 0x00000100UL;
const uint32_t IPTUX_SEGMENTOPT = 0x00000200UL;
const uint32_t IPTUX_GROUPOPT = 0x00000300UL;
const uint32_t IPTUX_BROADCASTOPT = 0x00000400UL;
enum GroupMsgOption {
IPTUX_REGULAROPT = 0x00000100UL,
IPTUX_SEGMENTOPT = 0x00000200UL,
IPTUX_GROUPOPT = 0x00000300UL,
IPTUX_BROADCASTOPT = 0x00000400UL,
};
} // namespace iptux

#endif
#endif
23 changes: 18 additions & 5 deletions src/iptux-core/CoreThread.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#include "config.h"
#include "iptux-core/CoreThread.h"

#include <deque>
#include <fstream>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <thread>

#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <glog/logging.h>
#include <poll.h>
#include <sys/stat.h>

#include "iptux-core/Exception.h"
#include "iptux-core/Models.h"
#include "iptux-core/internal/Command.h"
#include "iptux-core/internal/RecvFileData.h"
#include "iptux-core/internal/SendFile.h"
Expand Down Expand Up @@ -477,7 +475,9 @@ bool CoreThread::SendMessage(CPPalInfo palInfo, const string& message) {
return true;
}

bool CoreThread::SendMessage(CPPalInfo pal, shared_ptr<ChipData> chipData) {
bool CoreThread::SendMessage(CPPalInfo pal,
enum GroupMsgOption option,
shared_ptr<ChipData> chipData) {
switch (chipData->type) {
case MessageContentType::STRING:
/* 文本类型 */
Expand All @@ -500,8 +500,14 @@ bool CoreThread::SendMessage(CPPalInfo pal, shared_ptr<ChipData> chipData) {
}

bool CoreThread::SendMsgPara(shared_ptr<MsgPara> para) {
return SendMsgPara(para->getPal(), IPTUX_REGULAROPT, para);
}

bool CoreThread::SendMsgPara(CPPalInfo pal,
enum GroupMsgOption option,
shared_ptr<MsgPara> para) {
for (int i = 0; i < int(para->dtlist.size()); ++i) {
if (!SendMessage(para->getPal(), para->dtlist[i])) {
if (!SendMessage(pal, para->dtlist[i])) {
LOG_ERROR("send message failed: %s", para->dtlist[i]->ToString().c_str());
return false;
}
Expand Down Expand Up @@ -705,6 +711,13 @@ void CoreThread::SendUnitMessage(const PalKey& palKey,
Command(*this).SendUnitMsg(udpSock, GetPal(palKey), opttype, message.c_str());
}

void CoreThread::SendUnitMessage(const PalKey& palKey,
enum GroupMsgOption opttype,
std::shared_ptr<MsgPara> msgPara) {
auto pal = ((const CoreThread*)this)->GetPal(palKey);
SendMsgPara(pal, msgPara);
}

void CoreThread::SendGroupMessage(const PalKey& palKey,
const std::string& message) {
Command(*this).SendGroupMsg(udpSock, GetPal(palKey), message.c_str());
Expand Down
6 changes: 2 additions & 4 deletions src/iptux/DialogGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
//
#include "config.h"
#include "DialogGroup.h"

#include "iptux-core/Models.h"
#include <glib/gi18n.h>
#include <glog/logging.h>

#include "iptux-core/Const.h"
#include "iptux-core/Models.h"
#include "iptux-utils/output.h"
#include "iptux-utils/utils.h"
#include "iptux/DialogPeer.h"
Expand Down Expand Up @@ -431,7 +429,7 @@ void DialogGroup::broadcastTextMsg(shared_ptr<MsgPara> para) {
GtkTreeModel* model;
GtkTreeIter iter;
gboolean active;
uint32_t opttype;
enum GroupMsgOption opttype;
PalInfo* pal;

/* 考察是否有成员 */
Expand Down

0 comments on commit 0ece922

Please sign in to comment.