mukesh agrawal | 102a775 | 2011-07-28 14:57:14 -0700 | [diff] [blame^] | 1 | Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | Use of this source code is governed by a BSD-style license that can be |
| 3 | found in the LICENSE file. |
| 4 | |
| 5 | To keep the shill source code consistent, please follow the conventions below: |
| 6 | |
| 7 | - Use the Chromium Coding Style, as described at |
| 8 | http://www.chromium.org/developers/coding-style. |
| 9 | |
| 10 | If you use Emacs, the Google C Style mode will help you with the formatting |
| 11 | aspects of style. (Chromium Style generally follows Google Style). Get the |
| 12 | Emacs mode at |
| 13 | http://google-styleguide.googlecode.com/svn/trunk/google-c-style.el |
| 14 | |
| 15 | Note that we've deviated from the Chromium style in the following |
| 16 | ways. In these cases, follow the shill style, for consistency with |
| 17 | the rest of the shill code: |
| 18 | |
| 19 | - We denote pointer and reference variables by placing the '*' and '&' |
| 20 | adjacent to the variable name, rather than the type. E.g. |
| 21 | |
| 22 | void *bar |
| 23 | |
| 24 | rather than |
| 25 | |
| 26 | void* bar |
| 27 | |
| 28 | - <no other deviations documented yet> |
| 29 | |
| 30 | - When working with DBus::Variant: |
| 31 | - Read data via the appropriate named method, rather than depending on |
| 32 | implicit conversion. E.g., |
| 33 | |
| 34 | int8 data = var.reader().get_byte(); |
| 35 | |
| 36 | rather than |
| 37 | |
| 38 | int8 data = var; |
| 39 | |
| 40 | RATIONALE: The explicit version is only marginally longer than the |
| 41 | implicit version, and does not require the reader to understand C++ |
| 42 | conversion rules. |
| 43 | |
| 44 | - Where there is no named method, call the appropriate cast operator |
| 45 | explicitly. E.g. |
| 46 | |
| 47 | vector<unsigned int> data = var.operator vector<unsigned int>(); |
| 48 | |
| 49 | RATIONALE: Calling the cast operator explicitly avoids conflicts with |
| 50 | constructors that might also be used to make the conversion. It also |
| 51 | avoids requiring that the reader understand C++ conversion rules. |
| 52 | |
| 53 | - When deferring work from a signal handler (e.g. a D-Bus callback) to |
| 54 | the event loop, name the deferred work function by adding "Task" to |
| 55 | the name of the function deferring the work. E.g. |
| 56 | |
| 57 | void Modem::Init() { |
| 58 | dispatcher_->PostTask(task_factory_.NewRunnableMethod(&Modem::InitTask)); |
| 59 | } |
| 60 | |
| 61 | RATIONALE: The naming convention makes the relationship between the signal |
| 62 | handler and the task function obvious, at-a-glance. |