#include <vconf.h>
#include <libsyscommon/libgdbus.h>
#include <libsyscommon/list.h>
+#include <libsyscommon/bitmap.h>
#include "core/log.h"
-#include "shared/bitmap.h"
#include "shared/device-notifier.h"
#include "core.h"
#include "display-ops.h"
#define HDMI_NUMBER_MAX (64) // max number of supported hdmi
-static struct dd_bitmap *bm_hdmi;
+static struct syscommon_bitmap *bm_hdmi;
static struct extcon_ops hdmi_extcon_ops;
static void hdmi_send_broadcast(int status)
return HDMI_DISCONNECTED;
}
- if (count_set_bit(bm_hdmi) > 0)
+ if (syscommon_bitmap_count_set_bit(bm_hdmi) > 0)
return HDMI_CONNECTED;
return HDMI_DISCONNECTED;
}
if (status == HDMI_CONNECTED)
- set_bit(bm_hdmi, index);
+ syscommon_bitmap_set_bit(bm_hdmi, index);
else
- clear_bit(bm_hdmi, index);
+ syscommon_bitmap_clear_bit(bm_hdmi, index);
}
static void update_all_hdmi_bitmap(int status)
}
if (status == HDMI_CONNECTED)
- set_all_bits(bm_hdmi);
+ syscommon_bitmap_set_all_bits(bm_hdmi);
else
- clear_all_bits(bm_hdmi);
+ syscommon_bitmap_clear_all_bits(bm_hdmi);
}
static int hdmi_update(const char *index, int status)
if (ret < 0)
_E("Failed to init dbus method: %d", ret);
- bm_hdmi = init_bitmap(HDMI_NUMBER_MAX);
+ bm_hdmi = syscommon_bitmap_init_bitmap(HDMI_NUMBER_MAX);
}
static void hdmi_exit(void *data)
{
- deinit_bitmap(bm_hdmi);
+ syscommon_bitmap_deinit_bitmap(bm_hdmi);
+ bm_hdmi = NULL;
}
static struct extcon_ops hdmi_extcon_ops = {
#include <stdint.h>
#include <linux/input.h>
#include <libsyscommon/ini-parser.h>
+#include <libsyscommon/bitmap.h>
+#include <libsyscommon/file.h>
-#include "shared/bitmap.h"
#include "shared/device-notifier.h"
#include "shared/log.h"
#include "power-event-lock.h"
* of an event from going to sleep regardless of the power state. */
#define EVENT_LOCK "eventlock"
-static struct dd_bitmap *eventlock;
+static struct syscommon_bitmap *eventlock;
static int notifier_id[EL_MAX][2];
void event_wake_lock(enum eventlock_type type)
if (type <= EL_MIN || type >= EL_MAX)
return;
- set_bit(eventlock, type);
- setcount = count_set_bit(eventlock);
+ syscommon_bitmap_set_bit(eventlock, type);
+ setcount = syscommon_bitmap_count_set_bit(eventlock);
_I("Set eventlock of type=%d, current number of eventlock=%d", type, setcount);
if (type <= EL_MIN || type >= EL_MAX)
return;
- clear_bit(eventlock, type);
- setcount = count_set_bit(eventlock);
+ syscommon_bitmap_clear_bit(eventlock, type);
+ setcount = syscommon_bitmap_count_set_bit(eventlock);
_I("Unset eventlock of type=%d, current number of eventlock=%d", type, setcount);
{
int charger_wakelock = 0;
- eventlock = init_bitmap(EL_MAX);
+ eventlock = syscommon_bitmap_init_bitmap(EL_MAX);
if (!eventlock) {
_E("Failed to init event lock bitmap");
return;
#include <stdarg.h>
#include <libsyscommon/libgdbus.h>
+#include <libsyscommon/bitmap.h>
#include "core/log.h"
#include "shared/common.h"
#include "apps.h"
#include "display-plugin.h"
#include "display-state-transition.h"
-#include "shared/bitmap.h"
#define POPUP_METHOD "PopupLaunch"
#define BUFF_MAX 255
-static struct dd_bitmap *bm_background;
+static struct syscommon_bitmap *bm_background;
static int pid_max;
static const struct app_dbus_match {
bool is_app_background(pid_t pid)
{
- return test_bit(bm_background, pid);
+ return syscommon_bitmap_test_bit(bm_background, pid);
}
void init_bm_background(void)
pid_max = 32768;
/* need (pid_max + 1) bits to represent pid 0 ~ pid_max */
- bm_background = init_bitmap(pid_max + 1);
+ bm_background = syscommon_bitmap_init_bitmap(pid_max + 1);
if (!bm_background)
_E("Failed to allock bm_background.");
}
return;
if (as == APPLICATION_BACKGROUND)
- set_bit(bm_background, pid);
+ syscommon_bitmap_set_bit(bm_background, pid);
else if (as == APPLICATION_FOREGROUND || as == APPLICATION_TERMINATED)
- clear_bit(bm_background, pid);
+ syscommon_bitmap_clear_bit(bm_background, pid);
else
_E("Invalid as=%d", as);
}
static void __DESTRUCTOR__ finalize(void)
{
- deinit_bitmap(bm_background);
+ syscommon_bitmap_deinit_bitmap(bm_background);
}
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2020 - 2021 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 <stdlib.h>
-#include <errno.h>
-
-#include "bitmap.h"
-#include "log.h"
-
-static void bitmap_alloc_size(struct dd_bitmap *bm, unsigned int nbits)
-{
- unsigned int bytes = ROUNDUP_BITS_TO_LONGS(nbits) * BYTES_PER_LONG;
-
- bytes += BITMAP_MARGIN;
-
- bm->b = (unsigned long *) malloc(bytes);
- if (!bm->b)
- return;
-
- bm->size = nbits;
-}
-
-void set_all_bits(struct dd_bitmap *bm)
-{
- unsigned long complete_longs = bm->size / BITS_PER_LONG;
- unsigned long complete_bytes = complete_longs * BYTES_PER_LONG;
- unsigned long residue_bits = bm->size % BITS_PER_LONG;
-
- /* set all bits of the long element except the last long element */
- memset(bm->b, ~0, complete_bytes);
-
- /* set residue bits in the last long element */
- if (residue_bits)
- bm->b[complete_longs] = (1UL << residue_bits) - 1;
-}
-
-void clear_all_bits(struct dd_bitmap *bm)
-{
- unsigned int bytes = ROUNDUP_BITS_TO_LONGS(bm->size) * BYTES_PER_LONG;
- memset(bm->b, 0, bytes);
-}
-
-void set_bit(struct dd_bitmap *bm, unsigned long nr)
-{
- if (!bm)
- return;
-
- if (nr >= bm->size) {
- _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1);
- return;
- }
-
- bm->b[BIT_WORD(nr)] |= BIT_MASK(nr);
-}
-
-void clear_bit(struct dd_bitmap *bm, unsigned long nr)
-{
- if (!bm)
- return;
-
- if (nr >= bm->size) {
- _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1);
- return;
- }
-
- bm->b[BIT_WORD(nr)] &= ~BIT_MASK(nr);
-}
-
-bool test_bit(struct dd_bitmap *bm, unsigned long nr)
-{
- if (!bm)
- return false;
-
- if (nr >= bm->size) {
- _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1);
- return false;
- }
-
- return bm->b[BIT_WORD(nr)] & BIT_MASK(nr);
-}
-
-int count_set_bit(struct dd_bitmap *bm)
-{
- int i;
- int count = 0;
-
- if (!bm)
- return -1;
-
- for (i = 0; i < ROUNDUP_BITS_TO_LONGS(bm->size); ++i)
- count += __builtin_popcountl(bm->b[i]);
-
- return count;
-}
-
-int count_unset_bit(struct dd_bitmap *bm)
-{
- if (!bm)
- return -1;
-
- return bm->size - count_set_bit(bm);
-}
-
-struct dd_bitmap* init_bitmap(unsigned int nbits)
-{
- struct dd_bitmap *bm = NULL;
-
- if (nbits == 0)
- return NULL;
-
- bm = (struct dd_bitmap *) malloc(sizeof(struct dd_bitmap));
- if (!bm)
- return NULL;
-
- bm->b = NULL;
- bm->size = 0;
-
- bitmap_alloc_size(bm, nbits);
- if (!bm->b) {
- free(bm);
- return NULL;
- }
-
- clear_all_bits(bm);
- bm->size = nbits;
-
- return bm;
-}
-
-void deinit_bitmap(struct dd_bitmap *bm)
-{
- if (!bm)
- return;
-
- free(bm->b);
- free(bm);
-}
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2020 - 2021 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.
- */
-
-#ifndef __DD_BITMAP_H__
-#define __DD_BITMAP_H__
-
-#include <string.h>
-
-#include "shared/common.h"
-
-/* Align bits by size of long, and convert it to long,
- * for example, if long is 64bit then,
- * ROUNDUP_BITS_TO_LONGS(0) -> 0
- * ROUNDUP_BITS_TO_LONGS(1) -> 1
- * ROUNDUP_BITS_TO_LONGS(64) -> 1
- * ROUNDUP_BITS_TO_LONGS(65) -> 2
- * ROUNDUP_BITS_TO_LONGS(128) -> 2
- * ROUNDUP_BITS_TO_LONGS(129) -> 3
- * ... */
-#define ROUNDUP_BITS_TO_LONGS(nbits) (roundup(nbits, BITS_PER_LONG) / BITS_PER_LONG)
-
-#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
-#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
-#define BITMAP_MARGIN (BYTES_PER_LONG * 2) /* trailing margin for safety, bytes */
-
-struct dd_bitmap {
- /* bitmap */
- unsigned long *b;
-
- /* number of bits, not the maximum bit.
- * maximum bit is size - 1 */
- unsigned long size;
-};
-
-void set_bit(struct dd_bitmap *bm, unsigned long nr);
-void clear_bit(struct dd_bitmap *bm, unsigned long nr);
-bool test_bit(struct dd_bitmap *bm, unsigned long nr);
-void set_all_bits(struct dd_bitmap *bm);
-void clear_all_bits(struct dd_bitmap *bm);
-int count_set_bit(struct dd_bitmap *bm);
-int count_unset_bit(struct dd_bitmap *bm);
-struct dd_bitmap* init_bitmap(unsigned int nbits);
-void deinit_bitmap(struct dd_bitmap *bm);
-
-#endif
PKG_CHECK_MODULES(TEST_REQUIRED_PKGS REQUIRED cmocka)
-LIST(APPEND TEST_DRIVERS test-bitmap.c)
LIST(APPEND TEST_DRIVERS test-device-notifier.c)
LIST(APPEND TEST_DRIVERS test-plugin.c)
+++ /dev/null
-#include <shared/bitmap.h>
-
-#include "test-main.h"
-
-static void test_init_bitmap_p(void **state)
-{
- struct dd_bitmap *bm;
-
- bm = init_bitmap(10);
- assert_non_null(bm);
-
- deinit_bitmap(bm);
-}
-
-static void test_init_bitmap_n(void **state)
-{
- struct dd_bitmap *bm = NULL;
-
- bm = init_bitmap(0);
- assert_null(bm);
-}
-
-static void test_test_bit(void **state)
-{
- struct dd_bitmap *bm;
- const int bmsize = 37;
- bool bit;
- int i, nbit;
-
- bm = init_bitmap(bmsize);
- assert_non_null(bm);
-
- for (i = 0; i < bmsize; ++i) {
- bit = test_bit(bm, i);
- assert_false(bit);
- }
-
- /* count bit by setting one by one */
- for (i = 0; i < bmsize; ++i) {
- set_bit(bm, i);
- nbit = count_set_bit(bm);
- assert_int_equal(nbit, i + 1);
- }
-
- /* test the marginal bit */
- bit = test_bit(bm, 0);
- assert_true(bit);
- bit = test_bit(bm, bmsize - 1);
- assert_true(bit);
- bit = test_bit(bm, bmsize);
- assert_false(bit);
-
-
- /* count bit by clearing one by one */
- for (i = 0; i < bmsize; ++i) {
- clear_bit(bm, i);
- nbit = count_set_bit(bm);
- assert_int_equal(nbit, bmsize - i - 1);
- }
-
- deinit_bitmap(bm);
-}
-
-static void test_all_bit(void **state)
-{
- struct dd_bitmap *bm;
- const int bmsize = 37;
- int nbit;
-
- bm = init_bitmap(bmsize);
- assert_non_null(bm);
-
- set_all_bits(bm);
- nbit = count_set_bit(bm);
- assert_int_equal(nbit, bmsize);
-
- clear_all_bits(bm);
- nbit = count_set_bit(bm);
- assert_int_equal(nbit, 0);
-
- deinit_bitmap(bm);
-}
-
-static int run_bitmap_test(void)
-{
- static const struct CMUnitTest testsuite[] = {
- cmocka_unit_test(test_init_bitmap_p),
- cmocka_unit_test(test_init_bitmap_n),
- cmocka_unit_test(test_test_bit),
- cmocka_unit_test(test_all_bit),
- };
-
- return cmocka_run_group_tests(testsuite, NULL, NULL);
-}
-ADD_TEST_FUNCTION(run_bitmap_test)