4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sensor_logs.h>
26 #include <command_common.h>
33 cpacket::cpacket(size_t size)
36 set_payload_size(size);
41 delete[] (char*)m_packet;
44 void cpacket::set_cmd(int cmd)
52 int cpacket::cmd(void)
60 void *cpacket::data(void)
65 return m_packet->data;
68 void *cpacket::packet(void)
70 return (void*)m_packet;
73 size_t cpacket::size(void)
78 return m_packet->size + sizeof(packet_header);
81 size_t cpacket::payload_size(void)
86 return m_packet->size;
89 void cpacket::set_payload_size(size_t size)
91 int prev_cmd = CMD_NONE;
94 prev_cmd = m_packet->cmd;
98 m_packet = (packet_header*) new(std::nothrow) char[size + sizeof(packet_header)];
99 retm_if (!m_packet, "Failed to allocate memory");
100 m_packet->size = size;
102 if (prev_cmd != CMD_NONE)
103 m_packet->cmd = prev_cmd;