Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code modification according to cpplint. Add coding style check job in workflow. #22

Merged
merged 16 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/check_coding_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This is workflow to check coding style with cpplint
name: check-coding-style

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
check-coding-style:

name: check-coding-style-${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]

steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Check coding style with cpplint
run: ./scripts/check-coding-style.sh
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode
*.o
*.so
sample_srtcaller
sample_srtlistener
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Also do not hesitate to ask other users for opinion and discuss the ideas using

## Code Style

***T.B.D***
Please follow [Google C++ Style Guideline](https://google.github.io/styleguide/cppguide.html) when coding.

## Attribution

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

CXX = g++

CFLAGS = -I./include
CFLAGS += -I./export
CFLAGS = -I./
LDFLAGS = -shared
LDFLAGS += -fPIC
LDFLAGS += -Wl,-rpath-link
Expand Down
5 changes: 3 additions & 2 deletions export/srtexp_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <srt/srt.h>

#include "srtexp_define.hpp"
#include "export/srtexp_define.hpp"

/**
* SRT Exporter library initialization, load configuration to memory
Expand Down Expand Up @@ -66,7 +66,8 @@ SrtExpRet srtexp_stop(const char *exporterName);
* IN id: identity to allocate SRT Exporter object
* @return SrtExpRet::SRT_EXP_SUCCESS on success
*/
SrtExpRet srtexp_label_register(const char *name, const char *value, const char *var, int id);
SrtExpRet srtexp_label_register(const char *name, const char *value,
const char *var, int id);

/**
* Register SRT sockets to be tracked by one SRT Exporter object
Expand Down
3 changes: 2 additions & 1 deletion export/srtexp_api_c_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ SrtExpCRet srtexp_c_init(const char *configFile);
SrtExpCRet srtexp_c_deinit();
SrtExpCRet srtexp_c_start(const char *exporterName, int *id);
SrtExpCRet srtexp_c_stop(const char *exporterName, int id);
SrtExpCRet srtexp_c_label_register(const char *name, const char *value, const char *var, int id);
SrtExpCRet srtexp_c_label_register(const char *name, const char *value,
const char *var, int id);
SrtExpCRet srtexp_c_srt_socket_register(SRTSOCKET *sock, int sockNum, int id);
SrtExpCRet srtexp_c_set_log_dest(SrtExpCLogDestination dest);
SrtExpCRet srtexp_c_set_syslog_level(int level);
Expand Down
217 changes: 112 additions & 105 deletions include/srtexp_collector.hpp

Large diffs are not rendered by default.

41 changes: 23 additions & 18 deletions include/srtexp_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

#pragma once

#include <yaml-cpp/yaml.h>

#include <string>
#include <memory>
#include <vector>

#include <yaml-cpp/yaml.h>

#include "srtexp_define.hpp"
#include "export/srtexp_define.hpp"

namespace srt_exporter {

Expand All @@ -37,9 +37,9 @@ enum class SrtExpFilterMode {
};

// Default static variable list for preset filter modes.
#define SRT_SOURCE_VARLIST "['pktSentTotal', 'pktSndLossTotal', 'pktSent', 'pktSndLoss', 'pktRetrans', 'pktRecvACK', 'pktRecvNAK', 'byteSent', 'byteRetrans', 'byteSndDrop', 'pktSndDrop', 'mbpsSendRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']"
#define SRT_DESTINATION_VARLIST "['pktRecvTotal', 'pktRcvLossTotal', 'pktRecv', 'pktRcvLoss', 'pktRcvRetrans', 'pktSentACK', 'pktSentNAK', 'byteRecv', 'byteRcvDrop', 'pktRcvDrop', 'mbpsRecvRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']"
#define SRT_COMMON_VARLIST "['pktSentTotal', 'pktSndLossTotal', 'pktSent', 'pktSndLoss', 'pktRetrans', 'pktRecvACK', 'pktRecvNAK', 'byteSent', 'byteRetrans', 'byteSndDrop', 'pktSndDrop', 'mbpsSendRate', 'pktRecvTotal', 'pktRcvLossTotal', 'pktRecv', 'pktRcvLoss', 'pktRcvRetrans', 'pktSentACK', 'pktSentNAK', 'byteRecv', 'byteRcvDrop', 'pktRcvDrop', 'mbpsRecvRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']"
#define SRT_SOURCE_VARLIST "['pktSentTotal', 'pktSndLossTotal', 'pktSent', 'pktSndLoss', 'pktRetrans', 'pktRecvACK', 'pktRecvNAK', 'byteSent', 'byteRetrans', 'byteSndDrop', 'pktSndDrop', 'mbpsSendRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']" // NOLINT
#define SRT_DESTINATION_VARLIST "['pktRecvTotal', 'pktRcvLossTotal', 'pktRecv', 'pktRcvLoss', 'pktRcvRetrans', 'pktSentACK', 'pktSentNAK', 'byteRecv', 'byteRcvDrop', 'pktRcvDrop', 'mbpsRecvRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']" // NOLINT
#define SRT_COMMON_VARLIST "['pktSentTotal', 'pktSndLossTotal', 'pktSent', 'pktSndLoss', 'pktRetrans', 'pktRecvACK', 'pktRecvNAK', 'byteSent', 'byteRetrans', 'byteSndDrop', 'pktSndDrop', 'mbpsSendRate', 'pktRecvTotal', 'pktRcvLossTotal', 'pktRecv', 'pktRcvLoss', 'pktRcvRetrans', 'pktSentACK', 'pktSentNAK', 'byteRecv', 'byteRcvDrop', 'pktRcvDrop', 'mbpsRecvRate', 'usSndDuration', 'msSndTsbPdDelay', 'mbpsBandwidth', 'msRTT']" // NOLINT

typedef struct _SrtExpLabel {
std::string name;
Expand All @@ -51,14 +51,15 @@ typedef struct _SrtExpCollectorConfig {
SrtExpCollectorMode collectorMode;
SrtExpFilterMode filterMode;
std::vector<std::string> varList;
std::vector<SrtExpLabel> labelList;
std::vector<SrtExpLabel> labelList;
} SrtExpCollectorConfig;

// Structure for global configuration.
typedef struct _SrtExpGlobalConfig {
std::string ip;
int portMin;
int portMax; // a range of ports, from which available ports are assigned for new SRT Exporter objects
int portMax; // a range of ports, from which available ports are
// assigned for new SRT Exporter objects
SrtExpCollectorConfig config;
} SrtExpGlobalConfig;

Expand All @@ -71,29 +72,33 @@ typedef struct _SrtExpObjConfig {


class SrtExpConfig {
public:
public:
SrtExpConfig();

// load the yaml-style configuraion file or default values into _globalConfig and _objConfig
// load the yaml-style configuraion file or default values into
// _globalConfig and _objConfig
void LoadConfigFile(const std::string& configFile);

std::string GetServerIp(const std::string& exporterName);
int GetServerPort(const std::string& exporterName);
SrtExpCollectorMode GetCollectorMode(const std::string& exporterName);
SrtExpCollectorConfig& GetSrtExpCollectorConfig(const std::string& exporterName);
SrtExpCollectorConfig& GetSrtExpCollectorConfig(
const std::string& exporterName);
SrtExpObjConfig *FindSrtExpObjConfig(const std::string& exporterName);
void DumpConfig();

private:
// global configuration for SRT Exporter object without specified configuration
private:
// global configuration for SRT Exporter object without specified
// configuration
SrtExpGlobalConfig _globalConfig;
std::vector<SrtExpObjConfig> _objConfig;

void LoadDefaultConfig(SrtExpGlobalConfig &cfg);
void LoadDefaultSrtExpCollectorConfig(SrtExpCollectorConfig &cfg);
void LoadSrtExpCollectorConfig(SrtExpCollectorConfig &cfg, const YAML::Node &config);
void DumpSrtExpCollectorConfig(SrtExpCollectorConfig &cfg);
void LoadDefaultConfig(SrtExpGlobalConfig *cfg);
void LoadDefaultSrtExpCollectorConfig(SrtExpCollectorConfig *cfg);
void LoadSrtExpCollectorConfig(SrtExpCollectorConfig *cfg,
const YAML::Node &config);
void DumpSrtExpCollectorConfig(const SrtExpCollectorConfig &cfg);
int IsPortAvailable(std::string ip, int port);
};

}
} // namespace srt_exporter
37 changes: 20 additions & 17 deletions include/srtexp_exporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,51 @@

#pragma once

#include <prometheus/exposer.h>

#include <string>
#include <memory>

#include <prometheus/exposer.h>

#include "srtexp_define.hpp"
#include "srtexp_collector.hpp"
#include "srtexp_config.hpp"
#include "export/srtexp_define.hpp"
#include "include/srtexp_collector.hpp"
#include "include/srtexp_config.hpp"


namespace srt_exporter {

using namespace prometheus;

class SrtExpCollector;

class SrtExporter : public std::enable_shared_from_this<SrtExporter>{
public:
SrtExporter(std::string exporterName, int id) : _exporterName(exporterName), _id(id) {};
// create the exposer object and the collector object according to configuration
public:
SrtExporter(std::string exporterName, int id)
: _exporterName(exporterName), _id(id) {}
// create the exposer object and the collector object according to
// configuration
void InitSrtExporter();

std::shared_ptr<Exposer> GetSrtExposer() {return _exposer;}
std::shared_ptr<prometheus::Exposer> GetSrtExposer() {return _exposer;}
std::shared_ptr<SrtExpCollector> GetSrtExpCollector() {return _collector;}
void ResetSrtExpCollector() {_collector = nullptr;}
void SetSrtExpCollector(SrtExpCollectorMode collectorMode);

bool CompareExporterName(const char *exporterName) {return (std::string(exporterName) == _exporterName);}
bool CompareExporterName(const char *exporterName) {
return (std::string(exporterName) == _exporterName);}
bool CompareId(int id) {return (id == _id);}
std::string GetExporterName() {return _exporterName;}
int GetId() {return _id;}

private:
private:
// the unique name of the SRT Exporter object in string type
std::string _exporterName;
// unique integer identity of the SRT Exporter object generated when starting SRT Exporter object API is called
// unique integer identity of the SRT Exporter object generated when
// starting SRT Exporter object API is called
int _id;
// object implemented by Prometheus c++ client library
// providing the http server for Prometheus to request metrics from, and an interface to register collector function
std::shared_ptr<Exposer> _exposer;
// providing the http server for Prometheus to request metrics from,
// and an interface to register collector function
std::shared_ptr<prometheus::Exposer> _exposer;
// SRT Exporter collector object of this SRT Exporter object
std::shared_ptr<SrtExpCollector> _collector;
};

} //namespace srt_exporter
} // namespace srt_exporter
7 changes: 4 additions & 3 deletions include/srtexp_logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
#pragma once

#include <sys/syslog.h>

#include <iostream>
#include <string>

#include "srtexp_define.hpp"
#include "export/srtexp_define.hpp"


namespace srt_exporter {

// class logger
class logger {
public:
public:
static void SrtLog_SetDestination(SrtExpLogDestination dest);
static void SrtLog_SetSyslogLevel(int level);

Expand All @@ -35,4 +36,4 @@ class logger {
static void SrtLog_Debug(const std::string msg);
};

} //namespace srt_exporter
} // namespace srt_exporter
5 changes: 3 additions & 2 deletions sample/sample_srtcaller.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ int main() {
srtexp_c_label_register("application", "sample_srtcaller", NULL, id);
srtexp_c_label_register("importance", "special", "pktSentTotal", id);
srtexp_c_label_register("importance", "normal", "pktSentTotal", id);
//srtexp_c_label_register("importance", NULL, "pktSentTotal", id);
// srtexp_c_label_register("importance", NULL, "pktSentTotal", id);
srtexp_c_srt_socket_register(p, 1, id);

do {
printf("connecting\n");
if (SRT_INVALID_SOCK != srt_connect(srtsock, (const struct sockaddr *)&addr, sa_len)) {
if (SRT_INVALID_SOCK != srt_connect(
srtsock, (const struct sockaddr *)&addr, sa_len)) {
continueFlag = 0;
}
sleep(1);
Expand Down
37 changes: 37 additions & 0 deletions scripts/check-coding-style.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

#####################################################################
# SRT - Secure, Reliable, Transport
# Copyright (c) 2023 Sony Group Corporation.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#####################################################################

# To avoid updating and modifying the files under `.github/workflows`,
# this scripts should be adjusted building process accordingly.
# And `.github/workflows` just calls this script in the workflow pipeline.
# This allows us to maintain the workflow process easier for contributers.

########################
# Function Definitions #
########################

########
# Main #
########

pip install cpplint

output1=$(cpplint --recursive --extensions=hpp,cpp,h,c --exclude=include/srtexp_collector.hpp --quiet ./)

# definition of SRT_DATA_MAP_INITIALIZER in srtexp_collector.hpp needs a long linelength, so handle it separately.
output2=$(cpplint --linelength=320 --quiet ./include/srtexp_collector.hpp)

if [[ -z "$output1" && -z "$output2" ]]; then
exit 0
else
exit 1
fi
Loading
Loading