concurrencyview.tcl 5.24 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 32 33 34 35 36 37 38 39 40 41 42 43 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
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" } {
			Context::setAttribute "concurrencyview" state "normal"
			if { [ string match win32*64 [::platform::identify]] || [ string match win32* [::platform::identify]] } {
				return [concurrencyviewWindows_internal ]
			} else {
				return [concurrencyview_internal ]
			}
		}
    }
    
    #  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
108 109 110
		## 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
111
        set dtFilename [lindex [Object::getAttribute "dataview" "filenames" ] 0 ]
Arnaud Schach's avatar
Arnaud Schach committed
112
        set cvFilename "[LogManager::getLogDirectory]/concurrencyview.aadl"
Arnaud Schach's avatar
Arnaud Schach committed
113
		
Arnaud Schach's avatar
Arnaud Schach committed
114 115 116 117 118
		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
119

Arnaud Schach's avatar
Arnaud Schach committed
120 121 122 123 124 125 126 127 128 129
		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
130 131 132
					set content [read -nonewline $fin]
					close $fin
					puts $chan $content
Arnaud Schach's avatar
Arnaud Schach committed
133
					puts $chan "\n\n"
Arnaud Schach's avatar
Arnaud Schach committed
134
				}
Arnaud Schach's avatar
Arnaud Schach committed
135 136 137 138 139 140 141
				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
142 143

				::API::HMI::loadUI "$cvFilename" "concurrencyview"
Arnaud Schach's avatar
Arnaud Schach committed
144 145 146
			
				return [list 0 ""]
				
Arnaud Schach's avatar
Arnaud Schach committed
147 148
			}
		} else {
Arnaud Schach's avatar
Arnaud Schach committed
149
			return [list 1 [list "taste-edit-concurrency-view error:\n$errMsg" ] ]
Arnaud Schach's avatar
Arnaud Schach committed
150 151 152
		}
    } 
}