Skip to content

Commit

Permalink
Clang format (fixes versatica#74) (versatica#98)
Browse files Browse the repository at this point in the history
* More C++ syntax work

* Fix test-rtcp

* More camelCase

* Working on C++ style.

* More C++ styling

* More work in C++ styling

* More work on C++ styling

* C++ style: remove #defines

* doc/RoomOverview.md: some fixes

* More C++ styling: camelCase RTCP

* More C++ styling: camelCase RemoteBitrateEstimator

* C++ styling

* C++ styling

* clang-format proposal

clang-format can be disabled for certain code by using
clang-format [off|on] comments

May be usefull for static class maps for example.

* .clang-format: minimal change

* .clang-format: improve IncludeCategories

* clang-format: improve IncludeCategories

* Logger.hpp: ignore clang-format

* clang-format: mostly done

* Add clang-format off in map initializations

* Remove comment

* "gulp lint" includes C++ linter

* Habemus clang-format
  • Loading branch information
ibc authored and jmillan committed Apr 9, 2017
1 parent 1475206 commit b442947
Show file tree
Hide file tree
Showing 168 changed files with 11,376 additions and 10,081 deletions.
25 changes: 0 additions & 25 deletions TODO_CPP_SYNTAX.md

This file was deleted.

16 changes: 1 addition & 15 deletions doc/RoomOverview.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,12 @@ These codecs have the same fields as the peer's capabilities codecs above, with
* `kind` is ignored.
* `payloadType` MUST match the same value as the one set by the room (otherwise it will fail).

If `receive()` is called ith a codec that is not supported by the room or not present in the peer's given capabilities, it fails.
If `receive()` is called with a codec that is not supported by the room or not present in the peer's given capabilities, it fails.

Unsupported RTCP feedback mechanisms and RTP header extensions not supported by mediasoup or by the peer itself are removed.

Effective RTP parameters are returned to the `receive()` promise.

After that, C++ `RtpReceiver::FillRtpParameters()` is called. This method does nothing right now.

*TODO:* C++ `RtpReceiver::FillRtpParameters()` should:

* Set a random `muxId` and map the original value.
* If any SSRC value is not given, set a random one and be ready to match the unknown incoming SSRC value to it.
* If not given, set the `rtcp` field.
* Should map the `id` of the supported ones to a static value.
* *NOTE:* This is important so we can deal with PlanB in which all the RTP streams are sent over a single `m=` section.

*TODO:* The whole mapping system could be implemented by maintaing two `RtpParameters` objects within each `RtpReceiver`: the original one and the maped one (although that wouldn't be efficient when it comes to mangle each RTP packet so it may be better to handle an internal value mapping...).

After that, C++ `Peer::onRtpReceiverParametersDone()` is called, which just calls to C++ `Room::onPeerRtpReceiverParameters()`.

`Room::onPeerRtpReceiverParameters()` creates `RtpSenders` associated to this `RtpReceiver` (for every other `Peer` with its capabilities already set) by calling `Peer::AddRtpSender()` on them.

`Peer::AddRtpSender()` takes the associated `RtpParameters` of the `RtpReceiver` as parameter and call `RtpSender::Send(parameters)`.
Expand Down
4 changes: 1 addition & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ gulp.task('rtpcapabilities', () =>
.pipe(touch());
});

// TODO: Uncomment when C++ syntax and clang-format stuff is done.
// gulp.task('lint', gulp.series('lint:node', 'lint:worker'));
gulp.task('lint', gulp.series('lint:node'));
gulp.task('lint', gulp.series('lint:node', 'lint:worker'));

gulp.task('test', gulp.series('test:node', 'test:worker'));

Expand Down
58 changes: 40 additions & 18 deletions worker/.clang-format
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
Language: Cpp
AccessModifierOffset: -2
AlignConsecutiveAssignments: false
AlignEscapedNewlinesLeft: true
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
Expand All @@ -23,39 +29,55 @@ BraceWrapping:
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BinPackArguments: true
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakStringLiterals: true
ColumnLimit: 150
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 1
DerivePointerAlignment: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: true
IncludeCategories:
- Regex: '"common.hpp"'
Priority: 1
- Regex: '^"(Channel|RTC|handles)/'
Priority: 3
- Regex: '"*"'
Priority: 2
- Regex: '^<(uv|openssl|srtp|json|netstring)(.|/)'
Priority: 4
- Regex: '<*>'
Priority: 5
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: true
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 100
PenaltyBreakString: 100
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 100
PenaltyBreakFirstLessLess: 200
PenaltyBreakString: 20
PenaltyExcessCharacter: 10
PenaltyReturnTypeOnItsOwnLine: 1000
PointerAlignment: Left
ReflowComments: false
SortIncludes: false
SpaceAfterCStyleCast: true
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
Expand Down
9 changes: 7 additions & 2 deletions worker/include/Channel/Notifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "common.hpp"
#include "Channel/UnixStreamSocket.hpp"
#include <string>
#include <json/json.h>
#include <string>

namespace Channel
{
Expand All @@ -15,7 +15,12 @@ namespace Channel

void Emit(uint32_t targetId, std::string event);
void Emit(uint32_t targetId, std::string event, Json::Value& data);
void EmitWithBinary(uint32_t targetId, std::string event, Json::Value& data, const uint8_t* binary_data, size_t binary_len);
void EmitWithBinary(
uint32_t targetId,
std::string event,
Json::Value& data,
const uint8_t* binaryData,
size_t binaryLen);

public:
// Passed by argument.
Expand Down
4 changes: 2 additions & 2 deletions worker/include/Channel/Request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define MS_CHANNEL_REQUEST_HPP

#include "common.hpp"
#include <json/json.h>
#include <string>
#include <unordered_map>
#include <json/json.h>

namespace Channel
{
Expand Down Expand Up @@ -50,7 +50,7 @@ namespace Channel
virtual ~Request();

void Accept();
void Accept(Json::Value &data);
void Accept(Json::Value& data);
void Reject(std::string& reason);
void Reject(const char* reason = nullptr);

Expand Down
24 changes: 10 additions & 14 deletions worker/include/Channel/UnixStreamSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
#define MS_CHANNEL_UNIX_STREAM_SOCKET_HPP

#include "common.hpp"
#include "handles/UnixStreamSocket.hpp"
#include "Channel/Request.hpp"
#include "handles/UnixStreamSocket.hpp"
#include <json/json.h>

namespace Channel
{
class UnixStreamSocket :
public ::UnixStreamSocket
class UnixStreamSocket : public ::UnixStreamSocket
{
public:
class Listener
Expand All @@ -19,9 +18,6 @@ namespace Channel
virtual void onChannelUnixStreamSocketRemotelyClosed(Channel::UnixStreamSocket* channel) = 0;
};

private:
static uint8_t writeBuffer[];

public:
explicit UnixStreamSocket(int fd);

Expand All @@ -30,23 +26,23 @@ namespace Channel

public:
void SetListener(Listener* listener);
void Send(Json::Value &json);
void SendLog(char* ns_payload, size_t ns_payload_len);
void SendBinary(const uint8_t* ns_payload, size_t ns_payload_len);
void Send(Json::Value& json);
void SendLog(char* nsPayload, size_t nsPayloadLen);
void SendBinary(const uint8_t* nsPayload, size_t nsPayloadLen);

/* Pure virtual methods inherited from ::UnixStreamSocket. */
/* Pure virtual methods inherited from ::UnixStreamSocket. */
public:
virtual void userOnUnixStreamRead() override;
virtual void userOnUnixStreamSocketClosed(bool is_closed_by_peer) override;
virtual void userOnUnixStreamSocketClosed(bool isClosedByPeer) override;

private:
// Passed by argument.
Listener* listener = nullptr;
// Others.
Json::CharReader* jsonReader = nullptr;
Json::CharReader* jsonReader = nullptr;
Json::StreamWriter* jsonWriter = nullptr;
size_t msgStart = 0; // Where the latest message starts.
bool closed = false;
size_t msgStart = 0; // Where the latest message starts.
bool closed = false;
};
}

Expand Down
10 changes: 4 additions & 6 deletions worker/include/DepLibSRTP.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MS_DEP_LIBSRTP_HPP
#define MS_DEP_LIBSRTP_HPP
#define MS_DEP_LIBSRTP_HPP

#include <vector>
#include <srtp.h>
#include <vector>

class DepLibSRTP
{
Expand All @@ -18,14 +18,12 @@ class DepLibSRTP

/* Inline static methods. */

inline
bool DepLibSRTP::IsError(srtp_err_status_t code)
inline bool DepLibSRTP::IsError(srtp_err_status_t code)
{
return (code != srtp_err_status_ok);
}

inline
const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
inline const char* DepLibSRTP::GetErrorString(srtp_err_status_t code)
{
// This throws out_of_range if the given index is not in the vector.
return DepLibSRTP::errors.at(code);
Expand Down
8 changes: 3 additions & 5 deletions worker/include/DepLibUV.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MS_DEP_LIBUV_HPP
#define MS_DEP_LIBUV_HPP
#define MS_DEP_LIBUV_HPP

#include "common.hpp"
#include <uv.h>
Expand All @@ -20,14 +20,12 @@ class DepLibUV

/* Inline static methods. */

inline
uv_loop_t* DepLibUV::GetLoop()
inline uv_loop_t* DepLibUV::GetLoop()
{
return DepLibUV::loop;
}

inline
uint64_t DepLibUV::GetTime()
inline uint64_t DepLibUV::GetTime()
{
return uv_now(DepLibUV::loop);
}
Expand Down
6 changes: 3 additions & 3 deletions worker/include/DepOpenSSL.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef MS_DEP_OPENSSL_HPP
#define MS_DEP_OPENSSL_HPP
#define MS_DEP_OPENSSL_HPP

#include "common.hpp"
#include <openssl/ssl.h>
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <uv.h>

/* OpenSSL doc: struct CRYPTO_dynlock_value has to be defined by the application. */
Expand All @@ -20,7 +20,7 @@ class DepOpenSSL

private:
static void SetThreadId(CRYPTO_THREADID* id);
static void LockingFunction(int mode, int n, const char *file, int line);
static void LockingFunction(int mode, int n, const char* file, int line);
static CRYPTO_dynlock_value* DynCreateFunction(const char* file, int line);
static void DynLockFunction(int mode, CRYPTO_dynlock_value* v, const char* file, int line);
static void DynDestroyFunction(CRYPTO_dynlock_value* v, const char* file, int line);
Expand Down
2 changes: 1 addition & 1 deletion worker/include/LogLevel.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef MS_LOG_LEVEL_HPP
#define MS_LOG_LEVEL_HPP
#define MS_LOG_LEVEL_HPP

#include "common.hpp"

Expand Down
Loading

0 comments on commit b442947

Please sign in to comment.