1 /*
2 * Copyright (C) 2019 The Android Open Source Project
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 #include <processgroup/format/cgroup_controller.h>
18
19 namespace android {
20 namespace cgrouprc {
21 namespace format {
22
CgroupController(uint32_t version,uint32_t flags,const std::string & name,const std::string & path)23 CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
24 const std::string& path)
25 {
26 // strlcpy isn't available on host. Although there is an implementation
27 // in licutils, libcutils itself depends on libcgrouprc_format, causing
28 // a circular dependency.
29 version_ = version;
30 flags_ = flags;
31 strncpy(name_, name.c_str(), sizeof(name_) - 1);
32 name_[sizeof(name_) - 1] = '\0';
33 strncpy(path_, path.c_str(), sizeof(path_) - 1);
34 path_[sizeof(path_) - 1] = '\0';
35 }
36
version() const37 uint32_t CgroupController::version() const {
38 return version_;
39 }
40
flags() const41 uint32_t CgroupController::flags() const {
42 return flags_;
43 }
44
name() const45 const char* CgroupController::name() const {
46 return name_;
47 }
48
path() const49 const char* CgroupController::path() const {
50 return path_;
51 }
52
set_flags(uint32_t flags)53 void CgroupController::set_flags(uint32_t flags) {
54 flags_ = flags;
55 }
56
57 } // namespace format
58 } // namespace cgrouprc
59 } // namespace android
60