vendredi 27 mars 2015

OS Development in C [on hold]


I'm almost too new in C. I come from a python background. However, I'm studying operating systems and I found out that most operating systems are built in C due to speed and ease of processing . So I would like to get help. I'm running on Linux and I'm attempting to create a simple operating system in C.

Somehow, I can't seem to get where to begin from because I was thinking of creating my own bootloader, of which I have no idea. Any help? Like, I do not really want the bootloader, I just want to know how I'm going to start off. Of course I know how my operating system should look like but my only problem is where and how I'm going to do my testing.

This is what I want:



  • Create a kernel

  • Create a GUI

  • Link the GUI and the kernel

  • Process inputs and outputs


Any help guys? I have no idea!





REST Services with ASP MVC WebApi architecture feedback


I'm working on a new project and I had to design some REST Services with ASP MVC WebApi.


I would like to show you my app architecture and learn from more experienced architects what I have potentially done wrong (I'm not an experienced architect). Can you please let me know your thoughts and recommendations?


Self-identifiable and self-validatable entities


All my entities inherit from BaseEntity<T> which is a generic because is implementing IIdentifiable<T>.I created IIdentifiable<T> in order to be able to have a unique way of getting the id of an entity. The entity Ids don't always use the same data type that's why the interface is generic.


BaseEntity<T> base entity also implements IValidatable which provides with a unique way of validating an entity.


enter image description here


Data access layer


All my repositories implement IRepository<T, IdT> which is used to implement the basics default CRUD operations. T is the entity type and IdT is the type of the entity ID.


The repositories don't implement directly IRepository<T, IdT>, for example, TermRepository implements ITermRepository and ITermRepository implements IRepository<Term, int>. I did it that way so I can add the Term non-standard CRUD operations to the ITermRepository interface.


enter image description here


Service layer


I have created a generic abstract class BaseHttpController<T, IdT> which implements IService<T, IdT> just like in the data access layer T is the type of an entity an IdT is the type of the entity's ID.


I don't have to implement the default REST operations because they are implemented in the BaseHttpController<T, IdT> class. BaseHttpController<T, IdT> has access to IRepository<T, IdT>


If I need to implement something non-standard I can do it in the in the controller. From a controller (e.g. TermController ) I can access its repository (e.g. TTermRepository).


All the REST services return a generic Response<T> object to wrap the entities and errors.


enter image description here


Note: I'm using IoC and each layer is in an independent DLL.


Thanks!





Is the target of 3 dependencies per class always achievable?


I'm reading the Clean Code book and a chapter says that if a class has more than 3 dependencies is a code smell of that class isn't doing one thing. Or what is the same, it isn't following SRP. I'm thinking in certain scenarios in which I am unable to reset the number of dependencies to stick to that number.


Let's say we have an app that connects to a public API REST what offers varied information about a lot entities in our domain. In our app we detect an use case repeated in many places where we request to the API the info about an entity with other dependent entities that it has.


The API REST doesn't offer the data in the format we want because the calls when can make are to get data from a single table on the web database, not offers the data agrouped with other tables as we want. So our use case have to make different Api Call's for to get all different data about the entities we need and then merge in the model we will use in the app.


To connect with the external subsystem we will hide implementation in a single Service class however this class has grown too much resulting a class with a lot methods to get data about all entities of the api rest. So we split this huge class into differents following the Repository pattern. Each class for each possible operations with an entity on the API.


Then, to hide all this concrete and common interaction with the service layer we will use a Facade class to coordinating all this calls. The problem I'm figuring it will have, is that it will have a lot dependencies in her constructor. Will have classes for each repository class and mapper classes to adapt the web data into app data.


The solution in these cases is merge all related dependencies in one so you reduce the number. One example is this: Refactoring to Aggregate Services. http://ift.tt/1eEbm4f


But you merge when you see a clear relationship. What happend if in your class you can't see that? All classes are granulated but all of them are necesary to achieve the goal but can't not be merged in an aggregate service.


So my question is, the "rule" that more than three dependencies violates SRP is always applicable? Returning to our example, our facade needs to access many repository classes and mapper classes. The mapper classes can be hide on a agreggated service, maybe, but repository classes are fine like are. We could introduce a service locator to store them but it is a very bad practice.





Are there any compilers that will turn an else-if cascade into a switch?


I don't like switch in C and its descendants. Maybe its the need for a break or the clumsiness of the syntax requiring a shifting of mental gears, I don't know.


Whatever the reason, I will almost always write a sequence of else-if conditions examining the same variable rather than write a switch.


I see from http://ift.tt/1ICPGCZ that switch is more efficient in most cases and it got me wondering...


Are there any compilers (for any language) that will detect a number of else-if conditions on the same value and internally re-write it into a switch?





How to create DFA from regular expression without using NFA?


Objective is to create DFA from a regular expression and using "Regular exp>NFA>DFA conversion" is not an option. How should one go about doing that?


I asked this question to our professor but he told me that we can use intuition and kindly refused to provide any explaination. So I wanted to ask you.


"Regular exp>NFA>DFA conversion" is not an option because such conversation takes a lot of time to convert a rather complex regular expression. For example, for a certain regex "regex>NFA>DFA" takes 1 hour for a human being. I need to convert regex to DFA in less than 30 minutes.





Closing Nonduplex Unnamed Pipes in C


I have 8 children, and am trying to use 8 pairs of nonduplex unnamed pipes to communicate with them. Thus, I have 2 pipes for each child and 16 pipes in total (one for childRead_ParentWrite and the other for parentRead_ChildWrite).


Anyway, my main question is when to close the pipes. I was taught to initially close the sides that are not being used by the process, and then when the process is finished with its side of the pipe, to close it off. However, I am brand new to the subject and am having some trouble. Here is my code:



// The 16 pipes
int fd_childReads_ParentWrites[8][2]; // Parent closes 0, Child closes 1
int fd_parentReads_ChildWrites[8][2]; // Child closes 0, Parent closes 1

// The 16 buffers
char buf_ChildReads_ParentWrites[8][80];
char buf_ParentReads_ChildWrites[8][80];

// CREATE THE PIPES

// FORK THE CHILDREN


// Manage processes
if (pid == 0) // CHILD
{
printf("I am the child: %d\n", getpid());
// Close the appropriate pipe ends
close(fd_childReads_ParentWrites[playerNumber][1]);
close(fd_parentReads_ChildWrites[playerNumber][0]);


// CHILD DOES STUFF WITH PIPES


// When finished, close the working child pipe ends
close(fd_childReads_ParentWrites[playerNumber][0]);
close(fd_parentReads_ChildWrites[playerNumber][1]);
}
else // PARENT
{
printf("I am the parent: %d\n", getpid()); // NOT BEING PRINTED

// Close the appropriate pipe ends
for (i = 0; i < NUM_PLAYERS; i++)
{
close(fd_childReads_ParentWrites[i][0]);
close(fd_parentReads_ChildWrites[i][1]);
}


// PARENT DOES STUFF WITH PIPES


// Finally, close the working parent pipe ends
for (i = 0; NUM_PLAYERS < 8; i++)
{
close(fd_childReads_ParentWrites[i][1]);
close(fd_parentReads_ChildWrites[i][0]);
}
// Wait for the children
for (playerNumber = 0; playerNumber < NUM_PLAYERS; playerNumber++)
{
wait(NULL);
}
}


I must be doing something wrong. The program prints out the correct number of children, but the parent's printf() line is never printed. When I take out all of the close() functions it prints, but even taking out solely the children's close()'s doesn't print he parent line.


If someone could explain to me the correct way to close nonduplex unnamed pipes in a situation like this, that would be awesome.





Which view resolver is required for implementing tiles in Spring 3.0 MVC application


I have a working Spring application. I would like to add some common headers,footers and such, hence I need to use tiles along with this. Currently, I use InternalResourceViewResolver for request mapping in Spring. I read somewhere http://ift.tt/1xEBxEF that we need urlbasedviewresolver. Do we need both viewresolvers? Could someone clarify this ? How to redirect to tiles from the controller class?