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()23 CgroupController::CgroupController() : version_(0), flags_(0) {
24 memset(name_, 0, sizeof(name_));
25 memset(path_, 0, sizeof(path_));
26 }
27
CgroupController(uint32_t version,uint32_t flags,const std::string & name,const std::string & path)28 CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
29 const std::string& path)
30 : CgroupController() {
31 // strlcpy isn't available on host. Although there is an implementation
32 // in licutils, libcutils itself depends on libcgrouprc_format, causing
33 // a circular dependency.
34 version_ = version;
35 flags_ = flags;
36 strncpy(name_, name.c_str(), sizeof(name_) - 1);
37 name_[sizeof(name_) - 1] = '\0';
38 strncpy(path_, path.c_str(), sizeof(path_) - 1);
39 path_[sizeof(path_) - 1] = '\0';
40 }
41
version() const42 uint32_t CgroupController::version() const {
43 return version_;
44 }
45
flags() const46 uint32_t CgroupController::flags() const {
47 return flags_;
48 }
49
name() const50 const char* CgroupController::name() const {
51 return name_;
52 }
53
path() const54 const char* CgroupController::path() const {
55 return path_;
56 }
57
set_flags(uint32_t flags)58 void CgroupController::set_flags(uint32_t flags) {
59 flags_ = flags;
60 }
61
62 } // namespace format
63 } // namespace cgrouprc
64 } // namespace android
65