-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vchizhevsky
committed
Jul 4, 2016
1 parent
fc2c7e9
commit 22179b9
Showing
119 changed files
with
15,341 additions
and
1,185 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
client/client-multi/client-c/Modules/cppcheck/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
# | |||
# Copyright 2014-2016 CyberVision, Inc. | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
|
|||
# This cmake list is responsible for running cppcheck against sources. | |||
|
|||
find_program(CPPCHECK_COMMAND cppcheck) | |||
|
|||
if(CPPCHECK_COMMAND) | |||
add_custom_target(cppcheck | |||
COMMAND ${CPPCHECK_COMMAND} --quiet --enable=all --std=c99 --suppress=unusedFunction | |||
--force --error-exitcode=1 --template=gcc -I src/kaa | |||
--inline-suppr src/ test/ | |||
WORKING_DERICTORY ${KAA_SDK_DIR} | |||
COMMENT "Running cppcheck" | |||
VERBATIM | |||
) | |||
else() | |||
message (STATUS "Could NOT find cppcheck") | |||
endif() |
28 changes: 28 additions & 0 deletions
28
client/client-multi/client-c/Modules/doxygen/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
# | |||
# Copyright 2014-2016 CyberVision, Inc. | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
|
|||
# This cmake list is responsible for building doxygen documentation. | |||
|
|||
find_package(Doxygen) | |||
|
|||
add_custom_target(doxygen | |||
COMMAND ${CMAKE_COMMAND} -E make_directory target/apidocs/doxygen | |||
COMMAND ${DOXYGEN_EXECUTABLE} Doxyfile | |||
WORKING_DIRECTORY | |||
${KAA_SDK_DIR} | |||
COMMENT "Generating doxygen docs" | |||
VERBATIM | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,96 @@ | |||
#+TITLE: C/C++ Code Style | |||
#+AUTHOR: Alexey Shmalko | |||
#+OPTIONS: toc:nil | |||
|
|||
# Confluence doesn't have C language highlight, so use C++ here. | |||
|
|||
* Rules | |||
|
|||
- Use 4 spaces for indentation. Don't use tabs. | |||
|
|||
- Use 100-character column width. | |||
|
|||
- Use snake_case for the names (not camelCase). | |||
|
|||
- All macro names must be in UPPERCASE. | |||
|
|||
- Use [[https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS][1TBS]] (the one true brace style). | |||
#+begin_src c++ | |||
int main(int argc, char *argv[]) | |||
{ | |||
if (argc > 2) { | |||
printf("too many args\n"); | |||
} else { | |||
printf("too little args\n"); | |||
} | |||
|
|||
return 0; | |||
} | |||
#+end_src | |||
Note brace position. The braces in control structures are required even for a single statement. | |||
|
|||
- The pointer star must be aligned to the variable name: | |||
#+begin_src c++ | |||
int *x; | |||
#+end_src | |||
|
|||
- Labels must be indented one level less than the normal indentation (except for case labels): | |||
#+begin_src c++ | |||
int main(int argc, char *argv[]) | |||
{ | |||
switch (argc) { | |||
case 3: | |||
printf("hi\n"); | |||
|
|||
default: | |||
goto fail; | |||
} | |||
return 0; | |||
|
|||
fail: | |||
return 1; | |||
} | |||
#+end_src | |||
|
|||
- Prefer double-indent instead of alignment in conditions and argument lists: | |||
#+begin_src c++ | |||
int my_function(int param1, int param2, | |||
int param3, int param4) | |||
{ | |||
if (param1 > 3 && param2 > 3 && | |||
param3 > 3 && param4 > 3) { | |||
return param1 + param2 + param3 + | |||
param4; | |||
} else { | |||
return 0; | |||
} | |||
} | |||
#+end_src | |||
|
|||
- Don't allow trailing spaces or lines. | |||
|
|||
* Editor configurations | |||
** Emacs | |||
|
|||
#+begin_src emacs-lisp | |||
(require 'whitespace) | |||
(setq-default whitespace-style '(face | |||
tab-mark | |||
empty | |||
trailing | |||
lines-tail)) | |||
(global-whitespace-mode t) | |||
|
|||
(c-add-style "kaa" | |||
'("k&r" | |||
(whitespace-line-column . 100) | |||
(indent-tabs-mode . nil) | |||
(c-basic-offset . 4) | |||
(c-label-minimum-indentation . 0) | |||
(c-offsets-alist . ((case-label . +) | |||
(arglist-intro . ++) | |||
(arglist-cont-nonempty . ++) | |||
(inextern-lang . 0))))) | |||
|
|||
(setq c-default-style "kaa") | |||
#+end_src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,73 @@ | |||
#+TITLE: How to Contribute | |||
#+OPTIONS: toc:nil | |||
|
|||
This guide is dedicated to self-review and contribution process of Kaa project. It involves comments and code introspection, functional and unit testing, commits preparation and external code review. | |||
|
|||
* Code introspection | |||
When you about to finish your feature or bug fix you need to check your changes following the procedure below: | |||
1. Code MUST use C99 (for C SDK) or C++11 (for C++ SDK) standards without using any compiler extensions, like GNU. | |||
2. Code MUST compile for every [[http://docs.kaaproject.org/display/KAA/Supported+platforms][supported platform]]. | |||
3. Code MUST NOT contain any compiler warnings. | |||
4. Corresponding doxygen comments SHOULD be added to new or changed interfaces/modules. | |||
5. Every TODO item MUST reference an issue on Jira and issue key must be placed in a comment next to the TODO. (e.g., =// TODO(KAA-982): Use asserts=) | |||
6. Bottlenecks and magic places MUST be well-commented. (/Well, ideally there should be no magic places./) | |||
7. Commented-out chunks of code are forbidden. | |||
8. Code style MUST be consistent. Check out our [[./code-style.org][Code Style Guide]]. | |||
9. It is RECOMMENDED to use a source formatting script against modified sources. The script is placed in =client/client-multi/client-c/scripts/srcformat.sh=. | |||
|
|||
* Instrumentation | |||
This section describes requirements that every developer must follow using existing tooling, like code analyzers, test frameworks etc. | |||
|
|||
1. Changes SHOULD be covered with unit tests, reflecting the essence of these changes. (Check out our [[./testing.org][Testing Tutorial]].) | |||
2. If possible and required, changes SHOULD be covered with functional tests too. | |||
3. Changes MUST NOT break any existing unit or functional tests. A fix SHOULD be provided if any of tests is failing due to introduced changes, except cases when test is no longer valid. | |||
4. A sample app that directly or indirectly relies on changes SHOULD be well tested in automated or manual fashion to make sure that nothing was broken. If it did break, a fix must be provided either in sample applications or SDK or both. | |||
5. Cppcheck MUST be triggered against changes; reported issues MUST be reviewed, and important ones MUST be fixed. | |||
|
|||
See also: [[./sandbox-updating.org][sandbox updating guide]]. | |||
|
|||
* Pre-commit checklist | |||
The following checklist guarantees your patch will pass the Travis build and increases chance for passing code review process: | |||
|
|||
#+begin_src sh | |||
# The next commands must be executed from the client-c/ directory | |||
cd client/client-multi/client-c/ | |||
|
|||
# Clean up source tree | |||
rm -rf target build-* | |||
|
|||
# Check license headers | |||
nix-shell -p maven --run 'mvn apache-rat:check' | |||
# If you have installed maven on your system you can use the following command: | |||
# mvn apache-rat:check | |||
# If it finds any violations, check ./target/rat.txt for the list of files. | |||
|
|||
# Format changed files | |||
nix-shell --run './scripts/srcformat.sh <changed files>' | |||
|
|||
# Check SDK builds for all platforms, passes cppcheck and builds doxygen | |||
nix-shell --arg withWerror true --pure --run './scripts/build.sh' | |||
#+end_src | |||
|
|||
Note: You should use nix-shell for source formatting as it contains a patch for the astyle to allow max-instatement-indent values lower than 40 (https://sourceforge.net/p/astyle/bugs/396/). Alternatively, you can patch your astyle with the [[../../../../nix/astyle/max_indent.patch][following patch]] manually. | |||
|
|||
* Committing | |||
1. All of the changes MUST be added to commit(s), and commit messages SHOULD NOT be too long. | |||
2. The commit message SHOULD begin with ticket number: =KAA-[TICKET NUMBER] Description=. | |||
3. Changes in commits SHOULD be as atomic as possible. It means that single commit of a pull request contains changes to a single entity (e.g., a module). | |||
4. Single pull request SHOULD expose single feature or bug fix if possible. That will help reviewers to do their job. | |||
|
|||
# TODO: Complete git guide of Kaa (using http://git.kernel.org/cgit/git/git.git/tree/Documentation/SubmittingPatches?id=HEAD as an example) | |||
|
|||
* Review | |||
According to our [[http://docs.kaaproject.org/display/KAA/Git+Flow][Git Flow]], every Pull Request must be reviewed and approved by at least two members of the responsible team. When you receive a comment, you should address it; that means either changing the code or answering a question in the comments. | |||
|
|||
If you do a small fix, don't add a new commit but rather squash your changes to the old commits. That's required to avoid commit chains as the next one: | |||
#+begin_src example | |||
KAA-XXX Implement feature xxx | |||
KAA-XXX Fix formatting | |||
KAA-XXX Fix typo | |||
KAA-XXX Address CR questions | |||
KAA-XXX Address CR questions | |||
KAA-XXX Fix typo | |||
#+end_src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
#+TITLE: Nix Guide | |||
#+AUTHOR: Alexey Shmalko | |||
#+OPTIONS: toc:nil | |||
|
|||
[[http://nixos.org/nix/][Nix]] is a powerful Linux package manager. We use it to create a better development environment for C client and manage all dependencies. | |||
|
|||
* Setup Nix | |||
The easiest way to setup Nix is next: | |||
#+begin_src sh | |||
curl https://nixos.org/nix/install | sh | |||
source $HOME/.nix-profile/etc/profile.d/nix.sh | |||
#+end_src | |||
|
|||
And add =source $HOME/.nix-profile/et/profile.d/nix.sh= to your =.bashrc=. | |||
|
|||
If you don't trust piping shell scripts from the Internet (and you shouldn't), feel free to examine the script or use alternate setup. (Though, you should google it up yourself.) | |||
|
|||
* Install all dependencies and enter the shell | |||
The first time you enter shell environment, the Nix will install all dependencies needed for development. | |||
#+begin_src sh | |||
nix-shell | |||
#+end_src | |||
|
|||
As CC3200 SDK is not freely available, nix-shell will abort and ask you to download the file manually and add it to nix-store -- follow instructions. Then re-run the command above. | |||
|
|||
* Using shell | |||
After dependencies are installed you'll find yourself in a custom bash shell (you can enter it with =nix-shell= whenever you want). | |||
|
|||
You can use all your development tools from there, =./build.sh=, =cmake=. Furthermore, a custom top-level Makefile is provided that propagates your commands to all targets (it also configures all targets appropriately). So just run =make= to build C SDK for all platforms. | |||
|
|||
If you want to run a single command within a shell, you can use =--run= option. For example: | |||
#+begin_src sh | |||
nix-shell --run make | |||
#+end_src | |||
|
|||
* Options | |||
| Option | Default value | Meaning | | |||
|--------------------+---------------+-----------------------------------------------| | |||
| posixSupport | true | Host build with gcc. Goes to =build-posix=. | | |||
| clangSupport | true | Host build with clang. Goes to =build-clang=. | | |||
| cc3200Support | true | CC3200. Goes to =build-cc3200=. | | |||
| esp8266Support | true | ESP8266. Goes to =build-esp8266=. | | |||
| raspberrypiSupport | true | Raspberry Pi. Goes to =build-rpi=. | | |||
| testSupport | true | Add all tools for build verification. | | |||
| withTooling | true | Add tools for building docs. | | |||
| withWerror | false | Enable =-Werror= for all builds. | | |||
|
|||
You can override any option with the following command: | |||
#+begin_src sh | |||
nix-shell --arg optionName value | |||
#+end_src | |||
|
|||
For example: | |||
#+begin_src sh | |||
nix-shell --arg withWerror true | |||
#+end_src | |||
|
|||
* Further reading | |||
- [[http://lethalman.blogspot.com/2014/07/nix-pill-1-why-you-should-give-it-try.html][Nix pills series]] | |||
- [[https://nixos.org/nixpkgs/manual/][Nixpkgs Contributors Guide]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
#+TITLE: Sandbox Updating | |||
#+AUTHOR: Maxim Olender | |||
#+OPTIONS: toc:nil | |||
|
|||
Sometimes there is a need to update already running sandbox with new Kaa server or upload new SDK code. This article describes how to do that with minimum hassle using C SDK as an example. You need Maven, JDK-8 (Java Development Kit), ssh and C compiler. | |||
|
|||
* Step-by-step guide | |||
|
|||
{info} | |||
Kaa requires JDK-8 to use maven with Kaa. Double check =$JAVA_HOME= environment variable and make sure that it points to JDK-8 home directory. | |||
{info} | |||
|
|||
When your sandbox up and running, perform following steps to update it: | |||
|
|||
1. Navigate to the root of the Kaa repository and launch Maven: | |||
#+begin_src sh | |||
mvn clean -P compile-client-c,compile-gwt,mongo-dao,mariadb-dao clean install verify -DskipTests | |||
#+end_src | |||
|
|||
2. After build succeeds it is time to copy node package to the sandbox. =$SANDBOX_HOST= is a host or IP of your sandbox: | |||
#+begin_src sh | |||
scp server/node/target/kaa-node.deb kaa@${SANDBOX_HOST}: | |||
#+end_src | |||
|
|||
3. Copy C SDK archive. =$SDK_VERSION= is a version of the SDK. At the time of this writing, SDK version is 0.9.0. Again, =$SANDBOX_HOST= is a host or IP of your sandbox: | |||
#+begin_src sh | |||
scp client/client-multi/client-c/target/client-c-${SDK_VERSION}-SNAPSHOT-c-sdk.tar.gz kaa@${SANDBOX_HOST}: | |||
ssh kaa@${SANDBOX_HOST} sudo mv -v /home/kaa/client-c-${SDK_VERSION}-SNAPSHOT-c-sdk.tar.gz /usr/lib/kaa-node/sdk/c/kaa-c-ep-sdk-${SDK_VERSION}-SNAPSHOT.tar.gz | |||
#+end_src | |||
|
|||
4. After all files are copied to the proper destinations in sandbox, it is time to install Kaa server node: | |||
#+begin_src sh | |||
ssh kaa@${SANDBOX_HOST} sudo dpkg -i kaa-node.deb | |||
#+end_src | |||
|
|||
5. Now, Kaa restart is required: | |||
#+begin_src sh | |||
ssh kaa@${SANDBOX_HOST} kaa-node stop | |||
ssh kaa@${SANDBOX_HOST} kaa-node start | |||
#+end_src | |||
|
|||
6. If errors occur during restarting of Kaa sandbox, I recommend you to reboot sandbox virtual machine: | |||
#+begin_src sh | |||
ssh kaa@${SANDBOX_HOST} sudo reboot | |||
#+end_src |
27 changes: 27 additions & 0 deletions
27
client/client-multi/client-c/examples/my-kaa-application/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,27 @@ | |||
# | |||
# Copyright 2014-2016 CyberVision, Inc. | |||
# | |||
# Licensed under the Apache License, Version 2.0 (the "License"); | |||
# you may not use this file except in compliance with the License. | |||
# You may obtain a copy of the License at | |||
# | |||
# http://www.apache.org/licenses/LICENSE-2.0 | |||
# | |||
# Unless required by applicable law or agreed to in writing, software | |||
# distributed under the License is distributed on an "AS IS" BASIS, | |||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
# | |||
|
|||
cmake_minimum_required(VERSION 3.5.2) | |||
project(kaa-application C) | |||
|
|||
find_package(OpenSSL REQUIRED) | |||
|
|||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -Wall -Wextra") | |||
|
|||
add_subdirectory(kaa) | |||
|
|||
add_executable(kaa-app src/kaa-application.c) | |||
target_link_libraries(kaa-app kaac crypto) |
Oops, something went wrong.