1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#include "include/private/dvr/performance_client.h"
#include <sys/types.h>
#include <pdx/default_transport/client_channel_factory.h>
#include <pdx/rpc/remote_method.h>
#include <pdx/rpc/string_wrapper.h>
#include <private/dvr/performance_rpc.h>
using android::pdx::rpc::WrapString;
namespace android {
namespace dvr {
PerformanceClient::PerformanceClient(int* error)
: BASE(pdx::default_transport::ClientChannelFactory::Create(
PerformanceRPC::kClientPath)) {
if (error)
*error = Client::error();
}
int PerformanceClient::SetCpuPartition(pid_t task_id,
const std::string& partition) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetCpuPartition>(task_id, partition));
}
int PerformanceClient::SetCpuPartition(pid_t task_id, const char* partition) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetCpuPartition>(
task_id, WrapString(partition)));
}
int PerformanceClient::SetSchedulerPolicy(pid_t task_id,
const std::string& scheduler_policy) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetSchedulerPolicy>(task_id,
scheduler_policy));
}
int PerformanceClient::SetSchedulerPolicy(pid_t task_id,
const char* scheduler_policy) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetSchedulerPolicy>(
task_id, WrapString(scheduler_policy)));
}
int PerformanceClient::SetSchedulerClass(pid_t task_id,
const std::string& scheduler_class) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetSchedulerClass>(task_id,
scheduler_class));
}
int PerformanceClient::SetSchedulerClass(pid_t task_id,
const char* scheduler_class) {
if (task_id == 0)
task_id = gettid();
return ReturnStatusOrError(
InvokeRemoteMethod<PerformanceRPC::SetSchedulerClass>(
task_id, WrapString(scheduler_class)));
}
int PerformanceClient::GetCpuPartition(pid_t task_id,
std::string* partition_out) {
if (partition_out == nullptr)
return -EINVAL;
if (task_id == 0)
task_id = gettid();
auto status = InvokeRemoteMethodInPlace<PerformanceRPC::GetCpuPartition>(
partition_out, task_id);
return status ? 0 : -status.error();
}
int PerformanceClient::GetCpuPartition(pid_t task_id, char* partition_out,
std::size_t size) {
if (partition_out == nullptr)
return -EINVAL;
if (task_id == 0)
task_id = gettid();
auto wrapper = WrapString(partition_out, size);
auto status = InvokeRemoteMethodInPlace<PerformanceRPC::GetCpuPartition>(
&wrapper, task_id);
if (!status)
return -status.error();
if (wrapper.size() < size)
partition_out[wrapper.size()] = '\0';
return 0;
}
} // namespace dvr
} // namespace android
extern "C" int dvrSetCpuPartition(pid_t task_id, const char* partition) {
int error;
if (auto client = android::dvr::PerformanceClient::Create(&error))
return client->SetCpuPartition(task_id, partition);
else
return error;
}
extern "C" int dvrSetSchedulerPolicy(pid_t task_id,
const char* scheduler_policy) {
int error;
if (auto client = android::dvr::PerformanceClient::Create(&error))
return client->SetSchedulerPolicy(task_id, scheduler_policy);
else
return error;
}
extern "C" int dvrSetSchedulerClass(pid_t task_id,
const char* scheduler_class) {
int error;
if (auto client = android::dvr::PerformanceClient::Create(&error))
return client->SetSchedulerClass(task_id, scheduler_class);
else
return error;
}
extern "C" int dvrGetCpuPartition(pid_t task_id, char* partition, size_t size) {
int error;
if (auto client = android::dvr::PerformanceClient::Create(&error))
return client->GetCpuPartition(task_id, partition, size);
else
return error;
}
|