Re-organized sub-directory by category
[staging/basesystem.git] / service / peripheral / communication / client_can / include / API_Local_Common.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef COMMUNICATION_CLIENT_CAN_INCLUDE_API_LOCAL_COMMON_H_
18 #define COMMUNICATION_CLIENT_CAN_INCLUDE_API_LOCAL_COMMON_H_
19 #include <string.h>
20 enum CANIF_PROTOCOL_IDX {
21   CANIF_CAN = 0,
22   NUM_OF_CANIF_PROTOCOL
23 };
24
25 static inline const char *Canif_PidxTosname(enum CANIF_PROTOCOL_IDX idx) {
26   switch (idx) {
27   case CANIF_CAN:
28     return LAN_SERVICE_CAN;
29     break;
30   default:
31     return "Unknown";
32     break;
33   }
34 }
35
36 #define CANIF_NOTIFY_NAME_MAX_SIZE 15
37 static inline bool Canif_CheckNotifyName(PCSTR notify_name) {
38   size_t n = CANIF_NOTIFY_NAME_MAX_SIZE + 1;
39
40   if (!notify_name)
41     return false;
42
43   return (strnlen(notify_name, n) < n);
44 }
45
46 static inline bool Canif_CheckNotifyNameWithoutNullCheck(PCSTR notify_name) {
47   size_t n = CANIF_NOTIFY_NAME_MAX_SIZE + 1;
48   return (strnlen(notify_name, n) < n);
49 }
50
51 static inline void Canif_CopyNotifyName(char *dest, PCSTR notify_name) {
52   strncpy(dest, notify_name,
53           strnlen(notify_name, CANIF_NOTIFY_NAME_MAX_SIZE));
54 }
55 #endif