From: YoungHun Kim Date: Fri, 2 Aug 2024 09:22:40 +0000 (+0900) Subject: Update file format X-Git-Tag: accepted/tizen/unified/20240806.010620^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c3eec9f6bb3123cbf319d8e70aef5a0a678a09f9;p=platform%2Fcore%2Fmultimedia%2Frscmgr-service.git Update file format - Remove CRLF line terminators Change-Id: I67e7337314a6f003872d16e0371331a7b28170db --- diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 index bbe9d02..f94008a 100644 --- a/LICENSE.APLv2 +++ b/LICENSE.APLv2 @@ -1,206 +1,206 @@ -Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - 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. - - 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, - 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 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 in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) 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 - - (d) 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 Apache License to your work. - - To apply the Apache 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 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. - - - +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + 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. + + 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, + 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 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 in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) 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 + + (d) 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 Apache License to your work. + + To apply the Apache 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 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. + + + diff --git a/include_internal/CAsyncQueue.h b/include_internal/CAsyncQueue.h index 619ae3a..f5a7f13 100644 --- a/include_internal/CAsyncQueue.h +++ b/include_internal/CAsyncQueue.h @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __C_ASYNC_QUEUE_H__ -#define __C_ASYNC_QUEUE_H__ - -#include - -typedef void (*destoryNotify)(void *data); - -class CAsyncQueue{ -public: - CAsyncQueue(); - CAsyncQueue(destoryNotify destory_cb); - ~CAsyncQueue(); - - void push(void *data); - void push(CAsyncQueue *src_queue); - void push_front(void *data); - void push_front(CAsyncQueue *src_queue); - - void *pop(void); - void *pop(unsigned int timeout_ms); - - int length(void); - -private: - GAsyncQueue *queue; -}; - -#endif // __C_ASYNC_QUEUE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __C_ASYNC_QUEUE_H__ +#define __C_ASYNC_QUEUE_H__ + +#include + +typedef void (*destoryNotify)(void *data); + +class CAsyncQueue{ +public: + CAsyncQueue(); + CAsyncQueue(destoryNotify destory_cb); + ~CAsyncQueue(); + + void push(void *data); + void push(CAsyncQueue *src_queue); + void push_front(void *data); + void push_front(CAsyncQueue *src_queue); + + void *pop(void); + void *pop(unsigned int timeout_ms); + + int length(void); + +private: + GAsyncQueue *queue; +}; + +#endif // __C_ASYNC_QUEUE_H__ diff --git a/include_internal/CCallback.h b/include_internal/CCallback.h index aee85c8..e2dd542 100644 --- a/include_internal/CCallback.h +++ b/include_internal/CCallback.h @@ -1,33 +1,33 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_CCALLBACK_H__ -#define __RMS_CCALLBACK_H__ - -class CCallback -{ -public: - CCallback() {} - ~CCallback() {} - - static void InitCallback(void); - static int SendCallbackMessage(int cid, int pid, void *callback_data, int size, int *err); - static int RemoveFIFOServerToClient(int pid, int cid); - static int ConvertCallbackType(int rm_return_type); - static unsigned int GetTimeout(void); -}; - -#endif //__RMS_CCALLBACK_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_CCALLBACK_H__ +#define __RMS_CCALLBACK_H__ + +class CCallback +{ +public: + CCallback() {} + ~CCallback() {} + + static void InitCallback(void); + static int SendCallbackMessage(int cid, int pid, void *callback_data, int size, int *err); + static int RemoveFIFOServerToClient(int pid, int cid); + static int ConvertCallbackType(int rm_return_type); + static unsigned int GetTimeout(void); +}; + +#endif //__RMS_CCALLBACK_H__ diff --git a/include_internal/CDbusHandler.h b/include_internal/CDbusHandler.h index 711c1e6..504563f 100644 --- a/include_internal/CDbusHandler.h +++ b/include_internal/CDbusHandler.h @@ -1,51 +1,51 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CDBUS_HANDLER_H__ -#define __CDBUS_HANDLER_H__ - -#include -#include - -#include - -class CDbusHandler -{ -public: - CDbusHandler(CAsyncQueue *queue); - ~CDbusHandler() = default; - - static void OnMethodCall(GDBusConnection *conn, const gchar *sender, const gchar *obj_path, const gchar *ifname, const gchar *method_name, GVariant *params, GDBusMethodInvocation *invoc, gpointer data); - static void OnBusAcquired(GDBusConnection *conn, const gchar *bus_name, gpointer data); - static void OnNameLost(GDBusConnection *conn, const gchar *bus_name, gpointer data); - -private: - - static const std::string m_methods; - static const GDBusInterfaceVTable m_vtable; - - GDBusConnection *m_conn; - unsigned int m_reg_id; - unsigned int m_own_id; - - CAsyncQueue *m_async_queue; - - bool MakeDbusConnection(void); - void RegisterObjects(void); - void GenerateReadyEvent(void); -}; - -#endif // __CDBUS_HANDLER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CDBUS_HANDLER_H__ +#define __CDBUS_HANDLER_H__ + +#include +#include + +#include + +class CDbusHandler +{ +public: + CDbusHandler(CAsyncQueue *queue); + ~CDbusHandler() = default; + + static void OnMethodCall(GDBusConnection *conn, const gchar *sender, const gchar *obj_path, const gchar *ifname, const gchar *method_name, GVariant *params, GDBusMethodInvocation *invoc, gpointer data); + static void OnBusAcquired(GDBusConnection *conn, const gchar *bus_name, gpointer data); + static void OnNameLost(GDBusConnection *conn, const gchar *bus_name, gpointer data); + +private: + + static const std::string m_methods; + static const GDBusInterfaceVTable m_vtable; + + GDBusConnection *m_conn; + unsigned int m_reg_id; + unsigned int m_own_id; + + CAsyncQueue *m_async_queue; + + bool MakeDbusConnection(void); + void RegisterObjects(void); + void GenerateReadyEvent(void); +}; + +#endif // __CDBUS_HANDLER_H__ diff --git a/include_internal/CHandle.h b/include_internal/CHandle.h index 2bc26ba..2dfb6d4 100644 --- a/include_internal/CHandle.h +++ b/include_internal/CHandle.h @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_CHANDLE_H__ -#define __RMS_CHANDLE_H__ -#include -class CHandle -{ -public: - CHandle() {} - CHandle(int handle, int is_used, int pid); - ~CHandle() {} - - int handle; - int is_used; - int pid; - int main_priority; - int sub_priority; - int app_pid; - char *app_id; - char process_name[RMS_NAME_BUF_SIZE]; -}; - -#endif //__RMS_CHANDLE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_CHANDLE_H__ +#define __RMS_CHANDLE_H__ +#include +class CHandle +{ +public: + CHandle() {} + CHandle(int handle, int is_used, int pid); + ~CHandle() {} + + int handle; + int is_used; + int pid; + int main_priority; + int sub_priority; + int app_pid; + char *app_id; + char process_name[RMS_NAME_BUF_SIZE]; +}; + +#endif //__RMS_CHANDLE_H__ diff --git a/include_internal/CHandleManager.h b/include_internal/CHandleManager.h index 2280b45..9c27e92 100644 --- a/include_internal/CHandleManager.h +++ b/include_internal/CHandleManager.h @@ -1,52 +1,52 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_CHANDLE_MANAGER_H__ -#define __RMS_CHANDLE_MANAGER_H__ - -#include -#include -#include - -class CHandleManager -{ -public: - CHandleManager(CResourceManager *rsc_mgr); - ~CHandleManager() {} - - int GetNewHandle(int pid, int main_priority, int sub_priority, int app_pid, char *app_id); - int RemoveHandle(int handle, int pid); - int SetPriority(int handle, int main_priority, int sub_priority); - int GetPriority(int handle, int *main_priority, int *sub_priority); - int SetAppID(int handle, char *app_id); - char *GetAppID(int handle); - void ReclaimAllInvalidCustomer(int request_pid); - -private: - int m_RemoveHandle(int handle, int pid); - int m_IsValidHandle(int handle); - int m_ReclaimHandle(void); - int m_AddNewHandle(int handle, int pid, int main_priority, int sub_priority, int app_pid, char *app_id); - int m_PrintHandleInfo(int handle, int pid); - void m_PrintHandleList(void); - CHandle *findHandle(int id); - - CResourceManager *m_rsc_mgr; - int m_next_handle; - std::map m_handles; -}; - -#endif //__RMS_CHANDLE_MANAGER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_CHANDLE_MANAGER_H__ +#define __RMS_CHANDLE_MANAGER_H__ + +#include +#include +#include + +class CHandleManager +{ +public: + CHandleManager(CResourceManager *rsc_mgr); + ~CHandleManager() {} + + int GetNewHandle(int pid, int main_priority, int sub_priority, int app_pid, char *app_id); + int RemoveHandle(int handle, int pid); + int SetPriority(int handle, int main_priority, int sub_priority); + int GetPriority(int handle, int *main_priority, int *sub_priority); + int SetAppID(int handle, char *app_id); + char *GetAppID(int handle); + void ReclaimAllInvalidCustomer(int request_pid); + +private: + int m_RemoveHandle(int handle, int pid); + int m_IsValidHandle(int handle); + int m_ReclaimHandle(void); + int m_AddNewHandle(int handle, int pid, int main_priority, int sub_priority, int app_pid, char *app_id); + int m_PrintHandleInfo(int handle, int pid); + void m_PrintHandleList(void); + CHandle *findHandle(int id); + + CResourceManager *m_rsc_mgr; + int m_next_handle; + std::map m_handles; +}; + +#endif //__RMS_CHANDLE_MANAGER_H__ diff --git a/include_internal/CMessage.h b/include_internal/CMessage.h index fb7e3aa..f7280d3 100644 --- a/include_internal/CMessage.h +++ b/include_internal/CMessage.h @@ -1,63 +1,63 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CMESSAGE_H__ -#define __CMESSAGE_H__ - -#include -#include -#include - -typedef enum { - MSG_SENDER_MSGQ, - MSG_SENDER_DBUS, - MSG_SENDER_INTERNAL -} msg_sender_e; - -class CMessage -{ -public: - CMessage(std::string name); - CMessage(rms_msg_request *msgq_req); - CMessage(GDBusMethodInvocation *invoc); - ~CMessage(); - - int GetReqType(void); - std::string GetName(void) { return m_name; } - msg_sender_e GetSender(void) { return m_sender; } - rms_msg_request *GetRequest(void) { return m_msgq_req; } - GDBusMethodInvocation *GetMethodInvocation(void) { return m_invoc; } - - bool IsUnlockMsg(void); - bool IsMsgFor(ResourceType rsc_type); - void PrintInfo(void); - -private: - rms_msg_request *m_msgq_req; - GDBusMethodInvocation *m_invoc; - msg_sender_e m_sender; - std::string m_name; - - void PrintDbus(void); - void PrintInternal(void); - void PrintMsgQ(void); - - bool IsMsgForScaler(void); - bool IsMsgForScalerDbus(void); - bool IsMsgForScalerMsgQ(void); -}; - -#endif //__CMESSAGE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CMESSAGE_H__ +#define __CMESSAGE_H__ + +#include +#include +#include + +typedef enum { + MSG_SENDER_MSGQ, + MSG_SENDER_DBUS, + MSG_SENDER_INTERNAL +} msg_sender_e; + +class CMessage +{ +public: + CMessage(std::string name); + CMessage(rms_msg_request *msgq_req); + CMessage(GDBusMethodInvocation *invoc); + ~CMessage(); + + int GetReqType(void); + std::string GetName(void) { return m_name; } + msg_sender_e GetSender(void) { return m_sender; } + rms_msg_request *GetRequest(void) { return m_msgq_req; } + GDBusMethodInvocation *GetMethodInvocation(void) { return m_invoc; } + + bool IsUnlockMsg(void); + bool IsMsgFor(ResourceType rsc_type); + void PrintInfo(void); + +private: + rms_msg_request *m_msgq_req; + GDBusMethodInvocation *m_invoc; + msg_sender_e m_sender; + std::string m_name; + + void PrintDbus(void); + void PrintInternal(void); + void PrintMsgQ(void); + + bool IsMsgForScaler(void); + bool IsMsgForScalerDbus(void); + bool IsMsgForScalerMsgQ(void); +}; + +#endif //__CMESSAGE_H__ diff --git a/include_internal/CMessageHandler.h b/include_internal/CMessageHandler.h index 61caafd..f8c3c0d 100644 --- a/include_internal/CMessageHandler.h +++ b/include_internal/CMessageHandler.h @@ -1,124 +1,124 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_CMESSAGE_HANDLER_H__ -#define __RMS_CMESSAGE_HANDLER_H__ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -class CMessageHandler -{ -public: - typedef GVariant *(CMessageHandler::*MsgHandler)(GVariant *params); - - CMessageHandler(CResourceManager *rsc_mgr); - ~CMessageHandler(void); - - int Run(void); - void NotifyWatchdog(void); - -private: - void InitDbusHandlers(void); - void InitInternalMsgHandlers(void); - - static gpointer msgThread(gpointer data); - static gpointer msgQThread(gpointer data); - - int ProcessMessage(void); - int ProcessCallbackMessage(rms_consumer_tobe_returned_s *consumer_info, int requester_cid); - void ProcessMessage(CAsyncQueue *queue, CMessage *msg, int cid_requester, int cid_releaser); - void ProcessMsgQMessage(CMessage *msg); - void ProcessDbusMessage(CMessage *msg); - void ProcessInternalMessage(CMessage *msg); - - void EmptyPendingQueue(void); - void InsertPendingQueue(CMessage *msg); - - int SendResponse(rms_msg_response *response); - int PushMessage(CAsyncQueue *queue, CMessage *msg); - - bool IsRegisteredHandle(int handle); - bool IsValidProcess(int pid); - bool IsValidRequest(int req_type); - bool IsAllResourcesReclaimed(rms_consumer_tobe_returned_s *consumer_info); - - int ReleaseInvalidProcessResources(int pid, int handle); - int ReclaimResources(int reason, int requester_cid, int requester_zone_id, consumer_reclaim_s *conflict_info, bool *need_response); - - void SetRequesterInfo(rms_msg_request *request); - - void m_ConstructResponse(rms_msg_response *response, int data_type, rms_response_type_e msg_type, int handle, int pid); - void m_ConstructRequestedDevice(rms_msg_request *request, rms_requests_device_s *requested_resource); - void m_FreeAllocatedDevice(rms_return_device_s *allocated_device); - int *m_SerializeCallbackData(const rms_consumer_tobe_returned_s *consumer_info, int reason, int *data_size); - void m_Free(consumer_reclaim_s *consumer_info); - - void m_RegisterConsumer(rms_msg_request *request, rms_msg_response *response); - void m_UnregisterConsumer(rms_msg_request *request, rms_msg_response *response); - void m_AllocateResources(rms_msg_request *request, rms_msg_response *response); - void m_ReleaseResources(rms_msg_request *request, rms_msg_response *response); - void m_Query(rms_msg_request *request, rms_msg_response *response); - void m_SetConsumerPriority(rms_msg_request *request, rms_msg_response *response); - void m_SetAppID(rms_msg_request *request, rms_msg_response *response); - - GVariant *RegisterResource(GVariant *params); - GVariant *GetResourceState(GVariant *params); - GVariant *GetResourceList(GVariant *params); - GVariant *GetResourceCollectionState(GVariant *params); - GVariant *FindDeviceId(GVariant *params); - GVariant *SwapResources(GVariant *params); - GVariant *GetScalerState(GVariant *params); - GVariant *GetAppId(GVariant *params); - GVariant *GetActiveAudioOut(GVariant *params); - GVariant *GetScalerHWID(GVariant *params); - GVariant *RestoreResources(GVariant *params); - GVariant *NotifyResourcePolicy(GVariant *params); - GVariant *NotifyAppZoneInfo(GVariant *params); - GVariant *NotifyWatchdog(GVariant *params); - - void NotifyConflict(consumer_reclaim_s *conflict_info, int zone_id); - - unsigned long m_req_timeout = 5; - - CMessageQueue *msgq_rx; - CMessageQueue *msgq_tx; - CAsyncQueue *async_queue; - CAsyncQueue *async_pending_queue; - CLockController *m_lock_ctr; - CResourceManager *m_rsc_mgr; - CHandleManager *m_handle_mgr; - CQueryHandler *m_query_h; - CDbusHandler *m_dbus_h; - - typedef void (CMessageHandler::*msg_handler)(rms_msg_request *request, rms_msg_response *response); - static msg_handler handlers[RMS_REQUEST_MAX]; - std::map m_dbus_handlers; - std::map m_internal_msg_handlers; -}; - -#endif //__RMS_CMESSAGE_HANDLER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_CMESSAGE_HANDLER_H__ +#define __RMS_CMESSAGE_HANDLER_H__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +class CMessageHandler +{ +public: + typedef GVariant *(CMessageHandler::*MsgHandler)(GVariant *params); + + CMessageHandler(CResourceManager *rsc_mgr); + ~CMessageHandler(void); + + int Run(void); + void NotifyWatchdog(void); + +private: + void InitDbusHandlers(void); + void InitInternalMsgHandlers(void); + + static gpointer msgThread(gpointer data); + static gpointer msgQThread(gpointer data); + + int ProcessMessage(void); + int ProcessCallbackMessage(rms_consumer_tobe_returned_s *consumer_info, int requester_cid); + void ProcessMessage(CAsyncQueue *queue, CMessage *msg, int cid_requester, int cid_releaser); + void ProcessMsgQMessage(CMessage *msg); + void ProcessDbusMessage(CMessage *msg); + void ProcessInternalMessage(CMessage *msg); + + void EmptyPendingQueue(void); + void InsertPendingQueue(CMessage *msg); + + int SendResponse(rms_msg_response *response); + int PushMessage(CAsyncQueue *queue, CMessage *msg); + + bool IsRegisteredHandle(int handle); + bool IsValidProcess(int pid); + bool IsValidRequest(int req_type); + bool IsAllResourcesReclaimed(rms_consumer_tobe_returned_s *consumer_info); + + int ReleaseInvalidProcessResources(int pid, int handle); + int ReclaimResources(int reason, int requester_cid, int requester_zone_id, consumer_reclaim_s *conflict_info, bool *need_response); + + void SetRequesterInfo(rms_msg_request *request); + + void m_ConstructResponse(rms_msg_response *response, int data_type, rms_response_type_e msg_type, int handle, int pid); + void m_ConstructRequestedDevice(rms_msg_request *request, rms_requests_device_s *requested_resource); + void m_FreeAllocatedDevice(rms_return_device_s *allocated_device); + int *m_SerializeCallbackData(const rms_consumer_tobe_returned_s *consumer_info, int reason, int *data_size); + void m_Free(consumer_reclaim_s *consumer_info); + + void m_RegisterConsumer(rms_msg_request *request, rms_msg_response *response); + void m_UnregisterConsumer(rms_msg_request *request, rms_msg_response *response); + void m_AllocateResources(rms_msg_request *request, rms_msg_response *response); + void m_ReleaseResources(rms_msg_request *request, rms_msg_response *response); + void m_Query(rms_msg_request *request, rms_msg_response *response); + void m_SetConsumerPriority(rms_msg_request *request, rms_msg_response *response); + void m_SetAppID(rms_msg_request *request, rms_msg_response *response); + + GVariant *RegisterResource(GVariant *params); + GVariant *GetResourceState(GVariant *params); + GVariant *GetResourceList(GVariant *params); + GVariant *GetResourceCollectionState(GVariant *params); + GVariant *FindDeviceId(GVariant *params); + GVariant *SwapResources(GVariant *params); + GVariant *GetScalerState(GVariant *params); + GVariant *GetAppId(GVariant *params); + GVariant *GetActiveAudioOut(GVariant *params); + GVariant *GetScalerHWID(GVariant *params); + GVariant *RestoreResources(GVariant *params); + GVariant *NotifyResourcePolicy(GVariant *params); + GVariant *NotifyAppZoneInfo(GVariant *params); + GVariant *NotifyWatchdog(GVariant *params); + + void NotifyConflict(consumer_reclaim_s *conflict_info, int zone_id); + + unsigned long m_req_timeout = 5; + + CMessageQueue *msgq_rx; + CMessageQueue *msgq_tx; + CAsyncQueue *async_queue; + CAsyncQueue *async_pending_queue; + CLockController *m_lock_ctr; + CResourceManager *m_rsc_mgr; + CHandleManager *m_handle_mgr; + CQueryHandler *m_query_h; + CDbusHandler *m_dbus_h; + + typedef void (CMessageHandler::*msg_handler)(rms_msg_request *request, rms_msg_response *response); + static msg_handler handlers[RMS_REQUEST_MAX]; + std::map m_dbus_handlers; + std::map m_internal_msg_handlers; +}; + +#endif //__RMS_CMESSAGE_HANDLER_H__ diff --git a/include_internal/CMessageQueue.h b/include_internal/CMessageQueue.h index 7630413..bf84783 100644 --- a/include_internal/CMessageQueue.h +++ b/include_internal/CMessageQueue.h @@ -1,49 +1,49 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CMESSAGE_QUEUE_H__ -#define __CMESSAGE_QUEUE_H__ - -#include -#include - -typedef enum { - MSG_QUEUE_RX = 0, - MSG_QUEUE_TX -} msgq_type_e; - -class CMessageQueue{ -public: - CMessageQueue(msgq_type_e type); - ~CMessageQueue(); - - int receive(rms_msg_request *req, int msg_type); - int send(rms_msg_response *response); - -private: - int init(void); - int recover(void); - static int getKey(msgq_type_e type); - - msgq_type_e msgq_type; - int msgq_id; - - static const long msgq_size = 131072; // 128KB - static const int key_rx = 8211; - static const int key_tx = 8212; -}; - -#endif //__CMESSAGE_QUEUE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CMESSAGE_QUEUE_H__ +#define __CMESSAGE_QUEUE_H__ + +#include +#include + +typedef enum { + MSG_QUEUE_RX = 0, + MSG_QUEUE_TX +} msgq_type_e; + +class CMessageQueue{ +public: + CMessageQueue(msgq_type_e type); + ~CMessageQueue(); + + int receive(rms_msg_request *req, int msg_type); + int send(rms_msg_response *response); + +private: + int init(void); + int recover(void); + static int getKey(msgq_type_e type); + + msgq_type_e msgq_type; + int msgq_id; + + static const long msgq_size = 131072; // 128KB + static const int key_rx = 8211; + static const int key_tx = 8212; +}; + +#endif //__CMESSAGE_QUEUE_H__ diff --git a/include_internal/CQueryHandler.h b/include_internal/CQueryHandler.h index 2a1bcaa..ea38a9c 100644 --- a/include_internal/CQueryHandler.h +++ b/include_internal/CQueryHandler.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CQUERY_HANDLER_H__ -#define __CQUERY_HANDLER_H__ - -#include -#include - -class CQueryHandler -{ -public: - CQueryHandler(CResourceManager *rsc_mgr); - ~CQueryHandler(); - - int GetAnswer(rms_msg_request *request, int *answer_out); -private: - CResourceManager *m_rsc_mgr; -}; - -#endif //__CQUERY_HANDLER_H__ \ No newline at end of file +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CQUERY_HANDLER_H__ +#define __CQUERY_HANDLER_H__ + +#include +#include + +class CQueryHandler +{ +public: + CQueryHandler(CResourceManager *rsc_mgr); + ~CQueryHandler(); + + int GetAnswer(rms_msg_request *request, int *answer_out); +private: + CResourceManager *m_rsc_mgr; +}; + +#endif //__CQUERY_HANDLER_H__ diff --git a/include_internal/CRequest.h b/include_internal/CRequest.h index e98279b..fa52674 100644 --- a/include_internal/CRequest.h +++ b/include_internal/CRequest.h @@ -1,94 +1,94 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CREQUEST_H__ -#define __CREQUEST_H__ - -#include "rms_type.h" - -class CRequester; -class CRequest -{ -public: - CRequest(CRequester *requester); - ~CRequest(); - - CRequester *getRequester(void); - - void SetCategory(int category_id, int category_option); - void SetState(int req_state); - - void SetResult(rms_return_code_e req_result); - void SetReason(rms_error_type_e reason) { m_reason = reason; } - void ResetResult(void) { m_result = RMS_ERROR; } - void SetCandidateDevice(int device_id) { m_candidate_device = device_id; } - void SetAllocatedDevice(int device_id) { m_allocated_device = device_id; } - void SetAllocatedVirtualDevice(int virtual_id) { m_virtual_device = virtual_id; } - - bool IsRequestByDevice(void) { return (m_device_id > 0); } - bool IsMainDeviceRequest(void); - bool IsSubDeviceRequest(void); - bool IsAIDeviceRequest(void); - - rms_rsc_category_e GetCategory(void); - int GetDevice(void) { return m_device_id; } - rms_requests_resource_state_e GetState(void) { return m_state; } - rms_error_type_e GetReason(void) { return m_reason; } - - rms_return_code_e GetResult(void); - int GetCandidateDevice(void) { return m_candidate_device; } - int GetAllocatedDevice(void) { return m_allocated_device; } - int GetAllocatedVirtualDevice(void) { return m_virtual_device; } - rms_mixing_mode_e GetMixingMode(void) { return m_mixing_mode; } - - int GetMultiviewZoneId(void) { return m_mv_zone_id; } - void PrintResult(void); - -private: - rms_rsc_category_e ToVideoDecoderCategory(int category, int category_option, bool force_main, bool force_sub); - rms_rsc_category_e ToJpegDecoderCategory(int category, int category_option); - rms_rsc_category_e ToMJpegDecoderCategory(int category, int category_option); - rms_rsc_category_e ToAudioDecoderCategory(int category, int category_option, bool force_main, bool force_sub); - rms_rsc_category_e ToScalerCategory(int category, int category_option, bool force_main, bool force_sub); - rms_rsc_category_e ToAudioOutCategory(int category, int category_option, bool force_main, bool force_sub); - rms_rsc_category_e ToResourceCategory(int category, int category_option); - rms_rsc_category_e ToImageDecoderCategory(int category, int category_option); - rms_mixing_mode_e ToMixingMode(int category, int category_option); - int ToMultiviewZoneId(int category_option); - bool IsSupportedCategory(int category_option); - int UnmaskMainSubOptions(int category_option); - int UnmaskMixingOptions(int category_option); - int UnmaskMVZoneInfo(int category_option); - int UnmaskForceOptions(int category_option); - - CRequester *m_requester; - - int m_category_id; - int m_category_option; - rms_rsc_category_e m_category; - rms_requests_resource_state_e m_state; - rms_mixing_mode_e m_mixing_mode; - int m_device_id; - - rms_return_code_e m_result; - int m_candidate_device; - int m_allocated_device; - int m_virtual_device; - int m_mv_zone_id; - rms_error_type_e m_reason; -}; - -#endif //__CREQUEST_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CREQUEST_H__ +#define __CREQUEST_H__ + +#include "rms_type.h" + +class CRequester; +class CRequest +{ +public: + CRequest(CRequester *requester); + ~CRequest(); + + CRequester *getRequester(void); + + void SetCategory(int category_id, int category_option); + void SetState(int req_state); + + void SetResult(rms_return_code_e req_result); + void SetReason(rms_error_type_e reason) { m_reason = reason; } + void ResetResult(void) { m_result = RMS_ERROR; } + void SetCandidateDevice(int device_id) { m_candidate_device = device_id; } + void SetAllocatedDevice(int device_id) { m_allocated_device = device_id; } + void SetAllocatedVirtualDevice(int virtual_id) { m_virtual_device = virtual_id; } + + bool IsRequestByDevice(void) { return (m_device_id > 0); } + bool IsMainDeviceRequest(void); + bool IsSubDeviceRequest(void); + bool IsAIDeviceRequest(void); + + rms_rsc_category_e GetCategory(void); + int GetDevice(void) { return m_device_id; } + rms_requests_resource_state_e GetState(void) { return m_state; } + rms_error_type_e GetReason(void) { return m_reason; } + + rms_return_code_e GetResult(void); + int GetCandidateDevice(void) { return m_candidate_device; } + int GetAllocatedDevice(void) { return m_allocated_device; } + int GetAllocatedVirtualDevice(void) { return m_virtual_device; } + rms_mixing_mode_e GetMixingMode(void) { return m_mixing_mode; } + + int GetMultiviewZoneId(void) { return m_mv_zone_id; } + void PrintResult(void); + +private: + rms_rsc_category_e ToVideoDecoderCategory(int category, int category_option, bool force_main, bool force_sub); + rms_rsc_category_e ToJpegDecoderCategory(int category, int category_option); + rms_rsc_category_e ToMJpegDecoderCategory(int category, int category_option); + rms_rsc_category_e ToAudioDecoderCategory(int category, int category_option, bool force_main, bool force_sub); + rms_rsc_category_e ToScalerCategory(int category, int category_option, bool force_main, bool force_sub); + rms_rsc_category_e ToAudioOutCategory(int category, int category_option, bool force_main, bool force_sub); + rms_rsc_category_e ToResourceCategory(int category, int category_option); + rms_rsc_category_e ToImageDecoderCategory(int category, int category_option); + rms_mixing_mode_e ToMixingMode(int category, int category_option); + int ToMultiviewZoneId(int category_option); + bool IsSupportedCategory(int category_option); + int UnmaskMainSubOptions(int category_option); + int UnmaskMixingOptions(int category_option); + int UnmaskMVZoneInfo(int category_option); + int UnmaskForceOptions(int category_option); + + CRequester *m_requester; + + int m_category_id; + int m_category_option; + rms_rsc_category_e m_category; + rms_requests_resource_state_e m_state; + rms_mixing_mode_e m_mixing_mode; + int m_device_id; + + rms_return_code_e m_result; + int m_candidate_device; + int m_allocated_device; + int m_virtual_device; + int m_mv_zone_id; + rms_error_type_e m_reason; +}; + +#endif //__CREQUEST_H__ diff --git a/include_internal/CRequester.h b/include_internal/CRequester.h index 03a12a0..0cd015a 100644 --- a/include_internal/CRequester.h +++ b/include_internal/CRequester.h @@ -1,48 +1,48 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CREQUESTER_H__ -#define __CREQUESTER_H__ - -#include - -#include "rms_type.h" - -class CRequester -{ -public: - CRequester(); - CRequester(rms_msg_request *req); - ~CRequester(); - - int getHandle(void); - int getPid(void); - int getMainPriority(void); - int getSubPriority(void); - std::string getAppId(void) { return m_app_id; } - void SetCmdName(int pid); - std::string GetCmdName(void) { return m_cmd_name; } - -private: - int m_handle; - int m_pid; - int m_main_priority; - int m_sub_priority; - std::string m_app_id; - std::string m_cmd_name; -}; - -#endif // __CREQUESTER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CREQUESTER_H__ +#define __CREQUESTER_H__ + +#include + +#include "rms_type.h" + +class CRequester +{ +public: + CRequester(); + CRequester(rms_msg_request *req); + ~CRequester(); + + int getHandle(void); + int getPid(void); + int getMainPriority(void); + int getSubPriority(void); + std::string getAppId(void) { return m_app_id; } + void SetCmdName(int pid); + std::string GetCmdName(void) { return m_cmd_name; } + +private: + int m_handle; + int m_pid; + int m_main_priority; + int m_sub_priority; + std::string m_app_id; + std::string m_cmd_name; +}; + +#endif // __CREQUESTER_H__ diff --git a/include_internal/CResourceService.h b/include_internal/CResourceService.h index c91d54b..e8e4e5d 100644 --- a/include_internal/CResourceService.h +++ b/include_internal/CResourceService.h @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_CRESOURCE_SERVICE_H__ -#define __RMS_CRESOURCE_SERVICE_H__ - -#include -#include - -class CResourceService -{ -public: - CResourceService(void) {} - ~CResourceService(void) {} - int Init(GMainLoop *main_loop); - -private: - - CMessageHandler *m_msg_h; - - int IsFirstLaunch(void); - void RequestColdPowerOff(void); - void CreateWatchDogTimer(void); - void SetVIPProcess(void); - static gboolean WatchDogCallback(gpointer data); - static gboolean InvalidResourceTableMsgCallback(gpointer data); -}; - -#endif //__RMS_CRESOURCE_SERVICE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_CRESOURCE_SERVICE_H__ +#define __RMS_CRESOURCE_SERVICE_H__ + +#include +#include + +class CResourceService +{ +public: + CResourceService(void) {} + ~CResourceService(void) {} + int Init(GMainLoop *main_loop); + +private: + + CMessageHandler *m_msg_h; + + int IsFirstLaunch(void); + void RequestColdPowerOff(void); + void CreateWatchDogTimer(void); + void SetVIPProcess(void); + static gboolean WatchDogCallback(gpointer data); + static gboolean InvalidResourceTableMsgCallback(gpointer data); +}; + +#endif //__RMS_CRESOURCE_SERVICE_H__ diff --git a/include_internal/CSysInfo.h b/include_internal/CSysInfo.h index 6347f53..f906ad5 100644 --- a/include_internal/CSysInfo.h +++ b/include_internal/CSysInfo.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CSYS_INFO_H__ -#define __CSYS_INFO_H__ - -class CSysInfo -{ -public: - ~CSysInfo() = default; - - static CSysInfo *GetInstance(void); - bool IsAudioMixingSupported(void); -private: - CSysInfo() = default; - - static CSysInfo *m_instance; - bool m_support_audio_mixing; -}; - -#endif //__CSYS_INFO_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CSYS_INFO_H__ +#define __CSYS_INFO_H__ + +class CSysInfo +{ +public: + ~CSysInfo() = default; + + static CSysInfo *GetInstance(void); + bool IsAudioMixingSupported(void); +private: + CSysInfo() = default; + + static CSysInfo *m_instance; + bool m_support_audio_mixing; +}; + +#endif //__CSYS_INFO_H__ diff --git a/include_internal/manager/CCache.h b/include_internal/manager/CCache.h index 553b985..aebacc7 100644 --- a/include_internal/manager/CCache.h +++ b/include_internal/manager/CCache.h @@ -1,40 +1,40 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CCACHE_H__ -#define __CCACHE_H__ - -#include -#include - -class CCache -{ -public: - static CCache *getInstance(void); - ~CCache() = default; - - void Drop(void); - int GetAppStatus(std::string app_id); - void SetAppStatus(std::string app_id, int status); - -private: - CCache() = default; - - static CCache *m_instance; - std::map m_visibility; // app id, app status -}; - -#endif //__CCACHE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CCACHE_H__ +#define __CCACHE_H__ + +#include +#include + +class CCache +{ +public: + static CCache *getInstance(void); + ~CCache() = default; + + void Drop(void); + int GetAppStatus(std::string app_id); + void SetAppStatus(std::string app_id, int status); + +private: + CCache() = default; + + static CCache *m_instance; + std::map m_visibility; // app id, app status +}; + +#endif //__CCACHE_H__ diff --git a/include_internal/manager/CConsumer.h b/include_internal/manager/CConsumer.h index d79039f..2292aaa 100644 --- a/include_internal/manager/CConsumer.h +++ b/include_internal/manager/CConsumer.h @@ -1,67 +1,67 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_CONSUMER_H__ -#define __RSC_MGR_SERVER_CONSUMER_H__ - -#include -#include -#include - -class CConsumer -{ -public: - CConsumer(IN const rms_consumer_s *consumer); - virtual ~CConsumer() {} - - long GetPid(void) { return m_pid; } - int GetId(void) { return m_consumerID; } - void SetAppID(IN const char *app_id); - std::string GetAppID(void) { return m_app_id; } - std::string GetCmdName(void) { return m_cmd_name; } - - bool AddResource(IN int device_id); - int ReleaseResource(IN int device_id); - bool IsUsingResource(IN int device_id); - std::set GetResources(void) { return m_resources; } - int GetResourceNum(void) { return m_resources.size(); } - - void SetPriority(rms_priority_s priority) { m_priority = priority; } - rms_error_type_e ComparePriority(CConsumer *requester); - -private: - rms_priority_s GetPriority(void) { return m_priority; } - bool ComparePriority(IN rms_priority_s priority1, IN rms_priority_s priority2); - bool CheckVisibility(IN std::string app_id_requester); - bool GetAppVisibility(IN std::string app_id, bool requester); - bool CheckWebAppState(IN std::string app_id_requesting); - bool IsVisibleStatus(int status); - bool NeedStatusUpdate(std::string app_id); - int UpdateAppStatus(std::string app_id); - void SetCmdName(long pid); - std::string GetAppId(int pid); - - std::set m_resources; - - int m_consumerID; - rms_priority_s m_priority; - long m_pid; - std::string m_app_id; - std::string m_cmd_name; -}; - - -#endif // __RSC_MGR_SERVER_CONSUMER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_CONSUMER_H__ +#define __RSC_MGR_SERVER_CONSUMER_H__ + +#include +#include +#include + +class CConsumer +{ +public: + CConsumer(IN const rms_consumer_s *consumer); + virtual ~CConsumer() {} + + long GetPid(void) { return m_pid; } + int GetId(void) { return m_consumerID; } + void SetAppID(IN const char *app_id); + std::string GetAppID(void) { return m_app_id; } + std::string GetCmdName(void) { return m_cmd_name; } + + bool AddResource(IN int device_id); + int ReleaseResource(IN int device_id); + bool IsUsingResource(IN int device_id); + std::set GetResources(void) { return m_resources; } + int GetResourceNum(void) { return m_resources.size(); } + + void SetPriority(rms_priority_s priority) { m_priority = priority; } + rms_error_type_e ComparePriority(CConsumer *requester); + +private: + rms_priority_s GetPriority(void) { return m_priority; } + bool ComparePriority(IN rms_priority_s priority1, IN rms_priority_s priority2); + bool CheckVisibility(IN std::string app_id_requester); + bool GetAppVisibility(IN std::string app_id, bool requester); + bool CheckWebAppState(IN std::string app_id_requesting); + bool IsVisibleStatus(int status); + bool NeedStatusUpdate(std::string app_id); + int UpdateAppStatus(std::string app_id); + void SetCmdName(long pid); + std::string GetAppId(int pid); + + std::set m_resources; + + int m_consumerID; + rms_priority_s m_priority; + long m_pid; + std::string m_app_id; + std::string m_cmd_name; +}; + + +#endif // __RSC_MGR_SERVER_CONSUMER_H__ diff --git a/include_internal/manager/CConsumerContainer.h b/include_internal/manager/CConsumerContainer.h index 750fdbd..3b995b5 100644 --- a/include_internal/manager/CConsumerContainer.h +++ b/include_internal/manager/CConsumerContainer.h @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CCONSUMER_CONTAINER_H__ -#define __CCONSUMER_CONTAINER_H__ - -#include -#include - -class CConsumer; -class CConsumerContainer -{ -public: - static CConsumerContainer *getInstance(void); - ~CConsumerContainer() = default; - - bool AddConsumer(int consumer_id, CConsumer *consumer); - void RemoveConsumer(int consumer_id); - CConsumer *findConsumer(int consumer_id); - std::map FindConsumers(std::string app_id); - std::map findConsumers(int pid); - -private: - CConsumerContainer() = default; - - static CConsumerContainer *m_instance; - std::map m_consumers; -}; - -#endif // __CCONSUMER_CONTAINER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CCONSUMER_CONTAINER_H__ +#define __CCONSUMER_CONTAINER_H__ + +#include +#include + +class CConsumer; +class CConsumerContainer +{ +public: + static CConsumerContainer *getInstance(void); + ~CConsumerContainer() = default; + + bool AddConsumer(int consumer_id, CConsumer *consumer); + void RemoveConsumer(int consumer_id); + CConsumer *findConsumer(int consumer_id); + std::map FindConsumers(std::string app_id); + std::map findConsumers(int pid); + +private: + CConsumerContainer() = default; + + static CConsumerContainer *m_instance; + std::map m_consumers; +}; + +#endif // __CCONSUMER_CONTAINER_H__ diff --git a/include_internal/manager/CDebugUtils.h b/include_internal/manager/CDebugUtils.h index 8ce5a50..fcff70d 100644 --- a/include_internal/manager/CDebugUtils.h +++ b/include_internal/manager/CDebugUtils.h @@ -1,53 +1,53 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_DEBUGUTILS_H__ -#define __RSC_MGR_SERVER_DEBUGUTILS_H__ - -#include -#include -#include - -#define RMS_CONSOLE_BUF_SIZE 256 - -typedef enum { - RMS_ALARM_NO_CALLBACK_RESPONSE, - RMS_ALARM_NO_DEALLOCATION, -} rms_alarm_reason_e; - -const char *rm_convert_state_enum_to_string(rms_resource_internal_state_e state_enum); -const char *rm_convert_requested_state_enum_to_string(rms_requests_resource_state_e state_enum); -const char *rm_convert_category_enum_to_string(rms_rsc_category_e category_enum); -const char *rm_print_allocation_failure_reason(int ret_value); -const char *rm_convert_device_enum_to_string(rms_device_e device_enum); - -int rms_get_cmd_name(pid_t pid, char *name_out, int size); -void rms_print_log_console(char *buf); - -int rm_get_product_type(void); -int rm_is_valid_pid(int pid); -int rms_report_emergency(IN int cid, IN int pid, IN int requester); - -int is_symlink_file(const char *path); -const char *rm_convert_error_type_to_string(rms_error_type_e error_type); - -void rms_display_timeout_error_popup(rms_alarm_reason_e reason, rms_consumer_tobe_returned_s info); -void rms_display_resource_table_error_popup(void); -void rms_print_model_info(void); - -bool process_htable_contains(const char *name); - -#endif //__RSC_MGR_SERVER_DEBUGUTILS_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_DEBUGUTILS_H__ +#define __RSC_MGR_SERVER_DEBUGUTILS_H__ + +#include +#include +#include + +#define RMS_CONSOLE_BUF_SIZE 256 + +typedef enum { + RMS_ALARM_NO_CALLBACK_RESPONSE, + RMS_ALARM_NO_DEALLOCATION, +} rms_alarm_reason_e; + +const char *rm_convert_state_enum_to_string(rms_resource_internal_state_e state_enum); +const char *rm_convert_requested_state_enum_to_string(rms_requests_resource_state_e state_enum); +const char *rm_convert_category_enum_to_string(rms_rsc_category_e category_enum); +const char *rm_print_allocation_failure_reason(int ret_value); +const char *rm_convert_device_enum_to_string(rms_device_e device_enum); + +int rms_get_cmd_name(pid_t pid, char *name_out, int size); +void rms_print_log_console(char *buf); + +int rm_get_product_type(void); +int rm_is_valid_pid(int pid); +int rms_report_emergency(IN int cid, IN int pid, IN int requester); + +int is_symlink_file(const char *path); +const char *rm_convert_error_type_to_string(rms_error_type_e error_type); + +void rms_display_timeout_error_popup(rms_alarm_reason_e reason, rms_consumer_tobe_returned_s info); +void rms_display_resource_table_error_popup(void); +void rms_print_model_info(void); + +bool process_htable_contains(const char *name); + +#endif //__RSC_MGR_SERVER_DEBUGUTILS_H__ diff --git a/include_internal/manager/CLockController.h b/include_internal/manager/CLockController.h index 24a85ed..0f7ad78 100644 --- a/include_internal/manager/CLockController.h +++ b/include_internal/manager/CLockController.h @@ -1,45 +1,45 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CLOCK_CONTROLLER_H__ -#define __CLOCK_CONTROLLER_H__ - -#include -#include -#include - -class CLockController -{ -public: - static CLockController *GetInstance(void); - void SetMsgQ(CAsyncQueue *queue) { m_msg_q = queue; } - - void Lock(ResourceType rsc_type); - void Unlock(ResourceType rsc_type); - unsigned int GetLockCount(void); - bool IsLocked(CMessage *msg); - -private: - CLockController() = default; - ~CLockController() = default; - void NotifyUnlock(void); - - static CLockController *m_instance; - std::map m_locks; - CAsyncQueue *m_msg_q; -}; - -#endif //__CLOCK_CONTROLLER_H__S +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CLOCK_CONTROLLER_H__ +#define __CLOCK_CONTROLLER_H__ + +#include +#include +#include + +class CLockController +{ +public: + static CLockController *GetInstance(void); + void SetMsgQ(CAsyncQueue *queue) { m_msg_q = queue; } + + void Lock(ResourceType rsc_type); + void Unlock(ResourceType rsc_type); + unsigned int GetLockCount(void); + bool IsLocked(CMessage *msg); + +private: + CLockController() = default; + ~CLockController() = default; + void NotifyUnlock(void); + + static CLockController *m_instance; + std::map m_locks; + CAsyncQueue *m_msg_q; +}; + +#endif //__CLOCK_CONTROLLER_H__S diff --git a/include_internal/manager/CPriority.h b/include_internal/manager/CPriority.h index 21cde0f..dec6d16 100644 --- a/include_internal/manager/CPriority.h +++ b/include_internal/manager/CPriority.h @@ -1,42 +1,42 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CPRIORITY_H__ -#define __CPRIORITY_H__ - -#include - -enum { - LOW_PRIORITY = -1, - SAME_PRIORITY = 0, - HIGH_PRIORITY = 1 -}; - -class CPriority -{ -public:; - ~CPriority(); - - static bool isReclaimableConsumer(int consumer_id, int requester_id, rms_error_type_e *err_type); - static int compareCurConsumers(int device_id, int consumer_id); - static int compare(int cur_consumer_id, int consumer_id); - static int getReclaimableConsumers(int device_id, int consumer_id, std::multimap* reclaimables, rms_error_type_e *err_type); - static int getReclaimableConsumersShare(int device_id, int consumer_id, std::multimap* reclaimables, rms_error_type_e *err_type); -private: - CPriority(); -}; - -#endif //__CPRIORITY_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CPRIORITY_H__ +#define __CPRIORITY_H__ + +#include + +enum { + LOW_PRIORITY = -1, + SAME_PRIORITY = 0, + HIGH_PRIORITY = 1 +}; + +class CPriority +{ +public:; + ~CPriority(); + + static bool isReclaimableConsumer(int consumer_id, int requester_id, rms_error_type_e *err_type); + static int compareCurConsumers(int device_id, int consumer_id); + static int compare(int cur_consumer_id, int consumer_id); + static int getReclaimableConsumers(int device_id, int consumer_id, std::multimap* reclaimables, rms_error_type_e *err_type); + static int getReclaimableConsumersShare(int device_id, int consumer_id, std::multimap* reclaimables, rms_error_type_e *err_type); +private: + CPriority(); +}; + +#endif //__CPRIORITY_H__ diff --git a/include_internal/manager/CResource.h b/include_internal/manager/CResource.h index 9ef1360..63a3bcc 100644 --- a/include_internal/manager/CResource.h +++ b/include_internal/manager/CResource.h @@ -1,141 +1,141 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_RESOURCE_H__ -#define __RSC_MGR_SERVER_RESOURCE_H__ - -#include -#include -#include -#include - -#include -#include - -class CResource : public CResourceSubject -{ -public: - CResource(IN const int device_id, IN const rms_rsc_category_e category_type, IN const char *name, IN const char *path, - IN std::set mem_cluster, IN int is_main_device, IN const char *audio_codec, IN int sharable_count); - ~CResource(); - - std::string GetName(void) { return std::string(m_device_name); } - int GetDeviceID(void) { return m_id; } - int GetVirtualResourceID(void) { return m_vrsc_id; } - const char *GetDevicePath(void) { return m_device_path; } - std::string GetAudioCodec(void) { return m_audio_codec; } - rms_mixing_mode_e GetMixingMode(void) { return m_mixing_mode; } - rms_rsc_category_e GetCategoryType(void) { return m_category_type; } - int GetCurCategory(void) { return m_cur_category; } - int getSharableCount(void) { return (m_sharable_count - m_shared_count - m_reserved_count); } - int GetCategoryClass(void) { return m_category_class; } - - bool IsFreeState(void) { return m_state == RMS_INTERNAL_STATE_FREE; }; - bool IsAllocatableState(IN rms_requests_resource_state_e requested_state); - bool IsSharableState(void) { return (m_state == RMS_INTERNAL_STATE_FREE || m_state == RMS_INTERNAL_STATE_SHARABLE); } - bool IsReserved(void) { return m_is_reserved; } - bool IsSharableDevice(void) { return (m_sharable_count >= 2); } - bool IsMainDevice(void) { return m_is_main_device; } - bool IsAudioDevice(void); - bool IsVideoDecoder(void); - bool IsScaler(void) { return m_is_scaler; } - bool IsJpegDecoder(void); - - void AddConsumer(IN int consumer_id, IN rms_requests_resource_state_e state); - void ResetConsumer(std::set new_consumers); - int RemoveConsumer(IN int consumer_id, IN bool force); - std::set GetConsumers(void) { return m_consumer_ids; } - int GetFirstConsumer(void); - - int Reserve(IN int consumer_id, rms_requests_resource_state_e state); - void CancelReservation(rms_requests_resource_state_e state); - - void SetDefaultBW(unsigned int bw); - unsigned int GetBW(void) { return m_occupied_bw; } - int GetDefaultBW(void) { return m_default_bw; } - void ResetBW(void) { m_occupied_bw = m_default_bw; } - void SetAllocatedTime(void); - unsigned long GetAllocatedTime(void) { return m_allocated_time; } - - void SetVirtualDeviceId(int id) { m_virtual_id = id; } - int GetVirtualDeviceId(void); - void SetDedicatedVirtualDeviceId(int id) { m_dedicated_virtual_id = id; } - int GetDedicatedVirtualDeviceId(void) { return m_dedicated_virtual_id; } - - std::set GetMemClusters(void) { return m_mem_clusters; } - void UpdateProperties(std::set mem_clusters, int bw, int category, int category_class, int vrsc_id); - void UpdateAudioCodec(std::string codec_name); - void updateMixingMode(rms_mixing_mode_e mode) { m_mixing_mode = mode; } - - void RegisterObserver(CResourceObserver *observer); - void UnregisterObserver(CResourceObserver *observer); - - bool Allocate(const int consumer_id, rms_requests_resource_state_e state, int mv_zone_id); - int GetState(void) { return (int) m_state; } - int GetZoneId(void) { return m_mv_zone_id; } - void SetZoneId(int zone_id); - - void ChangeState(rms_resource_internal_state_e next_state); - -private: - void m_SetSubScalerFlag(int next_state); - bool IsRegisteredConsumer(int consumer_id); - int IncreaseRefCount(int consumer_id); - int DecreaseRefCount(int consumer_id); - void NotifyObservers(resource_update_type_e type, int consumer_id); - bool ChangeStateByAllocation(IN rms_requests_resource_state_e state, const int consumer_id, int mv_zone_id); - bool ChangeStateByRelease(int consumer_id); - bool IsScaler(rms_rsc_category_e category); - - int ReserveExclusive(int consumer_id); - int ReserveShared(int consumer_id); - - std::map m_consumers; // consumer id, cnt - std::set m_shared_consumers; - std::set m_consumer_ids; - - int m_id; - int m_vrsc_id; - int m_virtual_id; - int m_dedicated_virtual_id; - rms_resource_internal_state_e m_state; - rms_rsc_category_e m_category_type; - const char *m_device_name; - const char *m_device_path; - int m_category_class; - int m_cur_category; - - unsigned int m_occupied_bw; - unsigned int m_default_bw; - int m_is_main_device; - int m_sharable_count; - - bool m_is_reserved; - bool m_is_scaler; - int m_reserved_consumer_id; - unsigned long m_allocated_time; - - int m_shared_count; - int m_reserved_count; - int m_mv_zone_id; - - std::string m_audio_codec; - std::vector m_observers; - std::set m_mem_clusters; - rms_mixing_mode_e m_mixing_mode; -}; - -#endif // __RSC_MGR_SERVER_RESOURCE_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_RESOURCE_H__ +#define __RSC_MGR_SERVER_RESOURCE_H__ + +#include +#include +#include +#include + +#include +#include + +class CResource : public CResourceSubject +{ +public: + CResource(IN const int device_id, IN const rms_rsc_category_e category_type, IN const char *name, IN const char *path, + IN std::set mem_cluster, IN int is_main_device, IN const char *audio_codec, IN int sharable_count); + ~CResource(); + + std::string GetName(void) { return std::string(m_device_name); } + int GetDeviceID(void) { return m_id; } + int GetVirtualResourceID(void) { return m_vrsc_id; } + const char *GetDevicePath(void) { return m_device_path; } + std::string GetAudioCodec(void) { return m_audio_codec; } + rms_mixing_mode_e GetMixingMode(void) { return m_mixing_mode; } + rms_rsc_category_e GetCategoryType(void) { return m_category_type; } + int GetCurCategory(void) { return m_cur_category; } + int getSharableCount(void) { return (m_sharable_count - m_shared_count - m_reserved_count); } + int GetCategoryClass(void) { return m_category_class; } + + bool IsFreeState(void) { return m_state == RMS_INTERNAL_STATE_FREE; }; + bool IsAllocatableState(IN rms_requests_resource_state_e requested_state); + bool IsSharableState(void) { return (m_state == RMS_INTERNAL_STATE_FREE || m_state == RMS_INTERNAL_STATE_SHARABLE); } + bool IsReserved(void) { return m_is_reserved; } + bool IsSharableDevice(void) { return (m_sharable_count >= 2); } + bool IsMainDevice(void) { return m_is_main_device; } + bool IsAudioDevice(void); + bool IsVideoDecoder(void); + bool IsScaler(void) { return m_is_scaler; } + bool IsJpegDecoder(void); + + void AddConsumer(IN int consumer_id, IN rms_requests_resource_state_e state); + void ResetConsumer(std::set new_consumers); + int RemoveConsumer(IN int consumer_id, IN bool force); + std::set GetConsumers(void) { return m_consumer_ids; } + int GetFirstConsumer(void); + + int Reserve(IN int consumer_id, rms_requests_resource_state_e state); + void CancelReservation(rms_requests_resource_state_e state); + + void SetDefaultBW(unsigned int bw); + unsigned int GetBW(void) { return m_occupied_bw; } + int GetDefaultBW(void) { return m_default_bw; } + void ResetBW(void) { m_occupied_bw = m_default_bw; } + void SetAllocatedTime(void); + unsigned long GetAllocatedTime(void) { return m_allocated_time; } + + void SetVirtualDeviceId(int id) { m_virtual_id = id; } + int GetVirtualDeviceId(void); + void SetDedicatedVirtualDeviceId(int id) { m_dedicated_virtual_id = id; } + int GetDedicatedVirtualDeviceId(void) { return m_dedicated_virtual_id; } + + std::set GetMemClusters(void) { return m_mem_clusters; } + void UpdateProperties(std::set mem_clusters, int bw, int category, int category_class, int vrsc_id); + void UpdateAudioCodec(std::string codec_name); + void updateMixingMode(rms_mixing_mode_e mode) { m_mixing_mode = mode; } + + void RegisterObserver(CResourceObserver *observer); + void UnregisterObserver(CResourceObserver *observer); + + bool Allocate(const int consumer_id, rms_requests_resource_state_e state, int mv_zone_id); + int GetState(void) { return (int) m_state; } + int GetZoneId(void) { return m_mv_zone_id; } + void SetZoneId(int zone_id); + + void ChangeState(rms_resource_internal_state_e next_state); + +private: + void m_SetSubScalerFlag(int next_state); + bool IsRegisteredConsumer(int consumer_id); + int IncreaseRefCount(int consumer_id); + int DecreaseRefCount(int consumer_id); + void NotifyObservers(resource_update_type_e type, int consumer_id); + bool ChangeStateByAllocation(IN rms_requests_resource_state_e state, const int consumer_id, int mv_zone_id); + bool ChangeStateByRelease(int consumer_id); + bool IsScaler(rms_rsc_category_e category); + + int ReserveExclusive(int consumer_id); + int ReserveShared(int consumer_id); + + std::map m_consumers; // consumer id, cnt + std::set m_shared_consumers; + std::set m_consumer_ids; + + int m_id; + int m_vrsc_id; + int m_virtual_id; + int m_dedicated_virtual_id; + rms_resource_internal_state_e m_state; + rms_rsc_category_e m_category_type; + const char *m_device_name; + const char *m_device_path; + int m_category_class; + int m_cur_category; + + unsigned int m_occupied_bw; + unsigned int m_default_bw; + int m_is_main_device; + int m_sharable_count; + + bool m_is_reserved; + bool m_is_scaler; + int m_reserved_consumer_id; + unsigned long m_allocated_time; + + int m_shared_count; + int m_reserved_count; + int m_mv_zone_id; + + std::string m_audio_codec; + std::vector m_observers; + std::set m_mem_clusters; + rms_mixing_mode_e m_mixing_mode; +}; + +#endif // __RSC_MGR_SERVER_RESOURCE_H__ diff --git a/include_internal/manager/CResourceCategory.h b/include_internal/manager/CResourceCategory.h index 6fdd6ac..acf20df 100644 --- a/include_internal/manager/CResourceCategory.h +++ b/include_internal/manager/CResourceCategory.h @@ -1,55 +1,55 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_CATEGORY_H__ -#define __RSC_MGR_SERVER_CATEGORY_H__ - -#include -#include -#include -#include - -#include - -class CConsumer; -class CVirtualResource; -class CRequest; -class CAllocateStrategy; -class CResourceCategory -{ -public: - CResourceCategory(rms_rsc_category_e resource_category_id, int category_class); - virtual ~CResourceCategory() {} - - rms_rsc_category_e GetCategoryID(void) { return m_categoryID; } - void AddVirtualResource(IN int device_id, IN CVirtualResource *vresource); - - CResource *ReserveCandidate(CRequest *req, bool apply_promotion); - void GetRetirableConsumers(CRequest *req, std::multimap* return_ids_in_category, rms_error_type_e *err_type); - bool hasFreeStateResource(void); - bool IsAvailableToUse(rms_requests_resource_state_e request_state); - void GetResources(std::map *resource_map); - CResource *FindMainResource(void); -private: - std::map m_device_id_to_vresource_map; - - rms_rsc_category_e m_categoryID; - CAllocateStrategy *m_alloc_strategy; - - void MakeResourceMapSortedByAllocTime(std::multimap *time_resource_map); -}; - -#endif // __RSC_MGR_SERVER_CATEGORY_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_CATEGORY_H__ +#define __RSC_MGR_SERVER_CATEGORY_H__ + +#include +#include +#include +#include + +#include + +class CConsumer; +class CVirtualResource; +class CRequest; +class CAllocateStrategy; +class CResourceCategory +{ +public: + CResourceCategory(rms_rsc_category_e resource_category_id, int category_class); + virtual ~CResourceCategory() {} + + rms_rsc_category_e GetCategoryID(void) { return m_categoryID; } + void AddVirtualResource(IN int device_id, IN CVirtualResource *vresource); + + CResource *ReserveCandidate(CRequest *req, bool apply_promotion); + void GetRetirableConsumers(CRequest *req, std::multimap* return_ids_in_category, rms_error_type_e *err_type); + bool hasFreeStateResource(void); + bool IsAvailableToUse(rms_requests_resource_state_e request_state); + void GetResources(std::map *resource_map); + CResource *FindMainResource(void); +private: + std::map m_device_id_to_vresource_map; + + rms_rsc_category_e m_categoryID; + CAllocateStrategy *m_alloc_strategy; + + void MakeResourceMapSortedByAllocTime(std::multimap *time_resource_map); +}; + +#endif // __RSC_MGR_SERVER_CATEGORY_H__ diff --git a/include_internal/manager/CResourceDB.h b/include_internal/manager/CResourceDB.h index 1912c74..f10ac54 100644 --- a/include_internal/manager/CResourceDB.h +++ b/include_internal/manager/CResourceDB.h @@ -1,121 +1,121 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_DB_H__ -#define __RSC_MGR_SERVER_DB_H__ - -#include -#include -#include -#include -#include -#include - -class CResourceCategory; -class CVirtualResource; -class CResource; -class CResourceDB : public CResourceObserver -{ -public: - CResourceDB(void) = default; - virtual ~CResourceDB(void) {} - static CResourceDB *getInstance(void); - - void AddVirtualResource(IN CVirtualResource *vrsc, IN rms_rsc_category_e resource_category_id, IN const char *name, - IN const char *path, IN std::set mem_cluster_info, - IN unsigned int device_id_unique, IN int is_main_device, IN const char *audio_codec, - IN int sharable_count, IN int mixing_count, IN CResourceObserver *observer); - - void AddResourceCategory(IN rms_rsc_category_e category_id, IN CResourceCategory *resource_category); - - CResourceCategory *FindResourceCategory(IN rms_rsc_category_e category_id); - CResource *FindResource(IN const int device_id); - CVirtualResource *FindVirtualResource(const int vid); - int FindRealDeviceId(int virtual_id); - void FindMainResources(IN std::map *resource_map); - void FindActiveVideoDecoders(IN std::map *resource_map); - - void SetMaxVideoDecoders(int n_decs) { m_max_vdecs = n_decs; } - std::map GetActiveVideoDecoders(void) { return m_active_vdecs; } - std::map GetActiveNVideoDecoders(void) { return m_active_nvdecs; } - int GetActiveDecoderNum(void); - bool HasAvailableDecoder(void); - bool HasAvailableDecoderNDecoding(void); - bool HasAvailableDecoder(std::multimap retirables); - bool HasAvailableDecoderNDecoding(std::multimap retirables); - void AddReclaimResources(consumer_reclaim_s *consumers); - void ClearReclaimResources(void); - void Update(resource_update_type_e type, const int device_id, const int consumer_id); - - void InitScalerTable(void); - int SwapScaler(int id_a, int id_b); - void GetScalerList(std::map *scalers); - int ToScalerId(int device_id); - void UpdateVirtualScalerIds(void); - void ResetZoneIds(void); - - static gboolean NotifyResourceStateUpdated(gpointer data); -private: - CResource *FindResource(const char *device_name); - CResource *FindMainResource(rms_rsc_category_e category_id); - - void AddDeviceID(IN int device_id, IN CResource *resource); - void AddDeviceName(IN const char *device_name, IN CResource *resource); - void AddVirtualDeviceID(IN CVirtualResource *vresource); - - void UpdateBWbyRelease(CResource *resource); - void UpdateBWbyAllocation(const unsigned int bandwidth, CResource *resource); - void UpdateByRelease(CResource *resource, const int device_id, const int consumer_id); - void UpdateByAllocation(CResource *resource, const int device_id, const int consumer_id); - void SetVirtualScalerId(CResource *resource); - int GetVirtualScalerId(CResource *resource); - int GetDedicatedVirtualScalerId(int device_id); - void PrintVirtualScalerMap(void); - - void AddActiveVideoDecoder(const int device_id, const int consumer_id, const int category_class); - void RemoveActiveVideoDecoder(const int device_id, const int category_class); - void AddActiveJpegDecoder(const int device_id, const int consumer_id); - void RemoveActiveJpegDecoder(const int device_id); - void PrintVideoDecoderConsumers(void); - - void NotifyResourceStateUpdatedAsync(CResource *resource, int consumer_id); - - CResource *FindScaler(int id); - void InsertVirtualScaler(int virtual_id, CResource *resource); - void SwapResource(std::set consumers, int cur_device_id, int new_device_id); - void UpdateConsumerInfoOfResource(CResource *resource, std::set new_consumers, int new_virtual_id); - - int CountNDecoders(std::map retirables); - void InsertResourceHasZoneId(CResource *resource); - void RemoveResourceHasZoneId(int device_id); - std::map m_resourceCategoryMap; //category info - std::map m_v_deviceid_to_rsc; - std::map m_deviceid_to_rsc; - std::map m_devicename_to_rsc; - std::map m_scaler_map; - std::map m_rscs_has_zone_id; - - static CResourceDB *m_instance; - unsigned int m_device_id; //for virtual resource - int m_max_vdecs; - - std::set m_reclaim_rscs; // resources reclaiming - std::map m_active_vdecs; // device id, consumer id - std::map m_active_jdecs; // device id, consumer id - std::map m_active_nvdecs; // device id, consumer id -}; - -#endif // __RSC_MGR_SERVER_DB_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_DB_H__ +#define __RSC_MGR_SERVER_DB_H__ + +#include +#include +#include +#include +#include +#include + +class CResourceCategory; +class CVirtualResource; +class CResource; +class CResourceDB : public CResourceObserver +{ +public: + CResourceDB(void) = default; + virtual ~CResourceDB(void) {} + static CResourceDB *getInstance(void); + + void AddVirtualResource(IN CVirtualResource *vrsc, IN rms_rsc_category_e resource_category_id, IN const char *name, + IN const char *path, IN std::set mem_cluster_info, + IN unsigned int device_id_unique, IN int is_main_device, IN const char *audio_codec, + IN int sharable_count, IN int mixing_count, IN CResourceObserver *observer); + + void AddResourceCategory(IN rms_rsc_category_e category_id, IN CResourceCategory *resource_category); + + CResourceCategory *FindResourceCategory(IN rms_rsc_category_e category_id); + CResource *FindResource(IN const int device_id); + CVirtualResource *FindVirtualResource(const int vid); + int FindRealDeviceId(int virtual_id); + void FindMainResources(IN std::map *resource_map); + void FindActiveVideoDecoders(IN std::map *resource_map); + + void SetMaxVideoDecoders(int n_decs) { m_max_vdecs = n_decs; } + std::map GetActiveVideoDecoders(void) { return m_active_vdecs; } + std::map GetActiveNVideoDecoders(void) { return m_active_nvdecs; } + int GetActiveDecoderNum(void); + bool HasAvailableDecoder(void); + bool HasAvailableDecoderNDecoding(void); + bool HasAvailableDecoder(std::multimap retirables); + bool HasAvailableDecoderNDecoding(std::multimap retirables); + void AddReclaimResources(consumer_reclaim_s *consumers); + void ClearReclaimResources(void); + void Update(resource_update_type_e type, const int device_id, const int consumer_id); + + void InitScalerTable(void); + int SwapScaler(int id_a, int id_b); + void GetScalerList(std::map *scalers); + int ToScalerId(int device_id); + void UpdateVirtualScalerIds(void); + void ResetZoneIds(void); + + static gboolean NotifyResourceStateUpdated(gpointer data); +private: + CResource *FindResource(const char *device_name); + CResource *FindMainResource(rms_rsc_category_e category_id); + + void AddDeviceID(IN int device_id, IN CResource *resource); + void AddDeviceName(IN const char *device_name, IN CResource *resource); + void AddVirtualDeviceID(IN CVirtualResource *vresource); + + void UpdateBWbyRelease(CResource *resource); + void UpdateBWbyAllocation(const unsigned int bandwidth, CResource *resource); + void UpdateByRelease(CResource *resource, const int device_id, const int consumer_id); + void UpdateByAllocation(CResource *resource, const int device_id, const int consumer_id); + void SetVirtualScalerId(CResource *resource); + int GetVirtualScalerId(CResource *resource); + int GetDedicatedVirtualScalerId(int device_id); + void PrintVirtualScalerMap(void); + + void AddActiveVideoDecoder(const int device_id, const int consumer_id, const int category_class); + void RemoveActiveVideoDecoder(const int device_id, const int category_class); + void AddActiveJpegDecoder(const int device_id, const int consumer_id); + void RemoveActiveJpegDecoder(const int device_id); + void PrintVideoDecoderConsumers(void); + + void NotifyResourceStateUpdatedAsync(CResource *resource, int consumer_id); + + CResource *FindScaler(int id); + void InsertVirtualScaler(int virtual_id, CResource *resource); + void SwapResource(std::set consumers, int cur_device_id, int new_device_id); + void UpdateConsumerInfoOfResource(CResource *resource, std::set new_consumers, int new_virtual_id); + + int CountNDecoders(std::map retirables); + void InsertResourceHasZoneId(CResource *resource); + void RemoveResourceHasZoneId(int device_id); + std::map m_resourceCategoryMap; //category info + std::map m_v_deviceid_to_rsc; + std::map m_deviceid_to_rsc; + std::map m_devicename_to_rsc; + std::map m_scaler_map; + std::map m_rscs_has_zone_id; + + static CResourceDB *m_instance; + unsigned int m_device_id; //for virtual resource + int m_max_vdecs; + + std::set m_reclaim_rscs; // resources reclaiming + std::map m_active_vdecs; // device id, consumer id + std::map m_active_jdecs; // device id, consumer id + std::map m_active_nvdecs; // device id, consumer id +}; + +#endif // __RSC_MGR_SERVER_DB_H__ diff --git a/include_internal/manager/CResourceManager.h b/include_internal/manager/CResourceManager.h index f25b963..29594f4 100644 --- a/include_internal/manager/CResourceManager.h +++ b/include_internal/manager/CResourceManager.h @@ -1,77 +1,77 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RSC_MGR_SERVER_MANAGER_H__ -#define __RSC_MGR_SERVER_MANAGER_H__ -#include -#include -#include -#include -#include -#include - -class CResourceManager -{ -public: - CResourceManager(); - ~CResourceManager() = default; - - int AllocateResources(rms_msg_request *req, rms_return_device_s *allocated_devices); - int ReleaseResourcesOfPid(IN const int pid); - int ReleaseResources(IN int consumer_id, IN const rms_requests_device_s *req); - int RegisterResources(void); - - int SetAppId(IN int consumer_id, IN const char *app_id); - int RegisterConsumer(int consumer_id, int process_id, const char *app_id, int main_priority, int sub_priority); - int UnregisterConsumer(IN int consumer_id); - int FindReclaimableConsumers(rms_msg_request *req, consumer_reclaim_s *return_consumer, int *zone_id); - int GetActiveDecoderNum(void); - int GetActiveAudioOut(int consumer_id); - - int IsCategoryAvailableToUse(rms_msg_request *request, int *is_available); - bool IsReclaimed(IN const int device_id, IN const int consumer_id); - - int GetResourceState(int device_id); - int FindDeviceId(int virtual_id); - int GetResourceList(int category_id, GVariantBuilder *builder); - int GetScalerState(GVariantBuilder *builder); - int GetResourceCollectionState(int collection, GVariantBuilder *builder); - int SwapResources(int device_id_a, int device_id_b); - int RestoreResources(int category_id); - int GetScalerHWId(int zone_id); - int GetZoneId(int device_id); - void ResetZoneIds(void); - void UpdateZoneIds(std::string app_id, int zone_id); - -private: - void MakeRequests(CRequester *requester, rms_msg_request *reqs, std::vector *requests); - void AllocateCandidates(std::vector requests); - void ReleaseResources(const int consumer_id); - int GetScalerState(int category_id, GVariantBuilder *builder); - - void MakeResourceMapPerConsumer(std::multimap *device_id_to_consumer_id_map, std::map > *consumer_id_to_resource_set_map); - void MakeConsumerInfoToBeReturned(consumer_reclaim_s *return_consumer, std::map > *consumer_id_to_resource_set_map); - void PrintConsumerInfoToBeReturned(consumer_reclaim_s *consumer_info); - - CResourceDB *m_db; - - int m_is_db_created; - rms_error_type_e m_error_type; - CConsumerContainer *m_consumers; - -}; - -#endif // __RSC_MGR_SERVER_MANAGER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RSC_MGR_SERVER_MANAGER_H__ +#define __RSC_MGR_SERVER_MANAGER_H__ +#include +#include +#include +#include +#include +#include + +class CResourceManager +{ +public: + CResourceManager(); + ~CResourceManager() = default; + + int AllocateResources(rms_msg_request *req, rms_return_device_s *allocated_devices); + int ReleaseResourcesOfPid(IN const int pid); + int ReleaseResources(IN int consumer_id, IN const rms_requests_device_s *req); + int RegisterResources(void); + + int SetAppId(IN int consumer_id, IN const char *app_id); + int RegisterConsumer(int consumer_id, int process_id, const char *app_id, int main_priority, int sub_priority); + int UnregisterConsumer(IN int consumer_id); + int FindReclaimableConsumers(rms_msg_request *req, consumer_reclaim_s *return_consumer, int *zone_id); + int GetActiveDecoderNum(void); + int GetActiveAudioOut(int consumer_id); + + int IsCategoryAvailableToUse(rms_msg_request *request, int *is_available); + bool IsReclaimed(IN const int device_id, IN const int consumer_id); + + int GetResourceState(int device_id); + int FindDeviceId(int virtual_id); + int GetResourceList(int category_id, GVariantBuilder *builder); + int GetScalerState(GVariantBuilder *builder); + int GetResourceCollectionState(int collection, GVariantBuilder *builder); + int SwapResources(int device_id_a, int device_id_b); + int RestoreResources(int category_id); + int GetScalerHWId(int zone_id); + int GetZoneId(int device_id); + void ResetZoneIds(void); + void UpdateZoneIds(std::string app_id, int zone_id); + +private: + void MakeRequests(CRequester *requester, rms_msg_request *reqs, std::vector *requests); + void AllocateCandidates(std::vector requests); + void ReleaseResources(const int consumer_id); + int GetScalerState(int category_id, GVariantBuilder *builder); + + void MakeResourceMapPerConsumer(std::multimap *device_id_to_consumer_id_map, std::map > *consumer_id_to_resource_set_map); + void MakeConsumerInfoToBeReturned(consumer_reclaim_s *return_consumer, std::map > *consumer_id_to_resource_set_map); + void PrintConsumerInfoToBeReturned(consumer_reclaim_s *consumer_info); + + CResourceDB *m_db; + + int m_is_db_created; + rms_error_type_e m_error_type; + CConsumerContainer *m_consumers; + +}; + +#endif // __RSC_MGR_SERVER_MANAGER_H__ diff --git a/include_internal/manager/CResourceObserver.h b/include_internal/manager/CResourceObserver.h index 9c1f246..20f7015 100644 --- a/include_internal/manager/CResourceObserver.h +++ b/include_internal/manager/CResourceObserver.h @@ -1,32 +1,32 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CRESOURCE_OBSERVER_H__ -#define __CRESOURCE_OBSERVER_H__ - -typedef enum _resource_update_type_e { - UPDATED_BY_ALLOC = 0, - UPDATED_BY_RELEASE -} resource_update_type_e; - -class CResourceObserver -{ -public: - virtual ~CResourceObserver() {} - virtual void Update(resource_update_type_e type, const int device_id, const int consumer_id) = 0; -}; - -#endif // __CRESOURCE_OBSERVER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CRESOURCE_OBSERVER_H__ +#define __CRESOURCE_OBSERVER_H__ + +typedef enum _resource_update_type_e { + UPDATED_BY_ALLOC = 0, + UPDATED_BY_RELEASE +} resource_update_type_e; + +class CResourceObserver +{ +public: + virtual ~CResourceObserver() {} + virtual void Update(resource_update_type_e type, const int device_id, const int consumer_id) = 0; +}; + +#endif // __CRESOURCE_OBSERVER_H__ diff --git a/include_internal/manager/CResourceState.h b/include_internal/manager/CResourceState.h index 5064e66..911346f 100644 --- a/include_internal/manager/CResourceState.h +++ b/include_internal/manager/CResourceState.h @@ -1,40 +1,40 @@ -/* -* Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved -* -* 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 __CRESOURCE_STATE_H__ -#include - -class CResourceState -{ -public: - CResourceState(int device_id, int category_type, int consumer_id, int state, std::string app_id); - ~CResourceState() = default; - - int GetDeviceId(void) { return m_device_id; } - int GetConsumerId(void) { return m_consumer_id; } - int GetState(void) { return m_state; } - int GetCategoryType(void) { return m_category_type; } - std::string GetAppId(void) { return m_app_id; } - -private: - int m_device_id; - int m_consumer_id; - int m_state; - int m_category_type; - std::string m_app_id; -}; - -#endif //__CRESOURCE_STATE_H__ \ No newline at end of file +/* +* Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved +* +* 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 __CRESOURCE_STATE_H__ +#include + +class CResourceState +{ +public: + CResourceState(int device_id, int category_type, int consumer_id, int state, std::string app_id); + ~CResourceState() = default; + + int GetDeviceId(void) { return m_device_id; } + int GetConsumerId(void) { return m_consumer_id; } + int GetState(void) { return m_state; } + int GetCategoryType(void) { return m_category_type; } + std::string GetAppId(void) { return m_app_id; } + +private: + int m_device_id; + int m_consumer_id; + int m_state; + int m_category_type; + std::string m_app_id; +}; + +#endif //__CRESOURCE_STATE_H__ diff --git a/include_internal/manager/CResourceSubject.h b/include_internal/manager/CResourceSubject.h index d8c2aaf..6390924 100644 --- a/include_internal/manager/CResourceSubject.h +++ b/include_internal/manager/CResourceSubject.h @@ -1,34 +1,34 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __CRESOURCE_SUBJECT_H__ -#define __CRESOURCE_SUBJECT_H__ - -#include - -class CResourceObserver; -class CResourceSubject -{ -public: - virtual ~CResourceSubject() {} - - virtual void RegisterObserver(CResourceObserver *observer) = 0; - virtual void UnregisterObserver(CResourceObserver *observer) = 0; - virtual void NotifyObservers(resource_update_type_e type, const int consumer_id) = 0; -}; - -#endif // __CRESOURCE_SUBJECT_H__ - +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __CRESOURCE_SUBJECT_H__ +#define __CRESOURCE_SUBJECT_H__ + +#include + +class CResourceObserver; +class CResourceSubject +{ +public: + virtual ~CResourceSubject() {} + + virtual void RegisterObserver(CResourceObserver *observer) = 0; + virtual void UnregisterObserver(CResourceObserver *observer) = 0; + virtual void NotifyObservers(resource_update_type_e type, const int consumer_id) = 0; +}; + +#endif // __CRESOURCE_SUBJECT_H__ + diff --git a/include_internal/manager/CVideoController.h b/include_internal/manager/CVideoController.h index d6ec594..fec6aa7 100644 --- a/include_internal/manager/CVideoController.h +++ b/include_internal/manager/CVideoController.h @@ -1,54 +1,54 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __C_VIDEO_CONTROLLER_H__ -#define __C_VIDEO_CONTROLLER_H__ - -#include -#include -#include -#include - -class CVideoController -{ -public: - ~CVideoController(void); - static CVideoController *GetInstance(void); - void UpdateVirtualScalerIds(std::map scaler_id_map); - -private: - typedef struct _scaler_id_pair { - unsigned int virtual_scaler_id; - unsigned int scaler_id; - } scaler_id_pair_t; - - CVideoController(void); - void WaylandDisplayCreate(void); - void WaylandDisplayDestroy(void); - void RunWaitingThread(void); - static gpointer WaitingThread(gpointer data); - - static CVideoController *m_instance; - struct wl_display *m_wl_display; - struct wl_registry *m_wl_registry; - struct tizen_video_rsc *m_tizen_video_rsc; - struct wl_registry_listener m_registry_listener; - - GThread *m_waiting_thread; - CLockController *m_lock_ctr; -}; - -#endif //__C_VIDEO_CONTROLLER_H__ +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __C_VIDEO_CONTROLLER_H__ +#define __C_VIDEO_CONTROLLER_H__ + +#include +#include +#include +#include + +class CVideoController +{ +public: + ~CVideoController(void); + static CVideoController *GetInstance(void); + void UpdateVirtualScalerIds(std::map scaler_id_map); + +private: + typedef struct _scaler_id_pair { + unsigned int virtual_scaler_id; + unsigned int scaler_id; + } scaler_id_pair_t; + + CVideoController(void); + void WaylandDisplayCreate(void); + void WaylandDisplayDestroy(void); + void RunWaitingThread(void); + static gpointer WaitingThread(gpointer data); + + static CVideoController *m_instance; + struct wl_display *m_wl_display; + struct wl_registry *m_wl_registry; + struct tizen_video_rsc *m_tizen_video_rsc; + struct wl_registry_listener m_registry_listener; + + GThread *m_waiting_thread; + CLockController *m_lock_ctr; +}; + +#endif //__C_VIDEO_CONTROLLER_H__ diff --git a/include_internal/manager/CVirtualResource.h b/include_internal/manager/CVirtualResource.h index 5bdfcaf..eed50b8 100644 --- a/include_internal/manager/CVirtualResource.h +++ b/include_internal/manager/CVirtualResource.h @@ -1,57 +1,57 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 _RM_VIRTUAL_RESOURCE_H_INCLUDED -#define _RM_VIRTUAL_RESOURCE_H_INCLUDED - -#include -#include -#include -#include - -class CResource; -class CVirtualResource -{ -public: - CVirtualResource(const int virtual_device_id, const rms_rsc_category_e category_type, unsigned int bw, std::set dependent, bool is_main_device, const char *audio_codec, int category_class); - virtual ~CVirtualResource(void) {} - - CResource *GetResource(void) { return m_rsc; } - void SetResource(CResource *resource); - - int GetVResourceID(void) { return m_vir_rsc_id; } - rms_rsc_category_e GetCategoryType(void) { return m_category_type; } - int GetCategoryClass(void) { return m_category_class; } - unsigned int GetBW(void) { return m_vir_rsc_bw; } - std::set GetMemClusters(void) { return m_mem_clusters; } - std::string GetAudioCodec(void) { return m_audio_codec; } - - bool IsMainDevice(void) { return m_is_main_device; } - bool IsAIDevice(void) { return m_is_ai_device; } -private: - int m_vir_rsc_id; - rms_rsc_category_e m_category_type; - unsigned int m_vir_rsc_bw; - bool m_is_main_device; - bool m_is_ai_device; - int m_category_class; - std::set m_mem_clusters; - std::string m_audio_codec; - - CResource *m_rsc; -}; - -#endif // _RM_VIRTUAL_RESOURCE_H_INCLUDED +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 _RM_VIRTUAL_RESOURCE_H_INCLUDED +#define _RM_VIRTUAL_RESOURCE_H_INCLUDED + +#include +#include +#include +#include + +class CResource; +class CVirtualResource +{ +public: + CVirtualResource(const int virtual_device_id, const rms_rsc_category_e category_type, unsigned int bw, std::set dependent, bool is_main_device, const char *audio_codec, int category_class); + virtual ~CVirtualResource(void) {} + + CResource *GetResource(void) { return m_rsc; } + void SetResource(CResource *resource); + + int GetVResourceID(void) { return m_vir_rsc_id; } + rms_rsc_category_e GetCategoryType(void) { return m_category_type; } + int GetCategoryClass(void) { return m_category_class; } + unsigned int GetBW(void) { return m_vir_rsc_bw; } + std::set GetMemClusters(void) { return m_mem_clusters; } + std::string GetAudioCodec(void) { return m_audio_codec; } + + bool IsMainDevice(void) { return m_is_main_device; } + bool IsAIDevice(void) { return m_is_ai_device; } +private: + int m_vir_rsc_id; + rms_rsc_category_e m_category_type; + unsigned int m_vir_rsc_bw; + bool m_is_main_device; + bool m_is_ai_device; + int m_category_class; + std::set m_mem_clusters; + std::string m_audio_codec; + + CResource *m_rsc; +}; + +#endif // _RM_VIRTUAL_RESOURCE_H_INCLUDED diff --git a/include_internal/rms_debug.h b/include_internal/rms_debug.h index 26214bf..f78a0c0 100644 --- a/include_internal/rms_debug.h +++ b/include_internal/rms_debug.h @@ -1,47 +1,47 @@ -/* -* Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved -* -* 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 __RMS_DEBUG_H__ -#define __RMS_DEBUG_H__ - -#include - - -#ifdef LOG_TAG -#undef LOG_TAG -#endif//LOG_TAG - -#define LOG_TAG "RSC_MGR_SERVER" - -#ifndef SERVER_ERR -#define SERVER_ERR(fmt, args...)SLOGE(fmt, ##args) -#endif - -#ifndef SERVER_DBG -#define SERVER_DBG(fmt, args...)SLOGD(fmt, ##args) -#endif - -#ifndef SERVER_INFO -#define SERVER_INFO(fmt, args...)SLOGI(fmt, ##args) -#endif - -#ifndef SERVER_WARN -#define SERVER_WARN(fmt, args...)SLOGW(fmt, ##args) -#endif - - -#endif//__RMS_DEBUG_H__ - +/* +* Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved +* +* 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 __RMS_DEBUG_H__ +#define __RMS_DEBUG_H__ + +#include + + +#ifdef LOG_TAG +#undef LOG_TAG +#endif//LOG_TAG + +#define LOG_TAG "RSC_MGR_SERVER" + +#ifndef SERVER_ERR +#define SERVER_ERR(fmt, args...)SLOGE(fmt, ##args) +#endif + +#ifndef SERVER_DBG +#define SERVER_DBG(fmt, args...)SLOGD(fmt, ##args) +#endif + +#ifndef SERVER_INFO +#define SERVER_INFO(fmt, args...)SLOGI(fmt, ##args) +#endif + +#ifndef SERVER_WARN +#define SERVER_WARN(fmt, args...)SLOGW(fmt, ##args) +#endif + + +#endif//__RMS_DEBUG_H__ + diff --git a/include_internal/rms_log.h b/include_internal/rms_log.h index fa8ae0a..ddda942 100644 --- a/include_internal/rms_log.h +++ b/include_internal/rms_log.h @@ -1,39 +1,39 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 __RMS_LOG_H__ -#define __RMS_LOG_H__ - -#include - -static char g_rms_dlog_msg[4096] = {0,}; -static int g_rms_dlog_msg_pose = 0; - -static void rms_log_reset() { g_rms_dlog_msg_pose = 0; } -static void rms_log_add(const char *format_str, ...) __attribute__ ((format (printf, 1, 2))); -static void rms_log_add(const char *format_str, ...) { - va_list argptr; - va_start(argptr, format_str); - g_rms_dlog_msg_pose += vsnprintf(g_rms_dlog_msg + g_rms_dlog_msg_pose, sizeof(g_rms_dlog_msg) - 1 - g_rms_dlog_msg_pose, format_str, argptr); - va_end(argptr); -} - -#define RMS_LOGE_FLUSH() SLOGE("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 -#define RMS_LOGI_FLUSH() SLOGI("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 -#define RMS_LOGD_FLUSH() SLOGD("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 - -#endif //__RMS_LOG_H__ - +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __RMS_LOG_H__ +#define __RMS_LOG_H__ + +#include + +static char g_rms_dlog_msg[4096] = {0,}; +static int g_rms_dlog_msg_pose = 0; + +static void rms_log_reset() { g_rms_dlog_msg_pose = 0; } +static void rms_log_add(const char *format_str, ...) __attribute__ ((format (printf, 1, 2))); +static void rms_log_add(const char *format_str, ...) { + va_list argptr; + va_start(argptr, format_str); + g_rms_dlog_msg_pose += vsnprintf(g_rms_dlog_msg + g_rms_dlog_msg_pose, sizeof(g_rms_dlog_msg) - 1 - g_rms_dlog_msg_pose, format_str, argptr); + va_end(argptr); +} + +#define RMS_LOGE_FLUSH() SLOGE("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 +#define RMS_LOGI_FLUSH() SLOGI("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 +#define RMS_LOGD_FLUSH() SLOGD("%s", g_rms_dlog_msg); g_rms_dlog_msg_pose = 0 + +#endif //__RMS_LOG_H__ + diff --git a/packaging/rscmgr-service.spec b/packaging/rscmgr-service.spec index d98cdeb..15ecfd2 100644 --- a/packaging/rscmgr-service.spec +++ b/packaging/rscmgr-service.spec @@ -1,7 +1,7 @@ Name: rscmgr-service Summary: Daemon for resource manager Version: 0.1 -Release: 1 +Release: 2 Group: Multimedia/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/CAsyncQueue.cpp b/src/CAsyncQueue.cpp index 537d878..50ad337 100644 --- a/src/CAsyncQueue.cpp +++ b/src/CAsyncQueue.cpp @@ -1,93 +1,93 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include - -CAsyncQueue::CAsyncQueue(void) -{ - queue = g_async_queue_new(); -} - -CAsyncQueue::CAsyncQueue(destoryNotify destory_cb) -{ - queue = g_async_queue_new_full(destory_cb); -} - -CAsyncQueue::~CAsyncQueue(void) -{ - g_async_queue_unref(queue); -} - -void CAsyncQueue::push(void *data) -{ - g_async_queue_push(queue, data); -} - -void CAsyncQueue::push(CAsyncQueue *src_queue) -{ - if (src_queue->length() <= 0) - return; - - SERVER_INFO("push given queue (%d)", src_queue->length()); - - g_async_queue_lock(queue); - - while (src_queue->length() > 0) { - g_async_queue_push_unlocked(queue, src_queue->pop()); - } - - g_async_queue_unlock(queue); -} - -void CAsyncQueue::push_front(void *data) -{ - g_async_queue_push_front(queue, data); -} - -void CAsyncQueue::push_front(CAsyncQueue *src_queue) -{ - if (src_queue->length() <= 0) - return; - - SERVER_INFO("push_front given queue (%d)", src_queue->length()); - - g_async_queue_lock(queue); - - while (src_queue->length() > 0) { - g_async_queue_push_front_unlocked(queue, src_queue->pop()); - } - - g_async_queue_unlock(queue); -} - -void *CAsyncQueue::pop(void) -{ - return g_async_queue_pop(queue); -} - -void *CAsyncQueue::pop(unsigned int timeout_ms) -{ - guint64 timeout_us = (guint64)((guint64) timeout_ms * 1000); - - return g_async_queue_timeout_pop(queue, timeout_us); -} - -int CAsyncQueue::length(void) -{ - return g_async_queue_length(queue); -} - +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include + +CAsyncQueue::CAsyncQueue(void) +{ + queue = g_async_queue_new(); +} + +CAsyncQueue::CAsyncQueue(destoryNotify destory_cb) +{ + queue = g_async_queue_new_full(destory_cb); +} + +CAsyncQueue::~CAsyncQueue(void) +{ + g_async_queue_unref(queue); +} + +void CAsyncQueue::push(void *data) +{ + g_async_queue_push(queue, data); +} + +void CAsyncQueue::push(CAsyncQueue *src_queue) +{ + if (src_queue->length() <= 0) + return; + + SERVER_INFO("push given queue (%d)", src_queue->length()); + + g_async_queue_lock(queue); + + while (src_queue->length() > 0) { + g_async_queue_push_unlocked(queue, src_queue->pop()); + } + + g_async_queue_unlock(queue); +} + +void CAsyncQueue::push_front(void *data) +{ + g_async_queue_push_front(queue, data); +} + +void CAsyncQueue::push_front(CAsyncQueue *src_queue) +{ + if (src_queue->length() <= 0) + return; + + SERVER_INFO("push_front given queue (%d)", src_queue->length()); + + g_async_queue_lock(queue); + + while (src_queue->length() > 0) { + g_async_queue_push_front_unlocked(queue, src_queue->pop()); + } + + g_async_queue_unlock(queue); +} + +void *CAsyncQueue::pop(void) +{ + return g_async_queue_pop(queue); +} + +void *CAsyncQueue::pop(unsigned int timeout_ms) +{ + guint64 timeout_us = (guint64)((guint64) timeout_ms * 1000); + + return g_async_queue_timeout_pop(queue, timeout_us); +} + +int CAsyncQueue::length(void) +{ + return g_async_queue_length(queue); +} + diff --git a/src/CCallback.cpp b/src/CCallback.cpp index 214943c..3422b68 100644 --- a/src/CCallback.cpp +++ b/src/CCallback.cpp @@ -1,127 +1,127 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define CB_TIMEOUT_3_SEC_IN_MS 3000 -#define CB_TIMEOUT_10_SEC_IN_MS 10000 - -#define RMS_IS_DEBUG_IMAGE (access("/etc/debug", F_OK) == 0) - -unsigned int CCallback::GetTimeout(void) -{ - return (RMS_IS_DEBUG_IMAGE) ? CB_TIMEOUT_10_SEC_IN_MS : CB_TIMEOUT_3_SEC_IN_MS; -} - -void CCallback::InitCallback(void) -{ - const char *cb_path = "/run/rsc_mgr"; - mode_t dir_mode = 0666 | 0111; - - if (mkdir(cb_path, dir_mode) !=0) { - SERVER_ERR("failed to create cb directory (%d)", errno); - return; - } - - chmod(cb_path, dir_mode); -} - -int CCallback::SendCallbackMessage(int cid, int pid, void *callback_data, int size, int *err) -{ - int fd = -1; - int ret = 0; - - char callback_path[256] = {0,}; - - snprintf(callback_path, 256, "/run/rsc_mgr/%d.%d.s2c.cb", pid, cid); - - if ((fd = open(callback_path, O_WRONLY|O_NONBLOCK)) < 0) { - SERVER_ERR("open error (%s), errno(%d)\n", callback_path, errno); - *err = errno; - return RMS_ERROR; - } - - if (is_symlink_file(callback_path)) { - SERVER_ERR("%s is symbolic link file", callback_path); - *err = EPERM; - close(fd); - return RMS_ERROR; - } - - ret = write(fd, callback_data, size); - - if (ret <= 0) { - SERVER_ERR("failed to write callback.(%s) ret(%d), errno(%d)\n", callback_path, ret, errno); - *err = errno; - close(fd); - return RMS_ERROR; - } - - SERVER_DBG("succeeded to write callback.(%s)", callback_path); - - close(fd); - - return RMS_OK; -} - -int CCallback::RemoveFIFOServerToClient(int pid, int cid) -{ - struct stat stat_info; - char cb_path_s2c[256] = {0, }; - - snprintf(cb_path_s2c, 256, "/run/rsc_mgr/%d.%d.s2c.cb", pid, cid); - - if (stat(cb_path_s2c, &stat_info) != 0) { - SERVER_INFO("%s not exists", cb_path_s2c); - return RMS_OK; - } - - if (remove(cb_path_s2c) != 0) { - SERVER_ERR("failed to remove cb for S2C(%s)-(%d)", cb_path_s2c, errno); - return RMS_ERROR; - } - - SERVER_DBG("Removed cb for S2C(%s)", cb_path_s2c); - return RMS_OK; -} - -int CCallback::ConvertCallbackType(int rm_return_type) -{ - switch (rm_return_type) { - case RMS_ERROR_TAKE_RESOURCE_FROM_OTHER_CONSUMER: - return RMS_CALLBACK_TYPE_RESOURCE_CONFLICT; - case RMS_OK_UHD_RESOURCE_CONFLICT: - return RMS_CALLBACK_TYPE_RESOURCE_CONFLICT_UD; - default: - break; - } - - SERVER_ERR("return RMS_CALLBACK_TYPE_UNKNOWN(%d)", RMS_CALLBACK_TYPE_UNKNOWN); - - return RMS_CALLBACK_TYPE_UNKNOWN; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define CB_TIMEOUT_3_SEC_IN_MS 3000 +#define CB_TIMEOUT_10_SEC_IN_MS 10000 + +#define RMS_IS_DEBUG_IMAGE (access("/etc/debug", F_OK) == 0) + +unsigned int CCallback::GetTimeout(void) +{ + return (RMS_IS_DEBUG_IMAGE) ? CB_TIMEOUT_10_SEC_IN_MS : CB_TIMEOUT_3_SEC_IN_MS; +} + +void CCallback::InitCallback(void) +{ + const char *cb_path = "/run/rsc_mgr"; + mode_t dir_mode = 0666 | 0111; + + if (mkdir(cb_path, dir_mode) !=0) { + SERVER_ERR("failed to create cb directory (%d)", errno); + return; + } + + chmod(cb_path, dir_mode); +} + +int CCallback::SendCallbackMessage(int cid, int pid, void *callback_data, int size, int *err) +{ + int fd = -1; + int ret = 0; + + char callback_path[256] = {0,}; + + snprintf(callback_path, 256, "/run/rsc_mgr/%d.%d.s2c.cb", pid, cid); + + if ((fd = open(callback_path, O_WRONLY|O_NONBLOCK)) < 0) { + SERVER_ERR("open error (%s), errno(%d)\n", callback_path, errno); + *err = errno; + return RMS_ERROR; + } + + if (is_symlink_file(callback_path)) { + SERVER_ERR("%s is symbolic link file", callback_path); + *err = EPERM; + close(fd); + return RMS_ERROR; + } + + ret = write(fd, callback_data, size); + + if (ret <= 0) { + SERVER_ERR("failed to write callback.(%s) ret(%d), errno(%d)\n", callback_path, ret, errno); + *err = errno; + close(fd); + return RMS_ERROR; + } + + SERVER_DBG("succeeded to write callback.(%s)", callback_path); + + close(fd); + + return RMS_OK; +} + +int CCallback::RemoveFIFOServerToClient(int pid, int cid) +{ + struct stat stat_info; + char cb_path_s2c[256] = {0, }; + + snprintf(cb_path_s2c, 256, "/run/rsc_mgr/%d.%d.s2c.cb", pid, cid); + + if (stat(cb_path_s2c, &stat_info) != 0) { + SERVER_INFO("%s not exists", cb_path_s2c); + return RMS_OK; + } + + if (remove(cb_path_s2c) != 0) { + SERVER_ERR("failed to remove cb for S2C(%s)-(%d)", cb_path_s2c, errno); + return RMS_ERROR; + } + + SERVER_DBG("Removed cb for S2C(%s)", cb_path_s2c); + return RMS_OK; +} + +int CCallback::ConvertCallbackType(int rm_return_type) +{ + switch (rm_return_type) { + case RMS_ERROR_TAKE_RESOURCE_FROM_OTHER_CONSUMER: + return RMS_CALLBACK_TYPE_RESOURCE_CONFLICT; + case RMS_OK_UHD_RESOURCE_CONFLICT: + return RMS_CALLBACK_TYPE_RESOURCE_CONFLICT_UD; + default: + break; + } + + SERVER_ERR("return RMS_CALLBACK_TYPE_UNKNOWN(%d)", RMS_CALLBACK_TYPE_UNKNOWN); + + return RMS_CALLBACK_TYPE_UNKNOWN; +} diff --git a/src/CDbusHandler.cpp b/src/CDbusHandler.cpp index d04f6f0..7f213b2 100644 --- a/src/CDbusHandler.cpp +++ b/src/CDbusHandler.cpp @@ -1,174 +1,174 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -const GDBusInterfaceVTable CDbusHandler::m_vtable = { CDbusHandler::OnMethodCall, NULL, NULL, {0} }; - -const std::string CDbusHandler::m_methods = - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - "" - ""; - -CDbusHandler::CDbusHandler(CAsyncQueue *queue) -{ - assert(queue); - m_async_queue = queue; - m_reg_id = 0; - - if (!MakeDbusConnection()) - return; - - RegisterObjects(); -} - -bool CDbusHandler::MakeDbusConnection(void) -{ - m_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); - - if (!m_conn) { - SERVER_ERR("failed to make dbus connection"); - return false; - } - - SERVER_INFO("making dbus connection success"); - return true; -} - -void CDbusHandler::OnMethodCall(GDBusConnection *conn, const gchar *sender, const gchar *obj_path, const gchar *ifname, const gchar *method_name, GVariant *params, GDBusMethodInvocation *invoc, gpointer data) -{ - CDbusHandler *handler = static_cast(data); - CAsyncQueue *queue = handler->m_async_queue; - CMessage *msg = new CMessage(invoc); - - SERVER_INFO("push msg(%s)", method_name); - - queue->push(msg); -} - -void CDbusHandler::GenerateReadyEvent(void) -{ - SERVER_INFO("We will notify clients when the server is ready by generating a ready event"); -} - -void CDbusHandler::OnBusAcquired(GDBusConnection *conn, const gchar *bus_name, gpointer data) -{ - trace_begin("[RSC_MGR] OnBusAcquired"); - trace_end(); - SERVER_INFO("bus acquired (%s)", bus_name); - - CDbusHandler *handler = static_cast(data); - handler->GenerateReadyEvent(); -} - -void CDbusHandler::OnNameLost(GDBusConnection *conn, const gchar *bus_name, gpointer data) -{ - SERVER_ERR("name lost (%s)", bus_name); -} - -void CDbusHandler::RegisterObjects(void) -{ - assert(m_conn); - GError *err = NULL; - - GDBusNodeInfo *node_info = g_dbus_node_info_new_for_xml(m_methods.c_str(), &err); - - if (!node_info) { - SERVER_ERR("failed to get node_info (%s)", err ? err->message : "unknown"); - g_clear_error(&err); - return; - } - - m_reg_id = g_dbus_connection_register_object(m_conn, RM_DBUS_OBJ_PATH, *(node_info->interfaces), &m_vtable, this, NULL, &err); - - if (m_reg_id == 0) { - SERVER_ERR("failed to register objects (%s)", err ? err->message : "unknown"); - g_clear_error(&err); - return; - } - - m_own_id = g_bus_own_name_on_connection(m_conn, RM_DBUS_BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, CDbusHandler::OnBusAcquired, CDbusHandler::OnNameLost, this, NULL); - - if (m_own_id == 0) { - SERVER_ERR("failed to own dbus name (%s)", RM_DBUS_BUS_NAME); - return; - } - - SERVER_INFO("registering dbus objects success"); -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +const GDBusInterfaceVTable CDbusHandler::m_vtable = { CDbusHandler::OnMethodCall, NULL, NULL, {0} }; + +const std::string CDbusHandler::m_methods = + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + ""; + +CDbusHandler::CDbusHandler(CAsyncQueue *queue) +{ + assert(queue); + m_async_queue = queue; + m_reg_id = 0; + + if (!MakeDbusConnection()) + return; + + RegisterObjects(); +} + +bool CDbusHandler::MakeDbusConnection(void) +{ + m_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); + + if (!m_conn) { + SERVER_ERR("failed to make dbus connection"); + return false; + } + + SERVER_INFO("making dbus connection success"); + return true; +} + +void CDbusHandler::OnMethodCall(GDBusConnection *conn, const gchar *sender, const gchar *obj_path, const gchar *ifname, const gchar *method_name, GVariant *params, GDBusMethodInvocation *invoc, gpointer data) +{ + CDbusHandler *handler = static_cast(data); + CAsyncQueue *queue = handler->m_async_queue; + CMessage *msg = new CMessage(invoc); + + SERVER_INFO("push msg(%s)", method_name); + + queue->push(msg); +} + +void CDbusHandler::GenerateReadyEvent(void) +{ + SERVER_INFO("We will notify clients when the server is ready by generating a ready event"); +} + +void CDbusHandler::OnBusAcquired(GDBusConnection *conn, const gchar *bus_name, gpointer data) +{ + trace_begin("[RSC_MGR] OnBusAcquired"); + trace_end(); + SERVER_INFO("bus acquired (%s)", bus_name); + + CDbusHandler *handler = static_cast(data); + handler->GenerateReadyEvent(); +} + +void CDbusHandler::OnNameLost(GDBusConnection *conn, const gchar *bus_name, gpointer data) +{ + SERVER_ERR("name lost (%s)", bus_name); +} + +void CDbusHandler::RegisterObjects(void) +{ + assert(m_conn); + GError *err = NULL; + + GDBusNodeInfo *node_info = g_dbus_node_info_new_for_xml(m_methods.c_str(), &err); + + if (!node_info) { + SERVER_ERR("failed to get node_info (%s)", err ? err->message : "unknown"); + g_clear_error(&err); + return; + } + + m_reg_id = g_dbus_connection_register_object(m_conn, RM_DBUS_OBJ_PATH, *(node_info->interfaces), &m_vtable, this, NULL, &err); + + if (m_reg_id == 0) { + SERVER_ERR("failed to register objects (%s)", err ? err->message : "unknown"); + g_clear_error(&err); + return; + } + + m_own_id = g_bus_own_name_on_connection(m_conn, RM_DBUS_BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, CDbusHandler::OnBusAcquired, CDbusHandler::OnNameLost, this, NULL); + + if (m_own_id == 0) { + SERVER_ERR("failed to own dbus name (%s)", RM_DBUS_BUS_NAME); + return; + } + + SERVER_INFO("registering dbus objects success"); +} diff --git a/src/CHandle.cpp b/src/CHandle.cpp index 3d53c3d..c274040 100644 --- a/src/CHandle.cpp +++ b/src/CHandle.cpp @@ -1,27 +1,27 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -CHandle::CHandle(int in_handle, int in_is_used, int in_pid) -{ - handle = in_handle; - is_used = in_is_used; - pid = in_pid; - rms_get_cmd_name(pid,process_name,RMS_NAME_BUF_SIZE); -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +CHandle::CHandle(int in_handle, int in_is_used, int in_pid) +{ + handle = in_handle; + is_used = in_is_used; + pid = in_pid; + rms_get_cmd_name(pid,process_name,RMS_NAME_BUF_SIZE); +} diff --git a/src/CHandleManager.cpp b/src/CHandleManager.cpp index 6be09f2..2694311 100644 --- a/src/CHandleManager.cpp +++ b/src/CHandleManager.cpp @@ -1,278 +1,278 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - - -static const int M_MIN_HANDLE = 101; -static const int M_MAX_HANDLE = 200; - -CHandleManager::CHandleManager(CResourceManager *rsc_mgr) -{ - assert(rsc_mgr); - m_rsc_mgr = rsc_mgr; - m_next_handle = M_MIN_HANDLE; -} - -int CHandleManager::m_IsValidHandle(int handle) -{ - return ((handle >= M_MIN_HANDLE) && (handle <= M_MAX_HANDLE)) ? 1 : 0; -} - -int CHandleManager::m_ReclaimHandle(void) -{ - for (int i = M_MIN_HANDLE; i < M_MAX_HANDLE; i++) { - CHandle *handle_info = findHandle(i); - - if (!handle_info) - return i; - - if (!rm_is_valid_pid(handle_info->pid)) { - SERVER_INFO("reclaim pid(%d)/handle(%d)", handle_info->pid, handle_info->handle); - - // release resources allocated to terminated process - m_rsc_mgr->UnregisterConsumer(handle_info->handle); - m_RemoveHandle(handle_info->handle, handle_info->pid); - return i; - } - } - - return RMS_HANDLE_NOT_AVAILABLE; -} - -void CHandleManager::m_PrintHandleList(void) -{ - for (int i = M_MIN_HANDLE; i < M_MAX_HANDLE; i++) { - std::map::iterator it = m_handles.find(i); - - if (it == m_handles.end()) - return ; - - CHandle *handle_info = (*it).second; - m_PrintHandleInfo(handle_info->handle, handle_info->pid); - } -} - -int CHandleManager::m_AddNewHandle(int handle, int pid, int main_priority, int sub_priority, int app_pid, char *app_id) -{ - CHandle *handle_info = new(std::nothrow) CHandle(handle, RMS_HANDLE_USE, pid); - if (!handle_info) { - SERVER_ERR("cannot create handle class"); - return RMS_ERROR; - } - - handle_info->main_priority = main_priority; - handle_info->sub_priority = sub_priority; - handle_info->app_pid = app_pid; - handle_info->app_id = strndup(app_id, strlen(app_id)); - - m_handles.insert(std::pair(handle, handle_info)); - SERVER_DBG("handle(%d) pid(%d) inserted", handle, pid); - - return RMS_OK; -} -int CHandleManager::m_RemoveHandle(int handle, int pid) -{ - CHandle *handle_info = findHandle(handle); - - if (!handle_info) { - SERVER_ERR("can't find handle (%d) in list. no need to remove", handle); - return RMS_OK; - } - - if (handle_info->pid != pid) { - SERVER_ERR("cannot remove handle (%d) - owner(%d)/requester(%d)", handle, handle_info->pid, pid); - return RMS_ERROR; - } - - if (handle_info->app_id) { - free(handle_info->app_id); - handle_info->app_id = NULL; - } - - for (int i = 0; i < RMS_NAME_BUF_SIZE; i++) { - handle_info->process_name[i] = 0; - } - - delete handle_info; - m_handles.erase(handle); - - CCallback::RemoveFIFOServerToClient(pid, handle); - - return RMS_OK; -} -int CHandleManager::GetNewHandle(int pid, int main_priority, int sub_priority, int app_pid, char *app_id) -{ - int handle = -1; - - if (m_next_handle >= (M_MAX_HANDLE - 1)) - m_next_handle = M_MIN_HANDLE; - - std::map::iterator it = m_handles.find(m_next_handle); - - handle = (it == m_handles.end()) ? m_next_handle:m_ReclaimHandle(); - - if (handle == RMS_HANDLE_NOT_AVAILABLE) { - SERVER_ERR("ERROR! can't assign new handle (FULL)"); - m_PrintHandleList(); - return RMS_HANDLE_NOT_AVAILABLE; - } - - m_AddNewHandle(handle, pid, main_priority, sub_priority, app_pid, app_id); - ++m_next_handle; - - return handle; -} - -int CHandleManager::RemoveHandle(int handle, int pid) -{ - return m_RemoveHandle(handle, pid); -} - -int CHandleManager::SetPriority(int handle, int main_priority, int sub_priority) -{ - CHandle *handle_info = findHandle(handle); - - if (!handle_info) { - SERVER_ERR("can't find handle (%d)", handle); - return RMS_ERROR; - } - - CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); - - if (!consumer) { - SERVER_ERR("handle[%d] not registered consumer", handle); - return RMS_ERROR; - } - - handle_info->main_priority = main_priority; - handle_info->sub_priority = sub_priority; - - rms_priority_s priority; - priority.main = main_priority; - priority.sub = sub_priority; - - consumer->SetPriority(priority); - - return RMS_OK; -} - -CHandle *CHandleManager::findHandle(int id) -{ - auto it = m_handles.find(id); - - return (it == m_handles.end()) ? NULL:it->second; -} - -int CHandleManager::GetPriority(int handle, int *main_priority, int *sub_priority) -{ - CHandle *handle_info = findHandle(handle); - - if (!handle_info) { - SERVER_ERR("can't find handle (%d)", handle); - return RMS_ERROR; - } - - *main_priority = handle_info->main_priority; - *sub_priority = handle_info->sub_priority; - - return RMS_OK; -} - -int CHandleManager::SetAppID(int handle, char *app_id) -{ - CHandle *handle_info = findHandle(handle); - - if (!handle_info) { - SERVER_ERR("can't find handle (%d)", handle); - return RMS_ERROR; - } - - if (handle_info->app_id) { - free(handle_info->app_id); - handle_info->app_id = NULL; - } - - handle_info->app_id = strndup(app_id, strlen(app_id)); - - return RMS_OK; -} - -char *CHandleManager::GetAppID(int handle) -{ - CHandle *handle_info = findHandle(handle); - - if (!handle_info) { - SERVER_ERR("can't find handle (%d)", handle); - return NULL; - } - - return strndup(handle_info->app_id, strlen(handle_info->app_id)); -} - -int CHandleManager::m_PrintHandleInfo(int handle, int pid) -{ - char name[RMS_NAME_BUF_SIZE] = {0,}; - rms_get_cmd_name(pid, name, sizeof(name)); - - rms_log_reset(); - rms_log_add("handle(%d) pid(%d) name(%s)", handle, pid, name); - - CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); - - if (!consumer) { - rms_log_add(": no consumer info"); - - RMS_LOGE_FLUSH(); - return RMS_OK; - } - - rms_log_add(": using %d resource(s)", consumer->GetResourceNum()); - - RMS_LOGE_FLUSH(); - return RMS_OK; -} - -void CHandleManager::ReclaimAllInvalidCustomer(int request_pid) -{ - for (std::map::iterator it = m_handles.begin(); it != m_handles.end(); it++) { - CHandle *handle_info = (*it).second; - int cid = handle_info->handle; - int pid = handle_info->pid; - - if ((pid != request_pid) &&(!rm_is_valid_pid(pid))) { - SERVER_ERR("Reclaim handle(%d)/pid(%d)", cid, pid); - m_rsc_mgr->ReleaseResourcesOfPid(pid); - RemoveHandle(cid, pid); - CCallback::RemoveFIFOServerToClient(pid, cid); - } - } -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + + +static const int M_MIN_HANDLE = 101; +static const int M_MAX_HANDLE = 200; + +CHandleManager::CHandleManager(CResourceManager *rsc_mgr) +{ + assert(rsc_mgr); + m_rsc_mgr = rsc_mgr; + m_next_handle = M_MIN_HANDLE; +} + +int CHandleManager::m_IsValidHandle(int handle) +{ + return ((handle >= M_MIN_HANDLE) && (handle <= M_MAX_HANDLE)) ? 1 : 0; +} + +int CHandleManager::m_ReclaimHandle(void) +{ + for (int i = M_MIN_HANDLE; i < M_MAX_HANDLE; i++) { + CHandle *handle_info = findHandle(i); + + if (!handle_info) + return i; + + if (!rm_is_valid_pid(handle_info->pid)) { + SERVER_INFO("reclaim pid(%d)/handle(%d)", handle_info->pid, handle_info->handle); + + // release resources allocated to terminated process + m_rsc_mgr->UnregisterConsumer(handle_info->handle); + m_RemoveHandle(handle_info->handle, handle_info->pid); + return i; + } + } + + return RMS_HANDLE_NOT_AVAILABLE; +} + +void CHandleManager::m_PrintHandleList(void) +{ + for (int i = M_MIN_HANDLE; i < M_MAX_HANDLE; i++) { + std::map::iterator it = m_handles.find(i); + + if (it == m_handles.end()) + return ; + + CHandle *handle_info = (*it).second; + m_PrintHandleInfo(handle_info->handle, handle_info->pid); + } +} + +int CHandleManager::m_AddNewHandle(int handle, int pid, int main_priority, int sub_priority, int app_pid, char *app_id) +{ + CHandle *handle_info = new(std::nothrow) CHandle(handle, RMS_HANDLE_USE, pid); + if (!handle_info) { + SERVER_ERR("cannot create handle class"); + return RMS_ERROR; + } + + handle_info->main_priority = main_priority; + handle_info->sub_priority = sub_priority; + handle_info->app_pid = app_pid; + handle_info->app_id = strndup(app_id, strlen(app_id)); + + m_handles.insert(std::pair(handle, handle_info)); + SERVER_DBG("handle(%d) pid(%d) inserted", handle, pid); + + return RMS_OK; +} +int CHandleManager::m_RemoveHandle(int handle, int pid) +{ + CHandle *handle_info = findHandle(handle); + + if (!handle_info) { + SERVER_ERR("can't find handle (%d) in list. no need to remove", handle); + return RMS_OK; + } + + if (handle_info->pid != pid) { + SERVER_ERR("cannot remove handle (%d) - owner(%d)/requester(%d)", handle, handle_info->pid, pid); + return RMS_ERROR; + } + + if (handle_info->app_id) { + free(handle_info->app_id); + handle_info->app_id = NULL; + } + + for (int i = 0; i < RMS_NAME_BUF_SIZE; i++) { + handle_info->process_name[i] = 0; + } + + delete handle_info; + m_handles.erase(handle); + + CCallback::RemoveFIFOServerToClient(pid, handle); + + return RMS_OK; +} +int CHandleManager::GetNewHandle(int pid, int main_priority, int sub_priority, int app_pid, char *app_id) +{ + int handle = -1; + + if (m_next_handle >= (M_MAX_HANDLE - 1)) + m_next_handle = M_MIN_HANDLE; + + std::map::iterator it = m_handles.find(m_next_handle); + + handle = (it == m_handles.end()) ? m_next_handle:m_ReclaimHandle(); + + if (handle == RMS_HANDLE_NOT_AVAILABLE) { + SERVER_ERR("ERROR! can't assign new handle (FULL)"); + m_PrintHandleList(); + return RMS_HANDLE_NOT_AVAILABLE; + } + + m_AddNewHandle(handle, pid, main_priority, sub_priority, app_pid, app_id); + ++m_next_handle; + + return handle; +} + +int CHandleManager::RemoveHandle(int handle, int pid) +{ + return m_RemoveHandle(handle, pid); +} + +int CHandleManager::SetPriority(int handle, int main_priority, int sub_priority) +{ + CHandle *handle_info = findHandle(handle); + + if (!handle_info) { + SERVER_ERR("can't find handle (%d)", handle); + return RMS_ERROR; + } + + CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); + + if (!consumer) { + SERVER_ERR("handle[%d] not registered consumer", handle); + return RMS_ERROR; + } + + handle_info->main_priority = main_priority; + handle_info->sub_priority = sub_priority; + + rms_priority_s priority; + priority.main = main_priority; + priority.sub = sub_priority; + + consumer->SetPriority(priority); + + return RMS_OK; +} + +CHandle *CHandleManager::findHandle(int id) +{ + auto it = m_handles.find(id); + + return (it == m_handles.end()) ? NULL:it->second; +} + +int CHandleManager::GetPriority(int handle, int *main_priority, int *sub_priority) +{ + CHandle *handle_info = findHandle(handle); + + if (!handle_info) { + SERVER_ERR("can't find handle (%d)", handle); + return RMS_ERROR; + } + + *main_priority = handle_info->main_priority; + *sub_priority = handle_info->sub_priority; + + return RMS_OK; +} + +int CHandleManager::SetAppID(int handle, char *app_id) +{ + CHandle *handle_info = findHandle(handle); + + if (!handle_info) { + SERVER_ERR("can't find handle (%d)", handle); + return RMS_ERROR; + } + + if (handle_info->app_id) { + free(handle_info->app_id); + handle_info->app_id = NULL; + } + + handle_info->app_id = strndup(app_id, strlen(app_id)); + + return RMS_OK; +} + +char *CHandleManager::GetAppID(int handle) +{ + CHandle *handle_info = findHandle(handle); + + if (!handle_info) { + SERVER_ERR("can't find handle (%d)", handle); + return NULL; + } + + return strndup(handle_info->app_id, strlen(handle_info->app_id)); +} + +int CHandleManager::m_PrintHandleInfo(int handle, int pid) +{ + char name[RMS_NAME_BUF_SIZE] = {0,}; + rms_get_cmd_name(pid, name, sizeof(name)); + + rms_log_reset(); + rms_log_add("handle(%d) pid(%d) name(%s)", handle, pid, name); + + CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); + + if (!consumer) { + rms_log_add(": no consumer info"); + + RMS_LOGE_FLUSH(); + return RMS_OK; + } + + rms_log_add(": using %d resource(s)", consumer->GetResourceNum()); + + RMS_LOGE_FLUSH(); + return RMS_OK; +} + +void CHandleManager::ReclaimAllInvalidCustomer(int request_pid) +{ + for (std::map::iterator it = m_handles.begin(); it != m_handles.end(); it++) { + CHandle *handle_info = (*it).second; + int cid = handle_info->handle; + int pid = handle_info->pid; + + if ((pid != request_pid) &&(!rm_is_valid_pid(pid))) { + SERVER_ERR("Reclaim handle(%d)/pid(%d)", cid, pid); + m_rsc_mgr->ReleaseResourcesOfPid(pid); + RemoveHandle(cid, pid); + CCallback::RemoveFIFOServerToClient(pid, cid); + } + } +} diff --git a/src/CMessage.cpp b/src/CMessage.cpp index 68c1916..00fda5a 100644 --- a/src/CMessage.cpp +++ b/src/CMessage.cpp @@ -1,210 +1,210 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include - -CMessage::CMessage(std::string name) -{ - m_sender = MSG_SENDER_INTERNAL; - m_msgq_req = NULL; - m_name = name; -} - -CMessage::CMessage(rms_msg_request *req) -{ - assert(req); - - m_msgq_req = (rms_msg_request*) calloc(1, sizeof(rms_msg_request)); - assert(m_msgq_req); - memcpy(m_msgq_req, req, sizeof(rms_msg_request)); - - m_sender = MSG_SENDER_MSGQ; -} - -CMessage::CMessage(GDBusMethodInvocation *invoc) -{ - assert(invoc); - - m_invoc = invoc; - m_sender = MSG_SENDER_DBUS; - m_msgq_req = NULL; -} - -CMessage::~CMessage(void) -{ - if (m_msgq_req) - free(m_msgq_req); -} - -int CMessage::GetReqType(void) -{ - int req_type = RMS_REQUEST_MAX; - assert(m_msgq_req); - - switch (m_sender) { - case MSG_SENDER_MSGQ: - req_type = m_msgq_req->type; - break; - case MSG_SENDER_DBUS: - case MSG_SENDER_INTERNAL: - break; - default: - SERVER_ERR("undefined sender(%d)", m_sender); - break; - } - - return req_type; -} - -bool CMessage::IsMsgForScalerDbus(void) -{ - std::string method_name = g_dbus_method_invocation_get_method_name(m_invoc); - - if (!method_name.compare("FindDeviceId")) - return true; - if (!method_name.compare("SwapResources")) - return true; - if (!method_name.compare("GetScalerState")) - return true; - if (!method_name.compare("GetScalerHWID")) - return true; - if (!method_name.compare("RestoreResources")) - return true; - - return false; -} - -bool CMessage::IsMsgForScalerMsgQ(void) -{ - bool result = false; - switch (m_msgq_req->type) { - case RMS_REQUEST_ALLOCATE_RESOURCE: - for (int i = 0; i < m_msgq_req->request_num; i++) { - if (ri_is_video_scaler_category(m_msgq_req->resource[i])) - { - result = true; - break; - } - } - break; - case RMS_REQUEST_RELEASE_RESOURCES: - int category_type; - for (int i = 0; i < m_msgq_req->request_num; i++) { - ri_get_category_type_by_device_id(m_msgq_req->resource[i], &category_type); - if (ri_is_video_scaler_category(category_type)) - { - result = true; - break; - } - } - break; - case RMS_REQUEST_UNREGISTER: - case RMS_REQUEST_REGISTER: - case RMS_REQUEST_QUERY: - case RMS_REQUEST_SET_PRIORITY: - case RMS_REQUEST_SET_APPID: - result = false; - break; - default: - SERVER_ERR("undefined req type(%d)", m_msgq_req->type); - break; - } - - return result; -} - -void CMessage::PrintInfo(void) -{ - switch (m_sender) { - case MSG_SENDER_MSGQ: - PrintMsgQ(); - break; - case MSG_SENDER_DBUS: - PrintDbus(); - break; - case MSG_SENDER_INTERNAL: - PrintInternal(); - break; - default: - SERVER_ERR("undefined sender(%d)", m_sender); - break; - } -} - -void CMessage::PrintDbus(void) -{ - SERVER_ERR("Sender:Dbus/%s", g_dbus_method_invocation_get_method_name(m_invoc)); -} - -void CMessage::PrintInternal(void) -{ - SERVER_ERR("Sender:Internal/%s", m_name.c_str()); -} - -void CMessage::PrintMsgQ(void) -{ - SERVER_ERR("Sender:MsgQ/type(%d)/cid(%d)/num(%d)", m_msgq_req->type, m_msgq_req->handle, m_msgq_req->request_num); -} - -bool CMessage::IsUnlockMsg(void) -{ - if (m_sender != MSG_SENDER_INTERNAL) - return false; - - return (!m_name.compare("NotifyUnlock")); -} - -bool CMessage::IsMsgForScaler(void) -{ - bool result = false; - - switch (m_sender) { - case MSG_SENDER_MSGQ: - result = IsMsgForScalerMsgQ(); - break; - case MSG_SENDER_DBUS: - result = IsMsgForScalerDbus(); - break; - case MSG_SENDER_INTERNAL: - result = false; - break; - default: - SERVER_ERR("undefined sender(%d)", m_sender); - break; - } - - return result; -} - -bool CMessage::IsMsgFor(ResourceType rsc_type) -{ - bool result = false; - - switch (rsc_type) { - case ResourceType::VIDEO_SCALER: - result = IsMsgForScaler(); - break; - default: - break; - } - - return result; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include + +CMessage::CMessage(std::string name) +{ + m_sender = MSG_SENDER_INTERNAL; + m_msgq_req = NULL; + m_name = name; +} + +CMessage::CMessage(rms_msg_request *req) +{ + assert(req); + + m_msgq_req = (rms_msg_request*) calloc(1, sizeof(rms_msg_request)); + assert(m_msgq_req); + memcpy(m_msgq_req, req, sizeof(rms_msg_request)); + + m_sender = MSG_SENDER_MSGQ; +} + +CMessage::CMessage(GDBusMethodInvocation *invoc) +{ + assert(invoc); + + m_invoc = invoc; + m_sender = MSG_SENDER_DBUS; + m_msgq_req = NULL; +} + +CMessage::~CMessage(void) +{ + if (m_msgq_req) + free(m_msgq_req); +} + +int CMessage::GetReqType(void) +{ + int req_type = RMS_REQUEST_MAX; + assert(m_msgq_req); + + switch (m_sender) { + case MSG_SENDER_MSGQ: + req_type = m_msgq_req->type; + break; + case MSG_SENDER_DBUS: + case MSG_SENDER_INTERNAL: + break; + default: + SERVER_ERR("undefined sender(%d)", m_sender); + break; + } + + return req_type; +} + +bool CMessage::IsMsgForScalerDbus(void) +{ + std::string method_name = g_dbus_method_invocation_get_method_name(m_invoc); + + if (!method_name.compare("FindDeviceId")) + return true; + if (!method_name.compare("SwapResources")) + return true; + if (!method_name.compare("GetScalerState")) + return true; + if (!method_name.compare("GetScalerHWID")) + return true; + if (!method_name.compare("RestoreResources")) + return true; + + return false; +} + +bool CMessage::IsMsgForScalerMsgQ(void) +{ + bool result = false; + switch (m_msgq_req->type) { + case RMS_REQUEST_ALLOCATE_RESOURCE: + for (int i = 0; i < m_msgq_req->request_num; i++) { + if (ri_is_video_scaler_category(m_msgq_req->resource[i])) + { + result = true; + break; + } + } + break; + case RMS_REQUEST_RELEASE_RESOURCES: + int category_type; + for (int i = 0; i < m_msgq_req->request_num; i++) { + ri_get_category_type_by_device_id(m_msgq_req->resource[i], &category_type); + if (ri_is_video_scaler_category(category_type)) + { + result = true; + break; + } + } + break; + case RMS_REQUEST_UNREGISTER: + case RMS_REQUEST_REGISTER: + case RMS_REQUEST_QUERY: + case RMS_REQUEST_SET_PRIORITY: + case RMS_REQUEST_SET_APPID: + result = false; + break; + default: + SERVER_ERR("undefined req type(%d)", m_msgq_req->type); + break; + } + + return result; +} + +void CMessage::PrintInfo(void) +{ + switch (m_sender) { + case MSG_SENDER_MSGQ: + PrintMsgQ(); + break; + case MSG_SENDER_DBUS: + PrintDbus(); + break; + case MSG_SENDER_INTERNAL: + PrintInternal(); + break; + default: + SERVER_ERR("undefined sender(%d)", m_sender); + break; + } +} + +void CMessage::PrintDbus(void) +{ + SERVER_ERR("Sender:Dbus/%s", g_dbus_method_invocation_get_method_name(m_invoc)); +} + +void CMessage::PrintInternal(void) +{ + SERVER_ERR("Sender:Internal/%s", m_name.c_str()); +} + +void CMessage::PrintMsgQ(void) +{ + SERVER_ERR("Sender:MsgQ/type(%d)/cid(%d)/num(%d)", m_msgq_req->type, m_msgq_req->handle, m_msgq_req->request_num); +} + +bool CMessage::IsUnlockMsg(void) +{ + if (m_sender != MSG_SENDER_INTERNAL) + return false; + + return (!m_name.compare("NotifyUnlock")); +} + +bool CMessage::IsMsgForScaler(void) +{ + bool result = false; + + switch (m_sender) { + case MSG_SENDER_MSGQ: + result = IsMsgForScalerMsgQ(); + break; + case MSG_SENDER_DBUS: + result = IsMsgForScalerDbus(); + break; + case MSG_SENDER_INTERNAL: + result = false; + break; + default: + SERVER_ERR("undefined sender(%d)", m_sender); + break; + } + + return result; +} + +bool CMessage::IsMsgFor(ResourceType rsc_type) +{ + bool result = false; + + switch (rsc_type) { + case ResourceType::VIDEO_SCALER: + result = IsMsgForScaler(); + break; + default: + break; + } + + return result; +} diff --git a/src/CMessageHandler.cpp b/src/CMessageHandler.cpp index 729d79c..08f1276 100644 --- a/src/CMessageHandler.cpp +++ b/src/CMessageHandler.cpp @@ -1,1049 +1,1049 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define RMS_HANLDE_COMMON 100 // common handle for the request rm_register() is not required -#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) - -struct rms_msg_handler { - const char *msg_name; - CMessageHandler::MsgHandler handler; -}; - -CMessageHandler::CMessageHandler(CResourceManager *rsc_mgr) -{ - assert(rsc_mgr); - - msgq_rx = new CMessageQueue(MSG_QUEUE_RX); - msgq_tx = new CMessageQueue(MSG_QUEUE_TX); - async_queue = new CAsyncQueue(); - async_pending_queue = new CAsyncQueue(); - - m_rsc_mgr = rsc_mgr; - m_query_h = new CQueryHandler(rsc_mgr); - m_handle_mgr = new CHandleManager(rsc_mgr); - m_lock_ctr = CLockController::GetInstance(); - m_lock_ctr->SetMsgQ(async_queue); - - CCallback::InitCallback(); - InitDbusHandlers(); - InitInternalMsgHandlers(); -} - -CMessageHandler::~CMessageHandler(void) -{ - -} - -void CMessageHandler::InitDbusHandlers(void) -{ - struct rms_msg_handler dbus_handlers[] = { - {"RegisterResource", &CMessageHandler::RegisterResource}, - {"GetResourceState", &CMessageHandler::GetResourceState}, - {"GetResourceList", &CMessageHandler::GetResourceList}, - {"GetRscCollectionState", &CMessageHandler::GetResourceCollectionState}, - {"FindDeviceId", &CMessageHandler::FindDeviceId}, - {"SwapResources", &CMessageHandler::SwapResources}, - {"GetScalerState", &CMessageHandler::GetScalerState}, - {"GetAppId", &CMessageHandler::GetAppId}, - {"GetActiveAudioOut", &CMessageHandler::GetActiveAudioOut}, - {"GetScalerHWID", &CMessageHandler::GetScalerHWID}, - {"RestoreResources", &CMessageHandler::RestoreResources}, - {"NotifyResourcePolicy", &CMessageHandler::NotifyResourcePolicy}, - {"NotifyAppZoneInfo", &CMessageHandler::NotifyAppZoneInfo} - // Please add a new dbus message handler here - }; - - std::string msg_name; - for (unsigned int i = 0; i < ARRAY_SIZE(dbus_handlers); i++) { - msg_name.assign(dbus_handlers[i].msg_name); - m_dbus_handlers.insert(std::pair(msg_name, dbus_handlers[i].handler)); - } -} - -void CMessageHandler::InitInternalMsgHandlers(void) -{ - struct rms_msg_handler internal_msg_handlers[] = { - {"NotifyWatchdog", &CMessageHandler::NotifyWatchdog} - // Please add a new internal message handler here - }; - - std::string msg_name; - for (unsigned int i = 0; i < ARRAY_SIZE(internal_msg_handlers); i++) { - msg_name.assign(internal_msg_handlers[i].msg_name); - m_internal_msg_handlers.insert(std::pair(msg_name, internal_msg_handlers[i].handler)); - } -} - -void CMessageHandler::m_ConstructRequestedDevice(rms_msg_request *request, rms_requests_device_s *requested_resource) -{ - requested_resource->resources_num = request->request_num; - - for (int i = 0; i < requested_resource->resources_num; i++) { - requested_resource->devices[i].device_id = request->resource[i]; - requested_resource->devices[i].requested_state = (rms_requests_resource_state_e) request->state[i]; - } -} - -int CMessageHandler::Run(void) -{ - if (g_thread_new("rms_msgq_thread", msgQThread, this) == NULL) { - SERVER_ERR("failed to create rms_msgq thread"); - assert(0); - return RMS_ERROR; - } - - if (g_thread_new("rms_msg_thread", msgThread, this) == NULL) { - SERVER_ERR("event loop thread create failed\n"); - assert(0); - return RMS_ERROR; - } - - m_dbus_h = new CDbusHandler(async_queue); - return RMS_OK; -} - -gpointer CMessageHandler::msgQThread(gpointer data) -{ - assert(data); - - CMessageHandler *msg_handler = (CMessageHandler*) data; - CAsyncQueue *asyncq = msg_handler->async_queue; - CMessageQueue *msgq = msg_handler->msgq_rx; - rms_msg_request req; - - while (1) { - memset(&req, 0, sizeof(rms_msg_request)); - - if (msgq->receive(&req, RMS_REQUEST_DATA_TYPE_ALL) != RMS_OK) - continue; - - SERVER_DBG("push req type(%d)-pid(%d)-cid(%d)-len(%d)", req.type, req.pid, req.handle, asyncq->length()); - - CMessage *msg = new CMessage(&req); - asyncq->push(msg); - } - - return NULL; -} - -gpointer CMessageHandler::msgThread(gpointer data) -{ - assert(data); - SERVER_INFO("prepare to handle messages"); - - CMessageHandler *msg_handler = (CMessageHandler*) data; - - while (1) { - msg_handler->ProcessMessage(); - usleep(30000); - } - - return NULL; -} - -bool CMessageHandler::IsRegisteredHandle(int handle) -{ - return (CConsumerContainer::getInstance()->findConsumer(handle) != NULL); -} - -void CMessageHandler::SetRequesterInfo(rms_msg_request *request) -{ - char *app_id = m_handle_mgr->GetAppID(request->handle); - m_handle_mgr->GetPriority(request->handle, &request->main_priority, &request->sub_priority); - - snprintf(request->app_id, RMS_APPID_LENGTH, "%s", (app_id) ? app_id : ""); - - SERVER_INFO("handle(%d)-app_id(%s)", request->handle, request->app_id); - - if (app_id) - free(app_id); -} - - -void CMessageHandler::m_RegisterConsumer(rms_msg_request *request, rms_msg_response *response) -{ - char cmd[RMS_NAME_BUF_SIZE] = {0,}; - - int handle = m_handle_mgr->GetNewHandle(request->pid, request->main_priority, request->sub_priority, request->app_pid, request->app_id); - - response->result = (handle == RMS_HANDLE_NOT_AVAILABLE) ? RMS_ERROR : RMS_OK; - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_REGISTER, handle, request->pid); - - if (response->result == RMS_ERROR) - return; - - if (m_rsc_mgr->RegisterConsumer(handle, request->pid, request->app_id, request->main_priority, request->sub_priority) != RMS_OK) - SERVER_ERR("failed to add consumer to manager. handle[%d]", handle); - - rms_get_cmd_name(request->pid, cmd, sizeof(cmd)); - - SERVER_INFO("newly assigned handle(%d) - pid(%d)-(%s)", response->handle, request->pid, cmd); -} - -void CMessageHandler::m_UnregisterConsumer(rms_msg_request *request, rms_msg_response *response) -{ - SERVER_INFO("request for unregister handle(%d)", request->handle); - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_UNREGISTER, request->handle, request->pid); - - if (!IsRegisteredHandle(request->handle)) { - response->result = RMS_ERROR; - return; - } - - response->result = m_handle_mgr->RemoveHandle(request->handle, request->pid); - - if (response->result != RMS_OK) - return; - - m_rsc_mgr->UnregisterConsumer(request->handle); -} - -void CMessageHandler::m_FreeAllocatedDevice(rms_return_device_s *allocated_device) -{ - if (allocated_device->device_ids) { - free(allocated_device->device_ids); - allocated_device->device_ids = NULL; - } - - for (int i=0 ; i < allocated_device->resources_num; i++) { - if (allocated_device->devices[i].device_path) { - free((void*)allocated_device->devices[i].device_path); - allocated_device->devices[i].device_path = NULL; - } - } - - if (allocated_device->devices) { - free(allocated_device->devices); - allocated_device->devices = NULL; - } -} - -void CMessageHandler::m_Free(consumer_reclaim_s *consumer_info) -{ - if (!consumer_info) - return; - - if (!consumer_info->consumer_info) - return; - - for (int i = 0; i < consumer_info->ret_quantity; i++) { - if (consumer_info->consumer_info[i].conflicted_resources != NULL) - free(consumer_info->consumer_info[i].conflicted_resources); - } - - free(consumer_info->consumer_info); -} - -void CMessageHandler::m_AllocateResources(rms_msg_request *request, rms_msg_response *response) -{ - trace_begin("RSC ALLOCATE START"); - trace_end(); - - if (!IsRegisteredHandle(request->handle)) { - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_ALLOCATE_RESOURCE, request->handle, request->pid); - response->result = RMS_ERROR; - return; - } - - int result = RMS_OK; - bool need_response = true; - rms_return_device_s allocated_device; - memset(&allocated_device, 0, sizeof(rms_return_device_s)); - - m_handle_mgr->ReclaimAllInvalidCustomer(request->pid); - - SetRequesterInfo(request); - - result = m_rsc_mgr->AllocateResources(request, &allocated_device); - - bool needReclaimResources = (result == RMS_ERROR_TAKE_RESOURCE_FROM_OTHER_CONSUMER); - - if (needReclaimResources) { - consumer_reclaim_s consumers_reclaim; - memset(&consumers_reclaim, 0, sizeof(consumers_reclaim)); - int zone_id = -1; - if (m_rsc_mgr->FindReclaimableConsumers(request, &consumers_reclaim, &zone_id) == RMS_OK) { - CResourceDB::getInstance()->AddReclaimResources(&consumers_reclaim); - if (ReclaimResources(result, request->handle, zone_id, &consumers_reclaim, &need_response) == RMS_OK) { - result = m_rsc_mgr->AllocateResources(request, &allocated_device); - } - CResourceDB::getInstance()->ClearReclaimResources(); - } - m_Free(&consumers_reclaim); - } - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_ALLOCATE_RESOURCE, request->handle, request->pid); - - response->result = result; - response->error_type = (result == RMS_OK) ? RMS_ERR_TYPE_NONE : (rms_error_type_e)allocated_device.error_type; - response->resource_num = allocated_device.resources_num; - - if (!need_response) - response->error_type = RMS_ERR_TYPE_TERMINATED_PROCESS; - - for (int i = 0; i < response->resource_num; i++) { - response->resource[i] = allocated_device.device_ids[i]; - } - - m_FreeAllocatedDevice(&allocated_device); - CCache::getInstance()->Drop(); - - trace_begin("RSC ALLOCATE END"); - trace_end(); -} - -void CMessageHandler::m_ReleaseResources(rms_msg_request *request, rms_msg_response *response) -{ - SERVER_DBG("request for deallocation"); - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_RELEASE_RESOURCES, request->handle, request->pid); - - if (!IsRegisteredHandle(request->handle)) { - response->result = RMS_ERROR; - return; - } - - rms_requests_device_s requested_resource; - memset(&requested_resource, 0, sizeof(rms_requests_device_s)); - - m_ConstructRequestedDevice(request, &requested_resource); - - response->result = m_rsc_mgr->ReleaseResources(request->handle, &requested_resource); -} - -void CMessageHandler::m_Query(rms_msg_request *request, rms_msg_response *response) -{ - int answer = 0; - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_QUERY, request->handle, request->pid); - - m_handle_mgr->ReclaimAllInvalidCustomer(request->handle); - - response->result = m_query_h->GetAnswer(request, &answer); - response->is_available = answer; - - SERVER_INFO("query on (%d), result(%d)", request->sub_type, answer); -} - -void CMessageHandler::m_SetConsumerPriority(rms_msg_request *request, rms_msg_response *response) -{ - SERVER_INFO("request for priority setting. priority(%d)", request->main_priority); - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_SET_PRIORITY, request->handle, request->pid); - - response->result = m_handle_mgr->SetPriority(request->handle, request->main_priority, request->sub_priority); -} - -void CMessageHandler::m_SetAppID(rms_msg_request *request, rms_msg_response *response) -{ - SERVER_INFO("request for appid setting. appid(%s)", request->app_id); - - m_ConstructResponse(response, request->data_type, RMS_RESPONSE_SET_APPID, request->handle, request->pid); - - int ret = m_handle_mgr->SetAppID(request->handle, request->app_id); - - if (ret != RMS_OK) { - SERVER_ERR("cannot update appid. handle(%d). ret(%d)", request->handle, ret); - - response->result = RMS_ERROR; - return; - } - - response->result = m_rsc_mgr->SetAppId(request->handle, request->app_id); -} - -CMessageHandler::msg_handler CMessageHandler::handlers[RMS_REQUEST_MAX] = { - &CMessageHandler::m_RegisterConsumer, - &CMessageHandler::m_UnregisterConsumer, - &CMessageHandler::m_AllocateResources, - &CMessageHandler::m_ReleaseResources, - &CMessageHandler::m_Query, - &CMessageHandler::m_SetConsumerPriority, - &CMessageHandler::m_SetAppID, -}; - -void CMessageHandler::ProcessMsgQMessage(CMessage *msg) -{ - if (!IsValidRequest(msg->GetReqType())) { - SERVER_ERR("invalid req type(%d)", msg->GetReqType()); - return; - } - - rms_msg_response resp; - memset(&resp, 0, sizeof(rms_msg_response)); - - rms_msg_request *req = msg->GetRequest(); - SERVER_INFO("req type(%d)-pid(%d)-cid(%d)-t(%lu)", req->type, req->pid, req->handle, req->time); - - (this->*handlers[req->type])(msg->GetRequest(), &resp); - - if (resp.error_type == RMS_ERR_TYPE_TERMINATED_PROCESS) { - SERVER_ERR("skip to send a response (%d)", req->pid); - return; - } - - if (msgq_tx->send(&resp) != RMS_OK) { - SERVER_ERR("failed to send response"); - } -} - -GVariant *CMessageHandler::RegisterResource(GVariant *params) -{ - char *dev_name; - char *dev_node; - int category; - int sharable_count; - - g_variant_get(params, "(&ssii)", &dev_name, &dev_node, &category, &sharable_count); - - SERVER_INFO("dev_name(%s)/dev_node(%s)/category(%d)/sharable(%d)", dev_name, dev_node, category, sharable_count); - return g_variant_new("(i)", RMS_OK); -} - -GVariant *CMessageHandler::GetResourceState(GVariant *params) -{ - int device_id; - int state; - - g_variant_get(params, "(i)", &device_id); - - state = m_rsc_mgr->GetResourceState(device_id); - - SERVER_INFO("state (%d:%d)", device_id, state); - - return g_variant_new("(i)", state); -} - -GVariant *CMessageHandler::FindDeviceId(GVariant *params) -{ - int virtual_id; - int real_id; - - g_variant_get(params, "(i)", &virtual_id); - - real_id = m_rsc_mgr->FindDeviceId(virtual_id); - - SERVER_INFO("real id (%d:%d)", virtual_id, real_id); - - return g_variant_new("(i)", real_id); -} - -GVariant *CMessageHandler::GetScalerHWID(GVariant *params) -{ - int zone_id; - int hw_id; - - g_variant_get(params, "(i)", &zone_id); - - hw_id = m_rsc_mgr->GetScalerHWId(zone_id); - - SERVER_INFO("hw id (%d:%d)", zone_id, hw_id); - - return g_variant_new("(i)", hw_id); -} - -GVariant *CMessageHandler::SwapResources(GVariant *params) -{ - int device_id_a; - int device_id_b; - int result = 0; - - g_variant_get(params, "(ii)", &device_id_a, &device_id_b); - - result = m_rsc_mgr->SwapResources(device_id_a, device_id_b); - - SERVER_INFO("swap result (%d:%d) > (%d)", device_id_a, device_id_b, result); - - return g_variant_new("(i)", result); -} - -GVariant *CMessageHandler::RestoreResources(GVariant *params) -{ - int category_id; - int result = 0; - - g_variant_get(params, "(i)", &category_id); - - result = m_rsc_mgr->RestoreResources(category_id); - - SERVER_INFO("restore result (%d) > (%d)", category_id, result); - - return g_variant_new("(i)", result); -} - -GVariant *CMessageHandler::NotifyResourcePolicy(GVariant *params) -{ - int policy; - int result = 0; - - g_variant_get(params, "(i)", &policy); - - m_rsc_mgr->ResetZoneIds(); - - SERVER_INFO("notify result (%d) > (%d)", policy, result); - return g_variant_new("(i)", result); -} - -GVariant *CMessageHandler::NotifyAppZoneInfo(GVariant *params) -{ - char *app_id; - int zone_id; - int result = 0; - - g_variant_get(params, "(&si)", &app_id, &zone_id); - - if (!app_id) { - result = -1; - SERVER_INFO("invalid param (%s:%d) - result(%d)", "null", zone_id, result); - return g_variant_new("(i)", result); - } - - m_rsc_mgr->UpdateZoneIds(app_id, zone_id); - - SERVER_INFO("notify result (%s:%d) > (%d)", app_id, zone_id, result); - return g_variant_new("(i)", result); -} - -GVariant *CMessageHandler::GetResourceList(GVariant *params) -{ - int category_id; - - g_variant_get(params, "(i)", &category_id); - - SERVER_DBG("category (%d)", category_id); - - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(iissi))")); - - g_variant_builder_open(&builder, G_VARIANT_TYPE("a(iissi)")); - m_rsc_mgr->GetResourceList(category_id, &builder); - g_variant_builder_close(&builder); - - return g_variant_builder_end(&builder); -} - -GVariant *CMessageHandler::GetScalerState(GVariant *params) -{ - SERVER_INFO("GetScalerState"); - - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(iiiiis))")); - - g_variant_builder_open(&builder, G_VARIANT_TYPE("a(iiiiis)")); - m_rsc_mgr->GetScalerState(&builder); - g_variant_builder_close(&builder); - - return g_variant_builder_end(&builder); -} - -GVariant *CMessageHandler::GetAppId(GVariant *params) -{ - int result = 0; - int handle; - g_variant_get(params, "(i)", &handle); - - SERVER_INFO("GetAppId(%d)", handle); - - CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); - if (!consumer) { - SERVER_ERR("consumer(%d) not found", handle); - result = -1; - return g_variant_new("(is)", result, ""); - } - - return g_variant_new("(is)", result, (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str()); -} - -GVariant *CMessageHandler::GetResourceCollectionState(GVariant *params) -{ - int collection; - - g_variant_get(params, "(i)", &collection); - - SERVER_INFO("collection (%d)", collection); - - GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(isiiis))")); - - g_variant_builder_open(&builder, G_VARIANT_TYPE("a(isiiis)")); - m_rsc_mgr->GetResourceCollectionState(collection, &builder); - g_variant_builder_close(&builder); - - return g_variant_builder_end(&builder); -} - -GVariant *CMessageHandler::GetActiveAudioOut(GVariant *params) -{ - int cid; - int active_audio_out; - - g_variant_get(params, "(i)", &cid); - - active_audio_out = m_rsc_mgr->GetActiveAudioOut(cid); - SERVER_INFO("active_audio_out(%d:%d)", cid, active_audio_out); - - return g_variant_new("(i)", active_audio_out); -} - -void CMessageHandler::ProcessDbusMessage(CMessage *msg) -{ - GDBusMethodInvocation *invoc = msg->GetMethodInvocation(); - std::string method_name(g_dbus_method_invocation_get_method_name(invoc)); - - auto it = m_dbus_handlers.find(method_name); - if (it == m_dbus_handlers.end()) { - SERVER_ERR("handler is not found (%s)", method_name.c_str()); - return; - } - - GVariant *params = g_dbus_method_invocation_get_parameters(invoc); - GVariant *result = (this->*(it->second))(params); - - g_dbus_method_invocation_return_value(invoc, result); -} - -void CMessageHandler::ProcessInternalMessage(CMessage *msg) -{ - auto it = m_internal_msg_handlers.find(msg->GetName()); - if (it == m_internal_msg_handlers.end()) { - SERVER_ERR("handler is not found (%s)", msg->GetName().c_str()); - return; - } - - (this->*(it->second))(NULL); -} - -void CMessageHandler::EmptyPendingQueue(void) -{ - if (async_pending_queue->length() <= 0) - return; - - SERVER_WARN("empty pending queue(%d)", async_pending_queue->length()); - async_queue->push(async_pending_queue); -} - -void CMessageHandler::InsertPendingQueue(CMessage *msg) -{ - SERVER_WARN("msg locked"); - msg->PrintInfo(); - async_pending_queue->push(msg); -} - -int CMessageHandler::ProcessMessage(void) -{ - CMessage *msg = (CMessage*) async_queue->pop(); - assert(msg); - - if ((m_lock_ctr->GetLockCount() > 0) && m_lock_ctr->IsLocked(msg)) { - InsertPendingQueue(msg); - return 0; - } - - if (msg->IsUnlockMsg()) { - EmptyPendingQueue(); - delete msg; - return 0; - } - - switch (msg->GetSender()) { - case MSG_SENDER_MSGQ: - ProcessMsgQMessage(msg); - break; - case MSG_SENDER_DBUS: - ProcessDbusMessage(msg); - break; - case MSG_SENDER_INTERNAL: - ProcessInternalMessage(msg); - break; - default: - break; - } - - delete msg; - - return 0; -} - -bool CMessageHandler::IsAllResourcesReclaimed(rms_consumer_tobe_returned_s *consumer_info) -{ - for (int idx = 0; idx < consumer_info->n_conflicted; idx++) { - if (!m_rsc_mgr->IsReclaimed(consumer_info->conflicted_resources[idx].device_id, consumer_info->consumer_id)) { - SERVER_WARN("IsReclaimed is failed"); - return false; - } - } - - SERVER_WARN("all conflicted resources are freed"); - - return true; -} - -void CMessageHandler::ProcessMessage(CAsyncQueue *queue, CMessage *msg, int cid_requester, int cid_releaser) -{ - rms_msg_request *req = msg->GetRequest(); - rms_msg_response resp; - int handle; - char cmd[RMS_NAME_BUF_SIZE] = {0,}; - - switch (req->type) { - case RMS_REQUEST_RELEASE_RESOURCES: - - rms_requests_device_s requested_resource; - memset(&requested_resource, 0, sizeof(rms_requests_device_s)); - - m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_RELEASE_RESOURCES, req->handle, req->pid); - m_ConstructRequestedDevice(req, &requested_resource); - - if ((resp.result = m_rsc_mgr->ReleaseResources(req->handle, &requested_resource)) != RMS_OK) - SERVER_ERR("failed to release resources requested by (%d)", req->handle); - - SendResponse(&resp); - - break; - - case RMS_REQUEST_UNREGISTER: - - m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_UNREGISTER, req->handle, req->pid); - - SERVER_WARN("unregister requested by handle(%d)", req->handle); - - if (req->handle == cid_requester) { - SERVER_WARN("unregister request from requester(%d), send to internal queue", req->handle); - - PushMessage(queue, msg); - } else { - if ((resp.result = m_handle_mgr->RemoveHandle(req->handle, req->pid)) == RMS_OK) { - m_rsc_mgr->UnregisterConsumer(req->handle); - } - - SendResponse(&resp); - } - break; - - case RMS_REQUEST_REGISTER: - handle = m_handle_mgr->GetNewHandle(req->pid, req->main_priority, req->sub_priority, req->app_pid, req->app_id); - - resp.result = (handle == RMS_HANDLE_NOT_AVAILABLE) ? RMS_ERROR : RMS_OK; - m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_REGISTER, handle, req->pid); - - if (resp.result == RMS_ERROR) { - SendResponse(&resp); - break; - } - - if (m_rsc_mgr->RegisterConsumer(handle, req->pid, req->app_id, req->main_priority, req->sub_priority) != RMS_OK) - SERVER_ERR("failed to add consumer to manager. handle[%d]", handle); - - rms_get_cmd_name(req->pid, cmd, sizeof(cmd)); - - SERVER_INFO("newly assigned handle(%d) date type(%ld)- pid(%d)-(%s)", resp.handle, req->data_type, req->pid, cmd); - SendResponse(&resp); - break; - - default: - SERVER_ERR("unexpected request(%d) by handle(%d)/pid(%d)", req->type, req->handle, req->pid); - - if (req->handle == cid_releaser) { - m_ConstructResponse(&resp, req->data_type, (rms_response_type_e)req->type, req->handle, req->pid); - resp.result = RMS_ERROR; - - SendResponse(&resp); - } else { - PushMessage(queue, msg); - } - break; - } -} - -int CMessageHandler::ProcessCallbackMessage(rms_consumer_tobe_returned_s *consumer_info, int requester_cid) -{ - CMessage *msg = NULL; - int result = RMS_OK; - CAsyncQueue *queue = new CAsyncQueue(); - - unsigned int timeout_ms = CCallback::GetTimeout(); - - while (!IsAllResourcesReclaimed(consumer_info)) { - msg = (CMessage*) async_queue->pop(timeout_ms); - - if (!msg) { - SERVER_ERR("receive cb request timeout! CID[%d]/PID[%ld]", consumer_info->consumer_id, consumer_info->process_id); - result = RMS_ERROR; - goto out; - } - - if (msg->GetSender() == MSG_SENDER_DBUS) { - ProcessDbusMessage(msg); - } else if (msg->GetSender() == MSG_SENDER_MSGQ) { - SERVER_WARN("[MSG_SENDER_MSGQ] requester cid %d consumer id %d", requester_cid, consumer_info->consumer_id); - ProcessMessage(queue, msg, requester_cid, consumer_info->consumer_id); - } else { - ProcessInternalMessage(msg); - } - - delete msg; - } - -out: - async_queue->push_front(queue); - - delete queue; - - return result; -} - -int *CMessageHandler::m_SerializeCallbackData(const rms_consumer_tobe_returned_s *consumer_info, int reason, int *data_size) -{ - int num_conflicted_resources = consumer_info->n_conflicted; - - int *callback_data = (int*) calloc(num_conflicted_resources + 4, sizeof(int)); - assert(callback_data); - - callback_data[0] = CCallback::ConvertCallbackType(reason); - callback_data[1] = consumer_info->consumer_id; - callback_data[2] = consumer_info->process_id; - callback_data[3] = num_conflicted_resources; - - for (int res = 0; res < num_conflicted_resources; res++) { - callback_data[(res+4)] = consumer_info->conflicted_resources[res].virtual_id; - SERVER_DBG("- virtual_id:%d ", consumer_info->conflicted_resources[res].virtual_id); - } - - *data_size = (num_conflicted_resources + 4) * sizeof(int); - - return callback_data; -} - -bool CMessageHandler::IsValidProcess(int pid) -{ - return rm_is_valid_pid(pid); -} - -bool CMessageHandler::IsValidRequest(int req_type) -{ - return (req_type >= RMS_REQUEST_REGISTER && req_type < RMS_REQUEST_MAX); -} - -int CMessageHandler::ReleaseInvalidProcessResources(int pid, int handle) -{ - m_handle_mgr->RemoveHandle(handle, pid); - CCallback::RemoveFIFOServerToClient(pid, handle); - - return RMS_OK; -} - -void CMessageHandler::NotifyConflict(consumer_reclaim_s *conflict_info, int zone_id) -{ - if (!conflict_info) - return; - - int consumer_id = -1; - int device_id = -1; - int category_id = -1; - int app_zone_id = -1; - int n_consumer = conflict_info->ret_quantity; - CConsumer *consumer = NULL; - - GError *error = NULL; - GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); - - if (!connection) { - SERVER_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); - goto out; - } - - for (int i = 0; i < n_consumer; i++) { - consumer_id = conflict_info->consumer_info[i].consumer_id; - consumer = CConsumerContainer::getInstance()->findConsumer(consumer_id); - - for (int j = 0; j < conflict_info->consumer_info[i].n_conflicted; j++) { - device_id = conflict_info->consumer_info[i].conflicted_resources[j].device_id; - app_zone_id = m_rsc_mgr->GetZoneId(device_id); - category_id = conflict_info->consumer_info[i].conflicted_resources[j].category_id; - SERVER_INFO("send resource conflict (%d:%d:%d:%s:%d:%d)", - category_id, device_id, consumer_id, (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str(), app_zone_id, zone_id); - if (!g_dbus_connection_emit_signal(connection, - NULL, - RM_DBUS_OBJ_PATH, - RM_DBUS_INTERFACE_NAME, - "RscConflicted", - g_variant_new("(iiisii)", category_id, device_id, consumer_id, - (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str(), app_zone_id, zone_id), - &error)) { - SERVER_ERR("failed to send resource conflict (%d:%d:%d:%s)-%s", category_id, device_id, consumer_id, - (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str():consumer->GetAppID().c_str(), (error) ? error->message : "unknown"); - } - } - } -out: - if (error) - g_error_free(error); -} - -int CMessageHandler::ReclaimResources(int reason, int requester_cid, int requester_zone_id, consumer_reclaim_s *conflict_info, bool *need_response) -{ - int num_consumers = conflict_info->ret_quantity; - int data_size = 0; - int *callback_data = NULL; - char cmd[RMS_NAME_BUF_SIZE] = {0,}; - int err = 0; - int cid = 0; - int pid = 0; - - SERVER_WARN("start to reclaim - retirable consumers : (%d)", num_consumers); - - if (num_consumers > 0) - NotifyConflict(conflict_info, requester_zone_id); - - for (int i = 0; i < num_consumers; i++) { - pid = (int) conflict_info->consumer_info[i].process_id; - cid = conflict_info->consumer_info[i].consumer_id; - - if (!IsValidProcess(pid)) { - SERVER_ERR("handle(%d)/pid(%d) terminated", cid, pid); - m_rsc_mgr->ReleaseResourcesOfPid(pid); - ReleaseInvalidProcessResources(pid, cid); - continue; - } - - SERVER_DBG("[%d]th cid[%d]/rscs[%d]", i+1, cid, conflict_info->consumer_info[i].n_conflicted); - - callback_data = m_SerializeCallbackData(&conflict_info->consumer_info[i], reason, &data_size); - - if (CCallback::SendCallbackMessage(cid, pid, (void*) callback_data, data_size, &err) != RMS_OK) { - if (err == ENXIO) { //ENXIO No such device or address - SERVER_ERR("Process cannot get callback (CID:%d)/(PID:%d)", cid, pid); - m_rsc_mgr->ReleaseResourcesOfPid(pid); - ReleaseInvalidProcessResources(pid, cid); - free(callback_data); - continue; - } - - if (err == ENOENT && !IsRegisteredHandle(cid)) { - SERVER_ERR("already unregistred (%d)", cid); - free(callback_data); - continue; - } - - SERVER_ERR("failed to send callback message to (CID:%d)/(PID:%d), errno(%d)", cid, pid, err); - free(callback_data); - return RMS_ERROR; - } - - SERVER_WARN("[%d]th callback message sent to CID[%d]/PID[%d]/RSCS[%d]", i+1, cid, pid, conflict_info->consumer_info[i].n_conflicted); - - if (ProcessCallbackMessage(&conflict_info->consumer_info[i], requester_cid) != RMS_OK) { - if (!IsValidProcess(pid)) { - SERVER_ERR("handle(%d)/pid(%d) terminated", cid, pid); - m_rsc_mgr->ReleaseResourcesOfPid(pid); - ReleaseInvalidProcessResources(pid, cid); - free(callback_data); - - if (!IsRegisteredHandle(requester_cid)) { - SERVER_ERR("requester(%d:%d) terminated as well", pid, requester_cid); - *need_response = false; - return RMS_ERROR; - } - continue; - } - - rms_get_cmd_name(pid, cmd, sizeof(cmd)); - SERVER_ERR("failed to process callback request from : (%s) /(CID:%d)/(PID:%d)", cmd, cid, pid); - - rms_display_timeout_error_popup(RMS_ALARM_NO_DEALLOCATION, conflict_info->consumer_info[i]); - int ret = rms_report_emergency(cid, pid, RMS_EMERGENCY_CONSUMER_NOT_RESPONDING); - - SERVER_ERR("release resources of cosumer(%d) forcely", pid); - m_rsc_mgr->UnregisterConsumer(cid); - m_handle_mgr->RemoveHandle(cid, pid); - - free(callback_data); - return ret; - } - - free(callback_data); - } - - return RMS_OK; -} - -int CMessageHandler::SendResponse(rms_msg_response *response) -{ - return msgq_tx->send(response); -} - -int CMessageHandler::PushMessage(CAsyncQueue *queue, CMessage *msg) -{ - CMessage *msg_copy = new CMessage(msg->GetRequest()); - rms_msg_request *req = msg->GetRequest(); - SERVER_INFO("push_front msg type(%d)-pid(%d)-cid(%d)", req->type, req->pid, req->handle); - - queue->push_front(msg_copy); - - return RMS_OK; -} - -void CMessageHandler::m_ConstructResponse(rms_msg_response *response, int data_type, rms_response_type_e msg_type, int handle, int pid) -{ - assert(response); - - response->data_type = data_type; - response->type = msg_type; - response->handle = handle; - response->pid = pid; -} - -void CMessageHandler::NotifyWatchdog(void) -{ - if (!async_queue) - return; - - SERVER_INFO("push watchdog msg"); - async_queue->push(new CMessage("NotifyWatchdog")); -} - -GVariant *CMessageHandler::NotifyWatchdog(GVariant *params) -{ - SERVER_INFO("send watchdog notify completed"); - return NULL; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RMS_HANLDE_COMMON 100 // common handle for the request rm_register() is not required +#define ARRAY_SIZE(name) (sizeof(name)/sizeof(name[0])) + +struct rms_msg_handler { + const char *msg_name; + CMessageHandler::MsgHandler handler; +}; + +CMessageHandler::CMessageHandler(CResourceManager *rsc_mgr) +{ + assert(rsc_mgr); + + msgq_rx = new CMessageQueue(MSG_QUEUE_RX); + msgq_tx = new CMessageQueue(MSG_QUEUE_TX); + async_queue = new CAsyncQueue(); + async_pending_queue = new CAsyncQueue(); + + m_rsc_mgr = rsc_mgr; + m_query_h = new CQueryHandler(rsc_mgr); + m_handle_mgr = new CHandleManager(rsc_mgr); + m_lock_ctr = CLockController::GetInstance(); + m_lock_ctr->SetMsgQ(async_queue); + + CCallback::InitCallback(); + InitDbusHandlers(); + InitInternalMsgHandlers(); +} + +CMessageHandler::~CMessageHandler(void) +{ + +} + +void CMessageHandler::InitDbusHandlers(void) +{ + struct rms_msg_handler dbus_handlers[] = { + {"RegisterResource", &CMessageHandler::RegisterResource}, + {"GetResourceState", &CMessageHandler::GetResourceState}, + {"GetResourceList", &CMessageHandler::GetResourceList}, + {"GetRscCollectionState", &CMessageHandler::GetResourceCollectionState}, + {"FindDeviceId", &CMessageHandler::FindDeviceId}, + {"SwapResources", &CMessageHandler::SwapResources}, + {"GetScalerState", &CMessageHandler::GetScalerState}, + {"GetAppId", &CMessageHandler::GetAppId}, + {"GetActiveAudioOut", &CMessageHandler::GetActiveAudioOut}, + {"GetScalerHWID", &CMessageHandler::GetScalerHWID}, + {"RestoreResources", &CMessageHandler::RestoreResources}, + {"NotifyResourcePolicy", &CMessageHandler::NotifyResourcePolicy}, + {"NotifyAppZoneInfo", &CMessageHandler::NotifyAppZoneInfo} + // Please add a new dbus message handler here + }; + + std::string msg_name; + for (unsigned int i = 0; i < ARRAY_SIZE(dbus_handlers); i++) { + msg_name.assign(dbus_handlers[i].msg_name); + m_dbus_handlers.insert(std::pair(msg_name, dbus_handlers[i].handler)); + } +} + +void CMessageHandler::InitInternalMsgHandlers(void) +{ + struct rms_msg_handler internal_msg_handlers[] = { + {"NotifyWatchdog", &CMessageHandler::NotifyWatchdog} + // Please add a new internal message handler here + }; + + std::string msg_name; + for (unsigned int i = 0; i < ARRAY_SIZE(internal_msg_handlers); i++) { + msg_name.assign(internal_msg_handlers[i].msg_name); + m_internal_msg_handlers.insert(std::pair(msg_name, internal_msg_handlers[i].handler)); + } +} + +void CMessageHandler::m_ConstructRequestedDevice(rms_msg_request *request, rms_requests_device_s *requested_resource) +{ + requested_resource->resources_num = request->request_num; + + for (int i = 0; i < requested_resource->resources_num; i++) { + requested_resource->devices[i].device_id = request->resource[i]; + requested_resource->devices[i].requested_state = (rms_requests_resource_state_e) request->state[i]; + } +} + +int CMessageHandler::Run(void) +{ + if (g_thread_new("rms_msgq_thread", msgQThread, this) == NULL) { + SERVER_ERR("failed to create rms_msgq thread"); + assert(0); + return RMS_ERROR; + } + + if (g_thread_new("rms_msg_thread", msgThread, this) == NULL) { + SERVER_ERR("event loop thread create failed\n"); + assert(0); + return RMS_ERROR; + } + + m_dbus_h = new CDbusHandler(async_queue); + return RMS_OK; +} + +gpointer CMessageHandler::msgQThread(gpointer data) +{ + assert(data); + + CMessageHandler *msg_handler = (CMessageHandler*) data; + CAsyncQueue *asyncq = msg_handler->async_queue; + CMessageQueue *msgq = msg_handler->msgq_rx; + rms_msg_request req; + + while (1) { + memset(&req, 0, sizeof(rms_msg_request)); + + if (msgq->receive(&req, RMS_REQUEST_DATA_TYPE_ALL) != RMS_OK) + continue; + + SERVER_DBG("push req type(%d)-pid(%d)-cid(%d)-len(%d)", req.type, req.pid, req.handle, asyncq->length()); + + CMessage *msg = new CMessage(&req); + asyncq->push(msg); + } + + return NULL; +} + +gpointer CMessageHandler::msgThread(gpointer data) +{ + assert(data); + SERVER_INFO("prepare to handle messages"); + + CMessageHandler *msg_handler = (CMessageHandler*) data; + + while (1) { + msg_handler->ProcessMessage(); + usleep(30000); + } + + return NULL; +} + +bool CMessageHandler::IsRegisteredHandle(int handle) +{ + return (CConsumerContainer::getInstance()->findConsumer(handle) != NULL); +} + +void CMessageHandler::SetRequesterInfo(rms_msg_request *request) +{ + char *app_id = m_handle_mgr->GetAppID(request->handle); + m_handle_mgr->GetPriority(request->handle, &request->main_priority, &request->sub_priority); + + snprintf(request->app_id, RMS_APPID_LENGTH, "%s", (app_id) ? app_id : ""); + + SERVER_INFO("handle(%d)-app_id(%s)", request->handle, request->app_id); + + if (app_id) + free(app_id); +} + + +void CMessageHandler::m_RegisterConsumer(rms_msg_request *request, rms_msg_response *response) +{ + char cmd[RMS_NAME_BUF_SIZE] = {0,}; + + int handle = m_handle_mgr->GetNewHandle(request->pid, request->main_priority, request->sub_priority, request->app_pid, request->app_id); + + response->result = (handle == RMS_HANDLE_NOT_AVAILABLE) ? RMS_ERROR : RMS_OK; + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_REGISTER, handle, request->pid); + + if (response->result == RMS_ERROR) + return; + + if (m_rsc_mgr->RegisterConsumer(handle, request->pid, request->app_id, request->main_priority, request->sub_priority) != RMS_OK) + SERVER_ERR("failed to add consumer to manager. handle[%d]", handle); + + rms_get_cmd_name(request->pid, cmd, sizeof(cmd)); + + SERVER_INFO("newly assigned handle(%d) - pid(%d)-(%s)", response->handle, request->pid, cmd); +} + +void CMessageHandler::m_UnregisterConsumer(rms_msg_request *request, rms_msg_response *response) +{ + SERVER_INFO("request for unregister handle(%d)", request->handle); + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_UNREGISTER, request->handle, request->pid); + + if (!IsRegisteredHandle(request->handle)) { + response->result = RMS_ERROR; + return; + } + + response->result = m_handle_mgr->RemoveHandle(request->handle, request->pid); + + if (response->result != RMS_OK) + return; + + m_rsc_mgr->UnregisterConsumer(request->handle); +} + +void CMessageHandler::m_FreeAllocatedDevice(rms_return_device_s *allocated_device) +{ + if (allocated_device->device_ids) { + free(allocated_device->device_ids); + allocated_device->device_ids = NULL; + } + + for (int i=0 ; i < allocated_device->resources_num; i++) { + if (allocated_device->devices[i].device_path) { + free((void*)allocated_device->devices[i].device_path); + allocated_device->devices[i].device_path = NULL; + } + } + + if (allocated_device->devices) { + free(allocated_device->devices); + allocated_device->devices = NULL; + } +} + +void CMessageHandler::m_Free(consumer_reclaim_s *consumer_info) +{ + if (!consumer_info) + return; + + if (!consumer_info->consumer_info) + return; + + for (int i = 0; i < consumer_info->ret_quantity; i++) { + if (consumer_info->consumer_info[i].conflicted_resources != NULL) + free(consumer_info->consumer_info[i].conflicted_resources); + } + + free(consumer_info->consumer_info); +} + +void CMessageHandler::m_AllocateResources(rms_msg_request *request, rms_msg_response *response) +{ + trace_begin("RSC ALLOCATE START"); + trace_end(); + + if (!IsRegisteredHandle(request->handle)) { + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_ALLOCATE_RESOURCE, request->handle, request->pid); + response->result = RMS_ERROR; + return; + } + + int result = RMS_OK; + bool need_response = true; + rms_return_device_s allocated_device; + memset(&allocated_device, 0, sizeof(rms_return_device_s)); + + m_handle_mgr->ReclaimAllInvalidCustomer(request->pid); + + SetRequesterInfo(request); + + result = m_rsc_mgr->AllocateResources(request, &allocated_device); + + bool needReclaimResources = (result == RMS_ERROR_TAKE_RESOURCE_FROM_OTHER_CONSUMER); + + if (needReclaimResources) { + consumer_reclaim_s consumers_reclaim; + memset(&consumers_reclaim, 0, sizeof(consumers_reclaim)); + int zone_id = -1; + if (m_rsc_mgr->FindReclaimableConsumers(request, &consumers_reclaim, &zone_id) == RMS_OK) { + CResourceDB::getInstance()->AddReclaimResources(&consumers_reclaim); + if (ReclaimResources(result, request->handle, zone_id, &consumers_reclaim, &need_response) == RMS_OK) { + result = m_rsc_mgr->AllocateResources(request, &allocated_device); + } + CResourceDB::getInstance()->ClearReclaimResources(); + } + m_Free(&consumers_reclaim); + } + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_ALLOCATE_RESOURCE, request->handle, request->pid); + + response->result = result; + response->error_type = (result == RMS_OK) ? RMS_ERR_TYPE_NONE : (rms_error_type_e)allocated_device.error_type; + response->resource_num = allocated_device.resources_num; + + if (!need_response) + response->error_type = RMS_ERR_TYPE_TERMINATED_PROCESS; + + for (int i = 0; i < response->resource_num; i++) { + response->resource[i] = allocated_device.device_ids[i]; + } + + m_FreeAllocatedDevice(&allocated_device); + CCache::getInstance()->Drop(); + + trace_begin("RSC ALLOCATE END"); + trace_end(); +} + +void CMessageHandler::m_ReleaseResources(rms_msg_request *request, rms_msg_response *response) +{ + SERVER_DBG("request for deallocation"); + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_RELEASE_RESOURCES, request->handle, request->pid); + + if (!IsRegisteredHandle(request->handle)) { + response->result = RMS_ERROR; + return; + } + + rms_requests_device_s requested_resource; + memset(&requested_resource, 0, sizeof(rms_requests_device_s)); + + m_ConstructRequestedDevice(request, &requested_resource); + + response->result = m_rsc_mgr->ReleaseResources(request->handle, &requested_resource); +} + +void CMessageHandler::m_Query(rms_msg_request *request, rms_msg_response *response) +{ + int answer = 0; + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_QUERY, request->handle, request->pid); + + m_handle_mgr->ReclaimAllInvalidCustomer(request->handle); + + response->result = m_query_h->GetAnswer(request, &answer); + response->is_available = answer; + + SERVER_INFO("query on (%d), result(%d)", request->sub_type, answer); +} + +void CMessageHandler::m_SetConsumerPriority(rms_msg_request *request, rms_msg_response *response) +{ + SERVER_INFO("request for priority setting. priority(%d)", request->main_priority); + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_SET_PRIORITY, request->handle, request->pid); + + response->result = m_handle_mgr->SetPriority(request->handle, request->main_priority, request->sub_priority); +} + +void CMessageHandler::m_SetAppID(rms_msg_request *request, rms_msg_response *response) +{ + SERVER_INFO("request for appid setting. appid(%s)", request->app_id); + + m_ConstructResponse(response, request->data_type, RMS_RESPONSE_SET_APPID, request->handle, request->pid); + + int ret = m_handle_mgr->SetAppID(request->handle, request->app_id); + + if (ret != RMS_OK) { + SERVER_ERR("cannot update appid. handle(%d). ret(%d)", request->handle, ret); + + response->result = RMS_ERROR; + return; + } + + response->result = m_rsc_mgr->SetAppId(request->handle, request->app_id); +} + +CMessageHandler::msg_handler CMessageHandler::handlers[RMS_REQUEST_MAX] = { + &CMessageHandler::m_RegisterConsumer, + &CMessageHandler::m_UnregisterConsumer, + &CMessageHandler::m_AllocateResources, + &CMessageHandler::m_ReleaseResources, + &CMessageHandler::m_Query, + &CMessageHandler::m_SetConsumerPriority, + &CMessageHandler::m_SetAppID, +}; + +void CMessageHandler::ProcessMsgQMessage(CMessage *msg) +{ + if (!IsValidRequest(msg->GetReqType())) { + SERVER_ERR("invalid req type(%d)", msg->GetReqType()); + return; + } + + rms_msg_response resp; + memset(&resp, 0, sizeof(rms_msg_response)); + + rms_msg_request *req = msg->GetRequest(); + SERVER_INFO("req type(%d)-pid(%d)-cid(%d)-t(%lu)", req->type, req->pid, req->handle, req->time); + + (this->*handlers[req->type])(msg->GetRequest(), &resp); + + if (resp.error_type == RMS_ERR_TYPE_TERMINATED_PROCESS) { + SERVER_ERR("skip to send a response (%d)", req->pid); + return; + } + + if (msgq_tx->send(&resp) != RMS_OK) { + SERVER_ERR("failed to send response"); + } +} + +GVariant *CMessageHandler::RegisterResource(GVariant *params) +{ + char *dev_name; + char *dev_node; + int category; + int sharable_count; + + g_variant_get(params, "(&ssii)", &dev_name, &dev_node, &category, &sharable_count); + + SERVER_INFO("dev_name(%s)/dev_node(%s)/category(%d)/sharable(%d)", dev_name, dev_node, category, sharable_count); + return g_variant_new("(i)", RMS_OK); +} + +GVariant *CMessageHandler::GetResourceState(GVariant *params) +{ + int device_id; + int state; + + g_variant_get(params, "(i)", &device_id); + + state = m_rsc_mgr->GetResourceState(device_id); + + SERVER_INFO("state (%d:%d)", device_id, state); + + return g_variant_new("(i)", state); +} + +GVariant *CMessageHandler::FindDeviceId(GVariant *params) +{ + int virtual_id; + int real_id; + + g_variant_get(params, "(i)", &virtual_id); + + real_id = m_rsc_mgr->FindDeviceId(virtual_id); + + SERVER_INFO("real id (%d:%d)", virtual_id, real_id); + + return g_variant_new("(i)", real_id); +} + +GVariant *CMessageHandler::GetScalerHWID(GVariant *params) +{ + int zone_id; + int hw_id; + + g_variant_get(params, "(i)", &zone_id); + + hw_id = m_rsc_mgr->GetScalerHWId(zone_id); + + SERVER_INFO("hw id (%d:%d)", zone_id, hw_id); + + return g_variant_new("(i)", hw_id); +} + +GVariant *CMessageHandler::SwapResources(GVariant *params) +{ + int device_id_a; + int device_id_b; + int result = 0; + + g_variant_get(params, "(ii)", &device_id_a, &device_id_b); + + result = m_rsc_mgr->SwapResources(device_id_a, device_id_b); + + SERVER_INFO("swap result (%d:%d) > (%d)", device_id_a, device_id_b, result); + + return g_variant_new("(i)", result); +} + +GVariant *CMessageHandler::RestoreResources(GVariant *params) +{ + int category_id; + int result = 0; + + g_variant_get(params, "(i)", &category_id); + + result = m_rsc_mgr->RestoreResources(category_id); + + SERVER_INFO("restore result (%d) > (%d)", category_id, result); + + return g_variant_new("(i)", result); +} + +GVariant *CMessageHandler::NotifyResourcePolicy(GVariant *params) +{ + int policy; + int result = 0; + + g_variant_get(params, "(i)", &policy); + + m_rsc_mgr->ResetZoneIds(); + + SERVER_INFO("notify result (%d) > (%d)", policy, result); + return g_variant_new("(i)", result); +} + +GVariant *CMessageHandler::NotifyAppZoneInfo(GVariant *params) +{ + char *app_id; + int zone_id; + int result = 0; + + g_variant_get(params, "(&si)", &app_id, &zone_id); + + if (!app_id) { + result = -1; + SERVER_INFO("invalid param (%s:%d) - result(%d)", "null", zone_id, result); + return g_variant_new("(i)", result); + } + + m_rsc_mgr->UpdateZoneIds(app_id, zone_id); + + SERVER_INFO("notify result (%s:%d) > (%d)", app_id, zone_id, result); + return g_variant_new("(i)", result); +} + +GVariant *CMessageHandler::GetResourceList(GVariant *params) +{ + int category_id; + + g_variant_get(params, "(i)", &category_id); + + SERVER_DBG("category (%d)", category_id); + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(iissi))")); + + g_variant_builder_open(&builder, G_VARIANT_TYPE("a(iissi)")); + m_rsc_mgr->GetResourceList(category_id, &builder); + g_variant_builder_close(&builder); + + return g_variant_builder_end(&builder); +} + +GVariant *CMessageHandler::GetScalerState(GVariant *params) +{ + SERVER_INFO("GetScalerState"); + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(iiiiis))")); + + g_variant_builder_open(&builder, G_VARIANT_TYPE("a(iiiiis)")); + m_rsc_mgr->GetScalerState(&builder); + g_variant_builder_close(&builder); + + return g_variant_builder_end(&builder); +} + +GVariant *CMessageHandler::GetAppId(GVariant *params) +{ + int result = 0; + int handle; + g_variant_get(params, "(i)", &handle); + + SERVER_INFO("GetAppId(%d)", handle); + + CConsumer *consumer = CConsumerContainer::getInstance()->findConsumer(handle); + if (!consumer) { + SERVER_ERR("consumer(%d) not found", handle); + result = -1; + return g_variant_new("(is)", result, ""); + } + + return g_variant_new("(is)", result, (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str()); +} + +GVariant *CMessageHandler::GetResourceCollectionState(GVariant *params) +{ + int collection; + + g_variant_get(params, "(i)", &collection); + + SERVER_INFO("collection (%d)", collection); + + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("(a(isiiis))")); + + g_variant_builder_open(&builder, G_VARIANT_TYPE("a(isiiis)")); + m_rsc_mgr->GetResourceCollectionState(collection, &builder); + g_variant_builder_close(&builder); + + return g_variant_builder_end(&builder); +} + +GVariant *CMessageHandler::GetActiveAudioOut(GVariant *params) +{ + int cid; + int active_audio_out; + + g_variant_get(params, "(i)", &cid); + + active_audio_out = m_rsc_mgr->GetActiveAudioOut(cid); + SERVER_INFO("active_audio_out(%d:%d)", cid, active_audio_out); + + return g_variant_new("(i)", active_audio_out); +} + +void CMessageHandler::ProcessDbusMessage(CMessage *msg) +{ + GDBusMethodInvocation *invoc = msg->GetMethodInvocation(); + std::string method_name(g_dbus_method_invocation_get_method_name(invoc)); + + auto it = m_dbus_handlers.find(method_name); + if (it == m_dbus_handlers.end()) { + SERVER_ERR("handler is not found (%s)", method_name.c_str()); + return; + } + + GVariant *params = g_dbus_method_invocation_get_parameters(invoc); + GVariant *result = (this->*(it->second))(params); + + g_dbus_method_invocation_return_value(invoc, result); +} + +void CMessageHandler::ProcessInternalMessage(CMessage *msg) +{ + auto it = m_internal_msg_handlers.find(msg->GetName()); + if (it == m_internal_msg_handlers.end()) { + SERVER_ERR("handler is not found (%s)", msg->GetName().c_str()); + return; + } + + (this->*(it->second))(NULL); +} + +void CMessageHandler::EmptyPendingQueue(void) +{ + if (async_pending_queue->length() <= 0) + return; + + SERVER_WARN("empty pending queue(%d)", async_pending_queue->length()); + async_queue->push(async_pending_queue); +} + +void CMessageHandler::InsertPendingQueue(CMessage *msg) +{ + SERVER_WARN("msg locked"); + msg->PrintInfo(); + async_pending_queue->push(msg); +} + +int CMessageHandler::ProcessMessage(void) +{ + CMessage *msg = (CMessage*) async_queue->pop(); + assert(msg); + + if ((m_lock_ctr->GetLockCount() > 0) && m_lock_ctr->IsLocked(msg)) { + InsertPendingQueue(msg); + return 0; + } + + if (msg->IsUnlockMsg()) { + EmptyPendingQueue(); + delete msg; + return 0; + } + + switch (msg->GetSender()) { + case MSG_SENDER_MSGQ: + ProcessMsgQMessage(msg); + break; + case MSG_SENDER_DBUS: + ProcessDbusMessage(msg); + break; + case MSG_SENDER_INTERNAL: + ProcessInternalMessage(msg); + break; + default: + break; + } + + delete msg; + + return 0; +} + +bool CMessageHandler::IsAllResourcesReclaimed(rms_consumer_tobe_returned_s *consumer_info) +{ + for (int idx = 0; idx < consumer_info->n_conflicted; idx++) { + if (!m_rsc_mgr->IsReclaimed(consumer_info->conflicted_resources[idx].device_id, consumer_info->consumer_id)) { + SERVER_WARN("IsReclaimed is failed"); + return false; + } + } + + SERVER_WARN("all conflicted resources are freed"); + + return true; +} + +void CMessageHandler::ProcessMessage(CAsyncQueue *queue, CMessage *msg, int cid_requester, int cid_releaser) +{ + rms_msg_request *req = msg->GetRequest(); + rms_msg_response resp; + int handle; + char cmd[RMS_NAME_BUF_SIZE] = {0,}; + + switch (req->type) { + case RMS_REQUEST_RELEASE_RESOURCES: + + rms_requests_device_s requested_resource; + memset(&requested_resource, 0, sizeof(rms_requests_device_s)); + + m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_RELEASE_RESOURCES, req->handle, req->pid); + m_ConstructRequestedDevice(req, &requested_resource); + + if ((resp.result = m_rsc_mgr->ReleaseResources(req->handle, &requested_resource)) != RMS_OK) + SERVER_ERR("failed to release resources requested by (%d)", req->handle); + + SendResponse(&resp); + + break; + + case RMS_REQUEST_UNREGISTER: + + m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_UNREGISTER, req->handle, req->pid); + + SERVER_WARN("unregister requested by handle(%d)", req->handle); + + if (req->handle == cid_requester) { + SERVER_WARN("unregister request from requester(%d), send to internal queue", req->handle); + + PushMessage(queue, msg); + } else { + if ((resp.result = m_handle_mgr->RemoveHandle(req->handle, req->pid)) == RMS_OK) { + m_rsc_mgr->UnregisterConsumer(req->handle); + } + + SendResponse(&resp); + } + break; + + case RMS_REQUEST_REGISTER: + handle = m_handle_mgr->GetNewHandle(req->pid, req->main_priority, req->sub_priority, req->app_pid, req->app_id); + + resp.result = (handle == RMS_HANDLE_NOT_AVAILABLE) ? RMS_ERROR : RMS_OK; + m_ConstructResponse(&resp, req->data_type, RMS_RESPONSE_REGISTER, handle, req->pid); + + if (resp.result == RMS_ERROR) { + SendResponse(&resp); + break; + } + + if (m_rsc_mgr->RegisterConsumer(handle, req->pid, req->app_id, req->main_priority, req->sub_priority) != RMS_OK) + SERVER_ERR("failed to add consumer to manager. handle[%d]", handle); + + rms_get_cmd_name(req->pid, cmd, sizeof(cmd)); + + SERVER_INFO("newly assigned handle(%d) date type(%ld)- pid(%d)-(%s)", resp.handle, req->data_type, req->pid, cmd); + SendResponse(&resp); + break; + + default: + SERVER_ERR("unexpected request(%d) by handle(%d)/pid(%d)", req->type, req->handle, req->pid); + + if (req->handle == cid_releaser) { + m_ConstructResponse(&resp, req->data_type, (rms_response_type_e)req->type, req->handle, req->pid); + resp.result = RMS_ERROR; + + SendResponse(&resp); + } else { + PushMessage(queue, msg); + } + break; + } +} + +int CMessageHandler::ProcessCallbackMessage(rms_consumer_tobe_returned_s *consumer_info, int requester_cid) +{ + CMessage *msg = NULL; + int result = RMS_OK; + CAsyncQueue *queue = new CAsyncQueue(); + + unsigned int timeout_ms = CCallback::GetTimeout(); + + while (!IsAllResourcesReclaimed(consumer_info)) { + msg = (CMessage*) async_queue->pop(timeout_ms); + + if (!msg) { + SERVER_ERR("receive cb request timeout! CID[%d]/PID[%ld]", consumer_info->consumer_id, consumer_info->process_id); + result = RMS_ERROR; + goto out; + } + + if (msg->GetSender() == MSG_SENDER_DBUS) { + ProcessDbusMessage(msg); + } else if (msg->GetSender() == MSG_SENDER_MSGQ) { + SERVER_WARN("[MSG_SENDER_MSGQ] requester cid %d consumer id %d", requester_cid, consumer_info->consumer_id); + ProcessMessage(queue, msg, requester_cid, consumer_info->consumer_id); + } else { + ProcessInternalMessage(msg); + } + + delete msg; + } + +out: + async_queue->push_front(queue); + + delete queue; + + return result; +} + +int *CMessageHandler::m_SerializeCallbackData(const rms_consumer_tobe_returned_s *consumer_info, int reason, int *data_size) +{ + int num_conflicted_resources = consumer_info->n_conflicted; + + int *callback_data = (int*) calloc(num_conflicted_resources + 4, sizeof(int)); + assert(callback_data); + + callback_data[0] = CCallback::ConvertCallbackType(reason); + callback_data[1] = consumer_info->consumer_id; + callback_data[2] = consumer_info->process_id; + callback_data[3] = num_conflicted_resources; + + for (int res = 0; res < num_conflicted_resources; res++) { + callback_data[(res+4)] = consumer_info->conflicted_resources[res].virtual_id; + SERVER_DBG("- virtual_id:%d ", consumer_info->conflicted_resources[res].virtual_id); + } + + *data_size = (num_conflicted_resources + 4) * sizeof(int); + + return callback_data; +} + +bool CMessageHandler::IsValidProcess(int pid) +{ + return rm_is_valid_pid(pid); +} + +bool CMessageHandler::IsValidRequest(int req_type) +{ + return (req_type >= RMS_REQUEST_REGISTER && req_type < RMS_REQUEST_MAX); +} + +int CMessageHandler::ReleaseInvalidProcessResources(int pid, int handle) +{ + m_handle_mgr->RemoveHandle(handle, pid); + CCallback::RemoveFIFOServerToClient(pid, handle); + + return RMS_OK; +} + +void CMessageHandler::NotifyConflict(consumer_reclaim_s *conflict_info, int zone_id) +{ + if (!conflict_info) + return; + + int consumer_id = -1; + int device_id = -1; + int category_id = -1; + int app_zone_id = -1; + int n_consumer = conflict_info->ret_quantity; + CConsumer *consumer = NULL; + + GError *error = NULL; + GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + + if (!connection) { + SERVER_ERR("failed to get connection (%s)", (error) ? error->message : "unknown"); + goto out; + } + + for (int i = 0; i < n_consumer; i++) { + consumer_id = conflict_info->consumer_info[i].consumer_id; + consumer = CConsumerContainer::getInstance()->findConsumer(consumer_id); + + for (int j = 0; j < conflict_info->consumer_info[i].n_conflicted; j++) { + device_id = conflict_info->consumer_info[i].conflicted_resources[j].device_id; + app_zone_id = m_rsc_mgr->GetZoneId(device_id); + category_id = conflict_info->consumer_info[i].conflicted_resources[j].category_id; + SERVER_INFO("send resource conflict (%d:%d:%d:%s:%d:%d)", + category_id, device_id, consumer_id, (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str(), app_zone_id, zone_id); + if (!g_dbus_connection_emit_signal(connection, + NULL, + RM_DBUS_OBJ_PATH, + RM_DBUS_INTERFACE_NAME, + "RscConflicted", + g_variant_new("(iiisii)", category_id, device_id, consumer_id, + (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str() : consumer->GetAppID().c_str(), app_zone_id, zone_id), + &error)) { + SERVER_ERR("failed to send resource conflict (%d:%d:%d:%s)-%s", category_id, device_id, consumer_id, + (consumer->GetAppID().empty()) ? consumer->GetCmdName().c_str():consumer->GetAppID().c_str(), (error) ? error->message : "unknown"); + } + } + } +out: + if (error) + g_error_free(error); +} + +int CMessageHandler::ReclaimResources(int reason, int requester_cid, int requester_zone_id, consumer_reclaim_s *conflict_info, bool *need_response) +{ + int num_consumers = conflict_info->ret_quantity; + int data_size = 0; + int *callback_data = NULL; + char cmd[RMS_NAME_BUF_SIZE] = {0,}; + int err = 0; + int cid = 0; + int pid = 0; + + SERVER_WARN("start to reclaim - retirable consumers : (%d)", num_consumers); + + if (num_consumers > 0) + NotifyConflict(conflict_info, requester_zone_id); + + for (int i = 0; i < num_consumers; i++) { + pid = (int) conflict_info->consumer_info[i].process_id; + cid = conflict_info->consumer_info[i].consumer_id; + + if (!IsValidProcess(pid)) { + SERVER_ERR("handle(%d)/pid(%d) terminated", cid, pid); + m_rsc_mgr->ReleaseResourcesOfPid(pid); + ReleaseInvalidProcessResources(pid, cid); + continue; + } + + SERVER_DBG("[%d]th cid[%d]/rscs[%d]", i+1, cid, conflict_info->consumer_info[i].n_conflicted); + + callback_data = m_SerializeCallbackData(&conflict_info->consumer_info[i], reason, &data_size); + + if (CCallback::SendCallbackMessage(cid, pid, (void*) callback_data, data_size, &err) != RMS_OK) { + if (err == ENXIO) { //ENXIO No such device or address + SERVER_ERR("Process cannot get callback (CID:%d)/(PID:%d)", cid, pid); + m_rsc_mgr->ReleaseResourcesOfPid(pid); + ReleaseInvalidProcessResources(pid, cid); + free(callback_data); + continue; + } + + if (err == ENOENT && !IsRegisteredHandle(cid)) { + SERVER_ERR("already unregistred (%d)", cid); + free(callback_data); + continue; + } + + SERVER_ERR("failed to send callback message to (CID:%d)/(PID:%d), errno(%d)", cid, pid, err); + free(callback_data); + return RMS_ERROR; + } + + SERVER_WARN("[%d]th callback message sent to CID[%d]/PID[%d]/RSCS[%d]", i+1, cid, pid, conflict_info->consumer_info[i].n_conflicted); + + if (ProcessCallbackMessage(&conflict_info->consumer_info[i], requester_cid) != RMS_OK) { + if (!IsValidProcess(pid)) { + SERVER_ERR("handle(%d)/pid(%d) terminated", cid, pid); + m_rsc_mgr->ReleaseResourcesOfPid(pid); + ReleaseInvalidProcessResources(pid, cid); + free(callback_data); + + if (!IsRegisteredHandle(requester_cid)) { + SERVER_ERR("requester(%d:%d) terminated as well", pid, requester_cid); + *need_response = false; + return RMS_ERROR; + } + continue; + } + + rms_get_cmd_name(pid, cmd, sizeof(cmd)); + SERVER_ERR("failed to process callback request from : (%s) /(CID:%d)/(PID:%d)", cmd, cid, pid); + + rms_display_timeout_error_popup(RMS_ALARM_NO_DEALLOCATION, conflict_info->consumer_info[i]); + int ret = rms_report_emergency(cid, pid, RMS_EMERGENCY_CONSUMER_NOT_RESPONDING); + + SERVER_ERR("release resources of cosumer(%d) forcely", pid); + m_rsc_mgr->UnregisterConsumer(cid); + m_handle_mgr->RemoveHandle(cid, pid); + + free(callback_data); + return ret; + } + + free(callback_data); + } + + return RMS_OK; +} + +int CMessageHandler::SendResponse(rms_msg_response *response) +{ + return msgq_tx->send(response); +} + +int CMessageHandler::PushMessage(CAsyncQueue *queue, CMessage *msg) +{ + CMessage *msg_copy = new CMessage(msg->GetRequest()); + rms_msg_request *req = msg->GetRequest(); + SERVER_INFO("push_front msg type(%d)-pid(%d)-cid(%d)", req->type, req->pid, req->handle); + + queue->push_front(msg_copy); + + return RMS_OK; +} + +void CMessageHandler::m_ConstructResponse(rms_msg_response *response, int data_type, rms_response_type_e msg_type, int handle, int pid) +{ + assert(response); + + response->data_type = data_type; + response->type = msg_type; + response->handle = handle; + response->pid = pid; +} + +void CMessageHandler::NotifyWatchdog(void) +{ + if (!async_queue) + return; + + SERVER_INFO("push watchdog msg"); + async_queue->push(new CMessage("NotifyWatchdog")); +} + +GVariant *CMessageHandler::NotifyWatchdog(GVariant *params) +{ + SERVER_INFO("send watchdog notify completed"); + return NULL; +} diff --git a/src/CMessageQueue.cpp b/src/CMessageQueue.cpp index 8f114ba..afccaf1 100644 --- a/src/CMessageQueue.cpp +++ b/src/CMessageQueue.cpp @@ -1,140 +1,140 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include - -#include -#include - -CMessageQueue::CMessageQueue(msgq_type_e type) -{ - msgq_type = type; - - if (init() != RMS_OK) { - SERVER_ERR("failed to initialize message queue(%d)", type); - assert(0 && "failed to initialize message queue"); - } -} - -CMessageQueue::~CMessageQueue(void) -{ -} - -int CMessageQueue::init(void) -{ - int key = getKey(msgq_type); - - msgq_id = msgget((key_t) key, 0666 | IPC_CREAT); - if (msgq_id == -1) { - SERVER_ERR("failed to create a message queue (%d), errno(%d)", key, errno); - return RMS_ERROR; - } - - struct msqid_ds queue_stat; - long prev_size = 0; - - if (msgctl(msgq_id, IPC_STAT, &queue_stat) != 0) { - SERVER_ERR("failed to get queue info (%d:%d), errno(%d)", key, msgq_id, errno); - goto out; - } - - prev_size = queue_stat.msg_qbytes; - queue_stat.msg_qbytes = msgq_size; - - if (msgctl(msgq_id, IPC_SET, &queue_stat) != 0) { - SERVER_ERR("failed to set queue info (%d:%d), errno(%d)", key, msgq_id, errno); - goto out; - } - - SERVER_INFO("msgq(%d:%d) size changed (%ld) -> (%ld)", key, msgq_id, prev_size, msgq_size); - -out: - return RMS_OK; -} - -int CMessageQueue::send(rms_msg_response *response) -{ - int retry = 0; - - while (msgsnd(msgq_id, (void*) response, sizeof(rms_msg_response) - sizeof(long), 0) == -1) { - SERVER_ERR("failed to send response message (%d), retry(%d) - type(%d)/cid(%d)", errno, retry, response->type, response->handle); - - if (errno == EIDRM) { // errno 43 : identifier removed - SERVER_ERR("msgid removed from system"); - if (recover() != RMS_OK) - return RMS_ERROR; - } else if ((errno == EINVAL) && (response->data_type > 0)) { - SERVER_ERR("msgid might be removed from system"); - if (recover() != RMS_OK) { - return RMS_ERROR; - } - } - - if (retry >= 5) { //timeout - return RMS_ERROR; - } - - usleep(20*1000); // 20ms - retry++; - } - - return RMS_OK; - -} - -int CMessageQueue::receive(rms_msg_request *request, int msg_type) -{ - int ret = -1; - ret = msgrcv(msgq_id, (void*) request, sizeof(rms_msg_request) - sizeof(long), msg_type, 0); - - if (ret == -1) { - SERVER_ERR("failed to receive msg(%d:%d). errno(%d)", msgq_type, msgq_id, errno); - - if (errno == EIDRM) { // errno 43 : identifier removed - SERVER_ERR("WARNING! msgq(%d:%d) removed from system", msgq_type, msgq_id); - recover(); - } - - return RMS_ERROR; - } - - return RMS_OK; -} - -int CMessageQueue::recover(void) -{ - int key = getKey(msgq_type); - - msgq_id = msgget((key_t) key, 0666 | IPC_CREAT); - - if (msgq_id == -1) { - SERVER_ERR("failed to get new msgq_id, key(%d), errno(%d)", key, errno); - return RMS_ERROR; - } - - SERVER_ERR("message queue recovered - (%d:%d)", key, msgq_id); - return RMS_OK; -} - -int CMessageQueue::getKey(msgq_type_e type) -{ - return (type == MSG_QUEUE_RX) ? key_rx : key_tx; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include + +#include +#include + +CMessageQueue::CMessageQueue(msgq_type_e type) +{ + msgq_type = type; + + if (init() != RMS_OK) { + SERVER_ERR("failed to initialize message queue(%d)", type); + assert(0 && "failed to initialize message queue"); + } +} + +CMessageQueue::~CMessageQueue(void) +{ +} + +int CMessageQueue::init(void) +{ + int key = getKey(msgq_type); + + msgq_id = msgget((key_t) key, 0666 | IPC_CREAT); + if (msgq_id == -1) { + SERVER_ERR("failed to create a message queue (%d), errno(%d)", key, errno); + return RMS_ERROR; + } + + struct msqid_ds queue_stat; + long prev_size = 0; + + if (msgctl(msgq_id, IPC_STAT, &queue_stat) != 0) { + SERVER_ERR("failed to get queue info (%d:%d), errno(%d)", key, msgq_id, errno); + goto out; + } + + prev_size = queue_stat.msg_qbytes; + queue_stat.msg_qbytes = msgq_size; + + if (msgctl(msgq_id, IPC_SET, &queue_stat) != 0) { + SERVER_ERR("failed to set queue info (%d:%d), errno(%d)", key, msgq_id, errno); + goto out; + } + + SERVER_INFO("msgq(%d:%d) size changed (%ld) -> (%ld)", key, msgq_id, prev_size, msgq_size); + +out: + return RMS_OK; +} + +int CMessageQueue::send(rms_msg_response *response) +{ + int retry = 0; + + while (msgsnd(msgq_id, (void*) response, sizeof(rms_msg_response) - sizeof(long), 0) == -1) { + SERVER_ERR("failed to send response message (%d), retry(%d) - type(%d)/cid(%d)", errno, retry, response->type, response->handle); + + if (errno == EIDRM) { // errno 43 : identifier removed + SERVER_ERR("msgid removed from system"); + if (recover() != RMS_OK) + return RMS_ERROR; + } else if ((errno == EINVAL) && (response->data_type > 0)) { + SERVER_ERR("msgid might be removed from system"); + if (recover() != RMS_OK) { + return RMS_ERROR; + } + } + + if (retry >= 5) { //timeout + return RMS_ERROR; + } + + usleep(20*1000); // 20ms + retry++; + } + + return RMS_OK; + +} + +int CMessageQueue::receive(rms_msg_request *request, int msg_type) +{ + int ret = -1; + ret = msgrcv(msgq_id, (void*) request, sizeof(rms_msg_request) - sizeof(long), msg_type, 0); + + if (ret == -1) { + SERVER_ERR("failed to receive msg(%d:%d). errno(%d)", msgq_type, msgq_id, errno); + + if (errno == EIDRM) { // errno 43 : identifier removed + SERVER_ERR("WARNING! msgq(%d:%d) removed from system", msgq_type, msgq_id); + recover(); + } + + return RMS_ERROR; + } + + return RMS_OK; +} + +int CMessageQueue::recover(void) +{ + int key = getKey(msgq_type); + + msgq_id = msgget((key_t) key, 0666 | IPC_CREAT); + + if (msgq_id == -1) { + SERVER_ERR("failed to get new msgq_id, key(%d), errno(%d)", key, errno); + return RMS_ERROR; + } + + SERVER_ERR("message queue recovered - (%d:%d)", key, msgq_id); + return RMS_OK; +} + +int CMessageQueue::getKey(msgq_type_e type) +{ + return (type == MSG_QUEUE_RX) ? key_rx : key_tx; +} diff --git a/src/CQueryHandler.cpp b/src/CQueryHandler.cpp index a3cf4b6..6a8b146 100644 --- a/src/CQueryHandler.cpp +++ b/src/CQueryHandler.cpp @@ -1,61 +1,61 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include - -#include -#include -#include - -CQueryHandler::CQueryHandler(CResourceManager *rsc_mgr) -{ - assert(rsc_mgr); - m_rsc_mgr = rsc_mgr; -} - -CQueryHandler::~CQueryHandler(void) -{ -} - -int CQueryHandler::GetAnswer(rms_msg_request *request, int *answer_out) -{ - int result = RMS_OK; - int answer = 0; - char process_name[RMS_NAME_BUF_SIZE] = {0,}; - - switch (request->sub_type) { - case RMS_QUERY_ALLOCATION: - result = m_rsc_mgr->IsCategoryAvailableToUse(request, &answer); - *answer_out = answer; - break; - case RMS_QUERY_TERMINATE: - rms_get_cmd_name(request->pid, process_name, RMS_NAME_BUF_SIZE); - result = RMS_OK; - *answer_out = process_htable_contains(process_name); - break; - case RMS_QUERY_ACTIVE_DECS: - *answer_out = m_rsc_mgr->GetActiveDecoderNum(); - result = RMS_OK; - break; - default: - SERVER_ERR("not defined query type (%d)", request->sub_type); - break; - } - - return result; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include + +#include +#include +#include + +CQueryHandler::CQueryHandler(CResourceManager *rsc_mgr) +{ + assert(rsc_mgr); + m_rsc_mgr = rsc_mgr; +} + +CQueryHandler::~CQueryHandler(void) +{ +} + +int CQueryHandler::GetAnswer(rms_msg_request *request, int *answer_out) +{ + int result = RMS_OK; + int answer = 0; + char process_name[RMS_NAME_BUF_SIZE] = {0,}; + + switch (request->sub_type) { + case RMS_QUERY_ALLOCATION: + result = m_rsc_mgr->IsCategoryAvailableToUse(request, &answer); + *answer_out = answer; + break; + case RMS_QUERY_TERMINATE: + rms_get_cmd_name(request->pid, process_name, RMS_NAME_BUF_SIZE); + result = RMS_OK; + *answer_out = process_htable_contains(process_name); + break; + case RMS_QUERY_ACTIVE_DECS: + *answer_out = m_rsc_mgr->GetActiveDecoderNum(); + result = RMS_OK; + break; + default: + SERVER_ERR("not defined query type (%d)", request->sub_type); + break; + } + + return result; +} diff --git a/src/CRequest.cpp b/src/CRequest.cpp index 673ef53..bf4500c 100644 --- a/src/CRequest.cpp +++ b/src/CRequest.cpp @@ -1,432 +1,432 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 - -#include -#include "CSysInfo.h" -#include "CRequester.h" -#include "CRequest.h" - -CRequest::CRequest(CRequester *requester) -:m_requester(requester) -{ - m_device_id = 0; - m_category_id = 0; - m_category_option = 0; - m_category = RMS_CATEGORY_NONE; - m_result = RMS_ERROR; - m_candidate_device = RMS_DEVICE_NONE; - m_allocated_device = RMS_DEVICE_NONE; - m_virtual_device = RMS_DEVICE_NONE; -} - -CRequest::~CRequest() -{ -} - -CRequester *CRequest::getRequester(void) -{ - return m_requester; -} - -int CRequest::ToMultiviewZoneId(int category_option) -{ - const int ZONE_INFO = 0x1E00000; - int zone_id = ((category_option & ZONE_INFO) >> 21); - return zone_id; -} - -void CRequest::SetCategory(int category_id, int category_option) -{ - m_category_id = category_id; - m_category_option = category_option; - m_category = ToResourceCategory(category_id, category_option); - m_mixing_mode = ToMixingMode(category_id, category_option); - m_mv_zone_id = ToMultiviewZoneId(category_option); -} - -void CRequest::SetState(int req_state) -{ - m_state = (rms_requests_resource_state_e) req_state; -} - -void CRequest::SetResult(rms_return_code_e req_result) -{ - m_result = req_result; -} - -rms_return_code_e CRequest::GetResult(void) -{ - return m_result; -} - -rms_rsc_category_e CRequest::GetCategory(void) -{ - return m_category; -} - -bool CRequest::IsMainDeviceRequest(void) -{ - if (m_state == RMS_STATE_EXCLUSIVE_AUTO) - return false; - - SERVER_INFO("m_category_id(%d), option(%d)", m_category_id, m_category_option); - - if (IsSupportedCategory(m_category_option)) { - if ((m_category_option & RMS_DEVICE_OPT_MAIN) || (m_category_option & RMS_FORCE_TO_MAIN)) - return true; - } - - if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) { - return (m_category_option & RMS_DEVICE_OPT_MAIN); - } - - if (m_category_id == RMS_CATEGORY_AUDIO_DECODER) { - if (m_category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) - return false; - if (m_category_option == RMS_DEVICE_OPT_NONE) - return true; - - return (m_category_option & RMS_DEVICE_OPT_MAIN); - } - - if (m_category_id == RMS_CATEGORY_MJPEG_DECODER) - return (m_category_option & RMS_DEVICE_OPT_MAIN); - - if (m_category == RMS_CATEGORY_SCALER_MULTIVIEW) - return (m_category_option & RMS_DEVICE_OPT_MAIN); - - return false; -} - -bool CRequest::IsAIDeviceRequest(void) -{ - if (m_state == RMS_STATE_EXCLUSIVE_AUTO) - return false; - - if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) - return (m_category_option & RMS_VIDEO_DEC_OPT_AI); - - return false; -} - -bool CRequest::IsSubDeviceRequest(void) -{ - if (m_state == RMS_STATE_EXCLUSIVE_AUTO) - return false; - - //SERVER_DBG("m_category_id(%d), option(%d)", m_category_id, m_category_option); - - if (IsSupportedCategory(m_category_option)) { - if ((m_category_option & RMS_DEVICE_OPT_SUB) || (m_category_option & RMS_FORCE_TO_SUB)) - return true; - } - - if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER_SUB) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) - return (m_category_option & RMS_DEVICE_OPT_SUB); - - if (m_category_id == RMS_CATEGORY_AUDIO_DECODER_SUB) { - if (m_category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) - return false; - if (m_category_option == RMS_DEVICE_OPT_NONE) - return true; - - return (m_category_option & RMS_DEVICE_OPT_SUB); - } - - if (m_category_id == RMS_CATEGORY_MJPEG_DECODER) - return (m_category_option & RMS_DEVICE_OPT_SUB); - - if (m_category == RMS_CATEGORY_SCALER_MULTIVIEW) - return (m_category_option & RMS_DEVICE_OPT_SUB); - - return false; -} - -rms_rsc_category_e CRequest::ToVideoDecoderCategory(int category, int category_option, bool force_main, bool force_sub) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - - if (category_option == RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED) { - result = RMS_CATEGORY_NONE; - } else if ((category_option > RMS_CATEGORY_VIDEO_DECODER_OPTION) && (category_option < RMS_CATEGORY_VIDEO_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else { - if (category == RMS_CATEGORY_VIDEO_DECODER) { - result = (rms_rsc_category_e) ((force_sub) ? RMS_CATEGORY_VIDEO_DECODER_SUB : category); - } else if (category == RMS_CATEGORY_VIDEO_DECODER_SUB) { - result = (rms_rsc_category_e) ((force_main) ? (rms_rsc_category_e) RMS_CATEGORY_VIDEO_DECODER : category); - } else { - result = (rms_rsc_category_e) category; - } - } - - return result; -} - -rms_rsc_category_e CRequest::ToImageDecoderCategory(int category, int category_option) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - - SERVER_INFO("category(%d)/category_option(%d)", category, category_option); - - if (category_option == RMS_CATEGORY_IMAGE_DECODER_NOT_SUPPORTED) { - result = RMS_CATEGORY_NONE; - } else if ((category_option > RMS_CATEGORY_HEIC_DECODER_OPTION) && (category_option < RMS_CATEGORY_HEIC_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else if ((category_option > RMS_CATEGORY_JPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_JPEG_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else { - result = (rms_rsc_category_e) category; - } - - return result; -} - -rms_rsc_category_e CRequest::ToJpegDecoderCategory(int category, int category_option) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - - SERVER_INFO("category(%d)/category_option(%d)", category, category_option); - - if (category_option == RMS_CATEGORY_JPEG_DECODER_NOT_SUPPORTED) { - result = RMS_CATEGORY_NONE; - } else if ((category_option > RMS_CATEGORY_JPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_JPEG_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else { - result = (rms_rsc_category_e) category; - } - - return result; -} - -rms_rsc_category_e CRequest::ToMJpegDecoderCategory(int category, int category_option) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - - if (category_option == RMS_CATEGORY_MJPEG_DECODER_NOT_SUPPORTED) { - result = RMS_CATEGORY_NONE; - } else if ((category_option > RMS_CATEGORY_MJPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_MJPEG_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else { - result = (rms_rsc_category_e)category; - } - - return result; -} - -rms_rsc_category_e CRequest::ToAudioDecoderCategory(int category, int category_option, bool force_main, bool force_sub) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - bool support_mixing = CSysInfo::GetInstance()->IsAudioMixingSupported(); - - if (category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) { - result = RMS_CATEGORY_NONE; - } else if (category_option == RMS_CATEGORY_NOT_PERMITTED) { - result = RMS_CATEGORY_NOT_PERMITTED; - } else if (support_mixing && (category_option > RMS_CATEGORY_AUDIO_DECODER_OPTION && category_option < RMS_CATEGORY_AUDIO_DECODER_OPTION_MAX)) { - result = (rms_rsc_category_e) category_option; - } else { - if (category == RMS_CATEGORY_AUDIO_DECODER) { - result = (rms_rsc_category_e) ((force_sub) ? RMS_CATEGORY_AUDIO_DECODER_SUB : category); - } else if (category == RMS_CATEGORY_AUDIO_DECODER_SUB) { - result = (rms_rsc_category_e) ((force_main) ? RMS_CATEGORY_AUDIO_DECODER : category); - } else { - result = (rms_rsc_category_e) category; - } - } - - return result; -} - -rms_rsc_category_e CRequest::ToScalerCategory(int category, int category_option, bool force_main, bool force_sub) -{ - if (category_option == RMS_CATEGORY_NOT_PERMITTED) - return (rms_rsc_category_e) category_option; - - if (force_sub) - return RMS_CATEGORY_SCALER_SUB; - - if (force_main) - return RMS_CATEGORY_SCALER; - - if (category > RMS_CATEGORY_SCALER_OPTION && category < RMS_CATEGORY_SCALER_OPTION_MAX) - return (rms_rsc_category_e) category_option; - - if (category_option > RMS_CATEGORY_SCALER_OPTION && category_option < RMS_CATEGORY_SCALER_OPTION_MAX) - return (rms_rsc_category_e) category_option; - - return (rms_rsc_category_e) category; -} - -rms_rsc_category_e CRequest::ToAudioOutCategory(int category, int category_option, bool force_main, bool force_sub) -{ - if (category_option == RMS_CATEGORY_NOT_PERMITTED) - return (rms_rsc_category_e) category_option; - - if (force_sub) - return RMS_CATEGORY_AUDIO_SUB_OUT; - - if (force_main) - return RMS_CATEGORY_AUDIO_MAIN_OUT; - - return (rms_rsc_category_e) category; -} - -bool CRequest::IsSupportedCategory(int category_option) -{ - bool result = true; - - switch (category_option) { - case RMS_CATEGORY_IMAGE_DECODER_NOT_SUPPORTED: - case RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED: - case RMS_CATEGORY_JPEG_DECODER_NOT_SUPPORTED: - case RMS_CATEGORY_MJPEG_DECODER_NOT_SUPPORTED: - case RMS_CATEGORY_NOT_PERMITTED: - result = false; - break; - default: - result = true; - break; - } - - return result; -} - -int CRequest::UnmaskMainSubOptions(int category_option) -{ - int result = category_option; - - result = (result & ~RMS_DEVICE_OPT_MAIN); - result = (result & ~RMS_DEVICE_OPT_SUB); - - return result; -} - -int CRequest::UnmaskMixingOptions(int category_option) -{ - int result = category_option; - - result = (result & ~RMS_MIXING_OPT_DEFAULT); - result = (result & ~RMS_MIXING_OPT_MULTIVIEW); - result = (result & ~RMS_MIXING_OPT_INTERACTION_SOUND); - - return result; -} - -int CRequest::UnmaskForceOptions(int category_option) -{ - int result = category_option; - - result = (result & ~RMS_FORCE_TO_MAIN); - result = (result & ~RMS_FORCE_TO_SUB); - - return result; -} - -int CRequest::UnmaskMVZoneInfo(int category_option) -{ - const int ZONE_INFO = 0x1E00000; - - return (category_option & ~ZONE_INFO); -} - -rms_rsc_category_e CRequest::ToResourceCategory(int category, int category_option) -{ - rms_rsc_category_e result = RMS_CATEGORY_NONE; - bool supported = IsSupportedCategory(category_option); - bool force_main = false; - bool force_sub = false; - - if (supported) { - force_main = (category_option & RMS_FORCE_TO_MAIN); - force_sub = (category_option & RMS_FORCE_TO_SUB); - category_option = UnmaskMainSubOptions(category_option); - } - - switch (category) { - case RMS_CATEGORY_VIDEO_DECODER: - case RMS_CATEGORY_VIDEO_DECODER_SUB: - if (supported) { - category_option = UnmaskMVZoneInfo(category_option); - category_option = (category_option & ~RMS_VIDEO_DEC_OPT_AI); - category_option = UnmaskForceOptions(category_option); - } - result = ToVideoDecoderCategory(category, category_option, force_main, force_sub); - break; - case RMS_CATEGORY_JPEG_DECODER: - result = ToJpegDecoderCategory(category, category_option); - break; - case RMS_CATEGORY_MJPEG_DECODER: - if (supported) - category_option = UnmaskMVZoneInfo(category_option); - - result = ToMJpegDecoderCategory(category, category_option); - break; - case RMS_CATEGORY_IMAGE_DECODER: - result = ToImageDecoderCategory(category, category_option); - break; - case RMS_CATEGORY_AUDIO_DECODER: - case RMS_CATEGORY_AUDIO_DECODER_SUB: - if (supported) { - category_option = UnmaskMixingOptions(category_option); - category_option = UnmaskForceOptions(category_option); - } - - result = ToAudioDecoderCategory(category, category_option, force_main, force_sub); - break; - case RMS_CATEGORY_SCALER: - case RMS_CATEGORY_SCALER_SUB: - if (supported) - category_option = UnmaskMVZoneInfo(category_option); - - result = ToScalerCategory(category, category_option, force_main, force_sub); - break; - case RMS_CATEGORY_AUDIO_MAIN_OUT: - case RMS_CATEGORY_AUDIO_SUB_OUT: - result = ToAudioOutCategory(category, category_option, force_main, force_sub); - break; - default: - result = (rms_rsc_category_e) category; - break; - } - - return result; -} - -rms_mixing_mode_e CRequest::ToMixingMode(int category, int category_option) -{ - if (category != RMS_CATEGORY_AUDIO_DECODER && category != RMS_CATEGORY_AUDIO_DECODER_SUB) - return RMS_MIXING_MODE_DEFAULT; - - if (category_option & RMS_MIXING_OPT_MULTIVIEW) - return RMS_MIXING_MODE_MULTIVIEW; - - if (category_option & RMS_MIXING_OPT_INTERACTION_SOUND) - return RMS_MIXING_MODE_INTERACTION_SOUND; - - return RMS_MIXING_MODE_DEFAULT; -} - -void CRequest::PrintResult(void) -{ - SERVER_WARN("result (%d) - con(%d:%s) / cat(%d) / req(%d:%d) / devId(%d) / vId(%d) / rsn(%d)", - m_result, - m_requester->getHandle(), - m_requester->getAppId().empty() ? m_requester->GetCmdName().c_str() : m_requester->getAppId().c_str(), - m_category, m_category_id, m_category_option, m_allocated_device, m_virtual_device, m_reason); -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + +#include +#include "CSysInfo.h" +#include "CRequester.h" +#include "CRequest.h" + +CRequest::CRequest(CRequester *requester) +:m_requester(requester) +{ + m_device_id = 0; + m_category_id = 0; + m_category_option = 0; + m_category = RMS_CATEGORY_NONE; + m_result = RMS_ERROR; + m_candidate_device = RMS_DEVICE_NONE; + m_allocated_device = RMS_DEVICE_NONE; + m_virtual_device = RMS_DEVICE_NONE; +} + +CRequest::~CRequest() +{ +} + +CRequester *CRequest::getRequester(void) +{ + return m_requester; +} + +int CRequest::ToMultiviewZoneId(int category_option) +{ + const int ZONE_INFO = 0x1E00000; + int zone_id = ((category_option & ZONE_INFO) >> 21); + return zone_id; +} + +void CRequest::SetCategory(int category_id, int category_option) +{ + m_category_id = category_id; + m_category_option = category_option; + m_category = ToResourceCategory(category_id, category_option); + m_mixing_mode = ToMixingMode(category_id, category_option); + m_mv_zone_id = ToMultiviewZoneId(category_option); +} + +void CRequest::SetState(int req_state) +{ + m_state = (rms_requests_resource_state_e) req_state; +} + +void CRequest::SetResult(rms_return_code_e req_result) +{ + m_result = req_result; +} + +rms_return_code_e CRequest::GetResult(void) +{ + return m_result; +} + +rms_rsc_category_e CRequest::GetCategory(void) +{ + return m_category; +} + +bool CRequest::IsMainDeviceRequest(void) +{ + if (m_state == RMS_STATE_EXCLUSIVE_AUTO) + return false; + + SERVER_INFO("m_category_id(%d), option(%d)", m_category_id, m_category_option); + + if (IsSupportedCategory(m_category_option)) { + if ((m_category_option & RMS_DEVICE_OPT_MAIN) || (m_category_option & RMS_FORCE_TO_MAIN)) + return true; + } + + if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) { + return (m_category_option & RMS_DEVICE_OPT_MAIN); + } + + if (m_category_id == RMS_CATEGORY_AUDIO_DECODER) { + if (m_category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) + return false; + if (m_category_option == RMS_DEVICE_OPT_NONE) + return true; + + return (m_category_option & RMS_DEVICE_OPT_MAIN); + } + + if (m_category_id == RMS_CATEGORY_MJPEG_DECODER) + return (m_category_option & RMS_DEVICE_OPT_MAIN); + + if (m_category == RMS_CATEGORY_SCALER_MULTIVIEW) + return (m_category_option & RMS_DEVICE_OPT_MAIN); + + return false; +} + +bool CRequest::IsAIDeviceRequest(void) +{ + if (m_state == RMS_STATE_EXCLUSIVE_AUTO) + return false; + + if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) + return (m_category_option & RMS_VIDEO_DEC_OPT_AI); + + return false; +} + +bool CRequest::IsSubDeviceRequest(void) +{ + if (m_state == RMS_STATE_EXCLUSIVE_AUTO) + return false; + + //SERVER_DBG("m_category_id(%d), option(%d)", m_category_id, m_category_option); + + if (IsSupportedCategory(m_category_option)) { + if ((m_category_option & RMS_DEVICE_OPT_SUB) || (m_category_option & RMS_FORCE_TO_SUB)) + return true; + } + + if ((m_category_id == RMS_CATEGORY_VIDEO_DECODER_SUB) && (m_category_option != RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED)) + return (m_category_option & RMS_DEVICE_OPT_SUB); + + if (m_category_id == RMS_CATEGORY_AUDIO_DECODER_SUB) { + if (m_category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) + return false; + if (m_category_option == RMS_DEVICE_OPT_NONE) + return true; + + return (m_category_option & RMS_DEVICE_OPT_SUB); + } + + if (m_category_id == RMS_CATEGORY_MJPEG_DECODER) + return (m_category_option & RMS_DEVICE_OPT_SUB); + + if (m_category == RMS_CATEGORY_SCALER_MULTIVIEW) + return (m_category_option & RMS_DEVICE_OPT_SUB); + + return false; +} + +rms_rsc_category_e CRequest::ToVideoDecoderCategory(int category, int category_option, bool force_main, bool force_sub) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + + if (category_option == RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED) { + result = RMS_CATEGORY_NONE; + } else if ((category_option > RMS_CATEGORY_VIDEO_DECODER_OPTION) && (category_option < RMS_CATEGORY_VIDEO_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else { + if (category == RMS_CATEGORY_VIDEO_DECODER) { + result = (rms_rsc_category_e) ((force_sub) ? RMS_CATEGORY_VIDEO_DECODER_SUB : category); + } else if (category == RMS_CATEGORY_VIDEO_DECODER_SUB) { + result = (rms_rsc_category_e) ((force_main) ? (rms_rsc_category_e) RMS_CATEGORY_VIDEO_DECODER : category); + } else { + result = (rms_rsc_category_e) category; + } + } + + return result; +} + +rms_rsc_category_e CRequest::ToImageDecoderCategory(int category, int category_option) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + + SERVER_INFO("category(%d)/category_option(%d)", category, category_option); + + if (category_option == RMS_CATEGORY_IMAGE_DECODER_NOT_SUPPORTED) { + result = RMS_CATEGORY_NONE; + } else if ((category_option > RMS_CATEGORY_HEIC_DECODER_OPTION) && (category_option < RMS_CATEGORY_HEIC_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else if ((category_option > RMS_CATEGORY_JPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_JPEG_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else { + result = (rms_rsc_category_e) category; + } + + return result; +} + +rms_rsc_category_e CRequest::ToJpegDecoderCategory(int category, int category_option) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + + SERVER_INFO("category(%d)/category_option(%d)", category, category_option); + + if (category_option == RMS_CATEGORY_JPEG_DECODER_NOT_SUPPORTED) { + result = RMS_CATEGORY_NONE; + } else if ((category_option > RMS_CATEGORY_JPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_JPEG_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else { + result = (rms_rsc_category_e) category; + } + + return result; +} + +rms_rsc_category_e CRequest::ToMJpegDecoderCategory(int category, int category_option) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + + if (category_option == RMS_CATEGORY_MJPEG_DECODER_NOT_SUPPORTED) { + result = RMS_CATEGORY_NONE; + } else if ((category_option > RMS_CATEGORY_MJPEG_DECODER_OPTION) && (category_option < RMS_CATEGORY_MJPEG_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else { + result = (rms_rsc_category_e)category; + } + + return result; +} + +rms_rsc_category_e CRequest::ToAudioDecoderCategory(int category, int category_option, bool force_main, bool force_sub) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + bool support_mixing = CSysInfo::GetInstance()->IsAudioMixingSupported(); + + if (category_option == RMS_CATEGORY_AUDIO_DECODER_NOT_SUPPORTED) { + result = RMS_CATEGORY_NONE; + } else if (category_option == RMS_CATEGORY_NOT_PERMITTED) { + result = RMS_CATEGORY_NOT_PERMITTED; + } else if (support_mixing && (category_option > RMS_CATEGORY_AUDIO_DECODER_OPTION && category_option < RMS_CATEGORY_AUDIO_DECODER_OPTION_MAX)) { + result = (rms_rsc_category_e) category_option; + } else { + if (category == RMS_CATEGORY_AUDIO_DECODER) { + result = (rms_rsc_category_e) ((force_sub) ? RMS_CATEGORY_AUDIO_DECODER_SUB : category); + } else if (category == RMS_CATEGORY_AUDIO_DECODER_SUB) { + result = (rms_rsc_category_e) ((force_main) ? RMS_CATEGORY_AUDIO_DECODER : category); + } else { + result = (rms_rsc_category_e) category; + } + } + + return result; +} + +rms_rsc_category_e CRequest::ToScalerCategory(int category, int category_option, bool force_main, bool force_sub) +{ + if (category_option == RMS_CATEGORY_NOT_PERMITTED) + return (rms_rsc_category_e) category_option; + + if (force_sub) + return RMS_CATEGORY_SCALER_SUB; + + if (force_main) + return RMS_CATEGORY_SCALER; + + if (category > RMS_CATEGORY_SCALER_OPTION && category < RMS_CATEGORY_SCALER_OPTION_MAX) + return (rms_rsc_category_e) category_option; + + if (category_option > RMS_CATEGORY_SCALER_OPTION && category_option < RMS_CATEGORY_SCALER_OPTION_MAX) + return (rms_rsc_category_e) category_option; + + return (rms_rsc_category_e) category; +} + +rms_rsc_category_e CRequest::ToAudioOutCategory(int category, int category_option, bool force_main, bool force_sub) +{ + if (category_option == RMS_CATEGORY_NOT_PERMITTED) + return (rms_rsc_category_e) category_option; + + if (force_sub) + return RMS_CATEGORY_AUDIO_SUB_OUT; + + if (force_main) + return RMS_CATEGORY_AUDIO_MAIN_OUT; + + return (rms_rsc_category_e) category; +} + +bool CRequest::IsSupportedCategory(int category_option) +{ + bool result = true; + + switch (category_option) { + case RMS_CATEGORY_IMAGE_DECODER_NOT_SUPPORTED: + case RMS_CATEGORY_VIDEO_DECODER_NOT_SUPPORTED: + case RMS_CATEGORY_JPEG_DECODER_NOT_SUPPORTED: + case RMS_CATEGORY_MJPEG_DECODER_NOT_SUPPORTED: + case RMS_CATEGORY_NOT_PERMITTED: + result = false; + break; + default: + result = true; + break; + } + + return result; +} + +int CRequest::UnmaskMainSubOptions(int category_option) +{ + int result = category_option; + + result = (result & ~RMS_DEVICE_OPT_MAIN); + result = (result & ~RMS_DEVICE_OPT_SUB); + + return result; +} + +int CRequest::UnmaskMixingOptions(int category_option) +{ + int result = category_option; + + result = (result & ~RMS_MIXING_OPT_DEFAULT); + result = (result & ~RMS_MIXING_OPT_MULTIVIEW); + result = (result & ~RMS_MIXING_OPT_INTERACTION_SOUND); + + return result; +} + +int CRequest::UnmaskForceOptions(int category_option) +{ + int result = category_option; + + result = (result & ~RMS_FORCE_TO_MAIN); + result = (result & ~RMS_FORCE_TO_SUB); + + return result; +} + +int CRequest::UnmaskMVZoneInfo(int category_option) +{ + const int ZONE_INFO = 0x1E00000; + + return (category_option & ~ZONE_INFO); +} + +rms_rsc_category_e CRequest::ToResourceCategory(int category, int category_option) +{ + rms_rsc_category_e result = RMS_CATEGORY_NONE; + bool supported = IsSupportedCategory(category_option); + bool force_main = false; + bool force_sub = false; + + if (supported) { + force_main = (category_option & RMS_FORCE_TO_MAIN); + force_sub = (category_option & RMS_FORCE_TO_SUB); + category_option = UnmaskMainSubOptions(category_option); + } + + switch (category) { + case RMS_CATEGORY_VIDEO_DECODER: + case RMS_CATEGORY_VIDEO_DECODER_SUB: + if (supported) { + category_option = UnmaskMVZoneInfo(category_option); + category_option = (category_option & ~RMS_VIDEO_DEC_OPT_AI); + category_option = UnmaskForceOptions(category_option); + } + result = ToVideoDecoderCategory(category, category_option, force_main, force_sub); + break; + case RMS_CATEGORY_JPEG_DECODER: + result = ToJpegDecoderCategory(category, category_option); + break; + case RMS_CATEGORY_MJPEG_DECODER: + if (supported) + category_option = UnmaskMVZoneInfo(category_option); + + result = ToMJpegDecoderCategory(category, category_option); + break; + case RMS_CATEGORY_IMAGE_DECODER: + result = ToImageDecoderCategory(category, category_option); + break; + case RMS_CATEGORY_AUDIO_DECODER: + case RMS_CATEGORY_AUDIO_DECODER_SUB: + if (supported) { + category_option = UnmaskMixingOptions(category_option); + category_option = UnmaskForceOptions(category_option); + } + + result = ToAudioDecoderCategory(category, category_option, force_main, force_sub); + break; + case RMS_CATEGORY_SCALER: + case RMS_CATEGORY_SCALER_SUB: + if (supported) + category_option = UnmaskMVZoneInfo(category_option); + + result = ToScalerCategory(category, category_option, force_main, force_sub); + break; + case RMS_CATEGORY_AUDIO_MAIN_OUT: + case RMS_CATEGORY_AUDIO_SUB_OUT: + result = ToAudioOutCategory(category, category_option, force_main, force_sub); + break; + default: + result = (rms_rsc_category_e) category; + break; + } + + return result; +} + +rms_mixing_mode_e CRequest::ToMixingMode(int category, int category_option) +{ + if (category != RMS_CATEGORY_AUDIO_DECODER && category != RMS_CATEGORY_AUDIO_DECODER_SUB) + return RMS_MIXING_MODE_DEFAULT; + + if (category_option & RMS_MIXING_OPT_MULTIVIEW) + return RMS_MIXING_MODE_MULTIVIEW; + + if (category_option & RMS_MIXING_OPT_INTERACTION_SOUND) + return RMS_MIXING_MODE_INTERACTION_SOUND; + + return RMS_MIXING_MODE_DEFAULT; +} + +void CRequest::PrintResult(void) +{ + SERVER_WARN("result (%d) - con(%d:%s) / cat(%d) / req(%d:%d) / devId(%d) / vId(%d) / rsn(%d)", + m_result, + m_requester->getHandle(), + m_requester->getAppId().empty() ? m_requester->GetCmdName().c_str() : m_requester->getAppId().c_str(), + m_category, m_category_id, m_category_option, m_allocated_device, m_virtual_device, m_reason); +} diff --git a/src/CRequester.cpp b/src/CRequester.cpp index 13de37d..8d7f836 100644 --- a/src/CRequester.cpp +++ b/src/CRequester.cpp @@ -1,71 +1,71 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 "CDebugUtils.h" -#include "CRequester.h" - -CRequester::CRequester() -{ - m_handle = 0; - m_pid = 0; - m_main_priority = 0; - m_sub_priority = 0; - m_app_id.assign(""); -} - -CRequester::CRequester(rms_msg_request *req) -{ - m_handle = req->handle; - m_pid = req->pid; - m_main_priority = req->main_priority; - m_sub_priority = req->sub_priority; - m_app_id.assign(req->app_id); - SetCmdName(req->pid); -} - -CRequester::~CRequester() -{ -} - -void CRequester::SetCmdName(int pid) -{ - char cmd_name[512] = {0, }; - std::string delimiter = "/"; - - rms_get_cmd_name(pid, cmd_name, 512); - m_cmd_name.assign(cmd_name); - m_cmd_name = m_cmd_name.substr(m_cmd_name.find_last_of(delimiter) + 1, m_cmd_name.length()); -} - -int CRequester::getHandle(void) -{ - return m_handle; -} - -int CRequester::getPid(void) -{ - return m_pid; -} - -int CRequester::getMainPriority(void) -{ - return m_main_priority; -} - -int CRequester::getSubPriority(void) -{ - return m_sub_priority; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 "CDebugUtils.h" +#include "CRequester.h" + +CRequester::CRequester() +{ + m_handle = 0; + m_pid = 0; + m_main_priority = 0; + m_sub_priority = 0; + m_app_id.assign(""); +} + +CRequester::CRequester(rms_msg_request *req) +{ + m_handle = req->handle; + m_pid = req->pid; + m_main_priority = req->main_priority; + m_sub_priority = req->sub_priority; + m_app_id.assign(req->app_id); + SetCmdName(req->pid); +} + +CRequester::~CRequester() +{ +} + +void CRequester::SetCmdName(int pid) +{ + char cmd_name[512] = {0, }; + std::string delimiter = "/"; + + rms_get_cmd_name(pid, cmd_name, 512); + m_cmd_name.assign(cmd_name); + m_cmd_name = m_cmd_name.substr(m_cmd_name.find_last_of(delimiter) + 1, m_cmd_name.length()); +} + +int CRequester::getHandle(void) +{ + return m_handle; +} + +int CRequester::getPid(void) +{ + return m_pid; +} + +int CRequester::getMainPriority(void) +{ + return m_main_priority; +} + +int CRequester::getSubPriority(void) +{ + return m_sub_priority; +} diff --git a/src/CResourceService.cpp b/src/CResourceService.cpp index 7fe4b7a..124281b 100644 --- a/src/CResourceService.cpp +++ b/src/CResourceService.cpp @@ -1,123 +1,123 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#define RM_SERVER_SMART_DEADLOCK_WATCHDOG_TIME_90_SEC 90 -#define RM_SERVER_WATCHDOG_TIME_10000_MSEC 10000 -#define RM_SERVER_INVALID_TABLE_TIME_30000_MSEC 30000 - -int CResourceService::Init(GMainLoop *main_loop) -{ - CResourceManager *rsc_mgr = new CResourceManager(); - if (rsc_mgr->RegisterResources() != RMS_OK) { - SERVER_ERR("RegisterResources is failed"); - g_timeout_add(RM_SERVER_INVALID_TABLE_TIME_30000_MSEC, InvalidResourceTableMsgCallback, NULL); - return RMS_ERROR; - } - - m_msg_h = new CMessageHandler(rsc_mgr); - if (m_msg_h->Run() != RMS_OK) { - SERVER_ERR("RUN failed"); - return RMS_ERROR; - } - - SERVER_INFO("Done"); - return RMS_OK; -} - -int CResourceService::IsFirstLaunch(void) -{ - const char *vconf_key = "memory/rsc_mgr/is_launched_before"; - int is_launched_before = 0; - - if (vconf_get_int(vconf_key, &is_launched_before) != 0) - SERVER_ERR("Failed to get %s", vconf_key); - - if (is_launched_before == 1) { - SERVER_ERR("!!!!! Resource Manager 2nd Launch !!!!!"); - return 0; - } - - if (vconf_set_int(vconf_key, 1) != 0) - SERVER_ERR("Failed to set %s", vconf_key); - - return 1; -} - -void CResourceService::RequestColdPowerOff(void) -{ - const char *vconf_request_cold_poweroff = "memory/boot/cold_poweroff_request_pkg"; - - if (vconf_set_str(vconf_request_cold_poweroff, "resource-manager") != 0) { - SERVER_ERR("Failed to set %s", vconf_request_cold_poweroff); - } -} - -void CResourceService::CreateWatchDogTimer(void) -{ -} - -void CResourceService::SetVIPProcess(void) -{ - void *handle; - void (*vip_func)(void); - - handle = dlopen("/lib/libproc-stat.so.5", RTLD_LAZY); - - if (!handle) { - SERVER_ERR("failed to open libproc-stat.so (%s)", dlerror()); - return; - } - - *(void**)&vip_func = dlsym(handle, "proc_stat_set_vip_process"); - - if (!vip_func) { - SERVER_ERR("failed to find proc_stat_set_vip_process"); - dlclose(handle); - return; - } - - SERVER_INFO("set vip process"); - vip_func(); - dlclose(handle); -} - -gboolean CResourceService::WatchDogCallback(gpointer data) -{ - return G_SOURCE_CONTINUE; -} - -gboolean CResourceService::InvalidResourceTableMsgCallback(gpointer data) -{ - SERVER_ERR("resource table not loaded!"); - rms_print_model_info(); - return G_SOURCE_CONTINUE; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define RM_SERVER_SMART_DEADLOCK_WATCHDOG_TIME_90_SEC 90 +#define RM_SERVER_WATCHDOG_TIME_10000_MSEC 10000 +#define RM_SERVER_INVALID_TABLE_TIME_30000_MSEC 30000 + +int CResourceService::Init(GMainLoop *main_loop) +{ + CResourceManager *rsc_mgr = new CResourceManager(); + if (rsc_mgr->RegisterResources() != RMS_OK) { + SERVER_ERR("RegisterResources is failed"); + g_timeout_add(RM_SERVER_INVALID_TABLE_TIME_30000_MSEC, InvalidResourceTableMsgCallback, NULL); + return RMS_ERROR; + } + + m_msg_h = new CMessageHandler(rsc_mgr); + if (m_msg_h->Run() != RMS_OK) { + SERVER_ERR("RUN failed"); + return RMS_ERROR; + } + + SERVER_INFO("Done"); + return RMS_OK; +} + +int CResourceService::IsFirstLaunch(void) +{ + const char *vconf_key = "memory/rsc_mgr/is_launched_before"; + int is_launched_before = 0; + + if (vconf_get_int(vconf_key, &is_launched_before) != 0) + SERVER_ERR("Failed to get %s", vconf_key); + + if (is_launched_before == 1) { + SERVER_ERR("!!!!! Resource Manager 2nd Launch !!!!!"); + return 0; + } + + if (vconf_set_int(vconf_key, 1) != 0) + SERVER_ERR("Failed to set %s", vconf_key); + + return 1; +} + +void CResourceService::RequestColdPowerOff(void) +{ + const char *vconf_request_cold_poweroff = "memory/boot/cold_poweroff_request_pkg"; + + if (vconf_set_str(vconf_request_cold_poweroff, "resource-manager") != 0) { + SERVER_ERR("Failed to set %s", vconf_request_cold_poweroff); + } +} + +void CResourceService::CreateWatchDogTimer(void) +{ +} + +void CResourceService::SetVIPProcess(void) +{ + void *handle; + void (*vip_func)(void); + + handle = dlopen("/lib/libproc-stat.so.5", RTLD_LAZY); + + if (!handle) { + SERVER_ERR("failed to open libproc-stat.so (%s)", dlerror()); + return; + } + + *(void**)&vip_func = dlsym(handle, "proc_stat_set_vip_process"); + + if (!vip_func) { + SERVER_ERR("failed to find proc_stat_set_vip_process"); + dlclose(handle); + return; + } + + SERVER_INFO("set vip process"); + vip_func(); + dlclose(handle); +} + +gboolean CResourceService::WatchDogCallback(gpointer data) +{ + return G_SOURCE_CONTINUE; +} + +gboolean CResourceService::InvalidResourceTableMsgCallback(gpointer data) +{ + SERVER_ERR("resource table not loaded!"); + rms_print_model_info(); + return G_SOURCE_CONTINUE; +} diff --git a/src/CSysInfo.cpp b/src/CSysInfo.cpp index e33c761..7845225 100644 --- a/src/CSysInfo.cpp +++ b/src/CSysInfo.cpp @@ -1,53 +1,53 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include - -CSysInfo *CSysInfo::m_instance = NULL; - -CSysInfo *CSysInfo::GetInstance(void) -{ - if (!m_instance) { - m_instance = new(std::nothrow) CSysInfo; - assert(m_instance); - } - - return m_instance; -} - -bool CSysInfo::IsAudioMixingSupported(void) -{ - static bool init = false; - bool supported = false; - - if (init) - return m_support_audio_mixing; - - if (system_info_get_custom_bool("com.samsung/featureconf/multiview.dualsound", &supported) != SYSTEM_INFO_ERROR_NONE) { - SERVER_ERR("failed to get com.samsung/featureconf/multiview.dualsound"); - return m_support_audio_mixing; - } - - m_support_audio_mixing = supported; - init = true; - SERVER_INFO("multiview.dualsound (%d)", supported); - return m_support_audio_mixing; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include + +CSysInfo *CSysInfo::m_instance = NULL; + +CSysInfo *CSysInfo::GetInstance(void) +{ + if (!m_instance) { + m_instance = new(std::nothrow) CSysInfo; + assert(m_instance); + } + + return m_instance; +} + +bool CSysInfo::IsAudioMixingSupported(void) +{ + static bool init = false; + bool supported = false; + + if (init) + return m_support_audio_mixing; + + if (system_info_get_custom_bool("com.samsung/featureconf/multiview.dualsound", &supported) != SYSTEM_INFO_ERROR_NONE) { + SERVER_ERR("failed to get com.samsung/featureconf/multiview.dualsound"); + return m_support_audio_mixing; + } + + m_support_audio_mixing = supported; + init = true; + SERVER_INFO("multiview.dualsound (%d)", supported); + return m_support_audio_mixing; +} diff --git a/src/gen_rm_msgq.cpp b/src/gen_rm_msgq.cpp index 92e8cd5..4efd82e 100644 --- a/src/gen_rm_msgq.cpp +++ b/src/gen_rm_msgq.cpp @@ -1,119 +1,119 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define RM_MSGQ_KEY_TX 8212 -#define RM_MSGQ_KEY_RX 8211 - -static int _is_symlink_file(const char *path) -{ - struct stat st; - if (lstat(path, &st) == -1) { - SERVER_ERR("stat error. file path(%s)", path); - return 0; - } - - return (S_ISLNK(st.st_mode)) ? 1 : 0; -} - -static int _is_realpath(const char *path) -{ - char *rms_realpath = NULL; - int len_path = 0; - int len_realpath = 0; - int result = 1; - - rms_realpath = realpath(path, NULL); - - if (!rms_realpath) { - SERVER_INFO("realpath(%s) is null(%d)", path, errno); - return 0; - } - - len_path = strlen(path); - len_realpath = strlen(rms_realpath); - - if (len_path != len_realpath) { - SERVER_ERR("length mismatch(%d:%d)", len_path, len_realpath); - result = 0; - goto out; - } - - if (strncmp(path, rms_realpath, len_path)) { - SERVER_ERR("path mismatch(%s:%s)", path, rms_realpath); - result = 0; - goto out; - } - -out: - free(rms_realpath); - - return result; -} - -int main() -{ - int msgq_tx = -1, msgq_rx = -1; - msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); - msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); - - if ((msgq_tx == -1) || (msgq_rx == -1)) { - SERVER_ERR("NEW MSGQ_CREATE failed to get msgq_id - msgq_tx(%d), msgq_rx(%d)", msgq_tx, msgq_rx); - return -1; - } - - SERVER_INFO("msgq_tx (%d), msgq_rx(%d)", msgq_tx, msgq_rx); - - FILE *fp = NULL; - const char *flag_path = "/run/rsc_mgr_ready"; - - fp = fopen(flag_path,"w"); - - if (!fp) { - SERVER_ERR("NEW_MSGQ_CREATE Failed to create message queue(%s) errno(%d)", flag_path, errno); - return -1; - } - - if (!_is_realpath(flag_path)) { - SERVER_ERR("%s is not realpath", flag_path); - fclose(fp); - return -1; - } - - if (_is_symlink_file(flag_path)) { - SERVER_ERR("%s is symbolic link file", flag_path); - fclose(fp); - return -1; - } - - SERVER_INFO("NEW_MSGQ_CREATE resource manager message queue(%s) created", flag_path); - - fflush(fp); - fsync(fileno(fp)); - fclose(fp); - return 0; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RM_MSGQ_KEY_TX 8212 +#define RM_MSGQ_KEY_RX 8211 + +static int _is_symlink_file(const char *path) +{ + struct stat st; + if (lstat(path, &st) == -1) { + SERVER_ERR("stat error. file path(%s)", path); + return 0; + } + + return (S_ISLNK(st.st_mode)) ? 1 : 0; +} + +static int _is_realpath(const char *path) +{ + char *rms_realpath = NULL; + int len_path = 0; + int len_realpath = 0; + int result = 1; + + rms_realpath = realpath(path, NULL); + + if (!rms_realpath) { + SERVER_INFO("realpath(%s) is null(%d)", path, errno); + return 0; + } + + len_path = strlen(path); + len_realpath = strlen(rms_realpath); + + if (len_path != len_realpath) { + SERVER_ERR("length mismatch(%d:%d)", len_path, len_realpath); + result = 0; + goto out; + } + + if (strncmp(path, rms_realpath, len_path)) { + SERVER_ERR("path mismatch(%s:%s)", path, rms_realpath); + result = 0; + goto out; + } + +out: + free(rms_realpath); + + return result; +} + +int main() +{ + int msgq_tx = -1, msgq_rx = -1; + msgq_tx = msgget((key_t)RM_MSGQ_KEY_TX, 0666 | IPC_CREAT); + msgq_rx = msgget((key_t)RM_MSGQ_KEY_RX, 0666 | IPC_CREAT); + + if ((msgq_tx == -1) || (msgq_rx == -1)) { + SERVER_ERR("NEW MSGQ_CREATE failed to get msgq_id - msgq_tx(%d), msgq_rx(%d)", msgq_tx, msgq_rx); + return -1; + } + + SERVER_INFO("msgq_tx (%d), msgq_rx(%d)", msgq_tx, msgq_rx); + + FILE *fp = NULL; + const char *flag_path = "/run/rsc_mgr_ready"; + + fp = fopen(flag_path,"w"); + + if (!fp) { + SERVER_ERR("NEW_MSGQ_CREATE Failed to create message queue(%s) errno(%d)", flag_path, errno); + return -1; + } + + if (!_is_realpath(flag_path)) { + SERVER_ERR("%s is not realpath", flag_path); + fclose(fp); + return -1; + } + + if (_is_symlink_file(flag_path)) { + SERVER_ERR("%s is symbolic link file", flag_path); + fclose(fp); + return -1; + } + + SERVER_INFO("NEW_MSGQ_CREATE resource manager message queue(%s) created", flag_path); + + fflush(fp); + fsync(fileno(fp)); + fclose(fp); + return 0; +} diff --git a/src/rms_service.cpp b/src/rms_service.cpp index 2f73275..dbdbd95 100644 --- a/src/rms_service.cpp +++ b/src/rms_service.cpp @@ -1,44 +1,44 @@ -/* - * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved - * - * 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 -#include -#include - -#include - -int main(void) -{ - SERVER_INFO("RscMgr server main loop\n"); - trace_begin("[RSC_MGR] main start"); - trace_end(); - - GMainLoop *main_loop; - main_loop = g_main_loop_new(NULL, FALSE); - - if (!main_loop) { - SERVER_ERR("failed to create a main loop\n"); - return 0; - } - - CResourceService *service = new(std::nothrow) CResourceService; - service->Init(main_loop); - - g_main_loop_ref(main_loop); - g_main_loop_run(main_loop); - - return 0; -} +/* + * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 +#include +#include + +#include + +int main(void) +{ + SERVER_INFO("RscMgr server main loop\n"); + trace_begin("[RSC_MGR] main start"); + trace_end(); + + GMainLoop *main_loop; + main_loop = g_main_loop_new(NULL, FALSE); + + if (!main_loop) { + SERVER_ERR("failed to create a main loop\n"); + return 0; + } + + CResourceService *service = new(std::nothrow) CResourceService; + service->Init(main_loop); + + g_main_loop_ref(main_loop); + g_main_loop_run(main_loop); + + return 0; +}