Skip to content

Commit

Permalink
Feature/first implementation 20241007 (#1)
Browse files Browse the repository at this point in the history
* Create project and create template for it

* First implementation - blocking server

* Refactor server to module

* Finished server.c

* WIP ready to concurrent server

* WIP working concurrent with polling

* Refactor client

* Finish client code

* FInish refactoring

* Finish first version

* Update docs
  • Loading branch information
DanilBorchevkin authored Oct 8, 2024
1 parent 145eb3f commit 4c50adb
Show file tree
Hide file tree
Showing 15 changed files with 1,568 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
18 changes: 18 additions & 0 deletions .github/workflow/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,8 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

# Project-specific
artifacts/
build/
.vscode/
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]


## [0.1.0] - 2024-10-08

### Added

- Add first implementation
173 changes: 173 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
###############################################################################
#
# BSD 2-Clause License
#
# Copyright (c) 2024, Danil Borchevkin
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###############################################################################

# *****************************************************************************
# * INCLUDES
# *****************************************************************************

# TODO add includes if needed

# *****************************************************************************
# * FUNCTIONS
# *****************************************************************************

# TODO add functions here

# *****************************************************************************
# * VARIABLES
# *****************************************************************************

SHELL := /bin/bash
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
THREADS_NUM = $(shell nproc)
BUILD_OPTS_RELEASE = -j${THREADS_NUM}
BUILD_OPTS_DEBUG = -j1
INC=-I${ROOT_DIR}/inc

# *****************************************************************************
# * TARGETS - MANDATORY
# *****************************************************************************

# Init repository / project
.PHONY: init
init: clean
mkdir -p ${ROOT_DIR}/artifacts/build/debug
mkdir -p ${ROOT_DIR}/artifacts/build/release
mkdir -p ${ROOT_DIR}/artifacts/reports/check_style
mkdir -p ${ROOT_DIR}/artifacts/reports/check_static
mkdir -p ${ROOT_DIR}/artifacts/reports/check_security
mkdir -p ${ROOT_DIR}/artifacts/reports/test_unit
mkdir -p ${ROOT_DIR}/artifacts/reports/test_integration
mkdir -p ${ROOT_DIR}/artifacts/reports/test_e2e


# Clean
.PHONY: clean
clean:
rm -rf ${ROOT_DIR}/artifacts


# Apply codestyle to all codebase
.PHONY: apply_style
apply_style:
$(error Target not implemented)


# Check codestyle and return error if ther ere some violence,
# generate a report into ./artifacts/reports/check_style/
.PHONY: check_style
check_style:
$(error Target not implemented)


# Run static analyzers, generate an analyze report into ./artifacts/reports/check_static/
.PHONY: check_static
check_static:
$(error Target not implemented)


# Run security analyzers, generate an analyze report into ./artifacts/reports/check_security/
.PHONY: check_security
check_security:
$(error Target not implemented)


# Build project in debug configuration
.PHONY: build_debug
build_debug:
gcc $(INC) -o ${ROOT_DIR}/artifacts/srvc_server ${ROOT_DIR}/src/srvc_server.c ${ROOT_DIR}/src/server.c
gcc $(INC) -o ${ROOT_DIR}/artifacts/srvc_client ${ROOT_DIR}/src/srvc_client.c ${ROOT_DIR}/src/client.c
gcc ${INC} -o ${ROOT_DIR}/artifacts/srvc_controller ${ROOT_DIR}/src/srvc_controller.c ${ROOT_DIR}/src/client.c



# Build project in release configuraiton
.PHONY: build_release
build_release:
cmake -S ${ROOT_DIR} -B ${ROOT_DIR}/artifacts/build/release
cmake --build ${ROOT_DIR}/artifacts/build/release


# Run unit tests, generate a test report and a gcov report into ./artifacts/reports/test_unit/
.PHONY: test_unit
test_unit: build_debug
cd ${ROOT_DIR}/artifacts/build/debug && ctest --output-on-failure


# Run integration testing and generate artifacts into ./artifacts/reports/test_integration/
.PHONY: test_integration
test_integration: build_debug
cd ${ROOT_DIR}/artifacts/build/debug && ctest --output-on-failure


# Test E2E and generate artifacts into ./artifacts/reports/test_e2e/
.PHONY: test_e2e
test_e2e: build_debug
$(error Target not implemented)


# Build docs and generate a docs bundle into ./artifacts/docs
.PHONY: docs_build
docs_buld:
$(error Target not implemented)


# Run debug workflow
.PHONY: all_debug
all_debug:
init build_debug


# Run release workflow
.PHONY: all_release
all_release:
init check_style check_static check_security build_release
test_unit test_integration docs_build

# *****************************************************************************
# * TARGETS - PROJECT-SPECIFIC
# *****************************************************************************

.PHONY: run_server
run_server: build_debug
${ROOT_DIR}/artifacts/srvc_server


.PHONY: run_controller
run_controller: build_debug
${ROOT_DIR}/artifacts/srvc_controller localhost 8888


.PHONY: run_client
run_client: build_debug
${ROOT_DIR}/artifacts/srvc_client localhost 8888

# *****************************************************************************
# * END OF MAKEFILE
# *****************************************************************************
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# ex_server-ctrl-client_c
Server + Controller + Client example on C

Server + Controller + Client example on C.

## Dependencies

- gcc
- make

## Init repository

Run:

```bash
make init
```

## How to use

Doing step by step:

1. In separate terminal run one server by `make run_server`.
2. In separate terminal run one controller by `make run_controller`.
3. In separate terminals run one on more clients by `make run_client`.

## FAQ

### How to find started server

```bash
$ lsof -i | grep "srvc_*"
```

### Test connection to server without client

By `telnet`

```bash
telnet localhost 8888
```
89 changes: 89 additions & 0 deletions inc/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @file client.h
*
* @brief Client module
*
* @date 2024-10-08
*
* @par
* BSD 2-Clause License
*
* Copyright (c) 2024, Danil Borchevkin
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/

/** \addtogroup Doxygen group
* @{
*/

#ifndef __CLIENT_H_
#define __CLIENT_H_

#ifdef __cplusplus
extern "C" {
#endif

/******************************************************************************
* INCLUDES
******************************************************************************/

#include <stddef.h>
#include <stdint.h>

/******************************************************************************
* DEFINES
******************************************************************************/

#define CLIENT_ERR_OK ((int32_t)0) /**< Client error - no error */
#define CLIENT_ERR_PARAM ((int32_t)1) /**< Client error - parameters error */
#define CLIENT_ERR_RESOLVE ((int32_t)2) /**< Client error - resolve error */
#define CLIENT_ERR_CONNECT ((int32_t)3) /**< Client error - connect error */

/******************************************************************************
* PUBLIC TYPES
******************************************************************************/

/******************************************************************************
* INLINE FUNCTIONS
******************************************************************************/

/******************************************************************************
* PUBLIC FUNCTION PROTOTYPES
******************************************************************************/

int32_t client_connect(const char* p_host, const char* p_serv,
int* p_socket_fd);
int32_t client_disconnect(int* p_socket_fd);

/******************************************************************************
* END OF HEADER'S CODE
******************************************************************************/
#ifdef __cplusplus
}
#endif

#endif // __CLIENT_H_

/** @}*/
Loading

0 comments on commit 4c50adb

Please sign in to comment.