common_library: gettid is multiple declaration in cl_error
[staging/basesystem.git] / video_in_hal / agl-basefiles / bin / launch_xml2cfg.sh
1 #!/bin/bash
2 #
3 # @copyright Copyright (c) 2019 TOYOTA MOTOR CORPORATION.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 #Since xpath is slow, use sed as much as possible.
19
20 infile=$1
21 main_file=system_launcher_main.xml
22 body_file=system_launcher_body.xml
23
24
25 #check xmllint is exist 
26 if ! which xmllint > /dev/null ; then
27   echo "It need xmllint. Please install it."
28   exit 1;
29 fi 
30
31 #check xpath is exist 
32 if ! which xpath > /dev/null ; then
33   echo "It need xpath Please install it."
34   exit 1;
35 fi 
36
37 #arg check
38 if ! [[ "$infile" =~ .+\.xml ]] ;then
39   echo "$infile is not *.xml"
40   exit 1
41 elif ! [ -e $infile ];then
42   echo "$infile not found"
43   exit 1
44 fi
45
46 cp -f `dirname $0`/$main_file `dirname $1`
47 cp -f $infile $body_file
48
49 #check xml vaild 
50 if ! xmllint --noout --valid $main_file ;then
51   echo "XML is Invalid. "
52   exit 1;
53 fi
54
55 #Format into xpath and read into memory
56 xmem=`xpath -q -e /system_launcher $main_file`
57
58 echo "#  This file is created from $infile."
59 echo "#  created date : `LANG=en date`"
60 echo "[ModulesLaunchConfig]"
61
62 #GROUP LOOP
63 group_num=`echo $xmem | xpath -e /system_launcher/group 2>&1 | grep Found | cut -d ' ' -f2`
64
65 l_idx=1
66 cur_group=1
67 until [ $cur_group -gt $group_num ];  
68 do
69   #LAUNCH LOOP
70   group_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]`  #ALL XML text for group
71   group_attr=`echo $group_text | sed 's/\(<group[^>]\+>\)\(.*\)/\1/g'`
72
73   g_name=`echo $group_attr | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'`
74   g_wait_time=`echo $group_attr | sed 's/\(.* wait_time="\)\([^"]*\)\(.*\)/\2/g'`
75   g_trigger=`echo $group_attr | sed 's/\(.* trigger="\)\([^"]*\)\(.*\)/\2/g'`
76
77 #  echo $g_name $g_wait_time $g_trigger
78   l_launch_num=`echo $xmem | xpath -e /system_launcher/group[$cur_group]/launch  2>&1 | grep Found | cut -d ' ' -f2`
79   
80   cur_launch=1; 
81   until [ $cur_launch -gt $l_launch_num ];  do
82     launch_text=`echo $xmem | xpath -q -e /system_launcher/group[$cur_group]/launch[$cur_launch]`  
83     
84     l_attr="Launch${l_idx}=$g_name|$cur_group|$g_wait_time|$g_trigger"
85     l_attr+="|"`echo $launch_text | sed 's/\(.* name="\)\([^"]*\)\(.*\)/\2/g'`
86     l_attr+="|"`echo $launch_text | sed 's/\(.* path="\)\([^"]*\)\(.*\)/\2/g'`
87     l_attr+="|"`echo $launch_text | sed 's/\(.* priority="\)\([^"]*\)\(.*\)/\2/g'`
88     l_attr+="|"`echo $launch_text | sed 's/\(.* critical="\)\([^"]*\)\(.*\)/\2/g'`
89     l_attr+="|"`echo $launch_text | sed 's/\(.* retry_cnt="\)\([^"]*\)\(.*\)/\2/g'`
90     l_attr+="|"`echo $launch_text | sed 's/\(.* arguments="\)\([^"]*\)\(.*\)/\2/g'`
91     l_attr+="|"`echo $launch_text | sed 's/\(.* logging_mask="\)\([^"]*\)\(.*\)/\2/g'`
92     l_attr+="|"`echo $launch_text | sed 's/\(.* restart="\)\([^"]*\)\(.*\)/\2/g'`
93     l_attr+="|"`echo $launch_text | sed 's/\(.* is_start_required="\)\([^"]*\)\(.*\)/\2/g'`
94     l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_critical="\)\([^"]*\)\(.*\)/\2/g'`
95     l_attr+="|"`echo $launch_text | sed 's/\(.* shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'`
96     l_attr+="|"`echo $launch_text | sed 's/\(.* fast_shutdown_wait_time="\)\([^"]*\)\(.*\)/\2/g'`
97     l_attr+="|"`echo $launch_text | sed 's/\(.* user_name="\)\([^"]*\)\(.*\)/\2/g'`
98     if echo "$launch_text" | grep -sq 'is_agl_unit=' ; then
99       l_attr+="|"`echo $launch_text | sed 's/\(.* is_agl_unit="\)\([^"]*\)\(.*\)/\2/g'`
100     else
101       l_attr+="|"
102     fi
103     if echo "$launch_text" | grep -sq 'disable_agl_resethistory=' ; then
104       l_attr+="|"`echo $launch_text | sed 's/\(.* disable_agl_resethistory="\)\([^"]*\)\(.*\)/\2/g'`
105     else
106       l_attr+="|"
107     fi
108     if echo "$launch_text" | grep -sq 'disable_nonagl_resethistory=' ; then
109       l_attr+="|"`echo $launch_text | sed 's/\(.* disable_nonagl_resethistory="\)\([^"]*\)\(.*\)/\2/g'`
110     else
111       l_attr+="|"
112     fi
113     if echo "$launch_text" | grep -sq 'env_cond=' ; then
114       l_attr+="|"`echo $launch_text | sed 's/\(.* env_cond="\)\([^"]*\)\(.*\)/\2/g'`
115     else
116       l_attr+="|"
117     fi
118     
119     if echo "$launch_text" | grep -sq 'cpu_assign=' ; then
120       l_attr+="|"`echo $launch_text | sed 's/\(.* cpu_assign="\)\([^"]*\)\(.*\)/\2/g'`
121     else
122       l_attr+="|0x0"
123     fi
124
125     echo $l_attr
126
127     cur_launch=$(($cur_launch+1))
128     l_idx=$(($l_idx+1))
129   done
130
131   cur_group=$(($cur_group+1))
132 done
133
134
135 rm $body_file
136 rm $main_file
137
138