From cc1097c96151d527838ddc8a8fc10810716c7f05 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 20 Dec 2012 17:11:32 +0900 Subject: [PATCH] Initialize the project. Change-Id: I033f9b5b5b73c3d8a53a8edcade0cb3a8722a725 --- CMakeLists.txt | 61 ++++++ LICENSE | 83 +++++++ data/CMakeLists.txt | 0 include/debug.h | 19 ++ include/dlist.h | 43 ++++ include/livebox.h | 212 ++++++++++++++++++ include/livebox_PG.h | 16 ++ include/util.h | 20 ++ liblivebox.manifest | 5 + livebox.pc.in | 11 + packaging/liblivebox.spec | 48 +++++ src/dlist.c | 154 +++++++++++++ src/livebox.c | 537 ++++++++++++++++++++++++++++++++++++++++++++++ src/util.c | 53 +++++ 14 files changed, 1262 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 data/CMakeLists.txt create mode 100644 include/debug.h create mode 100644 include/dlist.h create mode 100644 include/livebox.h create mode 100644 include/livebox_PG.h create mode 100644 include/util.h create mode 100644 liblivebox.manifest create mode 100644 livebox.pc.in create mode 100644 packaging/liblivebox.spec create mode 100644 src/dlist.c create mode 100644 src/livebox.c create mode 100644 src/util.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..645673c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,61 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(livebox C) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR "\${exec_prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 0) +SET(VERSION "${VERSION_MAJOR}.0.1") + +set(CMAKE_SKIP_BUILD_RPATH true) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + dlog + livebox-service + provider +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -g") + +#ADD_DEFINITIONS("-Werror") +#ADD_DEFINITIONS("-Wall") +#ADD_DEFINITIONS("-Wextra") +#ADD_DEFINITIONS("-ansi") +#ADD_DEFINITIONS("-pedantic") + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DLOG_TAG=\"${PROJECT_NAME}\"") +ADD_DEFINITIONS("-DNDEBUG") +ADD_DEFINITIONS("-DMASTER_PKGNAME=\"org.tizen.data-provider-master\"") +ADD_DEFINITIONS("-DSLAVE_PKGNAME=\"org.tizen.data-provider-slave\"") + +ADD_LIBRARY(${PROJECT_NAME} SHARED + src/dlist.c + src/livebox.c + src/util.c +) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lpthread") + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox.h DESTINATION include/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/livebox_PG.h DESTINATION /usr/share/doc/${PROJECT_NAME}) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}") + +ADD_SUBDIRECTORY(data) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..27daa90 --- /dev/null +++ b/LICENSE @@ -0,0 +1,83 @@ +Flora License + +Version 1.0, May, 2012 + +http://www.tizenopensource.org/license + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +"Tizen Certified Platform" shall mean a software platform that complies with the standards set forth in the Compatibility Definition Document and passes the Compatibility Test Suite as defined from time to time by the Tizen Technical Steering Group and certified by the Tizen Association or its designated agent. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work solely as incorporated into a Tizen Certified Platform, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work solely as incorporated into a Tizen Certified Platform to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof pursuant to the copyright license above, in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of this License; and +You must cause any modified files to carry prominent notices stating that You changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Flora License to your work + +To apply the Flora License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + + + Licensed under the Flora License, Version 1.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.tizenopensource.org/license + + + + 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. diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/include/debug.h b/include/debug.h new file mode 100644 index 0000000..925dd47 --- /dev/null +++ b/include/debug.h @@ -0,0 +1,19 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + +#define DbgPrint(format, arg...) LOGD("[%s/%s:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg) +#define ErrPrint(format, arg...) LOGE("[%s/%s:%d] " format, basename(__FILE__), __func__, __LINE__, ##arg) +/* End of a file */ diff --git a/include/dlist.h b/include/dlist.h new file mode 100644 index 0000000..a0ad1a0 --- /dev/null +++ b/include/dlist.h @@ -0,0 +1,43 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + +#define dlist_remove_data(list, data) do { \ + struct dlist *l; \ + l = dlist_find_data(list, data); \ + list = dlist_remove(list, l); \ +} while (0) + +#define dlist_foreach(list, l, data) \ + for ((l) = (list); ((data) = dlist_data(l)); (l) = dlist_next(l)) + +#define dlist_foreach_safe(list, l, n, data) \ + for ((l) = (list), (n) = dlist_next(l); \ + ((data) = dlist_data(l)); \ + (l) = (n), (n) = dlist_next(l)) + +struct dlist; + +extern struct dlist *dlist_append(struct dlist *list, void *data); +extern struct dlist *dlist_prepend(struct dlist *list, void *data); +extern struct dlist *dlist_remove(struct dlist *list, struct dlist *l); +extern struct dlist *dlist_find_data(struct dlist *list, void *data); +extern void *dlist_data(struct dlist *l); +extern struct dlist *dlist_next(struct dlist *l); +extern struct dlist *dlist_prev(struct dlist *l); +extern int dlist_count(struct dlist *l); +extern struct dlist *dlist_nth(struct dlist *l, int nth); + +/* End of a file */ diff --git a/include/livebox.h b/include/livebox.h new file mode 100644 index 0000000..667a6e1 --- /dev/null +++ b/include/livebox.h @@ -0,0 +1,212 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 __LIVEBOX_HELPER_H +#define __LIVEBOX_HELPER_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct livebox_buffer; /* Defined by provider */ + +/*! + * \brief + * Return values of livebox programming interfaces. + */ +extern const int DONE; /*!< Operation is successfully done */ +extern const int NEED_TO_SCHEDULE; /*!< Need to call the livebox_need_to_update and livebox_update_content */ +extern const int OUTPUT_UPDATED; /*!< Contents is updated */ +extern const int NEED_TO_CREATE; /*!< Need to create a new instance */ +extern const int NEED_TO_DESTROY; /*!< Need to destroy this instance */ + +extern const int LB_SYS_EVENT_FONT_CHANGED; /*!< System font is changed */ +extern const int LB_SYS_EVENT_LANG_CHANGED; /*!< System language is changed */ +extern const int LB_SYS_EVENT_PAUSED; +extern const int LB_SYS_EVENT_RESUMED; + +#define LB_DESC_TYPE_TEXT "text" +#define LB_DESC_TYPE_IMAGE "image" +#define LB_DESC_TYPE_SIGNAL "signal" +#define LB_DESC_TYPE_INFO "info" +#define LB_DESC_TYPE_DRAG "drag" +#define LB_DESC_TYPE_SCRIPT "script" + +/*! + * \brief + * Extra event informatino for livebox_content_event interface function + */ +#ifndef __PROVIDER_H +struct event_info { + struct { + double x; + double y; + int down; + } pointer; /*!< Down/Up state and mouse position */ + + struct { + double sx; + double sy; + double ex; + double ey; + } part; /*!< Geometry of event received part */ +}; +#endif + +struct livebox_desc; + +/*! + * \brief Update a description file. + * \param[in] filename + * \param[in] for_pd + * \return handle + */ +extern struct livebox_desc *livebox_desc_open(const char *filename, int for_pd); + +/*! + * \brief Complete the description file updating + * \param[in] handle + * \return int + */ +extern int livebox_desc_close(struct livebox_desc *handle); + +/*! + * \brief Set the category information of current description data + * \param[in] handle + * \param[in] id + * \param[in] category + * \return int + */ +extern int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category); + +/*! + * \brief Set the content size + * \param[in] handle + * \param[in] id + * \param[in] w + * \param[in] h + * \return int + */ +extern int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h); + +/*! + * \breif Set the target id of given block + * Only available for the script block + * \param[in] handle + * \param[in] idx + * \param[in] id + * \return ret + */ +extern int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id); + +/*! + * \brief Add a new block + * \param[in] handle + * \param[in] id ID of source script object + * \param[in] type image|text|script|signal|... + * \param[in] part target part to update with given content(data) + * \param[in] data content for specified part + * \param[in] group script group name + * \return idx Index of current description block + */ +extern int livebox_desc_add_block(struct livebox_desc *handle, const char *id, const char *type, const char *part, const char *data, const char *group); + +/*! + * \brief Delete a added block + * \param[in] handle + * \param[in] idx Index of added block + * \return int + */ +extern int livebox_desc_del_block(struct livebox_desc *handle, int idx); + +/*! + * \brief Replace '\n' with '
' + * \param[in] str Source string + * \return char* allocated string + */ +extern char *livebox_util_nl2br(const char *str); + + +/*! + * Interfaces for direct buffer management (Available only for the PD area) + */ + + +#ifndef __PROVIDER_BUFFER_H +/*! + * \NOTE + * This enumeration value should be sync'd with provider + */ +enum buffer_event { + BUFFER_EVENT_ENTER, /*!< */ + BUFFER_EVENT_LEAVE, /*!< */ + BUFFER_EVENT_DOWN, /*!< */ + BUFFER_EVENT_MOVE, /*!< */ + BUFFER_EVENT_UP, /*!< */ +}; +#endif + +/*! + * \brief + * \param[in] filename + * \param[in] width + * \param[in] height + * \param[in] handler + * \param[in] data + * \return handler + */ +extern struct livebox_buffer *livebox_acquire_buffer(const char *filename, int is_pd, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data); + +/*! + * \param[in] filename + * \return pixmap ID + */ +extern unsigned long livebox_pixmap_id(struct livebox_buffer *handle); + +/*! + * \brief + * \param[in] handle + * \return int + */ +extern int livebox_release_buffer(struct livebox_buffer *handle); + +/*! + * \brief + * \param[in] handle + * \return void* buffer + */ +extern void *livebox_ref_buffer(struct livebox_buffer *handle); + +/*! + * \brief + * \param[in] buffer + * \return int + */ +extern int livebox_unref_buffer(void *buffer); + +/*! + * \brief + * \param[in] handler + * \return int + */ +extern int livebox_sync_buffer(struct livebox_buffer *handle); + +#ifdef __cplusplus +} +#endif + +#endif +/* End of a file */ diff --git a/include/livebox_PG.h b/include/livebox_PG.h new file mode 100644 index 0000000..62077ae --- /dev/null +++ b/include/livebox_PG.h @@ -0,0 +1,16 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..85abafa --- /dev/null +++ b/include/util.h @@ -0,0 +1,20 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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. + */ + +extern int util_check_extension(const char *filename, const char *check_ptr); +extern double util_get_timestamp(void); + +/* End of a file */ diff --git a/liblivebox.manifest b/liblivebox.manifest new file mode 100644 index 0000000..a76fdba --- /dev/null +++ b/liblivebox.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/livebox.pc.in b/livebox.pc.in new file mode 100644 index 0000000..60193d3 --- /dev/null +++ b/livebox.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: livebox +Description: livebox supporting library +Version: @VERSION@ +Libs: -L${libdir} -llivebox +Cflags: -I${includedir} +cppflags: -I${includedir} diff --git a/packaging/liblivebox.spec b/packaging/liblivebox.spec new file mode 100644 index 0000000..ae39bc3 --- /dev/null +++ b/packaging/liblivebox.spec @@ -0,0 +1,48 @@ +Name: liblivebox +Summary: Library for the development of a livebox +Version: 0.1.6 +Release: 1 +Group: main/app +License: Flora License +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake, gettext-tools +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(livebox-service) +BuildRequires: pkgconfig(provider) + +%description +Livebox development library + +%package devel +Summary: Files for livebox development. +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +Livebox development library (dev) + +%prep +%setup -q + +%build +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +mkdir -p %{buildroot}/usr/share/license + +%post + +%files -n liblivebox +%manifest liblivebox.manifest +%defattr(-,root,root,-) +/usr/lib/*.so* +/usr/share/license/* + +%files devel +%defattr(-,root,root,-) +/usr/include/livebox/livebox.h +/usr/share/doc/livebox/livebox_PG.h +/usr/lib/pkgconfig/*.pc diff --git a/src/dlist.c b/src/dlist.c new file mode 100644 index 0000000..90a7492 --- /dev/null +++ b/src/dlist.c @@ -0,0 +1,154 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 +#include +#include + +#include "dlist.h" + +struct dlist { + struct dlist *next; + struct dlist *prev; + void *data; +}; + +struct dlist *dlist_append(struct dlist *list, void *data) +{ + struct dlist *item; + + item = malloc(sizeof(*item)); + if (!item) + return NULL; + + item->next = NULL; + item->data = data; + + if (!list) { + item->prev = item; + + list = item; + } else { + item->prev = list->prev; + item->prev->next = item; + + list->prev = item; + } + + assert(!list->prev->next && "item NEXT"); + + return list; +} + +struct dlist *dlist_prepend(struct dlist *list, void *data) +{ + struct dlist *item; + + item = malloc(sizeof(*item)); + if (!item) + return NULL; + + if (!list) { + item->prev = item; + item->next = NULL; + } else { + item->prev = list->prev; + list->prev = item; + item->next = list; + } + + return item; +} + +struct dlist *dlist_remove(struct dlist *list, struct dlist *l) +{ + if (!list || !l) + return NULL; + + if (l == list) { + l->prev = list->prev; + list = l->next; + } else { + l->prev->next = l->next; + } + + if (l->next) + l->next->prev = l->prev; + + free(l); + return list; +} + +struct dlist *dlist_find_data(struct dlist *list, void *data) +{ + struct dlist *l; + void *_data; + + dlist_foreach(list, l, _data) { + if (data == _data) + return l; + } + + return NULL; +} + +void *dlist_data(struct dlist *l) +{ + return l ? l->data : NULL; +} + +struct dlist *dlist_next(struct dlist *l) +{ + return l ? l->next : NULL; +} + +struct dlist *dlist_prev(struct dlist *l) +{ + return l ? l->prev : NULL; +} + +int dlist_count(struct dlist *l) +{ + register int i; + struct dlist *n; + void *data; + + i = 0; + dlist_foreach(l, n, data) { + i++; + } + + return i; +} + +struct dlist *dlist_nth(struct dlist *l, int nth) +{ + register int i; + struct dlist *n; + void *data; + + i = 0; + dlist_foreach(l, n, data) { + if (i == nth) + return l; + + i++; + } + + return NULL; +} + +/* End of a file */ diff --git a/src/livebox.c b/src/livebox.c new file mode 100644 index 0000000..d36e777 --- /dev/null +++ b/src/livebox.c @@ -0,0 +1,537 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 +#include +#include /* malloc */ +#include /* strdup */ +#include + +#include +#include +#include +#include + +#include "debug.h" +#include "livebox.h" +#include "dlist.h" +#include "util.h" + +#define EAPI __attribute__((visibility("default"))) + +/*! + * \brief This function is defined by the data-provider-slave + */ +extern const char *livebox_find_pkgname(const char *filename); + +struct block { + unsigned int idx; + + char *type; + char *part; + char *data; + char *group; + char *id; + char *file; + char *target_id; +}; + +struct livebox_desc { + FILE *fp; + int for_pd; + + unsigned int last_idx; + + struct dlist *block_list; +}; + +EAPI const int DONE = 0x00; +EAPI const int NEED_TO_SCHEDULE = 0x01; +EAPI const int OUTPUT_UPDATED = 0x02; +EAPI const int NEED_TO_CREATE = 0x01; +EAPI const int NEED_TO_DESTROY = 0x01; +EAPI const int LB_SYS_EVENT_FONT_CHANGED = 0x01; +EAPI const int LB_SYS_EVENT_LANG_CHANGED = 0x02; +EAPI const int LB_SYS_EVENT_PAUSED = 0x04; +EAPI const int LB_SYS_EVENT_RESUMED = 0x08; + +EAPI struct livebox_desc *livebox_desc_open(const char *filename, int for_pd) +{ + struct livebox_desc *handle; + char *new_fname; + + handle = calloc(1, sizeof(*handle)); + if (!handle) { + ErrPrint("Error: %s\n", strerror(errno)); + return NULL; + } + + if (for_pd) { + int len; + len = strlen(filename) + strlen(".desc") + 1; + new_fname = malloc(len); + if (!new_fname) { + ErrPrint("Error: %s\n", strerror(errno)); + free(handle); + return NULL; + } + snprintf(new_fname, len, "%s.desc", filename); + } else { + new_fname = strdup(filename); + if (!new_fname) { + ErrPrint("Error: %s\n", strerror(errno)); + free(handle); + return NULL; + } + } + + DbgPrint("Open a new file: %s\n", new_fname); + handle->fp = fopen(new_fname, "w+t"); + free(new_fname); + if (!handle->fp) { + ErrPrint("Failed to open a file: %s\n", strerror(errno)); + free(handle); + return NULL; + } + + return handle; +} + +EAPI int livebox_desc_close(struct livebox_desc *handle) +{ + struct dlist *l; + struct dlist *n; + struct block *block; + + if (!handle) + return -EINVAL; + + DbgPrint("Close and flush\n"); + dlist_foreach_safe(handle->block_list, l, n, block) { + handle->block_list = dlist_remove(handle->block_list, l); + + DbgPrint("{\n"); + fprintf(handle->fp, "{\n"); + if (block->type) { + fprintf(handle->fp, "type=%s\n", block->type); + DbgPrint("type=%s\n", block->type); + } + + if (block->part) { + fprintf(handle->fp, "part=%s\n", block->part); + DbgPrint("part=%s\n", block->part); + } + + if (block->data) { + fprintf(handle->fp, "data=%s\n", block->data); + DbgPrint("data=%s\n", block->data); + } + + if (block->group) { + fprintf(handle->fp, "group=%s\n", block->group); + DbgPrint("group=%s\n", block->group); + } + + if (block->id) { + fprintf(handle->fp, "id=%s\n", block->id); + DbgPrint("id=%s\n", block->id); + } + + if (block->target_id) { + fprintf(handle->fp, "target=%s\n", block->target_id); + DbgPrint("target=%s\n", block->target_id); + } + + fprintf(handle->fp, "}\n"); + DbgPrint("}\n"); + + free(block->type); + free(block->part); + free(block->data); + free(block->group); + free(block->id); + free(block->target_id); + free(block); + } + + fclose(handle->fp); + free(handle); + return 0; +} + +EAPI int livebox_desc_set_category(struct livebox_desc *handle, const char *id, const char *category) +{ + struct block *block; + + if (!handle || !category) + return -EINVAL; + + block = calloc(1, sizeof(*block)); + if (!block) + return -ENOMEM; + + block->type = strdup(LB_DESC_TYPE_INFO); + if (!block->type) { + free(block); + return -ENOMEM; + } + + block->part = strdup("category"); + if (!block->part) { + free(block->type); + free(block); + return -ENOMEM; + } + + block->data = strdup(category); + if (!block->data) { + free(block->type); + free(block->part); + free(block); + return -ENOMEM; + } + + if (id) { + block->id = strdup(id); + if (!block->id) { + free(block->data); + free(block->type); + free(block->part); + free(block); + return -ENOMEM; + } + } + + block->idx = handle->last_idx++; + handle->block_list = dlist_append(handle->block_list, block); + return block->idx; +} + +EAPI int livebox_desc_set_size(struct livebox_desc *handle, const char *id, int w, int h) +{ + struct block *block; + char buffer[BUFSIZ]; + + if (!handle) + return -EINVAL; + + block = calloc(1, sizeof(*block)); + if (!block) + return -ENOMEM; + + block->type = strdup(LB_DESC_TYPE_INFO); + if (!block->type) { + free(block); + return -ENOMEM; + } + + block->part = strdup("size"); + if (!block->part) { + free(block->type); + free(block); + return -ENOMEM; + } + + if (id) { + block->id = strdup(id); + if (!block->id) { + free(block->part); + free(block->type); + free(block); + return -ENOMEM; + } + } + + snprintf(buffer, sizeof(buffer), "%dx%d", w, h); + block->data = strdup(buffer); + if (!block->data) { + free(block->part); + free(block->type); + free(block); + return -ENOMEM; + } + + block->idx = handle->last_idx++; + handle->block_list = dlist_append(handle->block_list, block); + return block->idx; +} + +EAPI char *livebox_util_nl2br(const char *str) +{ + int len; + register int i; + char *ret; + char *ptr; + + if (!str) + return NULL; + + len = strlen(str); + if (!len) + return NULL; + + ret = malloc(len); + if (!ret) + return NULL; + + ptr = ret; + i = 0; + while (*str) { + switch (*str) { + case '\n': + if (len - i < 5) { + char *tmp; + len += len; + + tmp = realloc(ret, len); + if (!tmp) { + free(ret); + return NULL; + } + + ret = tmp; + ptr = tmp + i; + } + + strcpy(ptr, "
"); + ptr += 4; + i += 4; + break; + default: + *ptr++ = *str; + i++; + break; + } + + str++; + } + *ptr = '\0'; + + return ret; +} + +EAPI int livebox_desc_set_id(struct livebox_desc *handle, int idx, const char *id) +{ + struct dlist *l; + struct block *block; + + dlist_foreach(handle->block_list, l, block) { + if (block->idx == idx) { + if (strcasecmp(block->type, LB_DESC_TYPE_SCRIPT)) { + ErrPrint("Invalid block is used\n"); + return -EINVAL; + } + + free(block->target_id); + block->target_id = NULL; + + if (!id || !strlen(id)) + return 0; + + block->target_id = strdup(id); + if (!block->target_id) { + ErrPrint("Heap: %s\n", strerror(errno)); + return -ENOMEM; + } + + return 0; + } + } + + return -ENOENT; +} + +/*! + * \return idx + */ +EAPI int livebox_desc_add_block(struct livebox_desc *handle, const char *id, const char *type, const char *part, const char *data, const char *group) +{ + struct block *block; + + if (!handle || !type) + return -EINVAL; + + if (!part) + part = ""; + + if (!data) + data = ""; + + block = calloc(1, sizeof(*block)); + if (!block) + return -ENOMEM; + + block->type = strdup(type); + if (!block->type) { + free(block); + return -ENOMEM; + } + + block->part = strdup(part); + if (!block->part) { + free(block->type); + free(block); + return -ENOMEM; + } + + block->data = strdup(data); + if (!block->data) { + free(block->type); + free(block->part); + free(block); + return -ENOMEM; + } + + if (group) { + block->group = strdup(group); + if (!block->group) { + free(block->data); + free(block->type); + free(block->part); + free(block); + return -ENOMEM; + } + } + + if (id) { + block->id = strdup(id); + if (!block->id) { + free(block->group); + free(block->data); + free(block->type); + free(block->part); + free(block); + return -ENOMEM; + } + } + + block->idx = handle->last_idx++; + handle->block_list = dlist_append(handle->block_list, block); + return block->idx; +} + +EAPI int livebox_desc_del_block(struct livebox_desc *handle, int idx) +{ + struct dlist *l; + struct block *block; + + dlist_foreach(handle->block_list, l, block) { + if (block->idx == idx) { + handle->block_list = dlist_remove(handle->block_list, l); + free(block->type); + free(block->part); + free(block->data); + free(block->group); + free(block->id); + free(block->target_id); + free(block); + return 0; + } + } + + return -ENOENT; +} + +EAPI struct livebox_buffer *livebox_acquire_buffer(const char *filename, int is_pd, int width, int height, int (*handler)(struct livebox_buffer *, enum buffer_event, double, double, double, void *), void *data) +{ + const char *pkgname; + struct livebox_buffer *handle; + char *uri; + int uri_len; + + if (!filename || !width || !height) { + ErrPrint("Invalid argument: %p(%dx%d)\n", filename, width, height); + return NULL; + } + + uri_len = strlen(filename) + strlen("file://") + 1; + uri = malloc(uri_len); + if (!uri) { + ErrPrint("Heap: %s\n", strerror(errno)); + return NULL; + } + + snprintf(uri, uri_len, "file://%s", filename); + DbgPrint("Before call the livebox_find_pkgname\n"); + pkgname = livebox_find_pkgname(uri); + DbgPrint("After call the livebox_find_pkgname\n"); + if (!pkgname) { + ErrPrint("Invalid Request\n"); + free(uri); + return NULL; + } + + DbgPrint("URI: %s\n", uri); + handle = provider_buffer_acquire((!!is_pd) ? TYPE_PD : TYPE_LB, pkgname, uri, width, height, sizeof(int), handler, data); + DbgPrint("Acquire buffer for PD(%s), %s, %p\n", pkgname, uri, handle); + free(uri); + return handle; +} + +EAPI unsigned long livebox_pixmap_id(struct livebox_buffer *handle) +{ + return provider_buffer_pixmap_id(handle); +} + +EAPI int livebox_release_buffer(struct livebox_buffer *handle) +{ + if (!handle) + return -EINVAL; + + DbgPrint("Release buffer\n"); + return provider_buffer_release(handle); +} + +EAPI void *livebox_ref_buffer(struct livebox_buffer *handle) +{ + if (!handle) + return -EINVAL; + + DbgPrint("Ref buffer\n"); + return provider_buffer_ref(handle); +} + +EAPI int livebox_unref_buffer(void *buffer) +{ + if (!buffer) + return -EINVAL; + + DbgPrint("Unref buffer\n"); + return provider_buffer_unref(buffer); +} + +EAPI int livebox_sync_buffer(struct livebox_buffer *handle) +{ + const char *pkgname; + const char *id; + + if (!handle) + return -EINVAL; + + pkgname = provider_buffer_pkgname(handle); + id = provider_buffer_id(handle); + if (!pkgname || !id) { + ErrPrint("Invalid buffer handler\n"); + return -EINVAL; + } + + DbgPrint("Sync buffer\n"); + provider_buffer_sync(handle); + provider_send_desc_updated(pkgname, id, NULL); + return 0; +} + +/* End of a file */ diff --git a/src/util.c b/src/util.c new file mode 100644 index 0000000..cdcc4cd --- /dev/null +++ b/src/util.c @@ -0,0 +1,53 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 +#include +#include +#include + +#include + +#include "debug.h" +#include "util.h" + +int errno; + +int util_check_extension(const char *filename, const char *check_ptr) +{ + int name_len; + + name_len = strlen(filename); + while (--name_len >= 0 && *check_ptr) { + if (filename[name_len] != *check_ptr) + return -EINVAL; + + check_ptr ++; + } + + return 0; +} + +double util_get_timestamp(void) +{ + struct timeval tv; + + gettimeofday(&tv, NULL); + + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0f; +} + +/* End of a file */ -- 2.7.4