Compare commits
8 Commits
e2d2e17407
...
main
Author | SHA1 | Date | |
---|---|---|---|
9bf3a922b2 | |||
6ceeffac0e | |||
8b6d447574 | |||
e35f36db4b | |||
7c72e94d8d | |||
a9782efcdd | |||
e8e867b878 | |||
96b3c953f8 |
67
DEV/DEV3.1/TP01/Exercise1/Database.java
Normal file
67
DEV/DEV3.1/TP01/Exercise1/Database.java
Normal file
@@ -0,0 +1,67 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Database {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
|
||||
this.connection = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier",
|
||||
"baudrier",
|
||||
"baudrier"
|
||||
);
|
||||
} catch(ClassNotFoundException exception) {
|
||||
System.err.println("Class 'org.mariadb.jdbc.Driver' not found.");
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to connect to the database");
|
||||
}
|
||||
}
|
||||
|
||||
public Votes getVotesFromCompetitor(String country) {
|
||||
try {
|
||||
PreparedStatement query = this.connection.prepareStatement(
|
||||
"SELECT Voters.name, Votes.points " +
|
||||
"FROM Votes " +
|
||||
"JOIN Countries AS Competitors ON Votes.competitor_id = Competitors.id " +
|
||||
"JOIN Countries AS Voters ON Votes.voter_id = Voters.id " +
|
||||
"WHERE Competitors.name = ?;"
|
||||
);
|
||||
query.setString(1, country);
|
||||
|
||||
ResultSet result = query.executeQuery();
|
||||
ArrayList<Vote> voteList = new ArrayList<>();
|
||||
|
||||
while(result.next()) {
|
||||
voteList.add(new Vote(result.getString("name"), result.getInt("points")));
|
||||
}
|
||||
|
||||
try {
|
||||
query.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the query.");
|
||||
}
|
||||
|
||||
return new Votes(country, voteList);
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to prepare or execute the query (" + exception.getMessage() + ").");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.connection.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the connection.");
|
||||
}
|
||||
}
|
||||
}
|
18
DEV/DEV3.1/TP01/Exercise1/Main.java
Normal file
18
DEV/DEV3.1/TP01/Exercise1/Main.java
Normal file
@@ -0,0 +1,18 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Database database = new Database();
|
||||
|
||||
Votes votesForItaly = database.getVotesFromCompetitor("Pays-Bas");
|
||||
|
||||
System.out.println("Vote " + votesForItaly.getCompetitorName() + " :");
|
||||
for(Vote vote : votesForItaly.getVoters()) {
|
||||
System.out.println(vote.getVoterName() + " " + vote.getPoints());
|
||||
}
|
||||
|
||||
System.out.println("-------------------");
|
||||
System.out.println("Total " + votesForItaly.getTotalPoints());
|
||||
|
||||
database.close();
|
||||
}
|
||||
}
|
18
DEV/DEV3.1/TP01/Exercise1/Vote.java
Normal file
18
DEV/DEV3.1/TP01/Exercise1/Vote.java
Normal file
@@ -0,0 +1,18 @@
|
||||
public class Vote {
|
||||
|
||||
private String voter;
|
||||
private int points;
|
||||
|
||||
public Vote(String voter, int points) {
|
||||
this.voter = voter;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public String getVoterName() {
|
||||
return this.voter;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return this.points;
|
||||
}
|
||||
}
|
30
DEV/DEV3.1/TP01/Exercise1/Votes.java
Normal file
30
DEV/DEV3.1/TP01/Exercise1/Votes.java
Normal file
@@ -0,0 +1,30 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Votes {
|
||||
|
||||
private String competitor;
|
||||
private ArrayList<Vote> voters;
|
||||
|
||||
public Votes(String competitor, ArrayList<Vote> voters) {
|
||||
this.competitor = competitor;
|
||||
this.voters = voters;
|
||||
}
|
||||
|
||||
public String getCompetitorName() {
|
||||
return this.competitor;
|
||||
}
|
||||
|
||||
public ArrayList<Vote> getVoters() {
|
||||
return this.voters;
|
||||
}
|
||||
|
||||
public int getTotalPoints() {
|
||||
int sum = 0;
|
||||
|
||||
for(Vote vote : this.voters) {
|
||||
sum += vote.getPoints();
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
}
|
23
DEV/DEV3.1/TP01/Exercise1/data.sql
Normal file
23
DEV/DEV3.1/TP01/Exercise1/data.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE TABLE Countries (
|
||||
id INT PRIMARY KEY,
|
||||
name VARCHAR(30)
|
||||
);
|
||||
|
||||
CREATE TABLE Votes (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
competitor_id INT REFERENCES Countries(id),
|
||||
voter_id INT REFERENCES Countries(id),
|
||||
points INT NOT NULL,
|
||||
UNIQUE (competitor_id, voter_id)
|
||||
)
|
||||
|
||||
INSERT INTO Countries VALUES (1, "France");
|
||||
INSERT INTO Countries VALUES (2, "Pays-Bas");
|
||||
INSERT INTO Countries VALUES (3, "Albanie");
|
||||
INSERT INTO Countries VALUES (4, "Italie");
|
||||
INSERT INTO Countries VALUES (5, "Russie");
|
||||
INSERT INTO Votes VALUES (2, 4, 5);
|
||||
INSERT INTO Votes VALUES (2, 5, 5);
|
||||
INSERT INTO Votes VALUES (4, 2, 16);
|
||||
INSERT INTO Votes VALUES (5, 2, 5);
|
||||
INSERT INTO Votes VALUES (5, 4, 8);
|
3
DEV/DEV3.1/TP01/Exercise1/start.sh
Executable file
3
DEV/DEV3.1/TP01/Exercise1/start.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
rm -rf *.class
|
||||
javac Main.java;
|
||||
java -cp ".:/export/documents/mariadb-client.jar" Main;
|
68
DEV/DEV3.1/TP01/Exercise2/Database.java
Normal file
68
DEV/DEV3.1/TP01/Exercise2/Database.java
Normal file
@@ -0,0 +1,68 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Database {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
|
||||
this.connection = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier",
|
||||
"baudrier",
|
||||
"baudrier"
|
||||
);
|
||||
} catch(ClassNotFoundException exception) {
|
||||
System.err.println("Class 'org.mariadb.jdbc.Driver' not found.");
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to connect to the database");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Votes getVotesFromCompetitor(String country) {
|
||||
try {
|
||||
PreparedStatement query = this.connection.prepareStatement(
|
||||
"SELECT VoterVotes.points " +
|
||||
"FROM Votes " +
|
||||
"JOIN Countries AS Competitors ON Votes.competitor_id = Competitors.id " +
|
||||
"JOIN Countries AS Voters ON Votes.voter_id = Voters.id " +
|
||||
"WHERE Competitors.name = ?;"
|
||||
);
|
||||
query.setString(1, country);
|
||||
|
||||
ResultSet result = query.executeQuery();
|
||||
ArrayList<Vote> voteList = new ArrayList<>();
|
||||
|
||||
while(result.next()) {
|
||||
voteList.add(new Vote(result.getString("name"), result.getInt("points")));
|
||||
}
|
||||
|
||||
try {
|
||||
query.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the query.");
|
||||
}
|
||||
|
||||
return new Votes(country, voteList);
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to prepare or execute the query (" + exception.getMessage() + ").");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.connection.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the connection.");
|
||||
}
|
||||
}
|
||||
}
|
3
DEV/DEV3.1/TP01/Exercise2/Main.java
Normal file
3
DEV/DEV3.1/TP01/Exercise2/Main.java
Normal file
@@ -0,0 +1,3 @@
|
||||
public class Main {
|
||||
|
||||
}
|
5
DEV/DEV3.1/TP01/Exercise2/ScoreBoardWindow.java
Normal file
5
DEV/DEV3.1/TP01/Exercise2/ScoreBoardWindow.java
Normal file
@@ -0,0 +1,5 @@
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class ScoreBoardWindow extends JFrame {
|
||||
|
||||
}
|
BIN
DEV/DEV3.1/TP02/.DS_Store
vendored
Normal file
BIN
DEV/DEV3.1/TP02/.DS_Store
vendored
Normal file
Binary file not shown.
23
DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java
Normal file
23
DEV/DEV3.1/TP02/Part1/ClickSwapImageEvent.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ClickSwapImageEvent extends MouseAdapter {
|
||||
|
||||
private ImageWindow window;
|
||||
|
||||
public ClickSwapImageEvent(ImageWindow window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent event) {
|
||||
System.out.println(this.window.manager.cursor);
|
||||
if(event.getX() > this.window.getWidth() / 2) {
|
||||
this.window.nextImage();
|
||||
System.out.println(this.window.manager.cursor);
|
||||
return;
|
||||
}
|
||||
|
||||
this.window.previousImage();
|
||||
System.out.println(this.window.manager.cursor);
|
||||
}
|
||||
}
|
49
DEV/DEV3.1/TP02/Part1/ImageManager.java
Normal file
49
DEV/DEV3.1/TP02/Part1/ImageManager.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class ImageManager {
|
||||
|
||||
private ImageIcon[] images;
|
||||
public int cursor;
|
||||
|
||||
public ImageManager() {
|
||||
File resourcesDirectory = new File("../resources/");
|
||||
|
||||
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
|
||||
File[] files = resourcesDirectory.listFiles();
|
||||
|
||||
if(files != null) {
|
||||
this.images = new ImageIcon[files.length];
|
||||
this.cursor = 0;
|
||||
|
||||
for(File file : files) {
|
||||
this.images[this.cursor] = new ImageIcon(file.getPath());
|
||||
this.cursor++;
|
||||
}
|
||||
|
||||
this.cursor = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImageIcon getNextImage() {
|
||||
if(this.cursor >= this.images.length - 1) {
|
||||
this.cursor = 0;
|
||||
} else {
|
||||
this.cursor++;
|
||||
}
|
||||
|
||||
return this.images[this.cursor];
|
||||
}
|
||||
|
||||
public ImageIcon getPreviousImage() {
|
||||
if(this.cursor <= 0) {
|
||||
this.cursor = this.images.length - 1;
|
||||
} else {
|
||||
this.cursor--;
|
||||
}
|
||||
|
||||
return this.images[this.cursor];
|
||||
}
|
||||
}
|
46
DEV/DEV3.1/TP02/Part1/ImageWindow.java
Normal file
46
DEV/DEV3.1/TP02/Part1/ImageWindow.java
Normal file
@@ -0,0 +1,46 @@
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class ImageWindow extends JFrame {
|
||||
|
||||
public ImageManager manager;
|
||||
private JLabel label;
|
||||
|
||||
public ImageWindow() {
|
||||
this.manager = new ImageManager();
|
||||
|
||||
this.setSize(1024, 1024);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
this.addMouseListener(new ClickSwapImageEvent(this));
|
||||
|
||||
this.nextImage();
|
||||
}
|
||||
|
||||
public void nextImage() {
|
||||
if(this.label != null) {
|
||||
this.remove(this.label);
|
||||
}
|
||||
|
||||
this.label = new JLabel(this.manager.getNextImage());
|
||||
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
this.add(label);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
public void previousImage() {
|
||||
if(this.label != null) {
|
||||
this.remove(this.label);
|
||||
}
|
||||
|
||||
this.label = new JLabel(this.manager.getPreviousImage());
|
||||
this.label.setVerticalAlignment(JLabel.CENTER);
|
||||
this.label.setHorizontalAlignment(JLabel.CENTER);
|
||||
|
||||
this.add(label);
|
||||
this.revalidate();
|
||||
}
|
||||
}
|
7
DEV/DEV3.1/TP02/Part1/Main.java
Normal file
7
DEV/DEV3.1/TP02/Part1/Main.java
Normal file
@@ -0,0 +1,7 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ImageWindow window = new ImageWindow();
|
||||
window.setVisible(true);
|
||||
}
|
||||
}
|
19
DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java
Normal file
19
DEV/DEV3.1/TP02/Part2/ApprovedButtonPressedEvent.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
|
||||
public class ApprovedButtonPressedEvent implements ActionListener{
|
||||
|
||||
private JDialog dialog;
|
||||
|
||||
public ApprovedButtonPressedEvent(JDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
this.dialog.dispose();
|
||||
this.dialog.getOwner().dispose();
|
||||
}
|
||||
}
|
18
DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java
Normal file
18
DEV/DEV3.1/TP02/Part2/CancelButtonPressedEvent.java
Normal file
@@ -0,0 +1,18 @@
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
|
||||
public class CancelButtonPressedEvent implements ActionListener{
|
||||
|
||||
private JDialog dialog;
|
||||
|
||||
public CancelButtonPressedEvent(JDialog dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
this.dialog.dispose();
|
||||
}
|
||||
}
|
20
DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java
Normal file
20
DEV/DEV3.1/TP02/Part2/ClickSwapImageEvent.java
Normal file
@@ -0,0 +1,20 @@
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class ClickSwapImageEvent extends MouseAdapter {
|
||||
|
||||
private ImageWindow window;
|
||||
|
||||
public ClickSwapImageEvent(ImageWindow window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent event) {
|
||||
if(event.getX() > this.window.getWidth() / 2) {
|
||||
this.window.nextImage();
|
||||
return;
|
||||
}
|
||||
|
||||
this.window.lastImage();
|
||||
}
|
||||
}
|
37
DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java
Normal file
37
DEV/DEV3.1/TP02/Part2/CloseVerificationWindow.java
Normal file
@@ -0,0 +1,37 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class CloseVerificationWindow extends JDialog {
|
||||
|
||||
public CloseVerificationWindow(ImageWindow parent) {
|
||||
super(parent, true);
|
||||
|
||||
this.setSize(parent.getWidth() / 3, parent.getHeight() / 3);
|
||||
this.setLocationRelativeTo(parent);
|
||||
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
this.setLayout(new GridLayout(2, 1));
|
||||
|
||||
JLabel text = new JLabel("Are you sure you want to close the window?");
|
||||
text.setVerticalAlignment(JLabel.CENTER);
|
||||
text.setHorizontalAlignment(JLabel.CENTER);
|
||||
this.add(text);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
|
||||
JButton approveButton = new JButton("Yes");
|
||||
approveButton.addActionListener(new ApprovedButtonPressedEvent(this));
|
||||
panel.add(approveButton, BorderLayout.WEST);
|
||||
|
||||
JButton cancelButton = new JButton("No");
|
||||
cancelButton.addActionListener(new CancelButtonPressedEvent(this));
|
||||
panel.add(cancelButton, BorderLayout.EAST);
|
||||
|
||||
this.add(panel);
|
||||
}
|
||||
}
|
55
DEV/DEV3.1/TP02/Part2/ImageWindow.java
Normal file
55
DEV/DEV3.1/TP02/Part2/ImageWindow.java
Normal file
@@ -0,0 +1,55 @@
|
||||
import java.io.File;
|
||||
|
||||
import java.awt.CardLayout;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ImageWindow extends JFrame {
|
||||
|
||||
private CardLayout cards;
|
||||
private JPanel imagePanel;
|
||||
|
||||
public ImageWindow() {
|
||||
this.setSize(1024, 1024);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
File resourcesDirectory = new File("../resources/");
|
||||
|
||||
if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) {
|
||||
File[] files = resourcesDirectory.listFiles();
|
||||
|
||||
if(files != null) {
|
||||
|
||||
this.cards = new CardLayout();
|
||||
this.imagePanel = new JPanel();
|
||||
this.imagePanel.setLayout(this.cards);
|
||||
|
||||
for(File file : files) {
|
||||
JLabel label = new JLabel(new ImageIcon(file.getPath()));
|
||||
label.setHorizontalAlignment(JLabel.CENTER);
|
||||
label.setVerticalAlignment(JLabel.CENTER);
|
||||
this.imagePanel.add(new JLabel(new ImageIcon(file.getPath())), file.getName());
|
||||
}
|
||||
|
||||
this.add(this.imagePanel);
|
||||
|
||||
this.addMouseListener(new ClickSwapImageEvent(this));
|
||||
this.addWindowListener(new WindowClosedEvent(this));
|
||||
|
||||
this.nextImage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void nextImage() {
|
||||
this.cards.next(this.imagePanel);
|
||||
}
|
||||
|
||||
public void lastImage() {
|
||||
this.cards.previous(this.imagePanel);
|
||||
}
|
||||
}
|
6
DEV/DEV3.1/TP02/Part2/Main.java
Normal file
6
DEV/DEV3.1/TP02/Part2/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
ImageWindow window = new ImageWindow();
|
||||
window.setVisible(true);
|
||||
}
|
||||
}
|
16
DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java
Normal file
16
DEV/DEV3.1/TP02/Part2/WindowClosedEvent.java
Normal file
@@ -0,0 +1,16 @@
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
public class WindowClosedEvent extends WindowAdapter {
|
||||
|
||||
private ImageWindow window;
|
||||
|
||||
public WindowClosedEvent(ImageWindow window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent event) {
|
||||
(new CloseVerificationWindow(this.window)).setVisible(true);
|
||||
}
|
||||
}
|
3
DEV/DEV3.1/TP02/Part2/start.sh
Executable file
3
DEV/DEV3.1/TP02/Part2/start.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
rm -rf *.class
|
||||
javac Main.java
|
||||
java Main
|
BIN
DEV/DEV3.1/TP02/resources/dice.jpg
Normal file
BIN
DEV/DEV3.1/TP02/resources/dice.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 70 KiB |
BIN
DEV/DEV3.1/TP02/resources/frog.png
Normal file
BIN
DEV/DEV3.1/TP02/resources/frog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
DEV/DEV3.1/TP02/resources/random.jpg
Normal file
BIN
DEV/DEV3.1/TP02/resources/random.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
86
DEV/DEV3.1/TP03/Exercise1/GridWindow.java
Normal file
86
DEV/DEV3.1/TP03/Exercise1/GridWindow.java
Normal file
@@ -0,0 +1,86 @@
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class GridWindow extends JFrame {
|
||||
|
||||
public GridWindow() {
|
||||
this.setSize(200, 200);
|
||||
this.setLocationRelativeTo(null);
|
||||
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
this.getContentPane().setLayout(new GridBagLayout());
|
||||
|
||||
this.placeButtons();
|
||||
|
||||
this.addWindowListener(new GridWindowClosedEvent(this));
|
||||
}
|
||||
|
||||
private void placeButtons() {
|
||||
GridBagConstraints constraints = new GridBagConstraints();
|
||||
|
||||
JButton one = new JButton("1");
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 0;
|
||||
constraints.gridwidth = 2;
|
||||
constraints.gridheight = 1;
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
constraints.insets = new Insets(0, 0, 0, 0);
|
||||
constraints.weightx = 1.0;
|
||||
constraints.weighty = 1.0;
|
||||
|
||||
this.getContentPane().add(one, constraints);
|
||||
|
||||
JButton two = new JButton("2");
|
||||
constraints.gridx = 2;
|
||||
constraints.gridy = 0;
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridheight = 2;
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
constraints.insets = new Insets(0, 0, 0, 0);
|
||||
constraints.weightx = 1.0;
|
||||
constraints.weighty = 1.0;
|
||||
|
||||
this.getContentPane().add(two, constraints);
|
||||
|
||||
JButton three = new JButton("3");
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 2;
|
||||
constraints.gridwidth = 2;
|
||||
constraints.gridheight = 1;
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
constraints.insets = new Insets(0, 0, 0, 0);
|
||||
constraints.weightx = 1.0;
|
||||
constraints.weighty = 1.0;
|
||||
|
||||
this.getContentPane().add(three, constraints);
|
||||
|
||||
JButton four = new JButton("4");
|
||||
constraints.gridx = 0;
|
||||
constraints.gridy = 1;
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridheight = 2;
|
||||
constraints.fill = GridBagConstraints.BOTH;
|
||||
constraints.insets = new Insets(0, 0, 0, 0);
|
||||
constraints.weightx = 1.0;
|
||||
constraints.weighty = 1.0;
|
||||
|
||||
this.getContentPane().add(four, constraints);
|
||||
|
||||
JButton five = new JButton("5");
|
||||
constraints.gridx = 1;
|
||||
constraints.gridy = 1;
|
||||
constraints.gridwidth = 1;
|
||||
constraints.gridheight = 1;
|
||||
constraints.fill = GridBagConstraints.NONE;
|
||||
constraints.insets = new Insets(0, 0, 0, 0);
|
||||
constraints.weightx = 0.0;
|
||||
constraints.weighty = 0.0;
|
||||
|
||||
this.getContentPane().add(five, constraints);
|
||||
}
|
||||
}
|
19
DEV/DEV3.1/TP03/Exercise1/GridWindowClosedEvent.java
Normal file
19
DEV/DEV3.1/TP03/Exercise1/GridWindowClosedEvent.java
Normal file
@@ -0,0 +1,19 @@
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
public class GridWindowClosedEvent extends WindowAdapter {
|
||||
|
||||
private GridWindow window;
|
||||
|
||||
public GridWindowClosedEvent(GridWindow window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent event) {
|
||||
int result = JOptionPane.showConfirmDialog(this.window, "Are you sure you want to close this window?", "Close current window", JOptionPane.YES_NO_OPTION);
|
||||
if(result == JOptionPane.YES_OPTION) this.window.dispose();
|
||||
}
|
||||
}
|
7
DEV/DEV3.1/TP03/Exercise1/Main.java
Normal file
7
DEV/DEV3.1/TP03/Exercise1/Main.java
Normal file
@@ -0,0 +1,7 @@
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
GridWindow window = new GridWindow();
|
||||
window.setVisible(true);
|
||||
}
|
||||
}
|
18
DEV/DEV3.1/TP03/Exercise2/Champ.java
Normal file
18
DEV/DEV3.1/TP03/Exercise2/Champ.java
Normal file
@@ -0,0 +1,18 @@
|
||||
public class Champ {
|
||||
|
||||
private String code;
|
||||
private String[] modules;
|
||||
|
||||
public Champ(String code, String[] modules) {
|
||||
this.code = code;
|
||||
this.modules = modules;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String[] getModules() {
|
||||
return this.modules;
|
||||
}
|
||||
}
|
44
DEV/DEV3.1/TP03/Exercise2/Database.java
Normal file
44
DEV/DEV3.1/TP03/Exercise2/Database.java
Normal file
@@ -0,0 +1,44 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Database {
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Database() {
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
|
||||
this.connection = DriverManager.getConnection(
|
||||
"jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier",
|
||||
"baudrier",
|
||||
"baudrier"
|
||||
);
|
||||
} catch(ClassNotFoundException exception) {
|
||||
System.err.println("Class 'org.mariadb.jdbc.Driver' not found.");
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to connect to the database");
|
||||
}
|
||||
}
|
||||
|
||||
public Champ[] getAllData() {
|
||||
PreparedStatement query = this.connection.prepareStatement("SELECT id, code FROM Champ");
|
||||
ResultSet result = query.executeQuery();
|
||||
|
||||
while(result.next()) {
|
||||
query = this.connection.prepareStatement("SELECT code FROM Modules WHERE champId = " + result.getInt("id"));
|
||||
}
|
||||
}
|
||||
|
||||
public void close() {
|
||||
try {
|
||||
this.connection.close();
|
||||
} catch(SQLException exception) {
|
||||
System.err.println("Error while trying to close the connection.");
|
||||
}
|
||||
}
|
||||
}
|
1
DEV/DEV3.1/TP03/Exercise2/Main.java
Normal file
1
DEV/DEV3.1/TP03/Exercise2/Main.java
Normal file
@@ -0,0 +1 @@
|
||||
|
21
DEV/DEV3.1/TP03/Exercise2/schema.sql
Normal file
21
DEV/DEV3.1/TP03/Exercise2/schema.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE TABLE Champ (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
code VARCHAR(20)
|
||||
);
|
||||
|
||||
CREATE TABLE Module (
|
||||
id INT PRIMARY KEY AUTO_INCREMENT,
|
||||
champId INT REFERENCES Champ(id),
|
||||
code VARCHAR(20)
|
||||
);
|
||||
|
||||
INSERT INTO Champ(code) VALUES ("APL");
|
||||
INSERT INTO Champ(code) VALUES ("WIM");
|
||||
|
||||
INSERT INTO Module(champId, code) VALUES (1, "M1102");
|
||||
INSERT INTO Module(champId, code) VALUES (1, "M1103");
|
||||
INSERT INTO Module(champId, code) VALUES (1, "M3103");
|
||||
INSERT INTO Module(champId, code) VALUES (2, "M1105");
|
||||
INSERT INTO Module(champId, code) VALUES (2, "M3104");
|
||||
INSERT INTO Module(champId, code) VALUES (2, "M4103C");
|
||||
INSERT INTO Module(champId, code) VALUES (2, "M4104C");
|
55
SCR/SCR3.1/TP01/Exercise1/answer.txt
Normal file
55
SCR/SCR3.1/TP01/Exercise1/answer.txt
Normal file
@@ -0,0 +1,55 @@
|
||||
[baudrier@salle224-14 Exercise1]$ gcc virtual_adress.c
|
||||
[baudrier@salle224-14 Exercise1]$ ./a.out
|
||||
je suis le pid 157247
|
||||
|
||||
main = 0x56435b8ae179
|
||||
gettimeofday = 0x7fbdaf0c6870
|
||||
&argc = 0x7ffcf1b50e1c
|
||||
&i = 0x7ffcf1b50e2c
|
||||
&j = 0x56435b8b2000
|
||||
t = 0x56435b8b1060
|
||||
m = 0x56435ff42310
|
||||
|
||||
[baudrier@salle224-14 BUT2]$ cat /proc/157247/maps
|
||||
56435b8ad000-56435b8ae000 r--p 00000000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8af000-56435b8b0000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap]
|
||||
7fbdaee00000-7fbdaee24000 r--p 00000000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaee24000-7fbdaef96000 r-xp 00024000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaef96000-7fbdaf005000 r--p 00196000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf005000-7fbdaf009000 r--p 00204000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf009000-7fbdaf00b000 rw-p 00208000 103:05 6028 /usr/lib/libc.so.6
|
||||
7fbdaf00b000-7fbdaf013000 rw-p 00000000 00:00 0
|
||||
7fbdaf08f000-7fbdaf094000 rw-p 00000000 00:00 0
|
||||
7fbdaf0c0000-7fbdaf0c4000 r--p 00000000 00:00 0 [vvar]
|
||||
7fbdaf0c4000-7fbdaf0c6000 r--p 00000000 00:00 0 [vvar_vclock]
|
||||
7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso]
|
||||
7fbdaf0c8000-7fbdaf0c9000 r--p 00000000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf0c9000-7fbdaf0f3000 r-xp 00001000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf0f3000-7fbdaf101000 r--p 0002b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf101000-7fbdaf103000 r--p 00039000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf103000-7fbdaf104000 rw-p 0003b000 103:05 6019 /usr/lib/ld-linux-x86-64.so.2
|
||||
7fbdaf104000-7fbdaf105000 rw-p 00000000 00:00 0
|
||||
7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0 [vsyscall]
|
||||
|
||||
- main appartient au segment de pages : 56435b8ae000-56435b8af000 r-xp 00001000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
-> C'est une fonction (donc du code) qui appartient au fichier a.out, et qui a besoin des droits d'exécutions (il a bien la permission 'x').
|
||||
|
||||
- gettimeofday : 7fbdaf0c6000-7fbdaf0c8000 r-xp 00000000 00:00 0 [vdso]
|
||||
-> Code du noyau, exécuté par le noyau
|
||||
|
||||
- &argc : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
-> Argument de la fonction main(), se trouve dans la pile (stack)
|
||||
|
||||
- &i : 7ffcf1b32000-7ffcf1b53000 rw-p 00000000 00:00 0 [stack]
|
||||
|
||||
- &j : 56435b8b1000-56435b8b3000 rw-p 00003000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
|
||||
- t : 56435b8b0000-56435b8b1000 r--p 00002000 00:3e 22477647 /export/home/info-but24/baudrier/Documents/BUT2/SCR/SCR3.1/TP01/Exercise1/a.out
|
||||
|
||||
- m : 56435ff42000-56435ff63000 rw-p 00000000 00:00 0 [heap]
|
||||
-> malloc() attribue de la mémoire dans le tas (heap)
|
27
SCR/SCR3.1/TP01/Exercise1/virtual_adress.c
Normal file
27
SCR/SCR3.1/TP01/Exercise1/virtual_adress.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* adresses virtuelles d'un processus */
|
||||
|
||||
#include<stdio.h>
|
||||
#include<sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int t[1000] = {[0 ... 999] = 2};
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int i=3;
|
||||
static int j = 3;
|
||||
char * m = (char*)malloc(1);
|
||||
printf("je suis le pid %d\n\n",getpid());
|
||||
/* ------- Affichage des adresses --------*/
|
||||
printf("main\t\t=\t%p\n",main);
|
||||
printf("gettimeofday\t=\t%p\n",gettimeofday);
|
||||
printf("&argc\t\t=\t%p\n",&argc);
|
||||
printf("&i\t\t=\t%p\n",&i);
|
||||
printf("&j\t\t=\t%p\n",&j);
|
||||
printf("t\t\t=\t%p\n",t);
|
||||
printf("m\t\t=\t%p\n",m);
|
||||
|
||||
getchar();
|
||||
}
|
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
189
SCR/SCR3.1/TP01/Exercise2/answer.txt
Normal file
@@ -0,0 +1,189 @@
|
||||
- Stack -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 16088
|
||||
16088: ./stack
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055fc39741000 4 4 0 r---- stack
|
||||
000055fc39742000 4 4 0 r-x-- stack
|
||||
000055fc39743000 4 4 0 r---- stack
|
||||
000055fc39744000 4 4 4 r---- stack
|
||||
000055fc39745000 4 4 4 rw--- stack
|
||||
000055fc55245000 132 4 4 rw--- [ anon ]
|
||||
00007fb88b000000 144 144 0 r---- libc.so.6
|
||||
00007fb88b024000 1480 1060 0 r-x-- libc.so.6
|
||||
00007fb88b196000 444 128 0 r---- libc.so.6
|
||||
00007fb88b205000 16 16 16 r---- libc.so.6
|
||||
00007fb88b209000 8 8 8 rw--- libc.so.6
|
||||
00007fb88b20b000 32 20 20 rw--- [ anon ]
|
||||
00007fb88b353000 20 12 12 rw--- [ anon ]
|
||||
00007fb88b384000 16 0 0 r---- [ anon ]
|
||||
00007fb88b388000 8 0 0 r---- [ anon ]
|
||||
00007fb88b38a000 8 8 0 r-x-- [ anon ]
|
||||
00007fb88b38c000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b38d000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007fb88b3b7000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c5000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007fb88b3c7000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007fb88b3c8000 4 4 4 rw--- [ anon ]
|
||||
00007ffcc07fd000 132 36 36 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1700 120
|
||||
|
||||
- MMAP -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 17734
|
||||
17734: ./mmap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000055e00c982000 4 4 0 r---- mmap
|
||||
000055e00c983000 4 4 0 r-x-- mmap
|
||||
000055e00c984000 4 4 0 r---- mmap
|
||||
000055e00c985000 4 4 4 r---- mmap
|
||||
000055e00c986000 4 4 4 rw--- mmap
|
||||
000055e020dd6000 132 4 4 rw--- [ anon ]
|
||||
00007f2007800000 144 144 0 r---- libc.so.6
|
||||
00007f2007824000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2007996000 444 128 0 r---- libc.so.6
|
||||
00007f2007a05000 16 16 16 r---- libc.so.6
|
||||
00007f2007a09000 8 8 8 rw--- libc.so.6
|
||||
00007f2007a0b000 32 20 20 rw--- [ anon ]
|
||||
00007f2007b2b000 256 128 128 rw--- 256k
|
||||
00007f2007b6b000 20 12 12 rw--- [ anon ]
|
||||
00007f2007b80000 64 64 64 rw-s- zero (deleted)
|
||||
00007f2007b90000 48 32 32 rw--- [ anon ]
|
||||
00007f2007b9c000 16 0 0 r---- [ anon ]
|
||||
00007f2007ba0000 8 0 0 r---- [ anon ]
|
||||
00007f2007ba2000 8 8 0 r-x-- [ anon ]
|
||||
00007f2007ba4000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007ba5000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2007bcf000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdd000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2007bdf000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2007be0000 4 4 4 rw--- [ anon ]
|
||||
00007ffcfccb6000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3076 1904 324
|
||||
|
||||
- Huge -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18284
|
||||
18284: ./huge
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000555e2f729000 4 4 0 r---- huge
|
||||
0000555e2f72a000 4 4 0 r-x-- huge
|
||||
0000555e2f72b000 4 4 0 r---- huge
|
||||
0000555e2f72c000 4 4 4 r---- huge
|
||||
0000555e2f72d000 4 4 4 rw--- huge
|
||||
0000555e40ba4000 228 100 100 rw--- [ anon ]
|
||||
00007f2f5d400000 144 144 0 r---- libc.so.6
|
||||
00007f2f5d424000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f2f5d596000 444 128 0 r---- libc.so.6
|
||||
00007f2f5d605000 16 16 16 r---- libc.so.6
|
||||
00007f2f5d609000 8 8 8 rw--- libc.so.6
|
||||
00007f2f5d60b000 32 20 20 rw--- [ anon ]
|
||||
00007f2f5d757000 280 272 272 rw--- [ anon ]
|
||||
00007f2f5d7c9000 16 0 0 r---- [ anon ]
|
||||
00007f2f5d7cd000 8 0 0 r---- [ anon ]
|
||||
00007f2f5d7cf000 8 8 0 r-x-- [ anon ]
|
||||
00007f2f5d7d1000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d7d2000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f2f5d7fc000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80a000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f2f5d80c000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f2f5d80d000 4 4 4 rw--- [ anon ]
|
||||
00007ffdcfdcf000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 3064 2036 456
|
||||
|
||||
- Null -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18519
|
||||
18519: ./null
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
0000561bf65bf000 4 4 0 r---- null
|
||||
0000561bf65c0000 4 4 0 r-x-- null
|
||||
0000561bf65c1000 4 4 0 r---- null
|
||||
0000561bf65c2000 4 4 4 r---- null
|
||||
0000561bf65c3000 4 4 4 rw--- null
|
||||
0000561c26834000 132 4 4 rw--- [ anon ]
|
||||
00007f293fa00000 144 144 0 r---- libc.so.6
|
||||
00007f293fa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f293fb96000 444 128 0 r---- libc.so.6
|
||||
00007f293fc05000 16 16 16 r---- libc.so.6
|
||||
00007f293fc09000 8 8 8 rw--- libc.so.6
|
||||
00007f293fc0b000 32 20 20 rw--- [ anon ]
|
||||
00007f293fca6000 20 12 12 rw--- [ anon ]
|
||||
00007f293fcd7000 16 0 0 r---- [ anon ]
|
||||
00007f293fcdb000 8 0 0 r---- [ anon ]
|
||||
00007f293fcdd000 8 8 0 r-x-- [ anon ]
|
||||
00007f293fcdf000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fce0000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f293fd0a000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd18000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f293fd1a000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f293fd1b000 4 4 4 rw--- [ anon ]
|
||||
00007ffe4e9df000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 2708 1680 100
|
||||
|
||||
- Heap -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 18846
|
||||
18846: ./heap
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
00005571639f9000 4 4 0 r---- heap
|
||||
00005571639fa000 4 4 0 r-x-- heap
|
||||
00005571639fb000 4 4 0 r---- heap
|
||||
00005571639fc000 4 4 4 r---- heap
|
||||
00005571639fd000 4 4 4 rw--- heap
|
||||
000055717e499000 50028 49924 49924 rw--- [ anon ]
|
||||
00007f485aa00000 144 144 0 r---- libc.so.6
|
||||
00007f485aa24000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f485ab96000 444 128 0 r---- libc.so.6
|
||||
00007f485ac05000 16 16 16 r---- libc.so.6
|
||||
00007f485ac09000 8 8 8 rw--- libc.so.6
|
||||
00007f485ac0b000 32 20 20 rw--- [ anon ]
|
||||
00007f485ad82000 20 12 12 rw--- [ anon ]
|
||||
00007f485adb3000 16 0 0 r---- [ anon ]
|
||||
00007f485adb7000 8 0 0 r---- [ anon ]
|
||||
00007f485adb9000 8 8 0 r-x-- [ anon ]
|
||||
00007f485adbb000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adbc000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f485ade6000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf4000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f485adf6000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f485adf7000 4 4 4 rw--- [ anon ]
|
||||
00007fffd8762000 132 16 16 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 52604 51600 50020
|
||||
|
||||
- Buf -
|
||||
[baudrier@salle224-14 BUT2]$ pmap -x 19569
|
||||
19569: ./buf
|
||||
Address Kbytes RSS Dirty Mode Mapping
|
||||
000056423e617000 4 4 0 r---- buf
|
||||
000056423e618000 4 4 0 r-x-- buf
|
||||
000056423e619000 4 4 0 r---- buf
|
||||
000056423e61a000 4 4 4 r---- buf
|
||||
000056423e61b000 4 4 4 rw--- buf
|
||||
000056423e61c000 16384 16384 16384 rw--- [ anon ]
|
||||
0000564255eda000 132 4 4 rw--- [ anon ]
|
||||
00007f576c600000 144 144 0 r---- libc.so.6
|
||||
00007f576c624000 1480 1060 0 r-x-- libc.so.6
|
||||
00007f576c796000 444 128 0 r---- libc.so.6
|
||||
00007f576c805000 16 16 16 r---- libc.so.6
|
||||
00007f576c809000 8 8 8 rw--- libc.so.6
|
||||
00007f576c80b000 32 20 20 rw--- [ anon ]
|
||||
00007f576c8c9000 20 12 12 rw--- [ anon ]
|
||||
00007f576c8fa000 16 0 0 r---- [ anon ]
|
||||
00007f576c8fe000 8 0 0 r---- [ anon ]
|
||||
00007f576c900000 8 8 0 r-x-- [ anon ]
|
||||
00007f576c902000 4 4 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c903000 168 168 0 r-x-- ld-linux-x86-64.so.2
|
||||
00007f576c92d000 56 56 0 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93b000 8 8 8 r---- ld-linux-x86-64.so.2
|
||||
00007f576c93d000 4 4 4 rw--- ld-linux-x86-64.so.2
|
||||
00007f576c93e000 4 4 4 rw--- [ anon ]
|
||||
00007ffd7eb9e000 132 12 12 rw--- [ stack ]
|
||||
ffffffffff600000 4 0 0 --x-- [ anon ]
|
||||
---------------- ------- ------- -------
|
||||
total kB 19092 18060 16480
|
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
17
SCR/SCR3.1/TP01/Exercise2/subject/Makefile
Normal file
@@ -0,0 +1,17 @@
|
||||
CFLAGS := -Wall -g -O0
|
||||
SRC=buf.c heap.c huge.c mmap.c null.c stack.c
|
||||
|
||||
DEPENDHELPERS=helpers.o
|
||||
|
||||
BINARIES=$(SRC:%.c=%)
|
||||
|
||||
%.o : %c
|
||||
gcc -c $+
|
||||
|
||||
$(BINARIES): % : %.o $(DEPENDHELPERS)
|
||||
gcc -o $@ $+
|
||||
|
||||
all : $(BINARIES)
|
||||
|
||||
clean:
|
||||
rm -f *.o $(BINARIES)
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/buf
Executable file
Binary file not shown.
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
9
SCR/SCR3.1/TP01/Exercise2/subject/buf.c
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "helpers.h"
|
||||
|
||||
static char buffer[16 MB] = {0};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
randomize(buffer, 16 MB);
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/data/256k
Normal file
Binary file not shown.
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/heap
Executable file
Binary file not shown.
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
8
SCR/SCR3.1/TP01/Exercise2/subject/heap.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
dirty(16 MB);
|
||||
clean(32 MB);
|
||||
return interlude();
|
||||
}
|
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
36
SCR/SCR3.1/TP01/Exercise2/subject/helpers.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "helpers.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void randomize(char *buf, size_t n)
|
||||
{
|
||||
assert(buf);
|
||||
memset(buf, rand() & 0xff, n);
|
||||
}
|
||||
|
||||
void clean(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
calloc(1 KB, sizeof(char));
|
||||
}
|
||||
|
||||
void dirty(size_t b)
|
||||
{
|
||||
for (; b > 0; b -= 1 KB)
|
||||
randomize(calloc(1 KB, sizeof(char)), 1 KB);
|
||||
}
|
||||
|
||||
int interlude(void)
|
||||
{
|
||||
pid_t pid = getpid();
|
||||
printf("pid %i\n", (int)pid);
|
||||
printf("------------------------------------------\n"
|
||||
"go check /proc/%i/smaps; I'll wait...\n"
|
||||
"press <Enter> when you're done\n", pid);
|
||||
fgetc(stdin);
|
||||
return 0;
|
||||
}
|
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
13
SCR/SCR3.1/TP01/Exercise2/subject/helpers.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _HELPERS_H
|
||||
#define _HELPERS_H
|
||||
#include <stdlib.h>
|
||||
|
||||
#define KB * 1024
|
||||
#define MB * 1024 * 1024
|
||||
|
||||
void randomize(char *buf, size_t n);
|
||||
void clean(size_t n);
|
||||
void dirty(size_t n);
|
||||
int interlude(void);
|
||||
|
||||
#endif
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/huge
Executable file
Binary file not shown.
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
12
SCR/SCR3.1/TP01/Exercise2/subject/huge.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *under = malloc(96 KB);
|
||||
randomize(under, 96 KB);
|
||||
|
||||
char *over = malloc(256 KB);
|
||||
randomize(over, 256 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/mmap
Executable file
Binary file not shown.
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
38
SCR/SCR3.1/TP01/Exercise2/subject/mmap.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "helpers.h"
|
||||
#include <sys/mman.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* inert map (never modified) */
|
||||
char *inert = mmap(NULL, 16 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
/* anonymous, private mmap */
|
||||
char *anon_priv = mmap(NULL, 32 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_PRIVATE,
|
||||
-1, 0);
|
||||
randomize(anon_priv, 32 KB);
|
||||
|
||||
/* anonymous, shared map */
|
||||
char *anon_shared = mmap(NULL, 64 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_ANONYMOUS|MAP_SHARED,
|
||||
-1, 0);
|
||||
randomize(anon_shared, 64 KB);
|
||||
|
||||
/* private, file-backed map */
|
||||
int fd = open("data/256k", O_RDWR);
|
||||
assert(fd >= 0);
|
||||
char *file = mmap(NULL, 256 KB,
|
||||
PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE,
|
||||
fd, 0);
|
||||
randomize(file, 128 KB);
|
||||
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/null
Executable file
Binary file not shown.
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
6
SCR/SCR3.1/TP01/Exercise2/subject/null.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "helpers.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return interlude();
|
||||
}
|
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
BIN
SCR/SCR3.1/TP01/Exercise2/subject/stack
Executable file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user