Skip to content

Commit

Permalink
Initialize member variables on declaration instead of contructor
Browse files Browse the repository at this point in the history
  • Loading branch information
bear101 committed Oct 18, 2024
1 parent 9cc15fd commit b1b6e14
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 422 deletions.
16 changes: 6 additions & 10 deletions Library/TeamTalkLib/teamtalk/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ namespace teamtalk {
const Channel& operator = (const Channel& ch);

Channel(channel_t parent, int channelid, ChannelTypes chantype, const ACE_TString& name)
: m_protected(false)
, m_maxusers(MAX_USERS_IN_CHANNEL)
, m_channelid(channelid)
, m_userdata(0)
, m_maxdiskusage(0)
: m_channelid(channelid)
, m_chantype(chantype)
, m_parent(parent)
, m_name(name)
Expand Down Expand Up @@ -525,13 +521,13 @@ namespace teamtalk {
ACE_TString m_topic;
std::set< int > m_setOps;
std::weak_ptr< CHANNEL > m_parent;
bool m_protected;
ACE_INT64 m_maxdiskusage;
bool m_protected = false;
ACE_INT64 m_maxdiskusage = 0;
typedef std::map<ACE_TString, RemoteFile> mfiles_t;
mfiles_t m_files;
int m_maxusers;
int m_channelid;
int m_userdata;
int m_maxusers = MAX_USERS_IN_CHANNEL;
int m_channelid = 0;
int m_userdata = 0;
AudioCodec m_audiocodec;
AudioConfig m_audiocfg;
ChannelTypes m_chantype;
Expand Down
4 changes: 2 additions & 2 deletions Library/TeamTalkLib/teamtalk/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ namespace teamtalk {

struct ErrorMsg
{
int errorno;
int errorno = TT_CMDERR_SUCCESS;
ACE_TString errmsg, paramname;
ErrorMsg() : errorno(TT_CMDERR_SUCCESS) { }
ErrorMsg() { }
ErrorMsg(int cmderrno, const ACE_TString& param = ACE_TEXT(""))
: errorno(cmderrno), paramname(param)
{
Expand Down
139 changes: 52 additions & 87 deletions Library/TeamTalkLib/teamtalk/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <ace/INET_Addr.h>
#include <ace/Time_Value.h>

#include <regex>
#include <map>
#include <vector>
#include <set>
Expand Down Expand Up @@ -107,45 +106,35 @@ namespace teamtalk {

struct ServerStats
{
ACE_INT64 total_bytessent;
ACE_INT64 total_bytesreceived;
ACE_INT64 last_bytessent;
ACE_INT64 last_bytesreceived;
ACE_INT64 avg_bytessent;
ACE_INT64 avg_bytesreceived;
ACE_INT64 voice_bytesreceived;
ACE_INT64 voice_bytessent;
ACE_INT64 last_voice_bytessent;
ACE_INT64 vidcap_bytesreceived;
ACE_INT64 vidcap_bytessent;
ACE_INT64 last_vidcap_bytessent;
ACE_INT64 mediafile_bytesreceived;
ACE_INT64 mediafile_bytessent;
ACE_INT64 last_mediafile_bytessent;
ACE_INT64 desktop_bytesreceived;
ACE_INT64 desktop_bytessent;
ACE_INT64 last_desktop_bytessent;
ACE_INT64 files_bytesreceived;
ACE_INT64 files_bytessent;

int userspeak;
int usersservered;
ACE_INT64 total_bytessent = 0;
ACE_INT64 total_bytesreceived = 0;
ACE_INT64 last_bytessent = 0;
ACE_INT64 last_bytesreceived = 0;
ACE_INT64 avg_bytessent = 0;
ACE_INT64 avg_bytesreceived = 0;
ACE_INT64 voice_bytesreceived = 0;
ACE_INT64 voice_bytessent = 0;
ACE_INT64 last_voice_bytessent = 0;
ACE_INT64 vidcap_bytesreceived = 0;
ACE_INT64 vidcap_bytessent = 0;
ACE_INT64 last_vidcap_bytessent = 0;
ACE_INT64 mediafile_bytesreceived = 0;
ACE_INT64 mediafile_bytessent = 0;
ACE_INT64 last_mediafile_bytessent = 0;
ACE_INT64 desktop_bytesreceived = 0;
ACE_INT64 desktop_bytessent = 0;
ACE_INT64 last_desktop_bytessent = 0;
ACE_INT64 files_bytesreceived = 0;
ACE_INT64 files_bytessent = 0;

int userspeak = 0;
int usersservered = 0;
//uptime
ACE_Time_Value starttime;

ACE_INT64 packets_received = 0, packets_sent = 0; // only used internally

ServerStats()
: total_bytessent(0), total_bytesreceived(0), last_bytessent(0)
, last_bytesreceived(0), avg_bytessent(0), avg_bytesreceived(0)
, voice_bytesreceived(0), voice_bytessent(0)
, vidcap_bytesreceived(0), vidcap_bytessent(0)
, last_voice_bytessent(0), last_vidcap_bytessent(0)
, mediafile_bytesreceived(0), desktop_bytesreceived(0)
, desktop_bytessent(0), last_desktop_bytessent(0)
, mediafile_bytessent(0), last_mediafile_bytessent(0), userspeak(0)
, usersservered(0), files_bytesreceived(0), files_bytessent(0)
{}
ServerStats() { }
};

/* Remember to updated DLL header file when modifying this */
Expand Down Expand Up @@ -232,9 +221,9 @@ namespace teamtalk {

struct Abuse
{
int n_cmds;
int cmd_msec;
Abuse() : n_cmds(0), cmd_msec(0) {}
int n_cmds = 0;
int cmd_msec = 0;
Abuse() { }

std::vector<int> toParam() const
{
Expand Down Expand Up @@ -440,30 +429,18 @@ namespace teamtalk {

struct SpeexDSP
{
bool enable_agc;
int agc_gainlevel;
int agc_maxincdbsec;
int agc_maxdecdbsec;
int agc_maxgaindb;
bool enable_denoise;
int maxnoisesuppressdb;
bool enable_aec;
int aec_suppress_level;
int aec_suppress_active;

SpeexDSP()
{
enable_agc = false;
agc_gainlevel = 0;
agc_maxincdbsec = 0;
agc_maxdecdbsec = 0;
agc_maxgaindb = 0;
enable_denoise = false;
maxnoisesuppressdb = 0;
enable_aec = false;
aec_suppress_level = 0;
aec_suppress_active = 0;
}
bool enable_agc = false;
int agc_gainlevel = 0;
int agc_maxincdbsec = 0;
int agc_maxdecdbsec = 0;
int agc_maxgaindb = 0;
bool enable_denoise = false;
int maxnoisesuppressdb = 0;
bool enable_aec = 0;
int aec_suppress_level = 0;
int aec_suppress_active = 0;

SpeexDSP() { }
};

struct TTAudioPreprocessor
Expand Down Expand Up @@ -600,18 +577,18 @@ namespace teamtalk {
ACE_TString passwd;
ACE_TString topic;
ACE_TString oppasswd;
ACE_INT64 diskquota;
int maxusers;
bool bProtected;
ACE_INT64 diskquota = 0;
int maxusers = MAX_USERS_IN_CHANNEL;
bool bProtected = false;
std::set<int> setops;
int channelid;
int parentid;
int channelid = 0;
int parentid = 0;
AudioCodec audiocodec;
AudioConfig audiocfg;
files_t files;
ChannelTypes chantype;
ACE_UINT32 chankey;
int userdata;
ChannelTypes chantype = CHANNEL_DEFAULT;
ACE_UINT32 chankey = 0;
int userdata = 0;
transmitusers_t transmitusers;
std::vector<int> transmitqueue;
int transmitswitchdelay = 0;
Expand All @@ -626,15 +603,8 @@ namespace teamtalk {

ChannelProp()
{
bProtected = false;
channelid = parentid = 0;
diskquota = 0;
chankey = 0;
userdata = 0;
maxusers = MAX_USERS_IN_CHANNEL;
memset(&audiocodec, 0, sizeof(audiocodec));
audiocodec.codec = CODEC_NO_CODEC;
chantype = CHANNEL_DEFAULT;

// ensure we can use std::map<>.at()
transmitusers[STREAMTYPE_VOICE] = std::set<int>();
Expand All @@ -656,16 +626,11 @@ namespace teamtalk {

struct DesktopInput
{
ACE_UINT16 x;
ACE_UINT16 y;
ACE_UINT32 keycode;
KeyStateMask keystate;
DesktopInput()
: x(-1)
, y(-1)
, keycode(-1)
, keystate(KEYSTATE_NONE)
{ }
ACE_UINT16 x = -1;
ACE_UINT16 y = -1;
ACE_UINT32 keycode = -1;
KeyStateMask keystate = KEYSTATE_NONE;
DesktopInput() { }
};

/* Remember to updated DLL header file when modifying this */
Expand Down
10 changes: 5 additions & 5 deletions Library/TeamTalkLib/teamtalk/DesktopSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ namespace teamtalk {
protected:
void Init();
DesktopWindow m_wnd;
int m_pixel_size;
int m_padding;
int m_w_blocks, m_h_blocks;
int m_block_width, m_block_height;
int m_bytes_per_line;
int m_pixel_size = 0;
int m_padding = 0;
int m_w_blocks = 0, m_h_blocks = 0;
int m_block_width = 0, m_block_height = 0;
int m_bytes_per_line = 0;
};

class BMPPalette
Expand Down
2 changes: 0 additions & 2 deletions Library/TeamTalkLib/teamtalk/PacketHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,6 @@ int RemoveObsoleteDesktopPackets(const DesktopPacket& packet,
DesktopTransmitter::DesktopTransmitter(uint8_t session_id, uint32_t upd_timeid)
: m_session_id(session_id)
, m_update_timeid(upd_timeid)
, m_tx_count(4)
, m_pingtime(0)
{
}

Expand Down
12 changes: 6 additions & 6 deletions Library/TeamTalkLib/teamtalk/PacketHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ namespace teamtalk {
private:
void AddSentDesktopPacket(const DesktopPacket& packet);

uint8_t m_session_id;
uint32_t m_update_timeid;
uint8_t m_session_id = 0;
uint32_t m_update_timeid = 0;

//packet id -> packet
typedef std::map<uint16_t, desktoppacket_t> map_desktop_packets_t;
Expand All @@ -191,9 +191,9 @@ namespace teamtalk {
//packet id -> sent time
typedef std::map<uint16_t, uint32_t> map_sent_time_t;
map_sent_time_t m_sent_times, m_sent_ack_times;
int m_tx_count;
int m_tx_count = 4;
//round trip time (sent -> ack time)
uint32_t m_pingtime;
uint32_t m_pingtime = 0;
};

typedef std::shared_ptr< DesktopTransmitter > desktop_transmitter_t;
Expand All @@ -207,8 +207,8 @@ namespace teamtalk {
uint32_t GetUpdateID() const { return m_update_timeid; }

private:
uint8_t m_session_id;
uint32_t m_update_timeid;
uint8_t m_session_id = 0;
uint32_t m_update_timeid = 0;
};

typedef std::shared_ptr< DesktopNakTransmitter > desktop_nak_tx_t;
Expand Down
16 changes: 8 additions & 8 deletions Library/TeamTalkLib/teamtalk/PacketLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ namespace teamtalk {
uint8_t* FindField_NonConst(uint8_t fieldtype) const;
const uint8_t* FindField(uint8_t fieldtype) const;
std::vector<iovec> m_iovec;
bool m_cleanup;
bool m_cleanup = false;
#ifdef ENABLE_ENCRYPTION
//Holds which part of 'm_iovec' should be encrypted by 'CryptPacket'
std::set<uint8_t> m_crypt_sections;
Expand Down Expand Up @@ -695,19 +695,19 @@ namespace teamtalk {
//desktop block with pointer to data
struct desktop_block
{
const char* block_data;
uint16_t block_size;
const char* block_data = nullptr;
uint16_t block_size = 0;
};
//blockno -> block
typedef std::map< uint16_t, desktop_block > map_block_t;
//a fragmented block
struct block_fragment
{
uint16_t block_no;
uint8_t frag_no;
uint8_t frag_cnt;
const char* frag_data;
uint16_t frag_size;
uint16_t block_no = 0;
uint8_t frag_no = 0;
uint8_t frag_cnt = 0;
const char* frag_data = nullptr;
uint16_t frag_size = 0;
};
//blockno -> fragment
typedef std::list<block_fragment> block_frags_t;
Expand Down
7 changes: 2 additions & 5 deletions Library/TeamTalkLib/teamtalk/StreamHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class StreamHandler : public ACE_Svc_Handler< ACE_SOCK_STREAM_TYPE, ACE_MT_SYNCH
ACE_Message_Queue<ACE_MT_SYNCH> *mq = 0,
ACE_Reactor *reactor = ACE_Reactor::instance())
: super(thr_mgr, mq, reactor)
, m_listener(NULL)
, sent_(0)
, recv_(0)
{
m_buffer.resize(4096);

Expand Down Expand Up @@ -206,10 +203,10 @@ class StreamHandler : public ACE_Svc_Handler< ACE_SOCK_STREAM_TYPE, ACE_MT_SYNCH
return -1;
}

ACE_INT64 sent_, recv_;
ACE_INT64 sent_ = 0, recv_ = 0;

protected:
StreamListener<StreamHandler>* m_listener;
StreamListener<StreamHandler>* m_listener = nullptr;
std::vector<char> m_buffer;
};

Expand Down
5 changes: 0 additions & 5 deletions Library/TeamTalkLib/teamtalk/User.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ namespace teamtalk {

User::User(int userid)
: m_userid(userid)
, m_statusmode(0)
, m_packet_protocol(0)
, m_tm_ok(false)
, m_mtu_data_size(MAX_PAYLOAD_DATA_SIZE)
, m_mtu_max_payload_size(MAX_PACKET_PAYLOAD_SIZE)
{
}

Expand Down
12 changes: 6 additions & 6 deletions Library/TeamTalkLib/teamtalk/User.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ namespace teamtalk {
ACE_TString GetClientName() const { return m_clientname; }

private:
int m_userid;
int m_packet_protocol;
int m_userid = 0;
int m_packet_protocol = 0;
ACE_TString m_ipaddr;
int m_statusmode;
int m_statusmode = 0;
ACE_TString m_statusmsg;
bool m_tm_ok;
ACE_UINT32 m_timestamp;
int m_mtu_data_size, m_mtu_max_payload_size;
bool m_tm_ok = false;
ACE_UINT32 m_timestamp = 0;
int m_mtu_data_size = MAX_PAYLOAD_DATA_SIZE, m_mtu_max_payload_size = MAX_PAYLOAD_DATA_SIZE;
typedef std::map<PacketKind, ACE_UINT32> packet_timestamps_t;
packet_timestamps_t m_pkt_timestamps;
protected:
Expand Down
Loading

0 comments on commit b1b6e14

Please sign in to comment.