* limitations under the License.
*/
-#ifndef __CONTEXT_SHARED_VARS_H__
-#define __CONTEXT_SHARED_VARS_H__
+#ifndef _CONTEXT_SHARED_VARS_H_
+#define _CONTEXT_SHARED_VARS_H_
+#include <glib.h>
#include <string>
+#include <map>
namespace ctx {
- namespace shared {
- extern std::string wifi_bssid;
- }
+
+ /*
+ * TODO: Maybe later, it would be possible to extend this to support a sort of
+ * 'update observation' feature, i.e., getting notifications when a variable is updated.
+ */
+ class SharedVars {
+ public:
+ enum VarId {
+ WIFI_BSSID,
+ };
+
+ SharedVars();
+ ~SharedVars();
+
+ const std::string& set(VarId id, std::string value) const;
+ std::string get(VarId id);
+ void clear(VarId id);
+
+ private:
+ static GMutex __mutex;
+ static std::map<VarId, std::string> __varsMap;
+ };
+
}
#endif
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <types_internal.h>
+#include <ScopeMutex.h>
+#include <SharedVars.h>
+
+using namespace ctx;
+
+GMutex SharedVars::__mutex;
+std::map<SharedVars::VarId, std::string> SharedVars::__varsMap;
+
+SharedVars::SharedVars()
+{
+}
+
+SharedVars::~SharedVars()
+{
+}
+
+const std::string& SharedVars::set(SharedVars::VarId id, std::string value) const
+{
+ ScopeMutex sm(&__mutex);
+ _D("var[%d] = %s", id, value.c_str());
+ __varsMap[id] = value;
+ return __varsMap[id];
+}
+
+std::string SharedVars::get(SharedVars::VarId id)
+{
+ ScopeMutex sm(&__mutex);
+ auto it = __varsMap.find(id);
+ if (it != __varsMap.end())
+ return it->second;
+ else
+ return EMPTY_STRING;
+}
+
+void SharedVars::clear(SharedVars::VarId id)
+{
+ ScopeMutex sm(&__mutex);
+ _D("Remove var[%d]", id);
+ __varsMap.erase(id);
+}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <shared_vars.h>
-
-std::string ctx::shared::wifi_bssid = "";