2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @author Grzegorz Krawczyk (g.krawczyk@samsung.com)
26 #include <sys/types.h>
28 #include <dpl/log/log.h>
29 #include <dpl/log/secure_log.h>
30 #include <dpl/scoped_resource.h>
31 #include <dpl/assert.h>
32 #include <Commons/Exception.h>
33 #include "WrtAccess.h"
34 #include <dpl/singleton_safe_impl.h>
36 IMPLEMENT_SAFE_SINGLETON(WrtDeviceApis::Commons::WrtAccess)
40 * Helper class - single parameter and its value
48 name(NULL), value(NULL)
51 AceParam(const char *name, const char *value) :
52 name(name), value(value)
57 * Helper class - list of params for single dev cap
69 struct DeviceCapParamPolicy
71 typedef AceParamList* Type;
72 static Type NullValue()
76 static void Destroy(Type ptr)
86 * Helper class - modified ScopedArray for ace_param_list_t
88 class ScopedDeviceCapArray : public DPL::ScopedResource<DeviceCapParamPolicy>
91 explicit ScopedDeviceCapArray(AceParamList *ptr =
92 DeviceCapParamPolicy::NullValue()) :
93 DPL::ScopedResource<DeviceCapParamPolicy>(ptr)
96 AceParamList & operator [](std::ptrdiff_t k) const
98 AssertMsg(this->m_value != DeviceCapParamPolicy::NullValue(),
99 "Dereference of scoped NULL array!");
100 AssertMsg(k >= 0, "Negative array index");
102 return this->m_value[k];
107 namespace WrtDeviceApis {
109 WrtAccess::WrtAccess() :
111 m_sessionId(GenerateSessionId())
114 WrtAccess::~WrtAccess()
117 WrtAccess::SessionId WrtAccess::GenerateSessionId()
119 const size_t SESSION_ID_LENGTH = 32;
121 std::ostringstream pid;
122 pid << static_cast<int>(getpid());
124 std::string session_id = pid.str();
126 session_id.reserve(session_id.length() + SESSION_ID_LENGTH);
128 for (size_t i = 0; i < SESSION_ID_LENGTH; ++i) {
129 int c = random() % 16;
131 session_id += (c < 10 ?
132 static_cast<char>('0' + c) :
133 static_cast<char>('A' + c - 10));
138 void WrtAccess::initialize(WidgetHandle widgetId)
142 _E("Invalid widget id");
146 m_widgetId = widgetId;
149 void WrtAccess::deinitialize(WidgetHandle /*widgetId*/)
154 WidgetHandle WrtAccess::getWidgetId() const
159 } // WrtDeviceApisCommon