Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

Commit

Permalink
Added old computer simulation from 2014
Browse files Browse the repository at this point in the history
  • Loading branch information
tykus160 committed Sep 3, 2017
1 parent 7575680 commit ddc7c5b
Show file tree
Hide file tree
Showing 30 changed files with 4,154 additions and 0 deletions.
Binary file added l3_me_tw/doc/raport_koncowy.pdf
Binary file not shown.
Binary file added l3_me_tw/doc/zadanie 1.pdf
Binary file not shown.
Binary file added l3_me_tw/doc/zadanie 2.pdf
Binary file not shown.
Binary file added l3_me_tw/doc/zadanie 3.pdf
Binary file not shown.
Binary file added l3_me_tw/doc/zadanie 4.pdf
Binary file not shown.
2,369 changes: 2,369 additions & 0 deletions l3_me_tw/doxyfile.cfg

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions l3_me_tw/l3_me_tw.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2F89E562-338A-47E1-951D-4725A65A71AF}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>l3_me_tw</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\buffer.h" />
<ClInclude Include="src\computer.h" />
<ClInclude Include="src\device.h" />
<ClInclude Include="src\event.h" />
<ClInclude Include="src\event_scheduling.h" />
<ClInclude Include="src\link.h" />
<ClInclude Include="src\message.h" />
<ClInclude Include="src\rng.h" />
<ClInclude Include="src\router.h" />
<ClInclude Include="src\sc.h" />
<ClInclude Include="src\students_t_distribution.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\buffer.cpp" />
<ClCompile Include="src\computer.cpp" />
<ClCompile Include="src\device.cpp" />
<ClCompile Include="src\event.cpp" />
<ClCompile Include="src\event_scheduling.cpp" />
<ClCompile Include="src\link.cpp" />
<ClCompile Include="src\message.cpp" />
<ClCompile Include="src\rng.cpp" />
<ClCompile Include="src\router.cpp" />
<ClCompile Include="src\sc.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="doc\raport_koncowy.pdf" />
<None Include="doc\zadanie 1.pdf" />
<None Include="doc\zadanie 2.pdf" />
<None Include="doc\zadanie 3.pdf" />
<None Include="doc\zadanie 4.pdf" />
<None Include="doxyfile.cfg" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
96 changes: 96 additions & 0 deletions l3_me_tw/l3_me_tw.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="doc">
<UniqueIdentifier>{7b11094c-8b14-48cf-a435-72d749ec9dce}</UniqueIdentifier>
</Filter>
<Filter Include="src">
<UniqueIdentifier>{2ed22b54-8648-4af8-b48b-430bd19f4cf6}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\sc.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\message.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\computer.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\router.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\buffer.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\link.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\device.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\event.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\rng.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\event_scheduling.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\students_t_distribution.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\sc.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\message.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\router.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\device.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\buffer.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\computer.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\link.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\event.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\rng.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\event_scheduling.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="doc\zadanie 1.pdf">
<Filter>doc</Filter>
</None>
<None Include="doxyfile.cfg" />
<None Include="doc\zadanie 2.pdf">
<Filter>doc</Filter>
</None>
<None Include="doc\zadanie 3.pdf">
<Filter>doc</Filter>
</None>
<None Include="doc\zadanie 4.pdf">
<Filter>doc</Filter>
</None>
<None Include="doc\raport_koncowy.pdf">
<Filter>doc</Filter>
</None>
</ItemGroup>
</Project>
85 changes: 85 additions & 0 deletions l3_me_tw/src/buffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/********************************************//**
* \file buffer.cpp
* \brief Buffer definition.
* \author Wojciech Tyczyñski ([email protected])
* \date 2014-04-26
***********************************************/
#include "sc.h"
//================================================
Buffer::Buffer(int size, int nr) : max_size(size), actual_size(0), devices(nr)
{
msg_list = new list<Message*>[devices];
}
//================================================
Buffer::~Buffer()
{
for(int i = 0; i < devices; ++i)
{
list<Message*>::iterator j;
for(j = msg_list[i].begin(); j != msg_list[i].end(); ++j)
delete (*j);
msg_list[i].clear();
}
delete [] msg_list;
}
//================================================
bool Buffer::add_to_queue(Message *msg, int which_buff)
{
if(msg->get_size() <= max_size - actual_size)
{
actual_size += msg->get_size();
if(msg->get_priority())
{
msg_list[which_buff].push_back(msg);
}
else
{
if(!msg_list[which_buff].empty())
{
list<Message*>::iterator it = msg_list[which_buff].begin();
while(it != msg_list[which_buff].end() && !((*it)->get_priority()) ) ++it;
msg_list[which_buff].insert(it, msg);
}
else
{
msg_list[which_buff].push_front(msg);
}

}
return true;
}
else
{
if(msg->get_priority())Message::incr_lost_msgs();
else msg->get_parent()->incr_lost_msgs();
return false;
}
}
//================================================
Message *Buffer::get_and_del_msg(int i)
{
if(!msg_list[i].empty())
{
Message *msg = msg_list[i].front(); // Get message.
msg_list[i].pop_front(); // Delete message from buffer.
return msg;
}
return 0;
}
//================================================
int Buffer::get_top_destination(int i)
{
Message *msg = msg_list[i].front();
return msg->get_destination();
}
//================================================
void Buffer::reset_buffer()
{
actual_size = 0;

for(int i = 0; i < devices; ++i)
{
msg_list[i].clear();
}
}
//================================================
56 changes: 56 additions & 0 deletions l3_me_tw/src/buffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/********************************************//**
* \file buffer.h
* \brief Buffer object definition.
* \author Wojciech Tyczynski ([email protected])
* \date 2014-04-13
***********************************************/
#ifndef BUFFER_H
#define BUFFER_H
////////////////////////////////////////
/*! \brief Buffer
*
* Buffer is place, where messages are stored.
*
*/
class Buffer
{
private:
int devices; //!< Number of lists in buffer (any link has it's buffer).
int actual_size; //!< Actual size of buffer (in kbit).
list<Message*> *msg_list; //!< List with messages in a buffer.

public:
const int max_size; //!< Maximum size of buffer (in kbit).

//! Constructor.
Buffer(int size, int devices);

//! Destructor.
~Buffer();

//! Add message to priority queue.
bool add_to_queue(Message *msg, int which_buff);

//! Get message and delete it from queue.
Message *get_and_del_msg(int i);

//! Get message.
Message *get_msg(int i) { return msg_list[i].front(); }

//! Get ID of message at the top of queue.
int get_top_destination(int i);

//! Decrement size of buffer.
void decrement_size(int size) { actual_size -= size; }

//! Check if msg_list is empty (true if yes).
bool check_msg_list(int i) { return msg_list[i].empty(); }

//! Get actual size.
int get_actual_size() { return actual_size; }

//! Reset buffer.
void reset_buffer();
};

#endif /* BUFFER_H */
28 changes: 28 additions & 0 deletions l3_me_tw/src/computer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/********************************************//**
* \file computer.cpp
* \brief Computer definition.
* \author Wojciech Tyczyñski ([email protected])
* \date 2014-04-26
***********************************************/
#include "sc.h"
//================================================
Computer::Computer(int id) : Device(id, BK), link(0) { }
//================================================
bool Computer::send_msg()
{
if(link->check_availability(0))
{
link->add_msg_to_link(0,0);
return true;
}
return false;
}
//================================================
bool Computer::save_msg(Message *msg)
{
//msg->deliver_message();
//cout << "Computer " << get_id() << " has got the message!" << endl;
if(msg->deliver_message()) delete msg;
return true;
}
//================================================
Loading

0 comments on commit ddc7c5b

Please sign in to comment.