concurrencyview.tcl 5.51 KB
Newer Older
Arnaud Schach's avatar
Arnaud Schach committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package provide concurrencyview 0.1 

lappend auto_path .
namespace eval concurrencyview {
    
    # Graphical name of the operation
    proc getLabel {} {
        return "Build Concurrency View"
    }
    
    # Name of the application this script can be used with
    # shall be either InterfaceView or DeploymentView
    proc getApplication {} {
        return "DeploymentView"
    }
    
    # Names of  the object this script can be used on
    # FIXME - it should be active all the time
    proc getApplyTo {} {
        return [list "alwayson" ]
    }
    
    # List of way to manage output in the Framework
    # Could be an empty list or one or both of 'dialogBox' and 'statusBar'
    proc getOutputManagement {} {
		## Ticket mantis 0000625
        return [list dialogBoxOnError ]
    }
    
    proc concurrencyview { args } {
		if { [Object::getAttribute "concurrencyview" state] == "deprecated" } {
Jerome Legrand's avatar
Jerome Legrand committed
32 33 34 35 36 37
			set dvRoot [Object::getAttribute "deploymentview" "rootID"]
			set res [API::Kernel::checkConsistency $dvRoot]
			if { [lindex $res 0] == -1 } {
				lset res 1 [ concat [ list "Deployment view is inconsistent" ] [lindex $res 1 ] ]
				return $res
			} else {
Arnaud Schach's avatar
Arnaud Schach committed
38 39 40 41 42
				Context::setAttribute "concurrencyview" state "normal"
				if { [ string match win32*64 [::platform::identify]] || [ string match win32* [::platform::identify]] } {
					return [concurrencyviewWindows_internal ]
				} else {
					return [concurrencyview_internal ]
Jerome Legrand's avatar
Jerome Legrand committed
43
				}
Arnaud Schach's avatar
Arnaud Schach committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
			}
		}
    }
    
    #  the line "exec {*}[auto_execok $::installationPath/config/externalTools/test.bat]"
    #  ask the current OS which software is to be used to open the file test.bat
    #  to launch using the absolute path, read the template2.tcl_
    
    # synchronous call
    proc concurrencyviewWindows_internal { } { 
        
        set ivFilename [lindex [Object::getAttribute "interfaceview" "filenames" ] 0 ]
        set dvFilename [lindex [Object::getAttribute "deploymentview" "filenames" ] 0 ]
        set dtFilename [lindex [Object::getAttribute "dataview" "filenames" ] 0 ]
        set hwFilenames [Object::getAttribute "hwlibrary" "filenames" ]
        
        if { [file exists $ivFilename ] && [file exists $dvFilename ] && [file exists $dtFilename ] } {
			set concatFilename "[LogManager::getLogDirectory]/concatenatedFile.aadl"
			set concatFilenamePredicates "[LogManager::getLogDirectory]/concatenatedFile.sbp"
			set cvFilename "[LogManager::getLogDirectory]/concurrencyview.aadl"
			set fout [ open $concatFilename w ]
			fconfigure $fout -translation lf
			set fin [ open $ivFilename r ]
			set content [read -nonewline $fin]
			close $fin
			puts $fout $content
			puts $fout "\n\n"
			set fin [ open $dvFilename r ]
			set content [read -nonewline $fin]
			close $fin
			puts $fout $content
			puts $fout "\n\n"
			if { [file exists $dtFilename ] } {
				set fin [ open $dtFilename r ]
				set content [read -nonewline $fin]
				close $fin
				puts $fout $content
				puts $fout "\n\n"
			}
			foreach hwFilename $hwFilenames {
				if { [file exists $hwFilename ] } {
					set fin [ open $hwFilename r ]
					set content [read -nonewline $fin]
					close $fin
					puts $fout $content
					puts $fout "\n\n"
				}
			}
			close $fout
			
			
			if { [ ::AADLInspectorTools::getFactsFromAADL $concatFilename $concatFilenamePredicates ] != 0 } {
				return [list -1 "error in aadlrev" ]
			}
			if { [lindex [ ::AADLInspectorTools::generateAadlFromFacts $concatFilenamePredicates "$::commonPluginPath/TasteVT.sbp" $cvFilename ] 0 ] != 0 } {
				return [list -1 "error in aadlrev" ]
			}
			::API::HMI::loadUI "$cvFilename" "concurrencyview"
		
			return [list 0 ""]
		} else {
			return [ list -1 "IV Dataview and DV shall be loaded." ]
		}
    } 
    
    #  the line "exec {*}[auto_execok $::installationPath/config/externalTools/test.bat]"
    #  ask the current OS which software is to be used to open the file test.bat
    #  to launch using the absolute path, read the template2.tcl_
    
    # synchronous call
    proc concurrencyview_internal { } { 
Arnaud Schach's avatar
Arnaud Schach committed
115 116 117
		## Ticket mantis 0000665
        set ivFilename [ lindex [::Object::getAttribute "interfaceview" "filenames" ] 0]
        set dvFilename [ lindex [::Object::getAttribute "deploymentview" "filenames" ] 0]
Arnaud Schach's avatar
Arnaud Schach committed
118
        set dtFilename [lindex [Object::getAttribute "dataview" "filenames" ] 0 ]
Arnaud Schach's avatar
Arnaud Schach committed
119
        set cvFilename "[LogManager::getLogDirectory]/concurrencyview.aadl"
Arnaud Schach's avatar
Arnaud Schach committed
120
		
Arnaud Schach's avatar
Arnaud Schach committed
121 122 123 124 125
		set res [catch { exec taste-config --prefix } tasteConfigDir ]
		if { $res != 0 } {
			#~ an error happend
			return [list 1 [list "taste-config error: $tasteConfigDir"] ]
		}
Arnaud Schach's avatar
Arnaud Schach committed
126

Arnaud Schach's avatar
Arnaud Schach committed
127 128 129 130 131 132 133 134 135 136
		set res [ catch { exec taste-edit-concurrency-view ${ivFilename} ${dvFilename} ${dtFilename} 2>@1 } errMsg ]
        
        if { $res == 0 } {
			if { [file exists "ConcurrencyView/process.aadl" ] } {
				file delete -force "$cvFilename"
				file copy -force "ConcurrencyView/process.aadl" "$cvFilename"
				set chan [open "$cvFilename" a+ ]
				fconfigure $chan -translation lf
				foreach threadFile [glob -nocomplain  -type f  -directory "ConcurrencyView" *_Thread.aadl ] {
					set fin [ open $threadFile r ]
Arnaud Schach's avatar
Arnaud Schach committed
137 138 139
					set content [read -nonewline $fin]
					close $fin
					puts $chan $content
Arnaud Schach's avatar
Arnaud Schach committed
140
					puts $chan "\n\n"
Arnaud Schach's avatar
Arnaud Schach committed
141
				}
Arnaud Schach's avatar
Arnaud Schach committed
142 143 144 145 146 147 148
				set OCARINA_COMPONENTS "$tasteConfigDir/share/ocarina/AADLv2/ocarina_components.aadl"
				set fin [ open $OCARINA_COMPONENTS r ]
				set content [read -nonewline $fin]
				close $fin
				puts $chan $content
				close $chan
				
Arnaud Schach's avatar
Arnaud Schach committed
149 150

				::API::HMI::loadUI "$cvFilename" "concurrencyview"
Arnaud Schach's avatar
Arnaud Schach committed
151 152 153
			
				return [list 0 ""]
				
Arnaud Schach's avatar
Arnaud Schach committed
154 155
			}
		} else {
Arnaud Schach's avatar
Arnaud Schach committed
156
			return [list 1 [list "taste-edit-concurrency-view error:\n$errMsg" ] ]
Arnaud Schach's avatar
Arnaud Schach committed
157 158 159
		}
    } 
}