{"action":"created","comment":{"url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/comments/231187169","pull_request_review_id":172093491,"id":231187169,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTE4NzE2OQ==","diff_hunk":"@@ -0,0 +1,216 @@\n+/*\n+ * Copyright (c) 2018 ARM Limited. All rights reserved.\n+ * SPDX-License-Identifier: Apache-2.0\n+ * Licensed under the Apache License, Version 2.0 (the License); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT\n+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#include \"KVStore.h\"\n+#include \"kv_map.h\"\n+#include \"kv_config.h\"\n+#include <stdlib.h>\n+#include \"platform/PlatformMutex.h\"\n+#include \"platform/SingletonPtr.h\"\n+#include \"string.h\"\n+#include \"mbed_error.h\"\n+\n+using namespace mbed;\n+\n+#define  MAX_ATTACHED_KVS 16\n+\n+typedef struct {\n+    char *partition_name;\n+    KVStore *kvstore_instance;\n+} kv_map_entry_t;\n+\n+// Attachment table\n+kv_map_entry_t kv_map_table[MAX_ATTACHED_KVS];\n+int kv_num_attached_kvs;\n+\n+static int is_initialized = 0;\n+static SingletonPtr<PlatformMutex> mutex;\n+\n+int kv_init()\n+{\n+    int ret = MBED_SUCCESS;\n+\n+    mutex->lock();\n+\n+    if (is_initialized) {\n+        goto exit;\n+    }\n+\n+    kv_num_attached_kvs = 0;\n+    memset(&kv_map_table, 0, sizeof(kv_map_table));\n+\n+    is_initialized = 1;\n+\n+exit:\n+    mutex->unlock();\n+    return ret;\n+}\n+\n+int kv_attach(const char *partition_name, KVStore *kv_instance)\n+{\n+    int ret = MBED_SUCCESS;\n+\n+    mutex->lock();\n+\n+    if (!is_initialized) {\n+        ret = MBED_ERROR_NOT_READY;\n+        goto exit;\n+    }\n+\n+    if (kv_num_attached_kvs >= MAX_ATTACHED_KVS) {\n+        ret =  MBED_ERROR_OUT_OF_MEMORY;\n+        goto exit;\n+    }\n+\n+    kv_map_table[kv_num_attached_kvs].partition_name = strdup(partition_name);\n+    kv_map_table[kv_num_attached_kvs].kvstore_instance = kv_instance;\n+    kv_num_attached_kvs++;\n+\n+exit:\n+    mutex->unlock();\n+    return ret;\n+}\n+\n+int kv_detach(const char *partition_name)\n+{\n+    int ret = MBED_SUCCESS;\n+\n+    mutex->lock();\n+\n+    if (!is_initialized) {\n+        ret = MBED_ERROR_NOT_READY;\n+        goto exit;\n+    }\n+\n+    ret = MBED_ERROR_ITEM_NOT_FOUND;\n+    for (int i = 0; i < kv_num_attached_kvs; i++ ) {\n+\n+        if (strcmp(partition_name, kv_map_table[i].partition_name) != 0) {\n+            continue;\n+        }\n+\n+        free(kv_map_table[i].partition_name);\n+        kv_map_table[i].kvstore_instance->deinit();\n+\n+        memcpy(&kv_map_table[i], &kv_map_table[i + 1], sizeof(kv_map_entry_t) * (MAX_ATTACHED_KVS - i - 1));\n+        kv_map_table[MAX_ATTACHED_KVS - 1].partition_name = NULL;\n+        kv_map_table[MAX_ATTACHED_KVS - 1].kvstore_instance = NULL;\n+        kv_num_attached_kvs--;\n+        ret = MBED_SUCCESS;\n+        break;\n+    }\n+\n+exit:\n+    mutex->unlock();\n+    return ret;\n+}\n+\n+int kv_deinit()\n+{\n+    int ret = MBED_SUCCESS;\n+\n+    mutex->lock();\n+\n+    if (!is_initialized) {\n+        ret = MBED_ERROR_NOT_READY;\n+        goto exit;\n+    }\n+\n+    for (int i = 0; i < kv_num_attached_kvs; i++ ) {\n+\n+        if (kv_map_table[i].kvstore_instance == NULL) {\n+            goto exit;\n+        }\n+\n+        free(kv_map_table[i].partition_name);\n+        if (kv_map_table[i].kvstore_instance != NULL) {\n+            kv_map_table[i].kvstore_instance->deinit();\n+        }\n+        kv_map_table[i].partition_name = NULL;\n+        kv_map_table[i].kvstore_instance = NULL;\n+    }\n+\n+exit:\n+    kv_num_attached_kvs = 0;\n+    mutex->unlock();\n+    return ret;\n+}\n+\n+//return -1 if delimiter is not found\n+int kv_get_delimiter_index(const char *str, char delimiter)","path":"features/storage/kvstore/kv_map/kv_map.cpp","position":153,"original_position":153,"commit_id":"91af69436bd3088e83ff3e1e7130e9913e67d6d6","original_commit_id":"91af69436bd3088e83ff3e1e7130e9913e67d6d6","user":{"login":"offirko","id":36957743,"node_id":"MDQ6VXNlcjM2OTU3NzQz","avatar_url":"https://avatars3.githubusercontent.com/u/36957743?v=4","gravatar_id":"","url":"https://api.github.com/users/offirko","html_url":"https://github.com/offirko","followers_url":"https://api.github.com/users/offirko/followers","following_url":"https://api.github.com/users/offirko/following{/other_user}","gists_url":"https://api.github.com/users/offirko/gists{/gist_id}","starred_url":"https://api.github.com/users/offirko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/offirko/subscriptions","organizations_url":"https://api.github.com/users/offirko/orgs","repos_url":"https://api.github.com/users/offirko/repos","events_url":"https://api.github.com/users/offirko/events{/privacy}","received_events_url":"https://api.github.com/users/offirko/received_events","type":"User","site_admin":false},"body":"can you use strchr ?","created_at":"2018-11-06T16:12:50Z","updated_at":"2018-11-06T16:36:17Z","html_url":"https://github.com/davidsaada/mbed-os/pull/21#discussion_r231187169","pull_request_url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/comments/231187169"},"html":{"href":"https://github.com/davidsaada/mbed-os/pull/21#discussion_r231187169"},"pull_request":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21","id":228705955,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI4NzA1OTU1","html_url":"https://github.com/davidsaada/mbed-os/pull/21","diff_url":"https://github.com/davidsaada/mbed-os/pull/21.diff","patch_url":"https://github.com/davidsaada/mbed-os/pull/21.patch","issue_url":"https://api.github.com/repos/davidsaada/mbed-os/issues/21","number":21,"state":"open","locked":false,"title":"KV store global api and configuration","user":{"login":"yossi2le","id":36073365,"node_id":"MDQ6VXNlcjM2MDczMzY1","avatar_url":"https://avatars1.githubusercontent.com/u/36073365?v=4","gravatar_id":"","url":"https://api.github.com/users/yossi2le","html_url":"https://github.com/yossi2le","followers_url":"https://api.github.com/users/yossi2le/followers","following_url":"https://api.github.com/users/yossi2le/following{/other_user}","gists_url":"https://api.github.com/users/yossi2le/gists{/gist_id}","starred_url":"https://api.github.com/users/yossi2le/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yossi2le/subscriptions","organizations_url":"https://api.github.com/users/yossi2le/orgs","repos_url":"https://api.github.com/users/yossi2le/repos","events_url":"https://api.github.com/users/yossi2le/events{/privacy}","received_events_url":"https://api.github.com/users/yossi2le/received_events","type":"User","site_admin":false},"body":"\r\nThis pull request includes the kv global api and the configuration. Please ignore kv_map files cause they are going to have a massive change soon.\r\n\r\n","created_at":"2018-11-06T14:15:21Z","updated_at":"2018-11-06T16:36:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"082ee000587fee6cf953c473c2a9b5cb46d66bfe","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21/commits","review_comments_url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21/comments","review_comment_url":"https://api.github.com/repos/davidsaada/mbed-os/pulls/comments{/number}","comments_url":"https://api.github.com/repos/davidsaada/mbed-os/issues/21/comments","statuses_url":"https://api.github.com/repos/davidsaada/mbed-os/statuses/91af69436bd3088e83ff3e1e7130e9913e67d6d6","head":{"label":"yossi2le:yossi_kv_retarget_cont","ref":"yossi_kv_retarget_cont","sha":"91af69436bd3088e83ff3e1e7130e9913e67d6d6","user":{"login":"yossi2le","id":36073365,"node_id":"MDQ6VXNlcjM2MDczMzY1","avatar_url":"https://avatars1.githubusercontent.com/u/36073365?v=4","gravatar_id":"","url":"https://api.github.com/users/yossi2le","html_url":"https://github.com/yossi2le","followers_url":"https://api.github.com/users/yossi2le/followers","following_url":"https://api.github.com/users/yossi2le/following{/other_user}","gists_url":"https://api.github.com/users/yossi2le/gists{/gist_id}","starred_url":"https://api.github.com/users/yossi2le/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yossi2le/subscriptions","organizations_url":"https://api.github.com/users/yossi2le/orgs","repos_url":"https://api.github.com/users/yossi2le/repos","events_url":"https://api.github.com/users/yossi2le/events{/privacy}","received_events_url":"https://api.github.com/users/yossi2le/received_events","type":"User","site_admin":false},"repo":{"id":120634866,"node_id":"MDEwOlJlcG9zaXRvcnkxMjA2MzQ4NjY=","name":"mbed-os","full_name":"yossi2le/mbed-os","private":false,"owner":{"login":"yossi2le","id":36073365,"node_id":"MDQ6VXNlcjM2MDczMzY1","avatar_url":"https://avatars1.githubusercontent.com/u/36073365?v=4","gravatar_id":"","url":"https://api.github.com/users/yossi2le","html_url":"https://github.com/yossi2le","followers_url":"https://api.github.com/users/yossi2le/followers","following_url":"https://api.github.com/users/yossi2le/following{/other_user}","gists_url":"https://api.github.com/users/yossi2le/gists{/gist_id}","starred_url":"https://api.github.com/users/yossi2le/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yossi2le/subscriptions","organizations_url":"https://api.github.com/users/yossi2le/orgs","repos_url":"https://api.github.com/users/yossi2le/repos","events_url":"https://api.github.com/users/yossi2le/events{/privacy}","received_events_url":"https://api.github.com/users/yossi2le/received_events","type":"User","site_admin":false},"html_url":"https://github.com/yossi2le/mbed-os","description":"ARM mbed OS is a platform operating system designed for the internet of things","fork":true,"url":"https://api.github.com/repos/yossi2le/mbed-os","forks_url":"https://api.github.com/repos/yossi2le/mbed-os/forks","keys_url":"https://api.github.com/repos/yossi2le/mbed-os/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yossi2le/mbed-os/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yossi2le/mbed-os/teams","hooks_url":"https://api.github.com/repos/yossi2le/mbed-os/hooks","issue_events_url":"https://api.github.com/repos/yossi2le/mbed-os/issues/events{/number}","events_url":"https://api.github.com/repos/yossi2le/mbed-os/events","assignees_url":"https://api.github.com/repos/yossi2le/mbed-os/assignees{/user}","branches_url":"https://api.github.com/repos/yossi2le/mbed-os/branches{/branch}","tags_url":"https://api.github.com/repos/yossi2le/mbed-os/tags","blobs_url":"https://api.github.com/repos/yossi2le/mbed-os/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yossi2le/mbed-os/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yossi2le/mbed-os/git/refs{/sha}","trees_url":"https://api.github.com/repos/yossi2le/mbed-os/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yossi2le/mbed-os/statuses/{sha}","languages_url":"https://api.github.com/repos/yossi2le/mbed-os/languages","stargazers_url":"https://api.github.com/repos/yossi2le/mbed-os/stargazers","contributors_url":"https://api.github.com/repos/yossi2le/mbed-os/contributors","subscribers_url":"https://api.github.com/repos/yossi2le/mbed-os/subscribers","subscription_url":"https://api.github.com/repos/yossi2le/mbed-os/subscription","commits_url":"https://api.github.com/repos/yossi2le/mbed-os/commits{/sha}","git_commits_url":"https://api.github.com/repos/yossi2le/mbed-os/git/commits{/sha}","comments_url":"https://api.github.com/repos/yossi2le/mbed-os/comments{/number}","issue_comment_url":"https://api.github.com/repos/yossi2le/mbed-os/issues/comments{/number}","contents_url":"https://api.github.com/repos/yossi2le/mbed-os/contents/{+path}","compare_url":"https://api.github.com/repos/yossi2le/mbed-os/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yossi2le/mbed-os/merges","archive_url":"https://api.github.com/repos/yossi2le/mbed-os/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yossi2le/mbed-os/downloads","issues_url":"https://api.github.com/repos/yossi2le/mbed-os/issues{/number}","pulls_url":"https://api.github.com/repos/yossi2le/mbed-os/pulls{/number}","milestones_url":"https://api.github.com/repos/yossi2le/mbed-os/milestones{/number}","notifications_url":"https://api.github.com/repos/yossi2le/mbed-os/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yossi2le/mbed-os/labels{/name}","releases_url":"https://api.github.com/repos/yossi2le/mbed-os/releases{/id}","deployments_url":"https://api.github.com/repos/yossi2le/mbed-os/deployments","created_at":"2018-02-07T15:43:05Z","updated_at":"2018-11-01T09:51:35Z","pushed_at":"2018-11-06T10:34:17Z","git_url":"git://github.com/yossi2le/mbed-os.git","ssh_url":"git@github.com:yossi2le/mbed-os.git","clone_url":"https://github.com/yossi2le/mbed-os.git","svn_url":"https://github.com/yossi2le/mbed-os","homepage":"https://mbed.com","size":236903,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"davidsaada:kvstore_integration","ref":"kvstore_integration","sha":"fdbebac9023705f5a4f2ca6507507705906baa13","user":{"login":"davidsaada","id":30656454,"node_id":"MDQ6VXNlcjMwNjU2NDU0","avatar_url":"https://avatars3.githubusercontent.com/u/30656454?v=4","gravatar_id":"","url":"https://api.github.com/users/davidsaada","html_url":"https://github.com/davidsaada","followers_url":"https://api.github.com/users/davidsaada/followers","following_url":"https://api.github.com/users/davidsaada/following{/other_user}","gists_url":"https://api.github.com/users/davidsaada/gists{/gist_id}","starred_url":"https://api.github.com/users/davidsaada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidsaada/subscriptions","organizations_url":"https://api.github.com/users/davidsaada/orgs","repos_url":"https://api.github.com/users/davidsaada/repos","events_url":"https://api.github.com/users/davidsaada/events{/privacy}","received_events_url":"https://api.github.com/users/davidsaada/received_events","type":"User","site_admin":false},"repo":{"id":113969228,"node_id":"MDEwOlJlcG9zaXRvcnkxMTM5NjkyMjg=","name":"mbed-os","full_name":"davidsaada/mbed-os","private":false,"owner":{"login":"davidsaada","id":30656454,"node_id":"MDQ6VXNlcjMwNjU2NDU0","avatar_url":"https://avatars3.githubusercontent.com/u/30656454?v=4","gravatar_id":"","url":"https://api.github.com/users/davidsaada","html_url":"https://github.com/davidsaada","followers_url":"https://api.github.com/users/davidsaada/followers","following_url":"https://api.github.com/users/davidsaada/following{/other_user}","gists_url":"https://api.github.com/users/davidsaada/gists{/gist_id}","starred_url":"https://api.github.com/users/davidsaada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidsaada/subscriptions","organizations_url":"https://api.github.com/users/davidsaada/orgs","repos_url":"https://api.github.com/users/davidsaada/repos","events_url":"https://api.github.com/users/davidsaada/events{/privacy}","received_events_url":"https://api.github.com/users/davidsaada/received_events","type":"User","site_admin":false},"html_url":"https://github.com/davidsaada/mbed-os","description":"ARM mbed OS is a platform operating system designed for the internet of things","fork":true,"url":"https://api.github.com/repos/davidsaada/mbed-os","forks_url":"https://api.github.com/repos/davidsaada/mbed-os/forks","keys_url":"https://api.github.com/repos/davidsaada/mbed-os/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidsaada/mbed-os/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidsaada/mbed-os/teams","hooks_url":"https://api.github.com/repos/davidsaada/mbed-os/hooks","issue_events_url":"https://api.github.com/repos/davidsaada/mbed-os/issues/events{/number}","events_url":"https://api.github.com/repos/davidsaada/mbed-os/events","assignees_url":"https://api.github.com/repos/davidsaada/mbed-os/assignees{/user}","branches_url":"https://api.github.com/repos/davidsaada/mbed-os/branches{/branch}","tags_url":"https://api.github.com/repos/davidsaada/mbed-os/tags","blobs_url":"https://api.github.com/repos/davidsaada/mbed-os/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidsaada/mbed-os/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidsaada/mbed-os/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidsaada/mbed-os/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidsaada/mbed-os/statuses/{sha}","languages_url":"https://api.github.com/repos/davidsaada/mbed-os/languages","stargazers_url":"https://api.github.com/repos/davidsaada/mbed-os/stargazers","contributors_url":"https://api.github.com/repos/davidsaada/mbed-os/contributors","subscribers_url":"https://api.github.com/repos/davidsaada/mbed-os/subscribers","subscription_url":"https://api.github.com/repos/davidsaada/mbed-os/subscription","commits_url":"https://api.github.com/repos/davidsaada/mbed-os/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidsaada/mbed-os/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidsaada/mbed-os/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidsaada/mbed-os/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidsaada/mbed-os/contents/{+path}","compare_url":"https://api.github.com/repos/davidsaada/mbed-os/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidsaada/mbed-os/merges","archive_url":"https://api.github.com/repos/davidsaada/mbed-os/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidsaada/mbed-os/downloads","issues_url":"https://api.github.com/repos/davidsaada/mbed-os/issues{/number}","pulls_url":"https://api.github.com/repos/davidsaada/mbed-os/pulls{/number}","milestones_url":"https://api.github.com/repos/davidsaada/mbed-os/milestones{/number}","notifications_url":"https://api.github.com/repos/davidsaada/mbed-os/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidsaada/mbed-os/labels{/name}","releases_url":"https://api.github.com/repos/davidsaada/mbed-os/releases{/id}","deployments_url":"https://api.github.com/repos/davidsaada/mbed-os/deployments","created_at":"2017-12-12T09:19:54Z","updated_at":"2018-11-05T13:27:26Z","pushed_at":"2018-11-06T16:02:05Z","git_url":"git://github.com/davidsaada/mbed-os.git","ssh_url":"git@github.com:davidsaada/mbed-os.git","clone_url":"https://github.com/davidsaada/mbed-os.git","svn_url":"https://github.com/davidsaada/mbed-os","homepage":"https://mbed.com","size":238030,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":8,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1,"open_issues":8,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21"},"html":{"href":"https://github.com/davidsaada/mbed-os/pull/21"},"issue":{"href":"https://api.github.com/repos/davidsaada/mbed-os/issues/21"},"comments":{"href":"https://api.github.com/repos/davidsaada/mbed-os/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/davidsaada/mbed-os/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/davidsaada/mbed-os/statuses/91af69436bd3088e83ff3e1e7130e9913e67d6d6"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"offirko"}}